/// <summary> /// Core function generating the outline for a portion of text /// </summary> /// <returns> /// The outline. /// </returns> /// <param name='txt'> /// The text to be rendered /// </param> /// <param name='charSpacing'> /// The default character spacing /// </param> /// <param name='embold'> /// Current embold /// </param> /// <param name='tm'> /// Link to the TTFText object /// </param> /// <param name='reversed'> /// Orientation of the outlines /// </param> /// <param name='charpositions'> /// Position of the character /// </param> /// <param name='charstyleidx'> /// Style index of each character /// </param> /// <param name='charmetadata'> /// Metadata associated to special character such as images and bitmap characters /// </param> /// <exception cref='System.Exception'> /// Is thrown when the exception. /// </exception> public static TTFTextOutline MakeOutline (string txt, float charSpacing, float embold, TTFText tm, bool reversed, float [] charpositions, int [] charstyleidx, object [] charmetadata) { TTFTextOutline outline = new TTFTextOutline (); int fp = 0; string currentfontid = ""; object cfont = null; object parameters = null; TTFTextStyle cttfstyle = null; if (charstyleidx == null) { cttfstyle = tm.InitTextStyle; fp = cttfstyle.PreferredEngine (Application.platform); #if ! TTFTEXT_LITE cfont = 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=cttfstyle.GetFontEngineParameters(0); } cfont= TTFTextInternal.TTFTextFontEngine.font_engines[0].GetFont(parameters,currentfontid); #endif if (cfont == null) { throw new System.Exception ("(TTFText) Font not found :" + tm.InitTextStyle.FontId); } } if (charpositions != null && charpositions.Length < txt.Length) { Debug.LogError ("(TTFText) Bad char position len=" + charpositions.Length + " txt = " + txt + " (len=" + txt.Length + ")"); charpositions = null; } int i = 0; foreach (char c in txt) { TTFTextOutline o = null; if (charstyleidx != null) { if ((cfont == null) || (currentfontid != tm.UsedStyles [charstyleidx [i]].GetFontEngineFontId (tm.UsedStyles [charstyleidx [i]].PreferredEngine (Application.platform)))) { cttfstyle = tm.UsedStyles [charstyleidx [i]]; fp = cttfstyle.PreferredEngine (Application.platform); //Debug.Log(fp); #if ! TTFTEXT_LITE cfont = 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=cttfstyle.GetFontEngineParameters(0); } cfont= TTFTextInternal.TTFTextFontEngine.font_engines[0].GetFont(parameters,currentfontid); #endif if (cfont == null) { throw new System.Exception ("Font not found :" + tm.InitTextStyle.FontId); } } } if ((charmetadata == null) || (charmetadata [i] == null)) { // a normal character if (TTFTextFontEngine.font_engines [fp].IsBitmapFontProvider (parameters)) { TTFTextTexturePortion p = TTFTextFontEngine.font_engines [fp].GetGlyphBitmap (parameters, cfont, c); o = new TTFTextOutline (); float w = ((float)p.w); float h = ((float)p.h); Vector3 b = new Vector3 (p.x, p.y, 0); //Vector3[] quad = {Vector3.zero,Vector3.right*w,new Vector3(w,h,0),Vector3.up*h}; Vector3[] quad = {b,b + Vector3.up * h,b + new Vector3 (w, h, 0),b + Vector3.right * w}; o.AddBoundary (quad); TTFTextInternal.TextureElement tel = new TTFTextInternal.TextureElement (); tel.width = w; tel.height = h; tel.material = p.material; tel.shouldReleaseMaterial = p.shouldReleaseMaterial; tel.texture = p.texture; tel.shouldReleaseTexture = p.shouldReleaseTexture; tel.UVstartx = p.sx; tel.UVstarty = p.sy; tel.UVwidth = p.dx; tel.UVheight = p.dy; charmetadata [i] = tel; } else { o = TTFTextFontEngine.font_engines [fp].GetGlyphOutline (parameters, cfont, c); if (charstyleidx != null) { for (int ii=0; ii<tm.UsedStyles[charstyleidx[i]].GetOutlineEffectStackElementLength(); ii++) { TTFTextStyle.TTFTextOutlineEffectStackElement tse = tm.InitTextStyle.GetOutlineEffectStackElement (ii); o = TTFTextOutline.AvailableOutlineEffects [tse.id].Apply (o, tse.parameters); } } else { for (int ii=0; ii<tm.InitTextStyle.GetOutlineEffectStackElementLength(); ii++) { TTFTextStyle.TTFTextOutlineEffectStackElement tse = tm.InitTextStyle.GetOutlineEffectStackElement (ii); o = TTFTextOutline.AvailableOutlineEffects [tse.id].Apply (o, tse.parameters); } } } } else { // it is some kind of special object (an embedded image... ?) //Debug.Log("Not yet implemented"); o = new TTFTextOutline (); float w = 1; float h = 1; Vector3[] quad = {Vector3.zero,Vector3.right * w,new Vector3 (w, h, 0),Vector3.up * h}; o.AddBoundary (quad); } o = o.Embolden (((charstyleidx != null) ? tm.UsedStyles [charstyleidx [i]].Embold : tm.Embold) + embold); o.Rescale ((charstyleidx != null) ? tm.UsedStyles [charstyleidx [i]].Size : tm.Size); if (charpositions == null) { outline.Append (o, outline.advance); } else { outline.Append (o, Vector3.right * charpositions [i]); } i += 1; } return outline; }