/// <summary> /// Create a SkiaSharp paint object to paint the ink stroke /// </summary> /// <param name="stroke">an ink stroke</param> /// <param name="paintStyle">the paint style (default is /// <see cref="SKPaintStyle.Stroke"/>)</param> /// <param name="blendMode">the pencil drawing blend mode (default is /// <see cref="SKBlendMode.SrcATop"/></param> /// <returns>a tuple with the<see cref="SKPaint"/> object and any /// disposable objects that need to be managed</returns> public static Tuple <SKPaint, IEnumerable <IDisposable> > CreatePaint(this XInkStroke stroke, SKPaintStyle paintStyle = SKPaintStyle.Stroke, SKBlendMode blendMode = SKBlendMode.SrcATop) { if (stroke == null) { throw new ArgumentNullException(nameof(stroke)); } var disposables = new List <IDisposable>(); SKShader shader = null; if (stroke.DrawingAttributes.Kind == XInkDrawingAttributesKind.Pencil) { var perlin = SKShader.CreatePerlinNoiseFractalNoise(0.01f, 0.01f, 1, 1.0f); var color = SKShader.CreateColor(stroke.DrawingAttributes.Color.ToSKColor().WithAlpha(0x7F)); disposables.Add(perlin); disposables.Add(color); shader = SKShader.CreateCompose( perlin, color, blendMode); } Tuple <SKPaint, IEnumerable <IDisposable> > tuple = null; SKPaint paint = null; if (!stroke.DrawingAttributes.IgnorePressure) { paintStyle = SKPaintStyle.Fill; } try { paint = new SKPaint { Color = stroke.DrawingAttributes.Kind == XInkDrawingAttributesKind.Default ? stroke.DrawingAttributes.Color.ToSKColor() : new SKColor(), StrokeWidth = stroke.DrawingAttributes.IgnorePressure ? stroke.DrawingAttributes.Size : 0.0f, Style = paintStyle, IsAntialias = true, StrokeCap = stroke.DrawingAttributes.PenTip == Inking.XPenTipShape.Circle ? SKStrokeCap.Round : SKStrokeCap.Butt, PathEffect = SKPathEffect.CreateCorner(100) }; if (shader != null) { paint.Shader = shader; } tuple = Tuple.Create(paint, disposables as IEnumerable <IDisposable>); paint = null; } finally { paint?.Dispose(); } return(tuple); }
SKSize MeasureAndPaint(SKCanvas canvas, SKMatrix matrix, SKPoint location, bool doPaint) { float[] values = matrix.Values; string[] texts = new string[9]; SKRect[] bounds = new SKRect[9]; float[] widths = new float[3]; for (int i = 0; i < 9; i++) { int row = i % 3; int col = i / 3; // Format string differently based on row texts[i] = values[i].ToString(row == 2 ? "F0" : (col == 2 ? PerspectiveFormat : "F2")); // Measure string with a '-' even if one is not present bool isNegative = texts[i][0] == '-'; string text = (isNegative ? "" : "-") + texts[i]; MatrixPaint.MeasureText(text, ref bounds[i]); // Get maximum width for each column widths[col] = Math.Max(widths[col], bounds[i].Width); // Measure the text again without the '-' in front MatrixPaint.MeasureText(texts[i], ref bounds[i]); } // Some formatting constants float horzGap = MatrixPaint.TextSize; float horzMarg = MatrixPaint.TextSize; float vertMarg = MatrixPaint.FontSpacing / 4; // Calculate the total width and height of the matrix display float totalWidth = widths[0] + widths[1] + widths[2] + 2 * horzGap + 2 * horzMarg; float totalHeight = 3 * MatrixPaint.FontSpacing + 2 * vertMarg; if (doPaint) { SKPaintStyle saveStyle = MatrixPaint.Style; for (int i = 0; i < 9; i++) { int row = i % 3; int col = i / 3; // Find x, y of upper-left corner of text float x = location.X + horzMarg; for (int c = 0; c < col; c++) { x += widths[c] + horzGap; } float y = location.Y + vertMarg + row * MatrixPaint.FontSpacing; // Adjust for right-justified text x += widths[col] - bounds[i].Width; y += (MatrixPaint.FontSpacing - bounds[i].Height) / 2 - bounds[i].Top; // Draw the text MatrixPaint.Style = SKPaintStyle.Fill; canvas.DrawText(texts[i], x, y, MatrixPaint); } // Display vertical lines at the sides of the matrix MatrixPaint.Style = SKPaintStyle.Stroke; canvas.DrawLine(location.X + horzMarg / 2, location.Y + vertMarg, location.X + horzMarg / 2, location.Y + totalHeight - vertMarg, MatrixPaint); canvas.DrawLine(location.X + totalWidth - horzMarg / 2, location.Y + vertMarg, location.X + totalWidth - horzMarg / 2, location.Y + totalHeight - vertMarg, MatrixPaint); MatrixPaint.Style = saveStyle; } return(new SKSize(totalWidth, totalHeight)); }
protected BaseTextStyle(SKPaintStyle paintStyle) { SKPaintStyle = paintStyle; }
public extern static void sk_paint_set_style(sk_paint_t t, SKPaintStyle style);
public DefaultPaintStyleAttribute(SKPaintStyle fill, bool antialias = true) { Fill = fill; Antialias = antialias; }
public YCircle(SKPoint center, float radius, SKColor color, float strokeWidth, SKPaintStyle paintStyle) { Center = center; Radius = radius; Paint = new SKPaint { Style = paintStyle, Color = color, StrokeWidth = strokeWidth }; }