protected void CreateTextBitmaps(int width, int height)
                {
                    // create a 32bit text bmp that will store the rendered text.
                    TextBmp = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);

                    // create a canvas and place the TextBmp as its target
                    Android.Graphics.Canvas canvas = new Android.Graphics.Canvas(TextBmp);

                    // render our text (which will put it into the TextBmp buffer)
                    base.OnDraw(canvas);

                    // set the TextPaint's shader to render with the Text we just rendered
                    TextPaint.SetShader(new BitmapShader(TextBmp, Shader.TileMode.Clamp, Shader.TileMode.Clamp));
                }
Example #2
0
        private static TextPaint InnerBuildPaint(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Color foreground, Shader shader, BaseLineAlignment baselineAlignment, TextDecorations textDecorations)
        {
            var paint = new TextPaint(PaintFlags.AntiAlias);

            var paintSpecs = BuildPaintValueSpecs(fontSize, characterSpacing);

            paint.Density        = paintSpecs.density;
            paint.TextSize       = paintSpecs.textSize;
            paint.UnderlineText  = (textDecorations & TextDecorations.Underline) == TextDecorations.Underline;
            paint.StrikeThruText = (textDecorations & TextDecorations.Strikethrough) == TextDecorations.Strikethrough;
            if (shader != null)
            {
                paint.SetShader(shader);
            }

            if (baselineAlignment == BaseLineAlignment.Superscript)
            {
                paint.BaselineShift += (int)(paint.Ascent() / 2);
            }

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                paint.LetterSpacing = paintSpecs.letterSpacing;
            }
            else
            {
                LogCharacterSpacingNotSupported();
            }

            var typefaceStyle = TypefaceStyleHelper.GetTypefaceStyle(fontStyle, fontWeight);
            var typeface      = FontHelper.FontFamilyToTypeFace(fontFamily, fontWeight, typefaceStyle);

            paint.SetTypeface(typeface);
            paint.Color = foreground;

            return(paint);
        }