/// <summary> /// 创建画笔 /// </summary> /// <param name="color"></param> /// <param name="fontSize"></param> /// <returns></returns> private static SKPaint CreatePaint(SKColor color, float fontSize) { SkiaSharp.SKTypeface font = SKTypeface.FromFamilyName(null, SKFontStyleWeight.Normal, SKFontStyleWidth.ExtraCondensed, SKFontStyleSlant.Upright); SKPaint paint = new SKPaint(); paint.IsAntialias = true; paint.Color = color; paint.Typeface = font; paint.TextSize = fontSize; return(paint); }
public static SKPaint CreatePaint(SKColor color, string fontName, float fontSize, SKTypefaceStyle fontStyle) { SkiaSharp.SKTypeface font = SkiaSharp.SKTypeface.FromFamilyName(fontName, fontStyle); SKPaint paint = new SKPaint(); paint.IsAntialias = true; paint.Color = color; // paint.StrokeCap = SKStrokeCap.Round; paint.Typeface = font; paint.TextSize = fontSize; return(paint); }
} // End Function MeasureText public static void DrawText(SKCanvas canvas, string text, SKColor color, string fontName, float fontSize, SKTypefaceStyle fontStyle) { using (SkiaSharp.SKTypeface font = SkiaSharp.SKTypeface.FromFamilyName(fontName, fontStyle)) { using (SKPaint paint = new SKPaint()) { paint.IsAntialias = true; paint.Color = color; // paint.StrokeCap = SKStrokeCap.Round; paint.Typeface = font; paint.TextSize = fontSize; canvas.DrawText(text, 10, 10, paint); } // End Using paint } // End Using font } // End Function MeasureText
} // End Function MeasureText // MeasureText("Impact", 12, SKTypefaceStyle.Bold); public static SkiaSharp.SKRect MeasureText(string text, string fontName, float fontSize, SKTypefaceStyle fontStyle) { SkiaSharp.SKRect rect = new SKRect(); using (SkiaSharp.SKTypeface font = SkiaSharp.SKTypeface.FromFamilyName(fontName, fontStyle)) { using (SKPaint paint = new SKPaint()) { paint.IsAntialias = true; // paint.Color = new SKColor(0x2c, 0x3e, 0x50); // paint.StrokeCap = SKStrokeCap.Round; paint.Typeface = font; paint.TextSize = fontSize; paint.MeasureText(text, ref rect); } // End Using paint } // End Using font return(rect); } // End Function MeasureText
public static SKTypeface FromTypeface (SKTypeface typeface, SKTypefaceStyle style = SKTypefaceStyle.Normal) { if (typeface == null) throw new ArgumentNullException (nameof (typeface)); return GetObject<SKTypeface> (SkiaApi.sk_typeface_create_from_typeface (typeface.Handle, style)); }
public static SKTypeface FromData(SKData data, int index = 0) { return(SKTypeface.FromStream(new SKMemoryStream(data), index)); }
static SKTypeface() { defaultTypeface = new SKTypefaceStatic(SkiaApi.sk_typeface_ref_default()); }