3 using System.Collections;
4 using System.Collections.Generic;
32 if (s_defaultFontAsset ==
null)
34 s_defaultFontAsset = Resources.Load<
TMP_FontAsset>(
"Fonts & Materials/LiberationSans SDF");
37 return s_defaultFontAsset;
43 public enum FontAssetTypes { None = 0, SDF = 1, Bitmap = 2 };
44 public FontAssetTypes fontAssetType;
50 {
get {
return m_fontInfo; } }
56 public Texture2D atlas;
61 private List<TMP_Glyph> m_glyphInfoList;
63 public Dictionary<int, TMP_Glyph> characterDictionary
67 if (m_characterDictionary ==
null)
70 return m_characterDictionary;
73 private Dictionary<int, TMP_Glyph> m_characterDictionary;
80 get {
return m_kerningDictionary; }
82 private Dictionary<int, KerningPair> m_kerningDictionary;
89 get {
return m_kerningInfo; }
96 #pragma warning disable 0169 // Property is used to create an empty Kerning Pair in the editor. 110 get {
return m_CreationSettings; }
111 set { m_CreationSettings = value; }
120 private int[] m_characterSet;
122 public float normalStyle = 0;
123 public float normalSpacingOffset = 0;
125 public float boldStyle = 0.75f;
126 public float boldSpacing = 7f;
127 public byte italicStyle = 35;
128 public byte tabSize = 10;
130 private byte m_oldTabSize;
150 if (m_oldTabSize != tabSize)
152 m_oldTabSize = tabSize;
165 m_fontInfo = faceInfo;
175 m_glyphInfoList =
new List<TMP_Glyph>();
176 int characterCount = glyphInfo.Length;
178 m_fontInfo.CharacterCount = characterCount;
179 m_characterSet =
new int[characterCount];
181 for (
int i = 0; i < characterCount; i++)
184 g.id = glyphInfo[i].id;
185 g.x = glyphInfo[i].x;
186 g.y = glyphInfo[i].y;
187 g.width = glyphInfo[i].width;
188 g.height = glyphInfo[i].height;
189 g.xOffset = glyphInfo[i].xOffset;
190 g.yOffset = (glyphInfo[i].yOffset);
191 g.xAdvance = glyphInfo[i].xAdvance;
194 m_glyphInfoList.Add(g);
200 m_characterSet[i] = g.id;
204 m_glyphInfoList = m_glyphInfoList.OrderBy(s => s.id).ToList();
214 m_kerningInfo = kerningTable;
225 if (m_fontInfo ==
null)
234 m_characterDictionary =
new Dictionary<int, TMP_Glyph>();
235 for (
int i = 0; i < m_glyphInfoList.Count; i++)
239 if (!m_characterDictionary.ContainsKey(glyph.id))
240 m_characterDictionary.Add(glyph.id, glyph);
243 if (glyph.scale == 0) glyph.scale = 1;
252 if (m_characterDictionary.ContainsKey(32))
254 m_characterDictionary[32].width = m_characterDictionary[32].xAdvance;
255 m_characterDictionary[32].height = m_fontInfo.Ascender - m_fontInfo.Descender;
256 m_characterDictionary[32].yOffset= m_fontInfo.Ascender;
257 m_characterDictionary[32].scale = 1;
263 temp_charInfo.id = 32;
266 temp_charInfo.width = m_fontInfo.Ascender / 5;
267 temp_charInfo.height = m_fontInfo.Ascender - m_fontInfo.Descender;
268 temp_charInfo.xOffset = 0;
269 temp_charInfo.yOffset = m_fontInfo.Ascender;
270 temp_charInfo.xAdvance = m_fontInfo.PointSize / 4;
271 temp_charInfo.scale = 1;
272 m_characterDictionary.Add(32, temp_charInfo);
276 if (!m_characterDictionary.ContainsKey(160))
279 m_characterDictionary.Add(160, temp_charInfo);
283 if (!m_characterDictionary.ContainsKey(8203))
286 temp_charInfo.width = 0;
287 temp_charInfo.xAdvance = 0;
288 m_characterDictionary.Add(8203, temp_charInfo);
292 if (!m_characterDictionary.ContainsKey(8288))
295 temp_charInfo.width = 0;
296 temp_charInfo.xAdvance = 0;
297 m_characterDictionary.Add(8288, temp_charInfo);
301 if (m_characterDictionary.ContainsKey(10) ==
false)
306 temp_charInfo.id = 10;
309 temp_charInfo.width = 10;
310 temp_charInfo.height = m_characterDictionary[32].height;
311 temp_charInfo.xOffset = 0;
312 temp_charInfo.yOffset = m_characterDictionary[32].yOffset;
313 temp_charInfo.xAdvance = 0;
314 temp_charInfo.scale = 1;
315 m_characterDictionary.Add(10, temp_charInfo);
317 if (!m_characterDictionary.ContainsKey(13))
318 m_characterDictionary.Add(13, temp_charInfo);
322 if (m_characterDictionary.ContainsKey(9) ==
false)
327 temp_charInfo.id = 9;
328 temp_charInfo.x = m_characterDictionary[32].x;
329 temp_charInfo.y = m_characterDictionary[32].y;
330 temp_charInfo.width = m_characterDictionary[32].width * tabSize + (m_characterDictionary[32].xAdvance - m_characterDictionary[32].width) * (tabSize - 1);
331 temp_charInfo.height = m_characterDictionary[32].height;
332 temp_charInfo.xOffset = m_characterDictionary[32].xOffset;
333 temp_charInfo.yOffset = m_characterDictionary[32].yOffset;
334 temp_charInfo.xAdvance = m_characterDictionary[32].xAdvance * tabSize;
335 temp_charInfo.scale = 1;
336 m_characterDictionary.Add(9, temp_charInfo);
343 m_fontInfo.TabWidth = m_characterDictionary[9].xAdvance;
346 if (m_fontInfo.CapHeight == 0 && m_characterDictionary.ContainsKey(72))
347 m_fontInfo.CapHeight = m_characterDictionary[72].yOffset;
350 if (m_fontInfo.Scale == 0)
351 m_fontInfo.Scale = 1.0f;
354 if (m_fontInfo.strikethrough == 0)
355 m_fontInfo.strikethrough = m_fontInfo.CapHeight / 2.5f;
358 if (m_fontInfo.Padding == 0)
360 if (
material.HasProperty(ShaderUtilities.ID_GradientScale))
361 m_fontInfo.Padding =
material.GetFloat(ShaderUtilities.ID_GradientScale) - 1;
365 m_kerningDictionary =
new Dictionary<int, KerningPair>();
366 List<KerningPair> pairs = m_kerningInfo.kerningPairs;
369 for (
int i = 0; i < pairs.Count; i++)
374 if (pair.xOffset != 0)
375 pairs[i].ConvertLegacyKerningData();
379 if (m_kerningDictionary.ContainsKey((
int)uniqueKey.key) ==
false)
381 m_kerningDictionary.Add((
int)uniqueKey.key, pair);
386 Debug.LogWarning(
"Kerning Key for [" + uniqueKey.ascii_Left +
"] and [" + uniqueKey.ascii_Right +
"] already exists.");
392 hashCode = TMP_TextUtilities.GetSimpleHashCode(this.name);
411 if (m_glyphInfoList ==
null || m_glyphInfoList.Count == 0)
return;
413 m_glyphInfoList = m_glyphInfoList.OrderBy(item => item.id).ToList();
425 if (m_characterDictionary ==
null)
428 if (m_characterDictionary.ContainsKey(character))
442 if (m_characterDictionary ==
null)
445 if (m_characterDictionary.ContainsKey(character))
461 if (m_characterDictionary ==
null)
465 if (m_characterDictionary ==
null)
470 if (m_characterDictionary.ContainsKey(character))
523 if (m_characterDictionary ==
null)
527 if (m_characterDictionary ==
null)
532 if (m_characterDictionary.ContainsKey(character))
559 if (m_characterDictionary ==
null)
561 missingCharacters =
null;
565 missingCharacters =
new List<char>();
567 for (
int i = 0; i < text.Length; i++)
569 if (!m_characterDictionary.ContainsKey(text[i]))
570 missingCharacters.Add(text[i]);
573 if (missingCharacters.Count == 0)
587 if (m_characterDictionary ==
null)
590 for (
int i = 0; i < text.Length; i++)
592 if (!m_characterDictionary.ContainsKey(text[i]))
607 string characters =
string.Empty;
609 for (
int i = 0; i < fontAsset.m_glyphInfoList.Count; i++)
611 characters += (char)fontAsset.m_glyphInfoList[i].id;
625 int[] characters =
new int[fontAsset.m_glyphInfoList.Count];
627 for (
int i = 0; i < fontAsset.m_glyphInfoList.Count; i++)
629 characters[i] = fontAsset.m_glyphInfoList[i].id;
bool HasCharacters(string text)
Function to check if certain characters exists in the font asset. Function returns false if any chara...
int hashCode
HashCode based on the name of the asset.
List< TMP_FontAsset > fallbackFontAssets
List containing the Fallback font assets for this font.
void AddKerningInfo(KerningTable kerningTable)
bool HasCharacter(int character)
Function to check if a certain character exists in the font asset.
static int [] GetCharactersArray(TMP_FontAsset fontAsset)
Function which returns an array that contains all the characters from a font asset.
Contains the font asset for the specified font weight styles.
static TMP_FontAsset defaultFontAsset
Returns the Default Font Asset to be used by newly created text objects.
void SortGlyphs()
Function to sort the list of glyphs.
Dictionary< int, KerningPair > kerningDictionary
Dictionary containing the kerning data
bool HasCharacters(string text, out List< char > missingCharacters)
Function to check if certain characters exists in the font asset. Function returns a list of missing ...
int materialHashCode
HashCode based on the name of the material assigned to this asset.
void ReadFontDefinition()
bool HasCharacter(char character, bool searchFallbacks)
Function to check if a character is contained in the font asset with the option to also check through...
static TMP_FontAsset defaultFontAsset
Default Font Asset used as last resort when glyphs are missing.
bool HasCharacter(char character)
Function to check if a certain character exists in the font asset.
static TMP_Glyph Clone(TMP_Glyph source)
Function to create a deep copy of a GlyphInfo.
bool HasCharacter_Internal(char character, bool searchFallbacks)
Function to check if a character is contained in a font asset with the option to also check through f...
Material material
The material used by this asset.
uint secondGlyph
The second glyph part of a kerning pair.
FontAssetCreationSettings creationSettings
The settings used in the Font Asset Creator when this font asset was created or edited.
void AddFaceInfo(FaceInfo faceInfo)
uint firstGlyph
The first glyph part of a kerning pair.
FaceInfo fontInfo
The general information about the font.
Class that contains the basic information about the font.
static bool warningsDisabled
Controls the display of warning message in the console.
static string GetCharacters(TMP_FontAsset fontAsset)
Function to extract all the characters from a font asset.
void AddGlyphInfo(TMP_Glyph[] glyphInfo)
static List< TMP_FontAsset > fallbackFontAssets
Returns the list of Fallback Fonts defined in the TMP Settings file.