FromFamilyName() public static méthode

public static FromFamilyName ( string familyName, SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant ) : SKTypeface
familyName string
weight SKFontStyleWeight
width SKFontStyleWidth
slant SKFontStyleSlant
Résultat SKTypeface
Exemple #1
0
        public static void UnicodeText(SKCanvas canvas, int width, int height)
        {
            // stops at 0x530 on Android
            string text = "\u03A3 and \u0750";

            using (var paint = new SKPaint())
                using (var tf = SKTypeface.FromFamilyName("Tahoma")) {
                    canvas.DrawColor(SKColors.White);

                    paint.IsAntialias = true;
                    paint.TextSize    = 60;
                    paint.Typeface    = tf;
                    canvas.DrawText(text, 50, 100, paint);
                }


            using (var paint = new SKPaint())
                using (var tf = SKTypeface.FromFamilyName("Times New Roman")) {
                    paint.Color = XamDkBlue;

                    paint.IsAntialias = true;
                    paint.TextSize    = 60;
                    paint.Typeface    = tf;
                    canvas.DrawText(text, 50, 200, paint);
                }
        }
Exemple #2
0
        public static void BitmapDecoder(SKCanvas canvas, int width, int height)
        {
            var assembly  = typeof(Demos).GetTypeInfo().Assembly;
            var imageName = assembly.GetName().Name + ".color-wheel.png";

            canvas.Clear(SKColors.White);

            // load the embedded resource stream
            using (var resource = assembly.GetManifestResourceStream(imageName))
                using (var stream = new SKManagedStream(resource))
                    using (var decoder = new SKImageDecoder(stream))
                        using (var paint = new SKPaint())
                            using (var tf = SKTypeface.FromFamilyName("Arial"))
                            {
                                paint.IsAntialias = true;
                                paint.TextSize    = 14;
                                paint.Typeface    = tf;
                                paint.Color       = SKColors.Black;

                                // read / set decoder settings
                                decoder.DitherImage            = true;
                                decoder.PreferQualityOverSpeed = true;
                                decoder.SampleSize             = 2;

                                // decode the image
                                using (var bitmap = new SKBitmap())
                                {
                                    var result = decoder.Decode(stream, bitmap);
                                    if (result != SKImageDecoderResult.Failure)
                                    {
                                        var info = bitmap.Info;
                                        var x    = 25;
                                        var y    = 25;

                                        canvas.DrawBitmap(bitmap, x, y);
                                        x += info.Width + 25;
                                        y += 14;

                                        canvas.DrawText(string.Format("Result: {0}", result), x, y, paint);
                                        y += 20;

                                        canvas.DrawText(string.Format("Size: {0}px x {1}px", bitmap.Width, bitmap.Height), x, y, paint);
                                        y += 20;

                                        canvas.DrawText(string.Format("Pixels: {0} @ {1}b/px", bitmap.Pixels.Length, bitmap.BytesPerPixel), x, y, paint);
                                    }
                                }
                            }
        }
Exemple #3
0
        private void ReadFontAttributes(XElement e, SKPaint paint)
        {
            var fontStyle = ReadStyle(e);

            string ffamily;

            if (!fontStyle.TryGetValue("font-family", out ffamily) || string.IsNullOrWhiteSpace(ffamily))
            {
                ffamily = paint.Typeface?.FamilyName;
            }
            var fweight = ReadFontWeight(fontStyle, paint.Typeface?.FontWeight ?? (int)SKFontStyleWeight.Normal);
            var fwidth  = ReadFontWidth(fontStyle, paint.Typeface?.FontWidth ?? (int)SKFontStyleWidth.Normal);
            var fstyle  = ReadFontStyle(fontStyle, paint.Typeface?.FontSlant ?? SKFontStyleSlant.Upright);

            paint.Typeface = SKTypeface.FromFamilyName(ffamily, fweight, fwidth, fstyle);

            string fsize;

            if (fontStyle.TryGetValue("font-size", out fsize) && !string.IsNullOrWhiteSpace(fsize))
            {
                paint.TextSize = ReadNumber(fsize);
            }
        }