public TTFTextOutline GetGlyph(Font f, char c) { AndroidJNI.PushLocalFrame(0); AndroidJavaObject path = AndroidISysFont.Call <AndroidJavaObject>("GetGlyph", f.typeface, "" + c ); AndroidJavaObject pm = AndroidISysFont.Call <AndroidJavaObject>("GetPathMeasure", path ); TTFTextOutline tto = new TTFTextOutline(); bool cont = true; while (cont) { List <Vector3> tb = new List <Vector3>(); float [] res = AndroidISysFont.Call <float []>("GetBoundary", pm, 0); int rl2 = res.Length / 2; for (int ci = 0; ci < rl2; ci++) { tb.Add(new Vector3(res[ci * 2], res[ci * 2 + 1], 0)); } tto.AddBoundary(tb); cont = AndroidISysFont.Call <bool>("NextBoundary", pm); } path.Dispose(); pm.Dispose(); AndroidJNI.PopLocalFrame(System.IntPtr.Zero); return(tto); }
public TTFTextOutline GetGlyph(Font f, char c) { AndroidJNI.PushLocalFrame(0); AndroidJavaObject path=AndroidISysFont.Call<AndroidJavaObject>("GetGlyph", f.typeface, ""+c ); AndroidJavaObject pm= AndroidISysFont.Call<AndroidJavaObject>("GetPathMeasure", path ); TTFTextOutline tto=new TTFTextOutline(); bool cont=true ; while (cont) { List<Vector3> tb=new List<Vector3>(); float [] res=AndroidISysFont.Call<float []>("GetBoundary",pm,0); int rl2=res.Length/2; for (int ci=0;ci<rl2;ci++) { tb.Add(new Vector3(res[ci*2],res[ci*2+1],0)); } tto.AddBoundary(tb); cont=AndroidISysFont.Call<bool>("NextBoundary",pm); } path.Dispose(); pm.Dispose(); AndroidJNI.PopLocalFrame(System.IntPtr.Zero); return tto; }
public override TTFTextOutline Apply(TTFTextOutline outline, object parameters) { float strength = (parameters as Parameters).Amount; strength /= 40f; if (strength == 0f) { return(new TTFTextOutline(outline)); } Vector3 so = new Vector3(strength, strength, 0); TTFTextOutline res = new TTFTextOutline(); Vector3[] nv = new Vector3[outline.nvertices]; Vector3[] d = new Vector3[outline.nvertices]; foreach (Boundary v in outline.boundaries) { int vlen = v.Count; for (int i = 0; i < vlen; ++i) { d[i] = (Quaternion.AngleAxis(90f, Vector3.forward) * (v[(i + 1) % vlen] - v[i])).normalized * strength; } for (int i = 0; i < vlen; ++i) { int ni = (i + 1) % vlen; if (!TTFTextInternal.Intersection.GetIntersection(v[i] + d[i], v[ni] + d[i], v[ni] + d[ni], v[(i + 2) % vlen] + d[ni], out nv[ni])) { nv[ni] = so + Vector3.Lerp(v[ni] + d[i], v[ni] + d[ni], 0.5f); } } res.AddBoundary(nv, vlen); } res.advance = outline.advance; return(res); }
public override TTFTextOutline Apply(TTFTextOutline outline, object parameters) { Parameters p = (parameters as Parameters); TTFTextOutline no = new TTFTextOutline(); Vector3 [] tv = new Vector3[p.ngons]; foreach (Boundary v in outline.boundaries) { int vlen = v.Count; for (int i = 0; i < vlen; ++i) { for (int r = 0; r < p.ngons; r++) { float a = -(p.phase + (((float)r) / p.ngons)) * Mathf.PI * 2; tv[r] = v[i] + new Vector3(Mathf.Cos(a) * p.radius * 0.01f, Mathf.Sin(a) * p.radius * 0.01f, 0); } no.AddBoundary(tv); } } return(no); }
public TTFTextOutline ApplyMask(bool [] b) { int cnt = 0; TTFTextOutline r = new TTFTextOutline(); foreach (Boundary cb in boundaries) { List <Vector3> nb = new List <Vector3> (); foreach (Vector3 v in cb) { if (b [cnt++]) { nb.Add(v); } } if (nb.Count > 0) { r.AddBoundary(nb); } } r.advance = advance; return(r); }
/// <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; }
public override TTFTextOutline Apply(TTFTextOutline outline, object parameters) { float rotate; float strength = (parameters as Parameters).Amount; strength /= 40f; //Vector3 so = new Vector3(strength/2f,strength/2f,0); //Vector3 so = new Vector3 (strength, strength, 0); Vector3 tr = Vector3.zero; Vector3 so = Vector3.zero; if (Mathf.Abs(strength) < 0.001f) { return(new TTFTextOutline(outline)); } int orientation = 1; if (orientation == 1) // True type ? { rotate = -Mathf.PI / 2; } else { rotate = Mathf.PI / 2; } TTFTextOutline r = new TTFTextOutline(); foreach (Boundary cb in outline.boundaries) { int clen = cb.Count; Vector3 [] nb = new Vector3 [clen]; if (clen > 0) { Vector3 pv = cb [clen - 1], v = cb [0], nv; for (int ctr = 0; ctr < (clen + 20); ctr++) { nv = cb [(ctr + 1) % clen]; bool skip_this_vertex = false; // We have actually keep all vertice // because extrusion rely on all outline having the same num of vertices if ((nv - v).magnitude < 0.001f) { if (ctr == 0) { //nb [0] = (v + so + tr); nb [ctr % clen] = (v + so); } else { nb [ctr % clen] = nb [(ctr - 1) % clen]; } skip_this_vertex = true; } if (!skip_this_vertex) { Vector2 d1 = v - pv; Vector3 d2 = nv - v; Vector3 d3; float angle_in = Mathf.Atan2(d1.x, d1.y); float angle_out = Mathf.Atan2(d2.x, d2.y); float angle_diff2 = ((angle_out - angle_in + 3 * Mathf.PI) % (Mathf.PI * 2) - Mathf.PI) / 2f; float scale = Mathf.Sign(Mathf.Cos(angle_diff2)); // * Mathf.Cos( angle_diff2/8 ); //float scale=Mathf.Tan(Mathf.Cos(angle_diff2)*1000)/Mathf.PI; //if (scale==0) {scale=1;} scale = 1; //float e = angle_in /*+ rotate*/ + angle_diff2; float e = angle_in + rotate + angle_diff2; // we progress in the direction of the bissetrix //d3=(new Vector3(Mathf.Cos(-e),Mathf.Sin(-e)))/strength; //d3=(new Vector3(Mathf.Cos(-e),Mathf.Sin(-e)))*strength; //d3=nv-pv;d3.Normalize(); //d3=(new Vector3(Mathf.Cos(-e),Mathf.Sin(-e)))*(strength / scale); //d3=(new Vector3(Mathf.Cos(-e),Mathf.Sin(-e)))*strength; d3 = (new Vector3(Mathf.Cos(-e), Mathf.Sin(-e))) * (strength * scale); tr = new Vector2(-d3.y, d3.x); nb [ctr % clen] = (v + so + tr); //nb [ctr % clen] =v+so; //nb [ctr % clen] = (v + tr); //} pv = v; v = nv; } } } if (nb.Length > 0) { r.AddBoundary(nb); } } r.advance = outline.advance; //Debug.Log(r.MaxDist()); //Debug.Log(r.boundaries) //r.Check(); return(r); }
public override TTFTextOutline Apply(TTFTextOutline outline, object parameters) { Parameters p = (parameters as Parameters); TTFTextOutline no = new TTFTextOutline(); //Vector3 [] tv=new Vector3[p.interpolation]; foreach (Boundary v in outline.boundaries) { float [] cumdist = v.cumDists(); Vector3 [] sg = new Vector3[p.interpolation]; Vector3 [] sr = new Vector3[p.interpolation]; Vector3 [] si = new Vector3[p.interpolation]; Vector3 [] sm = new Vector3[p.interpolation]; Vector3 [] sp = new Vector3[p.interpolation]; //Debug.Log(cumdist[cumdist.Length-1]); for (int i = 0; i < p.interpolation; ++i) { sg[i] = v.interpolatePosition1(cumdist, (((float)i) / ((float)(p.interpolation - 1))) ); } float sf = (2 * Mathf.PI) / ((float)p.interpolation); float af = 1f / ((float)p.interpolation); for (int i = 0; i < p.interpolation; ++i) { for (int j = 0; j < p.interpolation; ++j) { sr[i] += af * Mathf.Cos(j * i * sf) * sg[j]; si[i] += af * Mathf.Sin(j * i * sf) * sg[j]; } float q = p.ac.GetAnimcurve().Evaluate(1 - Mathf.Abs((((float)i) / p.interpolation) * 2 - 1)); sm[i] = new Vector3( Mathf.Sqrt(sr[i].x * sr[i].x + si[i].x * si[i].x) * q, Mathf.Sqrt(sr[i].y * sr[i].y + si[i].y * si[i].y) * q, Mathf.Sqrt(sr[i].z * sr[i].z + si[i].z * si[i].z) * q); sp[i] = new Vector3( (sm[i].x != 0)?Mathf.Atan2(si[i].x, sr[i].x):0, (sm[i].y != 0)?Mathf.Atan2(si[i].y, sr[i].y):0, (sm[i].z != 0)?Mathf.Atan2(si[i].z, sr[i].z):0 ) ; } for (int j = 0; j < p.interpolation; ++j) { sg[j] = Vector3.zero; } for (int i = 0; i < p.interpolation; ++i) { for (int j = 0; j < p.interpolation; ++j) { float alphax = sp[j].x + i * j * sf; float alphay = sp[j].y + i * j * sf; float alphaz = sp[j].z + i * j * sf; sg[i] += /*af**/ new Vector3( Mathf.Cos(alphax) * sm[j].x /*+Mathf.Sin(alphax)*sm[i].x*/, Mathf.Cos(alphay) * sm[j].y /*+Mathf.Sin(alphay)*sm[i].y*/, Mathf.Cos(alphaz) * sm[j].z /*+Mathf.Sin(alphaz)*sm[i].z*/ ) ; } } no.AddBoundary(sg); } //Debug.Log(no.Min); //Debug.Log(no.Max); return(no); }
public override TTFTextOutline Apply(TTFTextOutline outline, object parameters) { float rotate; int octr = 0; float strength = (parameters as Parameters).Amount; int interpolation = (parameters as Parameters).Interpolation; strength /= 40f; //Vector3 so = new Vector3(strength/2f,strength/2f,0); //Vector3 so = new Vector3 (strength, strength, 0); Vector3 tr = Vector3.zero; Vector3 so = Vector3.zero; if (Mathf.Abs(strength) < 0.001f) { return(new TTFTextOutline(outline)); } int orientation = 1; if (orientation == 1) // True type ? { rotate = -Mathf.PI / 2; } else { rotate = Mathf.PI / 2; } TTFTextOutline r = new TTFTextOutline(); foreach (Boundary cb in outline.boundaries) { int clen = cb.Count; Vector3 [] nb = new Vector3 [clen * interpolation]; if (clen > 0) { Vector3 pv = cb [clen - 1], v = cb [0], nv; for (int ctr = 0; ctr < (clen + 20); ctr++) { nv = cb [(ctr + 1) % clen]; bool skip_this_vertex = false; // We have actually keep all vertice // because extrusion rely on all outline having the same num of vertices if ((nv - v).magnitude < 0.001f) { if (ctr == 0) { //nb [0] = (v + so + tr); for (int ci = 0; ci < interpolation; ci++) { nb [octr++ % (clen * interpolation)] = (v + so); } } else { for (int ci = 0; ci < interpolation; ci++) { nb [octr++ % (clen * interpolation)] = nb [(ctr - 1) % clen]; } } skip_this_vertex = true; } if (!skip_this_vertex) { Vector2 d1 = v - pv; Vector3 d2 = nv - v; Vector3 d3; float angle_in = Mathf.Atan2(d1.x, d1.y); float angle_out = Mathf.Atan2(d2.x, d2.y); for (int ci = 0; ci < interpolation; ci++) { float angle_diff2 = ((angle_out - angle_in + 3 * Mathf.PI) % (Mathf.PI * 2) - Mathf.PI) * ((float)(1 + ci)) / (1 + interpolation); float scale = Mathf.Sign(Mathf.Cos(angle_diff2)); // * Mathf.Cos( angle_diff2/8 ); scale = 1; float e = angle_in + rotate + angle_diff2; d3 = (new Vector3(Mathf.Cos(-e), Mathf.Sin(-e))) * (strength * scale); tr = new Vector2(-d3.y, d3.x); nb [octr++ % (clen * interpolation)] = (v + so + tr); } pv = v; v = nv; } } } if (nb.Length > 0) { r.AddBoundary(nb); } } r.advance = outline.advance; return(r); }