public string GetFontEngineFontIdD(int i) { if ((!overrideFontId) && (stackparent != null)) { return(stackparent.GetFontEngineFontIdD(i)); } if (fontengine_specific_fontid != null) { if ((i >= 0) && (i < fontengine_specific_fontid.Count)) { if (fontengine_specific_fontid [i] != null) { return(fontengine_specific_fontid [i]); } } } return(fontId); }
/// <summary> /// Appends some text to the line. /// </summary> /// <param name='s'> /// text to be appended. /// </param> /// <exception cref='System.Exception'> /// Is thrown when the font may not be found, or when we /// are unable to compute the layout info /// </exception> public void AppendText(string s) { if (s.Length == 0) { return; } int l0 = linetext.Length; linetext += s; #if TTFTEXT_LITE if (tm.DemoMode) { #endif SetCharStyle(l0, l0 + s.Length, tm.currentStyleIdx); #if TTFTEXT_LITE } else { SetCharStyle(l0, l0 + s.Length, 0); } #endif // UPDATE THE METRIC INFO object f = null; object parameters = null; ; int fp = 0; float sumadvance = 0; for (int i = 0; i < l0; i++) { sumadvance += charadvances[i]; } string currentfontid = ""; //f = tm.InitTextStyle.GetFont (ref fp, ref currentfontid, ref parameters); //f = tm.CurrentTextStyle.GetFont (ref fp, ref currentfontid, ref parameters); #if !TTFTEXT_LITE f = tm.CurrentTextStyle.GetFont(ref fp, ref currentfontid, ref parameters); #else fp = 0; currentfontid = tm.CurrentTextStyle.FontId; parameters = tm.CurrentTextStyle.GetFontEngineParameters(0); if (parameters == null) { System.Type t = TTFTextInternal.TTFTextFontEngine.font_engines [0].GetType().GetNestedType("Parameters"); tm.CurrentTextStyle.SetFontEngineParameters(0, t.InvokeMember(t.Name, BindingFlags.CreateInstance, null, null, null)); parameters = tm.CurrentTextStyle.GetFontEngineParameters(0); } f = TTFTextInternal.TTFTextFontEngine.font_engines[0].GetFont(parameters, currentfontid); #endif if (f == null) { //throw new System.Exception ("Font not found :" + fp + "/" + tm.InitTextStyle.GetFontEngineFontId (fp)); throw new System.Exception("Font not found :" + fp + "/" + tm.CurrentTextStyle.GetFontEngineFontId(fp)); } for (int i = 0; i < s.Length; i++) { TTFTextStyle cttfstyle = GetCharStyle(l0 + i); if ((cttfstyle != null) && (currentfontid != cttfstyle.GetFontEngineFontIdD(fp))) { TTFTextFontEngine.font_engines [fp].DisposeFont(f); // f = cttfstyle.GetFont (ref fp, ref currentfontid, ref parameters); #if !TTFTEXT_LITE f = cttfstyle.GetFont(ref fp, ref currentfontid, ref parameters); #else fp = 0; currentfontid = cttfstyle.FontId; parameters = cttfstyle.GetFontEngineParameters(0); if (parameters == null) { System.Type t = TTFTextInternal.TTFTextFontEngine.font_engines [0].GetType().GetNestedType("Parameters"); cttfstyle.SetFontEngineParameters(0, t.InvokeMember(t.Name, BindingFlags.CreateInstance, null, null, null)); parameters = tm.CurrentTextStyle.GetFontEngineParameters(0); } f = TTFTextInternal.TTFTextFontEngine.font_engines[0].GetFont(parameters, currentfontid); #endif if (f == null) { //throw new System.Exception ("Font not found :" + fp + "/" + tm.InitTextStyle.GetFontEngineFontId (fp)); throw new System.Exception("Font not found :" + fp + "/" + tm.CurrentTextStyle.GetFontEngineFontId(fp)); } } charadvances [l0 + i] = TTFTextFontEngine.font_engines [fp].GetAdvance(parameters, f, s [i]).x *cttfstyle.Size; charheights [l0 + i] = TTFTextFontEngine.font_engines [fp].GetHeight(parameters, f); charmetadata [l0 + i] = null; if (!TTFTextFontEngine.font_engines[fp].IsBitmapFontProvider(parameters)) { TTFTextOutline o = TTFTextFontEngine.font_engines [fp].GetGlyphOutline(parameters, f, s [i]); o.Rescale(cttfstyle.Size); if (l0 + i == 0) { Xmin0 = o.Min.x; } if (l0 + i == line.Length - 1) { XmaxN = o.Max.x; } } else { //Debug.LogWarning("NYI !"); sumadvance += charadvances [l0 + i]; if (l0 + i == 0) { Xmin0 = 0; } if (l0 + i == line.Length - 1) { XmaxN = sumadvance; } } } TTFTextFontEngine.font_engines [fp].DisposeFont(f); // can happen when the first or last char is non printable, like a space for example if (float.IsNaN(XmaxN) || float.IsInfinity(XmaxN)) { XmaxN = 0; } if (float.IsNaN(Xmin0) || float.IsInfinity(Xmin0)) { Xmin0 = 0; } }