/// <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; } }
public object GetFontEngineParameters(int i) { #if !TTFTEXT_LITE if ((!overrideFontId) && (stackparent != null)) { return(stackparent.GetFontEngineParameters(i)); } if ((fontengine_parameters == null) || (fontengine_parameters.Count < TTFTextInternal.TTFTextFontEngine.font_engines.Length) //||((fontengine_parameters[0]==null)&&(fontengine_parameters_serialized[0].bytes.Length>0)) ) { if (fontengine_parameters == null) { fontengine_parameters = new System.Collections.Generic.List <object> (); } if (fontengine_parameters_serialized == null) { fontengine_parameters_serialized = new System.Collections.Generic.List <ByteArray> (); } int mi = fontengine_parameters.Count; for (int ci = 0; ci < mi; ci++) { if (fontengine_parameters [i] == null) { mi = ci; break; } } for (int ci = mi; ci < TTFTextInternal.TTFTextFontEngine.font_engines.Length; ci++ ) { // try deserialize if ((fontengine_parameters_serialized != null) && (fontengine_parameters_serialized.Count > ci) && (fontengine_parameters_serialized [ci] != null) ) { object to = DeserializeObject(fontengine_parameters_serialized [ci]); if (fontengine_parameters.Count == ci) { fontengine_parameters.Add(to); } else { fontengine_parameters [ci] = to; } } else { if ((fontengine_parameters.Count == ci)) { System.Type t = TTFTextInternal.TTFTextFontEngine.font_engines [ci].GetType().GetNestedType("Parameters"); fontengine_parameters.Add(t.InvokeMember(t.Name, BindingFlags.CreateInstance, null, null, null)); fontengine_parameters_serialized.Add(SerializeObject(fontengine_parameters [ci])); } // try instantiate if ((fontengine_parameters [ci] == null)) { System.Type t = TTFTextInternal.TTFTextFontEngine.font_engines [ci].GetType().GetNestedType("Parameters"); fontengine_parameters [ci] = t.InvokeMember(t.Name, BindingFlags.CreateInstance, null, null, null); //if (fontengine_specific_fontid [ci] == null) // SetFontengineFontId (i, fontengine_specific_fontid [0]); } } } } if (i == 0) { if (fontengine_parameters [i] == null) { Debug.LogWarning("(TTFText) For some reason, the serialized font parameters have not been recovered... Are you sure the font engine parameters were declared serializable ? Are you upgrading the project from a previous version of TTF Text ?"); fontengine_parameters = null; fontengine_parameters_serialized = null; return(GetFontEngineParameters(0)); } } if (i == -1) { i = 0; } return(fontengine_parameters [i]); #endif #if TTFTEXT_LITE if (fontengine_parameters == null) { fontengine_parameters = new System.Collections.Generic.List <object> (); fontengine_parameters.Add(null); } return(fontengine_parameters [0]); #endif }