/// <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 TTFTextStyle Push() { // TTFTextStyle tp=(TTFTextStyle)ScriptableObject.Instantiate(this); TTFTextStyle tp = new TTFTextStyle(this); tp.stackparent = this; //tp.renewid(); return(tp); }
public TTFTextStyle PushF(string name, bool createstyle, ref bool notfound) { GameObject go = (GameObject)GameObject.Find("/TTFText Styles/" + name); if (go == null) { Object o = Resources.Load("/TTFText/Styles/" + name + ".prefab"); if (o != null) { GameObject ngo = (GameObject)o; ngo.name = name; ngo.transform.parent = GameObject.Find("/TTFText Styles").transform; go = ngo; } if (go == null) { if (createstyle) { GameObject gop = (GameObject)GameObject.Find("/TTFText Styles"); if (gop == null) { gop = new GameObject(); gop.name = "TTFText Styles"; } go = new GameObject(); go.transform.parent = gop.transform; go.name = name; go.AddComponent <TTFText> (); TTFText tm = go.GetComponent <TTFText> (); go.AddComponent <MeshRenderer> (); go.AddComponent <TTFTextExtra_SetMaterialColor> (); tm.Text = ""; tm.IsStyleObject = true; tm.updateObjectName = false; //tm.InitTextStyle=(TTFTextStyle)ScriptableObject.Instantiate(this); tm.InitTextStyle = new TTFTextStyle(this); tm.InitTextStyle.materialSource = go; tm.InitTextStyle.ResetStyle(); } else { notfound = true; return(new TTFTextStyle(this)); } } } //TTFTextStyle tp=(TTFTextStyle)ScriptableObject.Instantiate(go.GetComponent<TTFText>().InitTextStyle); TTFTextStyle tp = new TTFTextStyle(go.GetComponent <TTFText> ().InitTextStyle); tp.stackparent = this; //tp.renewid(); return(tp); }
public TTFTextStyle(TTFTextStyle s) { // Debug.Log("copy ctor s "+s.GetInstanceID()+(s!=null)); PropertyInfo[] properties = typeof(TTFTextStyle).GetProperties(); foreach (PropertyInfo pi in properties) { try { if ((pi.Name != "name") && (pi.Name != "hideFlags")) { if ((pi.CanRead) && (pi.CanWrite)) { pi.SetValue(this, pi.GetValue(s, null), null); } } } catch (System.Exception e) { Debug.LogError("(TTF Text)Error during copy of property :" + pi.Name + ":" + e); } } if (s.fontengine_specific_fontid != null) { fontengine_specific_fontid = new System.Collections.Generic.List <string> (s.fontengine_specific_fontid); } if (s.fontengine_parameters != null) { fontengine_parameters = new System.Collections.Generic.List <object> (s.fontengine_parameters); } if (s.fontengine_parameters_serialized != null) { fontengine_parameters_serialized = new System.Collections.Generic.List <ByteArray> (s.fontengine_parameters_serialized); } orientationReversed = s.orientationReversed; materialSource = s.materialSource; //xid=0; renewid(); // Debug.Log("New style :"+getid().ToString()); }
static TTFTextOutline[] MakeBentOutlines (TTFTextInternal.LineLayout ll, TTFText tm, TTFTextStyle ts) { //Vector3 min=Vector3.zero; Vector3 max=Vector3.zero; int NS = ts.ExtrusionSteps.Length; TTFTextOutline[] outlines = new TTFTextOutline[NS]; //Vector3 [] szs = new Vector3[NS]; for (int i = 0; i < NS; i++) { //Vector3 min_, max_; float embold = ts.Embold + ts.BevelForce * Mathf.Sin (i * Mathf.PI / (NS - 1)); // wierd error with poly2tri/embold for the backface if (i == NS - 1) { embold = ts.Embold; } outlines [i] = MakeOutline (ll, embold, tm); float z = (ts.ExtrusionSteps [i] - 0.5f) * ts.ExtrusionDepth;// - tm.exstrusionDepth / 2; outlines [i].Translate (Vector3.forward * z); if (ts.Slant != 0) { outlines [i].Slant (ts.Slant); } //outlines[i].GetMinMax(out min_, out max_); //szs[i]=max_-min_; //min = Vector3.Min(min, min_); //max = Vector3.Max(max, max_); } //Vector3 sz=max-min; //for (int i=0;i<NS;i++) { // outlines[i].Translate((sz-szs[i])/2); //} return outlines; }
// FreeHand Curve Extrusion public static TTFTextOutline[] MakeFreeHandOutlines (TTFTextInternal.LineLayout ll, TTFText tm, TTFTextStyle ts) { //Vector3 min=Vector3.zero; Vector3 max=Vector3.zero; Keyframe[] keys = ts.FreeHandCurve.keys; int NS = keys.Length; TTFTextOutline[] outlines = new TTFTextOutline[NS]; float[] z = new float[NS]; //min = Vector3.zero; //max = Vector3.zero; //Vector3 [] szs = new Vector3[NS]; for (int i=0; i<NS; i++) { // Vector3 min_, max_; z [i] = keys [i].time * ts.ExtrusionDepth; outlines [i] = MakeOutline (ll, ts.Embold + keys [i].value * ts.BevelForce, tm); outlines [i].Translate (Vector3.forward * z [i]); if (ts.Slant != 0) { outlines [i].Slant (ts.Slant); } //outlines[i].GetMinMax(out min_, out max_); //szs[i]=max_-min_; //min = Vector3.Min(min, min_); //max = Vector3.Max(max, max_); } //Vector3 sz=max-min; //for (int i=0;i<NS;i++) { // outlines[i].Translate((sz-szs[i])/2); //} return outlines; }
// Simple extrusion public static TTFTextOutline[] MakeSimpleOutlines (TTFTextInternal.LineLayout ll, TTFText tm, TTFTextStyle ts) { TTFTextOutline o = MakeOutline (ll, ts.Embold, tm); if (ts.Slant != 0) { o.Slant (ts.Slant); } TTFTextOutline[] outlines = new TTFTextOutline[2]; outlines [0] = o; outlines [1] = new TTFTextOutline (o); outlines [0].Translate (Vector3.forward * (-ts.ExtrusionDepth) / 2); outlines [1].Translate (Vector3.forward * ts.ExtrusionDepth / 2); return outlines; }
public static TTF.Font TryOpenFont(TTFTextStyle ts, int resolution) { return(TryOpenFont(ts, ts.Size, resolution)); }
public TTFTextStyleAsset Init(TTFTextStyle s, string n) { style=s; _name=n; return this; }
public TTFTextStyle PushF(string name, bool createstyle, ref bool notfound) { GameObject go = (GameObject)GameObject.Find ("/TTFText Styles/" + name); if (go == null) { Object o=Resources.Load("/TTFText/Styles/"+name+".prefab"); if (o!=null) { GameObject ngo=(GameObject)o; ngo.name=name; ngo.transform.parent=GameObject.Find("/TTFText Styles").transform; go=ngo; } if (go==null) { if (createstyle) { GameObject gop = (GameObject)GameObject.Find ("/TTFText Styles"); if (gop == null) { gop = new GameObject (); gop.name = "TTFText Styles"; } go = new GameObject (); go.transform.parent = gop.transform; go.name = name; go.AddComponent<TTFText> (); TTFText tm = go.GetComponent<TTFText> (); go.AddComponent<MeshRenderer> (); go.AddComponent<TTFTextExtra_SetMaterialColor> (); tm.Text = ""; tm.IsStyleObject = true; tm.updateObjectName = false; //tm.InitTextStyle=(TTFTextStyle)ScriptableObject.Instantiate(this); tm.InitTextStyle = new TTFTextStyle (this); tm.InitTextStyle.materialSource = go; tm.InitTextStyle.ResetStyle (); } else { notfound = true; return new TTFTextStyle (this); } } } //TTFTextStyle tp=(TTFTextStyle)ScriptableObject.Instantiate(go.GetComponent<TTFText>().InitTextStyle); TTFTextStyle tp = new TTFTextStyle (go.GetComponent<TTFText> ().InitTextStyle); tp.stackparent = this; //tp.renewid(); return tp; }
/// <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 static TTF.Font TryOpenFont(TTFTextStyle ts, int resolution) { return TryOpenFont (ts, ts.Size, resolution); }
/// <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> public static 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 TTFTextStyle(TTFTextStyle s) { // Debug.Log("copy ctor s "+s.GetInstanceID()+(s!=null)); PropertyInfo[] properties = typeof(TTFTextStyle).GetProperties (); foreach (PropertyInfo pi in properties) { try { if ((pi.Name != "name") && (pi.Name != "hideFlags")) { if ((pi.CanRead) && (pi.CanWrite)) { pi.SetValue (this, pi.GetValue (s, null), null); } } } catch (System.Exception e) { Debug.LogError ("(TTF Text)Error during copy of property :" + pi.Name + ":" + e); } } if (s.fontengine_specific_fontid != null) { fontengine_specific_fontid = new System.Collections.Generic.List<string> (s.fontengine_specific_fontid); } if (s.fontengine_parameters != null) { fontengine_parameters = new System.Collections.Generic.List<object> (s.fontengine_parameters); } if (s.fontengine_parameters_serialized != null) { fontengine_parameters_serialized = new System.Collections.Generic.List<ByteArray> (s.fontengine_parameters_serialized); } orientationReversed = s.orientationReversed; materialSource = s.materialSource; //xid=0; renewid(); // Debug.Log("New style :"+getid().ToString()); }
static TTFTextOutline[] MakeBevelOutlines (TTFTextInternal.LineLayout ll, TTFText tm, TTFTextStyle ts) { //Vector3 min=Vector3.zero; Vector3 max=Vector3.zero; //Vector3 min_; Vector3 max_; int NS = tm.NbDiv; if (NS < 2) { NS = 2; } TTFTextOutline[] outlines = new TTFTextOutline[NS * 2]; //Vector3[] szs = new Vector3[NS*2]; float bevelDepth = ts.BevelDepth * ts.ExtrusionDepth / 2; for (int i = 0; i < NS; ++i) { float f = ((float)i) / ((float)NS - 1); // [0,1] float embold = ts.Embold + Mathf.Sin (Mathf.Acos (1 - f)) * ts.BevelForce; TTFTextOutline o = MakeOutline (ll, embold, tm); o.Slant (ts.Slant); outlines [i] = o; outlines [2 * NS - 1 - i] = new TTFTextOutline (o); //outlines[i].GetMinMax(out min_, out max_); //szs[i]=max_-min_; float z = f * bevelDepth; outlines [i].Translate (Vector3.forward * z); outlines [2 * NS - 1 - i].Translate (Vector3.forward * (ts.ExtrusionDepth - z)); //szs[2*NS-1-i]=max_-min_; //min = Vector3.Min(min, min_); //max = Vector3.Max(max, max_); } //Vector3 sz=max-min; //for (int i=0;i<(2*NS);i++) { // outlines[i].Translate((sz-szs[i])/2); //} return outlines; }
public TTFTextStyleAsset Init(TTFTextStyle s, string n) { style = s; _name = n; return(this); }
void Awake() { // Trace.DEBUG("Awake:" + Text + " id:" + instanceID_ + " playing=" + Application.isPlaying); // We want to clone the mesh on Object duplication. // TODO: find a better way to detect GameObject duplication // Not Perfect as this still get called on scene load, // but no more on Play/Edit mode switch // Debug.Log("id:" + instanceID_ ); #if !TTFTEXT_LITE if ((mesh == null) && (TokenMode == TTFText.TokenModeEnum.Text)) { if (initTextStyle != null) { initTextStyle = new TTFTextStyle (initTextStyle); } else { initTextStyle = new TTFTextStyle (); } instanceID_ = GetInstanceID (); RebuildText (); } #endif if (instanceID_ != GetInstanceID ()) { if (mesh != null) { //Clone the mesh if (!Application.isEditor || Application.isPlaying) { // Unexpected context, log a warning // MAY HAPPEN WITH PREFAB //Debug.LogWarning("TTFTextMesh Duplicate: isEditor=" + Application.isEditor + " isPlaying=" + Application.isPlaying); } else { // We are in Edit Mode //Debug.LogWarning("Duplicate Mesh:" + instanceID_ + "->" + GetInstanceID()); initTextStyle = new TTFTextStyle (initTextStyle); mesh = (Mesh)Instantiate (mesh); #if !TTFTEXT_LITE TTFTextInternal.Engine.UpdateComponentsWithNewMesh (gameObject, mesh); #else MeshFilter mf = GetComponent<MeshFilter>(); if (mf != null) { mf.sharedMesh = mesh; } InteractiveCloth ic = GetComponent<InteractiveCloth>(); if (ic != null) { ic.mesh = mesh; } #endif } } } instanceID_ = GetInstanceID (); currentStyleIdx = 0; }
public TTFTextStyle Push() { // TTFTextStyle tp=(TTFTextStyle)ScriptableObject.Instantiate(this); TTFTextStyle tp = new TTFTextStyle (this); tp.stackparent = this; //tp.renewid(); return tp; }