/// <summary> /// Utility function that tries to open a font. /// </summary> /// <returns> /// The open font. /// </returns> /// <param name='ts'> /// Ts. /// </param> /// <param name='size'> /// Size. /// </param> static public TTF.Font TryOpenFont(TTFTextStyle ts, float size, int resolution) { #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR TTFTextFontListManager flm = TTFTextFontListManager.Instance; TTF.Font font = null; if (flm.Count == 0) { return(null); } // 1. set fontId to a sane value // do not override fontId if it's already set if (ts.FontId == "") { ts.FontId = flm.GetOneId(); } // Try Open it font = flm.OpenFont(ts.FontId, size, ref ts.orientationReversed, resolution); if (font != null) { return(font); } Debug.LogWarning("Font '" + ts.FontId + "' not found."); // Try fallback fonts #if !TTFTEXT_LITE char[] sep = new char[] { ';' }; foreach (string s in ts.runtimeFontFallback.Split(sep, System.StringSplitOptions.RemoveEmptyEntries)) { font = flm.OpenFont(s, size, ref ts.orientationReversed, resolution); if (font != null) { Debug.Log("Found fallback font " + font.Name); return(font); } } #endif // Last resort try another font font = flm.OpenFont(flm.GetOneId(), size, ref ts.orientationReversed, resolution); if (font != null) { Debug.Log("Found fallback font " + font.Name); return(font); } #endif ts.orientationReversed = false; return(null); }
public TTFontInfo(string path) { #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR Path = path; using (TTF.Font f = new TTF.Font(path)) { Name = f.Name; } #endif }
/// <summary> /// Builds a whole charset for a specific fontid /// </summary> public void BuildCharSet(string fontid) { #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR int istep = TTFTextFontStore.Instance.defaultInterpolationSteps; bool reversed = false; charset = new TTFTextOutline[0x80]; charset_advance = new Vector3[0x80]; System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding(); TTF.Font font = TTFTextInternal.Utilities.TryOpenFont(fontid, ref reversed, "", 72); // TODO: < Check the last bool if (font == null) { Debug.LogError("BuildCharSet: no font found"); return; } for (byte i = 0x20; i < 0x7F; i++) { string s = ae.GetString(new byte [] { i }); charset[i] = TTFTextInternal.Engine.MakeNativeOutline(s, 1, 0, font, reversed, istep); //TTFTextInternal.MakeOutline(s, font, 1, 0, null,false,null,null); charset_advance[i] = charset[i].advance; } addCharset = new TTFTextOutline[additionalChar.Length]; int idx = 0; foreach (char c in additionalChar) { addCharset[idx] = TTFTextInternal.Engine.MakeNativeOutline( "" + c, 1, 0, font, reversed, istep); ++idx; } font.Dispose(); _needRebuild = false; #endif }
/// <summary> /// Tries to build a whole charset according current parameters of a textmesh object /// </summary> public void BuildCharSet(TTFText tm) { #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR int istep = TTFTextFontStore.Instance.defaultInterpolationSteps; charset = new TTFTextOutline[0x80]; charset_advance = new Vector3[0x80]; System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding(); TTF.Font font = TTFTextInternal.Utilities.TryOpenFont(tm.InitTextStyle, 1); if (font == null) { Debug.LogError("(TTFText) BuildCharSet: no font found"); return; } height = font.Height; for (byte i = 0x20; i < 0x7F; i++) { string s = ae.GetString(new byte [] { i }); charset[i] = TTFTextInternal.Engine.MakeNativeOutline(s, 1, 0, font, tm.OrientationReversed, istep); charset_advance[i] = charset[i].advance; } // Additional Custom Characters AddRequiredCharacters(TTFTextFontStore.Instance.defaultAdditionalCharacters + (tm.InitTextStyle.GetFontEngineParameters(1) as TTFTextInternal.FontStoreFontEngine.Parameters).additionalCharacters); addCharset = new TTFTextOutline[additionalChar.Length]; int idx = 0; foreach (char c in additionalChar) { addCharset[idx] = TTFTextInternal.Engine.MakeNativeOutline("" + c, 1, 0, font, tm.OrientationReversed, istep); ++idx; } font.Dispose(); _needRebuild = false; #endif }