/// <inheritdoc /> public Size MeasureText(string text, ITextPaint paint) { using var skPaint = GetSkiaTextPaint(paint); var bounds = new SKRect(); skPaint.MeasureText(text, ref bounds); return(new Size(bounds.Width, bounds.Height)); }
/// <summary> /// Gets Skia text paint. /// </summary> /// <param name="paint">Waves's paint.</param> /// <returns>Skia text paint.</returns> private SKPaint GetSkiaTextPaint(ITextPaint paint) { return(new SKPaint { TextSize = paint.TextStyle.FontSize, Color = paint.Fill.ToSkColor(), IsStroke = false, SubpixelText = true, IsAntialias = true, TextAlign = paint.TextStyle.Alignment.ToSkTextAlign(), Typeface = SKTypeface.FromFamilyName(paint.TextStyle.FontFamily) }); }
/// <inheritdoc /> public Size MeasureText(string text, ITextPaint paint) { var textBlock = new TextBlock { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Text = text, Foreground = new SolidColorBrush(paint.Fill.ToSystemColor()), FontSize = paint.TextStyle.FontSize, FontFamily = new FontFamily(paint.TextStyle.FontFamily), TextAlignment = paint.TextStyle.Alignment.ToSystemTextAlignment(), Opacity = paint.Opacity }; textBlock.Measure(new global::System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity)); textBlock.Arrange(new Rect(0, 0, textBlock.DesiredSize.Width, textBlock.DesiredSize.Height)); return(new Size(Convert.ToSingle(textBlock.ActualWidth), Convert.ToSingle(textBlock.ActualHeight))); }
/// <inheritdoc /> public void DrawText(Point location, string text, ITextPaint paint) { var textBlock = new TextBlock { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Text = text, Foreground = new SolidColorBrush(paint.Fill.ToSystemColor()), FontSize = paint.TextStyle.FontSize, FontFamily = new FontFamily(paint.TextStyle.FontFamily), Margin = new Thickness(location.X, location.Y, 0, 0), TextAlignment = paint.TextStyle.Alignment.ToSystemTextAlignment(), Opacity = paint.Opacity }; textBlock.Measure(new global::System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity)); textBlock.Arrange(new Rect(0, 0, textBlock.DesiredSize.Width, textBlock.DesiredSize.Height)); textBlock.Margin = new Thickness(location.X, location.Y - textBlock.ActualHeight, 0, 0); Canvas.Children.Add(textBlock); }
/// <inheritdoc /> public void DrawText(Point location, string text, ITextPaint paint) { using var skPaint = GetSkiaTextPaint(paint); Surface.Canvas.DrawText(text, location.ToSkPoint(), skPaint); }