private static TMP_FontAsset SearchForGlyphInternal(TMP_FontAsset font, int character, out TMP_Glyph glyph) { glyph = null; if (font == null) { return(null); } if (font.characterDictionary.TryGetValue(character, out glyph)) { return(font); } if (font.fallbackFontAssets != null && font.fallbackFontAssets.Count > 0) { int num = 0; while (num < font.fallbackFontAssets.Count && glyph == null) { TMP_FontAsset tmp_FontAsset = font.fallbackFontAssets[num]; if (!(tmp_FontAsset == null)) { int instanceID = tmp_FontAsset.GetInstanceID(); if (!TMP_FontUtilities.k_searchedFontAssets.Contains(instanceID)) { TMP_FontUtilities.k_searchedFontAssets.Add(instanceID); tmp_FontAsset = TMP_FontUtilities.SearchForGlyphInternal(tmp_FontAsset, character, out glyph); if (tmp_FontAsset != null) { return(tmp_FontAsset); } } } num++; } } return(null); }
private static TMP_FontAsset SearchForGlyphInternal(TMP_FontAsset font, int character, out TMP_Glyph glyph) { glyph = null; if (font == null) { return(null); } if (font.characterDictionary.TryGetValue(character, out glyph)) { return(font); } if (font.fallbackFontAssets != null && font.fallbackFontAssets.Count > 0) { for (int i = 0; i < font.fallbackFontAssets.Count; i++) { if (glyph != null) { break; } TMP_FontAsset tMP_FontAsset = font.fallbackFontAssets[i]; int instanceID = tMP_FontAsset.GetInstanceID(); if (!(tMP_FontAsset == null) && !k_searchedFontAssets.Contains(instanceID)) { k_searchedFontAssets.Add(instanceID); tMP_FontAsset = SearchForGlyphInternal(tMP_FontAsset, character, out glyph); if (tMP_FontAsset != null) { return(tMP_FontAsset); } } } } return(null); }
private void ON_FONT_PROPERTY_CHANGED(bool isChanged, TMP_FontAsset font) { if (font.GetInstanceID() == m_fontAsset.GetInstanceID() && m_fallbackMaterial != null) { m_fallbackMaterial.SetFloat(ShaderUtilities.ID_WeightNormal, m_fontAsset.normalStyle); m_fallbackMaterial.SetFloat(ShaderUtilities.ID_WeightBold, m_fontAsset.boldStyle); } }
/// <summary> /// Function to check if a certain font asset is contained in the material reference array. /// </summary> /// <param name="materialReferences"></param> /// <param name="fontAsset"></param> /// <returns></returns> public static bool Contains(MaterialReference[] materialReferences, TMP_FontAsset fontAsset) { int id = fontAsset.GetInstanceID(); for (int i = 0; i < materialReferences.Length && materialReferences[i].fontAsset != null; i++) { if (materialReferences[i].fontAsset.GetInstanceID() == id) return true; } return false; }
private void InternalRegisterFontAssetForDefinitionRefresh(TMP_FontAsset fontAsset) { int id = fontAsset.GetInstanceID(); if (m_FontAssetDefinitionRefreshQueueLookup.Contains(id)) { return; } m_FontAssetDefinitionRefreshQueueLookup.Add(id); m_FontAssetDefinitionRefreshQueue.Add(fontAsset); }
// Event received when font asset properties are changed in Font Inspector void ON_FONT_PROPERTY_CHANGED(bool isChanged, TMP_FontAsset font) { if (m_fontAsset != null && font.GetInstanceID() == m_fontAsset.GetInstanceID()) { // Copy Normal and Bold Weight if (m_fallbackMaterial != null) { if (TMP_Settings.matchMaterialPreset) { TMP_MaterialManager.ReleaseFallbackMaterial(m_fallbackMaterial); TMP_MaterialManager.CleanupFallbackMaterials(); } } } }
public static bool Contains(MaterialReference[] materialReferences, TMP_FontAsset fontAsset) { int instanceID = fontAsset.GetInstanceID(); int num = 0; while (num < materialReferences.Length && materialReferences[num].fontAsset != null) { if (materialReferences[num].fontAsset.GetInstanceID() == instanceID) { return(true); } num++; } return(false); }
private static TMP_FontAsset SearchForGlyphInternal(TMP_FontAsset font, int character, out TMP_Glyph glyph) { glyph = null; if (font == null) { return(null); } if (font.characterDictionary.TryGetValue(character, out glyph)) { return(font); } else if (font.fallbackFontAssets != null && font.fallbackFontAssets.Count > 0) { for (int i = 0; i < font.fallbackFontAssets.Count && glyph == null; i++) { TMP_FontAsset temp = font.fallbackFontAssets[i]; if (temp == null) { continue; } int id = temp.GetInstanceID(); // Skip over the fallback font asset in the event it is null or if already searched. if (k_searchedFontAssets.Contains(id)) { continue; } // Add to list of font assets already searched. k_searchedFontAssets.Add(id); temp = SearchForGlyphInternal(temp, character, out glyph); if (temp != null) { return(temp); } } } return(null); }
private static TMP_FontAsset SearchForCharacterInternal(TMP_FontAsset font, uint unicode, out TMP_Character character) { character = null; if (font == null) { return(null); } if (font.characterLookupTable.TryGetValue(unicode, out character)) { return(font); } else if (font.fallbackFontAssetTable != null && font.fallbackFontAssetTable.Count > 0) { for (int i = 0; i < font.fallbackFontAssetTable.Count && character == null; i++) { TMP_FontAsset temp = font.fallbackFontAssetTable[i]; if (temp == null) { continue; } int id = temp.GetInstanceID(); // Skip over the fallback font asset in the event it is null or if already searched. if (k_searchedFontAssets.Contains(id)) { continue; } // Add to list of font assets already searched. k_searchedFontAssets.Add(id); temp = SearchForCharacterInternal(temp, unicode, out character); if (temp != null) { return(temp); } } } return(null); }
/// <summary> /// Internal function returning the text element character for the given unicode value taking into consideration the font style and weight. /// Function searches the source font asset, list of font assets assigned as alternative typefaces and list of fallback font assets. /// </summary> private static TMP_Character GetCharacterFromFontAsset_Internal(uint unicode, TMP_FontAsset sourceFontAsset, bool includeFallbacks, FontStyles fontStyle, FontWeight fontWeight, out bool isAlternativeTypeface, out TMP_FontAsset fontAsset) { fontAsset = null; isAlternativeTypeface = false; TMP_Character characterData = null; #region FONT WEIGHT AND FONT STYLE HANDLING // Determine if a font weight or style is used. If so check if an alternative typeface is assigned for the given weight and / or style. bool isItalic = (fontStyle & FontStyles.Italic) == FontStyles.Italic; if (isItalic || fontWeight != FontWeight.Regular) { // Get reference to the font weight pairs of the given font asset. TMP_FontWeightPair[] fontWeights = sourceFontAsset.fontWeightTable; int fontWeightIndex = 4; switch (fontWeight) { case FontWeight.Thin: fontWeightIndex = 1; break; case FontWeight.ExtraLight: fontWeightIndex = 2; break; case FontWeight.Light: fontWeightIndex = 3; break; case FontWeight.Regular: fontWeightIndex = 4; break; case FontWeight.Medium: fontWeightIndex = 5; break; case FontWeight.SemiBold: fontWeightIndex = 6; break; case FontWeight.Bold: fontWeightIndex = 7; break; case FontWeight.Heavy: fontWeightIndex = 8; break; case FontWeight.Black: fontWeightIndex = 9; break; } fontAsset = isItalic ? fontWeights[fontWeightIndex].italicTypeface : fontWeights[fontWeightIndex].regularTypeface; if (fontAsset != null) { if (fontAsset.characterLookupTable.TryGetValue(unicode, out characterData)) { isAlternativeTypeface = true; return(characterData); } else if (fontAsset.atlasPopulationMode == AtlasPopulationMode.Dynamic) { if (fontAsset.TryAddCharacterInternal(unicode, out characterData)) { isAlternativeTypeface = true; return(characterData); } // Check if the source font file contains the requested character. //if (TryGetCharacterFromFontFile(unicode, fontAsset, out characterData)) //{ // isAlternativeTypeface = true; // return characterData; //} // If we find the requested character, we add it to the font asset character table // and return its character data. // We also add this character to the list of characters we will need to add to the font atlas. // We assume the font atlas has room otherwise this font asset should not be marked as dynamic. // Alternatively, we could also add multiple pages of font atlas textures (feature consideration). } // At this point, we were not able to find the requested character in the alternative typeface // so we check the source font asset and its potential fallbacks. } } #endregion // Search the source font asset for the requested character. if (sourceFontAsset.characterLookupTable.TryGetValue(unicode, out characterData)) { // We were able to locate the requested character in the given font asset. fontAsset = sourceFontAsset; return(characterData); } else if (sourceFontAsset.atlasPopulationMode == AtlasPopulationMode.Dynamic) { if (sourceFontAsset.TryAddCharacterInternal(unicode, out characterData)) { fontAsset = sourceFontAsset; return(characterData); } //// Check if the source font file contains the requested character. //if (TryGetCharacterFromFontFile(unicode, sourceFontAsset, out characterData)) //{ // fontAsset = sourceFontAsset; // //fontAsset.AddCharacterToRasterList(unicode); // return characterData; //} // If we find the requested character, we add it to the font asset character table // and return its character data. // We also add this character to the list of characters we will need to add to the font atlas. // We assume the font atlas has room otherwise this font asset should not be marked as dynamic. // Alternatively, we could also add multiple pages of font atlas textures (feature consideration) } // Search fallback font assets if we still don't have a valid character and include fallback is set to true. if (characterData == null && includeFallbacks && sourceFontAsset.fallbackFontAssetTable != null) { // Get reference to the list of fallback font assets. List <TMP_FontAsset> fallbackFontAssets = sourceFontAsset.fallbackFontAssetTable; int fallbackCount = fallbackFontAssets.Count; if (fallbackFontAssets != null && fallbackCount > 0) { for (int i = 0; i < fallbackCount && characterData == null; i++) { TMP_FontAsset temp = fallbackFontAssets[i]; if (temp == null) { continue; } int id = temp.GetInstanceID(); // Skip over the fallback font asset in the event it is null or if already searched. if (k_SearchedFontAssets.Contains(id)) { continue; } // Add to list of font assets already searched. k_SearchedFontAssets.Add(id); characterData = GetCharacterFromFontAsset_Internal(unicode, temp, includeFallbacks, fontStyle, fontWeight, out isAlternativeTypeface, out fontAsset); if (characterData != null) { return(characterData); } } } } return(null); }