/// <summary> /// Render a string from an atlas. /// </summary> /// <param name="position">The top left position of where to start drawing the string.</param> /// <param name="color">The text color.</param> /// <param name="text">The text itself.</param> /// <param name="atlas">The font atlas to use.</param> /// <param name="layouter">The layouter to use.</param> /// <param name="effect">Effect to apply</param> /// <param name="effectAmount">The effect amount.</param> /// <param name="effectColor">The effect color.</param> public void RenderString( Vector3 position, Color color, string text, DrawableFontAtlas atlas, TextLayouter layouter = null, FontEffect effect = FontEffect.None, float effectAmount = 0f, Color?effectColor = null) { layouter ??= new TextLayouter(atlas); atlas.SetupDrawing(this, text, effect, effectAmount, effectColor); var reUsableVector = new Vector3(); foreach (char c in text) { Vector2 gPos = layouter.AddLetter(c, out DrawableGlyph g); if (g == null || g.GlyphUV == Rectangle.Empty) { continue; } reUsableVector.X = gPos.X; reUsableVector.Y = gPos.Y; atlas.DrawGlyph(this, g, position + reUsableVector, color); } atlas.FinishDrawing(this); }
protected override void OnAttached() { if (Element is Label == false) { return; } var label = Control as TextView; oldFont = label.Typeface; string fontName = FontEffect.GetFontName(Element); var font = Typeface.CreateFromAsset(Android.App.Application.Context.Assets, fontName);// "materialdesignicons-webfont.ttf"); label.Typeface = font; }