/// <summary> /// Converts a pen to a Direct2D stroke style. /// </summary> /// <param name="pen">The pen to convert.</param> /// <param name="factory">The factory associated with this resource.</param> /// <returns>The Direct2D brush.</returns> public static StrokeStyle ToDirect2DStrokeStyle(this Avalonia.Media.IPen pen, Factory factory) { var d2dLineCap = pen.LineCap.ToDirect2D(); var properties = new StrokeStyleProperties { DashStyle = DashStyle.Solid, MiterLimit = (float)pen.MiterLimit, LineJoin = pen.LineJoin.ToDirect2D(), StartCap = d2dLineCap, EndCap = d2dLineCap, DashCap = d2dLineCap }; float[] dashes = null; if (pen.DashStyle?.Dashes != null && pen.DashStyle.Dashes.Count > 0) { properties.DashStyle = DashStyle.Custom; properties.DashOffset = (float)pen.DashStyle.Offset; dashes = pen.DashStyle.Dashes.Select(x => (float)x).ToArray(); } dashes = dashes ?? Array.Empty <float>(); return(new StrokeStyle(factory, properties, dashes)); }
/// <inheritdoc/> public bool StrokeContains(Avalonia.Media.IPen pen, Point point) { return(Geometry.StrokeContainsPoint(point.ToSharpDX(), (float)(pen?.Thickness ?? 0))); }
/// <inheritdoc/> public Rect GetRenderBounds(Avalonia.Media.IPen pen) { return(Geometry.GetWidenedBounds((float)(pen?.Thickness ?? 0)).ToAvalonia()); }
/// <summary> /// Converts a pen to a Direct2D stroke style. /// </summary> /// <param name="pen">The pen to convert.</param> /// <param name="renderTarget">The render target.</param> /// <returns>The Direct2D brush.</returns> public static StrokeStyle ToDirect2DStrokeStyle(this Avalonia.Media.IPen pen, SharpDX.Direct2D1.RenderTarget renderTarget) { return(pen.ToDirect2DStrokeStyle(renderTarget.Factory)); }