4 using System.Collections;
5 using System.Collections.Generic;
18 public float PointSize;
21 public int CharacterCount;
23 public float LineHeight;
24 public float Baseline;
25 public float Ascender;
26 public float CapHeight;
27 public float Descender;
28 public float CenterLine;
30 public float SuperscriptOffset;
31 public float SubscriptOffset;
34 public float Underline;
35 public float UnderlineThickness;
37 public float strikethrough;
38 public float strikethroughThickness;
40 public float TabWidth;
43 public float AtlasWidth;
44 public float AtlasHeight;
64 copy.width = source.width;
65 copy.height = source.height;
66 copy.xOffset = source.xOffset;
67 copy.yOffset = source.yOffset;
68 copy.xAdvance = source.xAdvance;
69 copy.scale = source.scale;
80 public string sourceFontFileName;
81 public string sourceFontFileGUID;
82 public int pointSizeSamplingMode;
85 public int packingMode;
86 public int atlasWidth;
87 public int atlasHeight;
88 public int characterSetSelectionMode;
89 public string characterSequence;
90 public string referencedFontAssetGUID;
91 public string referencedTextAssetGUID;
93 public float fontStyleModifier;
94 public int renderMode;
95 public bool includeFontFeatures;
101 public uint ascii_Left;
102 public uint ascii_Right;
107 ascii_Left = ascii_left;
108 ascii_Right = ascii_right;
109 key = (ascii_right << 16) + ascii_left;
119 public float xPlacement;
120 public float yPlacement;
121 public float xAdvance;
122 public float yAdvance;
127 c.xPlacement = a.xPlacement + b.xPlacement;
128 c.yPlacement = a.yPlacement + b.yPlacement;
129 c.xAdvance = a.xAdvance + b.xAdvance;
130 c.yAdvance = a.yAdvance + b.yAdvance;
145 get {
return m_FirstGlyph; }
146 set { m_FirstGlyph = value; }
148 [FormerlySerializedAs(
"AscII_Left")]
150 private uint m_FirstGlyph;
157 get {
return m_FirstGlyphAdjustments; }
167 get {
return m_SecondGlyph; }
168 set { m_SecondGlyph = value; }
170 [FormerlySerializedAs(
"AscII_Right")]
172 private uint m_SecondGlyph;
179 get {
return m_SecondGlyphAdjustments; }
184 [FormerlySerializedAs(
"XadvanceOffset")]
185 public float xOffset;
197 public KerningPair(uint left, uint right,
float offset)
200 m_SecondGlyph = right;
212 internal void ConvertLegacyKerningData()
214 m_FirstGlyphAdjustments.xAdvance = xOffset;
224 public List<KerningPair> kerningPairs;
229 kerningPairs =
new List<KerningPair>();
233 public void AddKerningPair()
235 if (kerningPairs.Count == 0)
241 uint left = kerningPairs.Last().firstGlyph;
242 uint right = kerningPairs.Last().secondGlyph;
243 float xoffset = kerningPairs.Last().xOffset;
245 kerningPairs.Add(
new KerningPair(left, right, xoffset));
259 int index = kerningPairs.FindIndex(item => item.firstGlyph == first && item.secondGlyph == second);
263 kerningPairs.Add(
new KerningPair(first, second, offset));
281 int index = kerningPairs.FindIndex(item => item.firstGlyph == first && item.secondGlyph == second);
285 kerningPairs.Add(
new KerningPair(first, firstAdjustments, second, secondAdjustments));
293 public void RemoveKerningPair(
int left,
int right)
295 int index = kerningPairs.FindIndex(item => item.firstGlyph == left && item.secondGlyph == right);
298 kerningPairs.RemoveAt(index);
302 public void RemoveKerningPair(
int index)
304 kerningPairs.RemoveAt(index);
308 public void SortKerningPairs()
311 if (kerningPairs.Count > 0)
312 kerningPairs = kerningPairs.OrderBy(s => s.firstGlyph).ThenBy(s => s.secondGlyph).ToList();
317 public static class TMP_FontUtilities
319 private static List<int> k_searchedFontAssets;
328 public static TMP_FontAsset SearchForGlyph(TMP_FontAsset font,
int character, out TMP_Glyph glyph)
330 if (k_searchedFontAssets ==
null)
331 k_searchedFontAssets =
new List<int>();
333 k_searchedFontAssets.Clear();
335 return SearchForGlyphInternal(font, character, out glyph);
346 public static TMP_FontAsset SearchForGlyph(List<TMP_FontAsset> fonts,
int character, out TMP_Glyph glyph)
348 return SearchForGlyphInternal(fonts, character, out glyph);
352 private static TMP_FontAsset SearchForGlyphInternal (TMP_FontAsset font,
int character, out TMP_Glyph glyph)
356 if (font ==
null)
return null;
358 if (font.characterDictionary.TryGetValue(character, out glyph))
362 else if (font.fallbackFontAssets !=
null && font.fallbackFontAssets.Count > 0)
364 for (
int i = 0; i < font.fallbackFontAssets.Count && glyph ==
null; i++)
366 TMP_FontAsset temp = font.fallbackFontAssets[i];
367 if (temp ==
null)
continue;
369 int id = temp.GetInstanceID();
372 if (k_searchedFontAssets.Contains(
id))
continue;
375 k_searchedFontAssets.Add(
id);
377 temp = SearchForGlyphInternal(temp, character, out glyph);
388 private static TMP_FontAsset SearchForGlyphInternal(List<TMP_FontAsset> fonts,
int character, out TMP_Glyph glyph)
392 if (fonts !=
null && fonts.Count > 0)
394 for (
int i = 0; i < fonts.Count; i++)
396 TMP_FontAsset fontAsset = SearchForGlyphInternal(fonts[i], character, out glyph);
398 if (fontAsset !=
null)
Positional adjustments of a glyph
int AddKerningPair(uint first, uint second, float offset)
Add Kerning Pair
GlyphValueRecord secondGlyphAdjustments
The positional adjustment of the second glyph.
GlyphValueRecord firstGlyphAdjustments
The positional adjustment of the first glyph.
int AddGlyphPairAdjustmentRecord(uint first, GlyphValueRecord firstAdjustments, uint second, GlyphValueRecord secondAdjustments)
Add Glyph pair adjustment record
Base class for all text elements like characters (glyphs) and sprites.
static TMP_Glyph Clone(TMP_Glyph source)
Function to create a deep copy of a GlyphInfo.
uint secondGlyph
The second glyph part of a kerning pair.
uint firstGlyph
The first glyph part of a kerning pair.
Class that contains the basic information about the font.