/// <summary> /// Draws a polyline. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param> public abstract void DrawLine( IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased);
public void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { var e = new Polyline(); if (stroke != null && thickness > 0) { e.Stroke = GetCachedBrush(stroke); switch (lineJoin) { case LineJoin.Round: e.StrokeLineJoin = PenLineJoin.Round; break; case LineJoin.Bevel: e.StrokeLineJoin = PenLineJoin.Bevel; break; // The default StrokeLineJoin is Miter } if (thickness != 1) // default values is 1 e.StrokeThickness = thickness; if (dashArray != null) e.StrokeDashArray = new DoubleCollection(dashArray); } // pl.Fill = null; if (aliased) e.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased); var pc = new PointCollection(points.Count); foreach (var p in points) pc.Add(ToPoint(p)); e.Points = pc; Add(e); }
/// <summary> /// Draws a polyline. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param> /// <param name="dashArray">The dash array (in device independent units, 1/96 inch). Use <c>null</c> to get a solid line.</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param> public void DrawLine( IList<ScreenPoint> points, OxyColor stroke, double thickness = 1, double[] dashArray = null, LineJoin lineJoin = LineJoin.Miter, bool aliased = false) { }
/// <summary> /// 在原有波形上添加一条线 /// 不可动态循环 /// </summary> /// <param name="listX">X轴</param> /// <param name="listY">Y轴</param> /// <param name="listColor">线条颜色</param> /// <param name="listWidth">线条宽度</param> /// <param name="listLineJoin">线条连接点</param> /// <param name="listLineCap">线条起始线帽</param> /// <param name="listDrawStyle">线条样式</param> public void f_AddPix(ref List<float> listX, ref List<float> listY, Color listColor, int listWidth, LineJoin listLineJoin, LineCap listLineCap, DrawStyle listDrawStyle) { //装载 _listX.Add(listX); _listY.Add(listY); _listColor.Add(listColor); _listWidth.Add(listWidth); _listLineJoin.Add(listLineJoin); _listLineCap.Add(listLineCap); _listDrawStyle.Add(listDrawStyle); }
/// <summary> /// Initializes a new instance of the <see cref="OxyPen" /> class. /// </summary> /// <param name="color">The color.</param> /// <param name="thickness">The thickness.</param> /// <param name="lineStyle">The line style.</param> /// <param name="lineJoin">The line join.</param> public OxyPen( OxyColor color, double thickness = 1.0, LineStyle lineStyle = LineStyle.Solid, LineJoin lineJoin = LineJoin.Miter) { this.Color = color; this.Thickness = thickness; this.DashArray = lineStyle.GetDashArray(); this.LineStyle = lineStyle; this.LineJoin = lineJoin; }
void SetDataSource(LineJoin selected) { this.BeginUpdate(); Items.Clear(); foreach (LineJoin o in Enum.GetValues(typeof(LineJoin))) Items.Add(o); SelectedItem = selected; this.EndUpdate(); }
public StrokeMath() { m_width = 0.5; m_width_abs = 0.5; m_width_eps = 0.5 / 1024.0; m_width_sign = 1; m_miter_limit = 4.0; m_inner_miter_limit = 1.01; m_approx_scale = 1.0; m_line_cap = LineCap.Butt; m_line_join = LineJoin.Miter; m_inner_join = InnerJoin.Miter; }
public Pen (Brush brush, float width) { _brush = (Brush)brush.Clone();; _width = width; _dashStyle = DashStyle.Solid; _startCap = LineCap.Flat; _dashCap = DashCap.Flat; _endCap = LineCap.Flat; _alignment = PenAlignment.Center; _lineJoin = LineJoin.Miter; _miterLimit = 10f; _transform = new Matrix(); }
// Methods public Stroke() { this.pen = Pens.Black; this.brush = new SolidColor(Color.Empty); this.strokeColor = Color.Empty; this.Width = 1f; this.Linecap = LineCap.Square; this.Linejoin = LineJoin.Miter; this.MiterLimit = 4; this.DashArray = null; this.DashOffset = 0f; this.Opacity = 1f; }
/// <summary> /// 清空原有数据并加载一条波形数据 /// </summary> /// <param name="listX">X轴</param> /// <param name="listY">Y轴</param> /// <param name="listColor">线条颜色</param> /// <param name="listWidth">线条宽度</param> /// <param name="listLineJoin">线条连接点</param> /// <param name="listLineCap">线条起始线帽</param> /// <param name="listDrawStyle">线条样式</param> public void f_LoadOnePix(ref List<float> listX, ref List<float> listY, Color listColor, int listWidth, LineJoin listLineJoin, LineCap listLineCap,DrawStyle listDrawStyle) { //重新初始化 f_ClearAllPix(); //装载 _listX.Add(listX); _listY.Add(listY); _listColor.Add(listColor); _listWidth.Add(listWidth); _listLineJoin.Add(listLineJoin); _listLineCap.Add(listLineCap); _listDrawStyle.Add(listDrawStyle); }
// Map the join style from "System.Drawing" to "Xsharp". private static JoinStyle MapJoinStyle(LineJoin style) { switch(style) { case LineJoin.Miter: case LineJoin.MiterClipped: default: return JoinStyle.JoinMiter; case LineJoin.Bevel: return JoinStyle.JoinBevel; case LineJoin.Round: return JoinStyle.JoinRound; } }
public Stroke(ISvgBrush brush) { this.pen = brush.Pen; //this.brush = new SolidColor(pen.Color); this.strokeColor = pen.Color; this.Width = 1f; this.Linecap = LineCap.Square; this.Linejoin = LineJoin.Miter; this.MiterLimit = 4; this.DashArray = null; this.DashOffset = 0f; this.Opacity = 1f; this.brush = brush.Clone(); }
public void DrawLines(IEnumerable<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { var startPoint = new ScreenPoint(); bool first = true; foreach (var p in points) { if (!first) { Add(new Line { X1 = startPoint.X, Y1 = startPoint.Y, X2 = p.X, Y2 = p.Y }); } else { startPoint = p; } first = !first; } }
private static Pen CreatePen(OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin = LineJoin.Miter) { if (stroke == null) return null; var pen = new Pen(stroke.ToBrush(), thickness); if (dashArray != null) { pen.DashStyle = new DashStyle(dashArray, 0); } switch (lineJoin) { case LineJoin.Round: pen.LineJoin = PenLineJoin.Round; break; case LineJoin.Bevel: pen.LineJoin = PenLineJoin.Bevel; break; // The default LineJoin is Miter } return pen; }
/// <summary> /// Creates a new line2D. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="color"></param> /// <param name="width"></param> /// <param name="lineJoin"></param> /// <param name="dashes"></param> public Line2D(double[] x, double[] y, int color, float width, LineJoin lineJoin, int[] dashes) { this.X = x; this.Y = y; this.Color = color; this.Width = width; this.LineJoin = lineJoin; this.Dashes = dashes; MinX = int.MaxValue; MaxX = int.MinValue; for (int idx = 0; idx < x.Length; idx++) { if (x[idx] > MaxX) { MaxX = x[idx]; } if (x[idx] < MinX) { MinX = x[idx]; } } MinY = int.MaxValue; MaxY = int.MinValue; for (int idx = 0; idx < y.Length; idx++) { if (y[idx] > MaxY) { MaxY = y[idx]; } if (y[idx] < MinY) { MinY = y[idx]; } } this.MinZoom = float.MinValue; this.MaxZoom = float.MaxValue; }
public void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { var pen = CreatePen(stroke, thickness, dashArray, lineJoin); // todo: alias line // if (aliased) // .SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased); var lp = new Point(); int i = 0; foreach (var point in points) { var p = point.ToPoint(); if (i > 0) { dc.DrawLine(pen, lp, p); } i++; lp = p; } }
internal static extern Status GdipGetCustomLineCapStrokeJoin (IntPtr customCap, out LineJoin lineJoin);
/// <summary> /// Draws a polyline. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param> public override void DrawLine(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { if (stroke.IsVisible() && thickness > 0) { this.SetAlias(aliased); this.SetStroke(stroke, thickness, dashArray, lineJoin); using (var path = new CGPath()) { var convertedPoints = (aliased ? points.Select(p => p.ConvertAliased()) : points.Select(p => p.Convert())).ToArray(); path.AddLines(convertedPoints); this.gctx.AddPath(path); } this.gctx.DrawPath(CGPathDrawingMode.Stroke); } }
/// <summary> /// Draws a line on the target. The coordinates given are scene coordinates. /// </summary> protected override void DrawLine(Target2DWrapper <global::Android.Graphics.Canvas> target, double[] x, double[] y, int color, double width, LineJoin lineJoine, int[] dashes) { if (x.Length > 1) { _paint.AntiAlias = true; _paint.SetStyle(global::Android.Graphics.Paint.Style.Stroke); if (dashes != null && dashes.Length > 0) { // set the dashes effect. float[] intervals = new float[dashes.Length]; for (int idx = 0; idx < dashes.Length; idx++) { intervals [idx] = dashes [idx]; } _paint.SetPathEffect( new global::Android.Graphics.DashPathEffect( intervals, 0)); } float minX = float.MaxValue, maxX = float.MinValue, minY = float.MaxValue, maxY = float.MinValue; float xT, yT; // convert to the weid android api array! _path.Rewind(); this.Transform(x [0], y [0], _transformed1); xT = (float)_transformed1 [0]; yT = (float)_transformed1 [1]; _path.MoveTo(xT, yT); if (xT < minX) { minX = xT; } if (xT > maxX) { maxX = xT; } if (yT < minY) { minY = yT; } if (yT > maxY) { maxY = yT; } for (int idx = 1; idx < x.Length; idx++) { this.Transform(x [idx], y [idx], _transformed1); xT = (float)_transformed1 [0]; yT = (float)_transformed1 [1]; _path.LineTo(xT, yT); if (xT < minX) { minX = xT; } if (xT > maxX) { maxX = xT; } if (yT < minY) { minY = yT; } if (yT > maxY) { maxY = yT; } } if ((maxX - minX) > 1 || (maxY - minY) > 1) { float widthInPixels = this.ToPixels(width) * _scaleFactor; _paint.Color = new global::Android.Graphics.Color(color); _paint.StrokeWidth = widthInPixels; target.Target.DrawPath(_path, _paint); } _paint.Reset(); } }
internal static extern void cairo_set_line_join(IntPtr cr, LineJoin line_join);
/// <summary> /// Adds a line. /// </summary> /// <param name="layer"></param> /// <param name="maxZoom"></param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="color">Color.</param> /// <param name="width">Width.</param> /// <param name="lineJoin"></param> /// <param name="dashes"></param> /// <param name="minZoom"></param> /// <param name="casingWidth"></param> /// <param name="casingColor"></param> public abstract uint AddLine(int layer, float minZoom, float maxZoom, double[] x, double[] y, int color, double width, LineJoin lineJoin, int[] dashes);
public IDrawables <QuantumType> StrokeLineJoin(LineJoin lineJoin) { _drawables.Add(new DrawableStrokeLineJoin(lineJoin)); return(this); }
public void DrawPolygons(System.Collections.Generic.IList <System.Collections.Generic.IList <ScreenPoint> > polygons, OxyColor fill, OxyColor stroke, double thickness = 1, double[] dashArray = null, LineJoin lineJoin = LineJoin.Miter, bool aliased = false) { throw new System.NotImplementedException(); }
void CalcMiter(IVertexDest <T> vc, VertexDist <T> v0, VertexDist <T> v1, VertexDist <T> v2, T dx1, T dy1, T dx2, T dy2, LineJoin lj, T mlimit, T dbevel) { T xi = v1.X; T yi = v1.Y; T di = M.One <T>(); T lim = m_width_abs.Multiply(mlimit); bool miter_limit_exceeded = true; // Assume the worst bool intersection_failed = true; // Assume the worst if (MathUtil.CalcIntersection(v0.X.Add(dx1), v0.Y.Subtract(dy1), v1.X.Add(dx1), v1.Y.Subtract(dy1), v1.X.Add(dx2), v1.Y.Subtract(dy2), v2.X.Add(dx2), v2.Y.Subtract(dy2), out xi, out yi)) { // Calculation of the intersection succeeded //--------------------- di = MathUtil.CalcDistance(v1.X, v1.Y, xi, yi); if (di.LessThanOrEqualTo(lim)) { // Inside the miter limit //--------------------- AddVertex(vc, xi, yi); miter_limit_exceeded = false; } intersection_failed = false; } else { // Calculation of the intersection failed, most probably // the three points lie one straight line. // First check if v0 and v2 lie on the opposite sides of vector: // (v1.x, v1.y) -> (v1.x+dx1, v1.y-dy1), that is, the perpendicular // to the line determined by vertices v0 and v1. // This condition determines whether the next line segments continues // the previous one or goes back. //---------------- T x2 = v1.X.Add(dx1); T y2 = v1.Y.Subtract(dy1); if ((MathUtil.CrossProduct(v0.X, v0.Y, v1.X, v1.Y, x2, y2).LessThan(0.0)) == (MathUtil.CrossProduct(v1.X, v1.Y, v2.X, v2.Y, x2, y2).LessThan(0.0))) { // This case means that the next segment continues // the previous one (straight line) //----------------- AddVertex(vc, v1.X.Add(dx1), v1.Y.Subtract(dy1)); miter_limit_exceeded = false; } } if (miter_limit_exceeded) { // Miter limit exceeded //------------------------ switch (lj) { case LineJoin.MiterJoinRevert: // For the compatibility with SVG, PDF, etc, // we use a simple bevel join instead of // "smart" bevel //------------------- AddVertex(vc, v1.X.Add(dx1), v1.Y.Subtract(dy1)); AddVertex(vc, v1.X.Add(dx2), v1.Y.Subtract(dy2)); break; case LineJoin.MiterJoinRound: CalcArc(vc, v1.X, v1.Y, dx1, dy1.Negative(), dx2, dy2.Negative()); break; default: // If no miter-revert, calculate new dx1, dy1, dx2, dy2 //---------------- if (intersection_failed) { mlimit.MultiplyEquals(m_width_sign); AddVertex(vc, v1.X.Add(dx1).Add(dy1.Multiply(mlimit)), v1.Y.Subtract(dy1).Add(dx1.Multiply(mlimit))); AddVertex(vc, v1.X.Add(dx2).Subtract(dy2.Multiply(mlimit)), v1.Y.Subtract(dy2).Subtract(dx2.Multiply(mlimit))); } else { T x1 = v1.X.Add(dx1); T y1 = v1.Y.Subtract(dy1); T x2 = v1.X.Add(dx2); T y2 = v1.Y.Subtract(dy2); di = lim.Subtract(dbevel).Divide(di.Subtract(dbevel)); AddVertex(vc, x1.Add(xi.Subtract(x1).Multiply(di)), y1.Add(yi.Subtract(y1).Multiply(di))); AddVertex(vc, x2.Add(xi.Subtract(x2).Multiply(di)), y2.Add(yi.Subtract(y2).Multiply(di))); } break; } } }
/// <summary> /// Draws a line on the target. The coordinates given are scene coordinates. /// </summary> /// <param name="target"></param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="color">Color.</param> /// <param name="width">Width.</param> /// <param name="lineJoin"></param> /// <param name="dashes"></param> protected abstract void DrawLine(Target2DWrapper <TTarget> target, double[] x, double[] y, int color, double width, LineJoin lineJoin, int[] dashes);
public void line_join(LineJoin lj) { m_stroker.line_join(lj); }
public void line_join(LineJoin lj) { base.GetGenerator().line_join(lj); }
public DrawableStrokeLineJoin(LineJoin lineJoin) : base(AssemblyHelper.CreateInstance(Types.DrawableStrokeLineJoin, new Type[] { Types.LineJoin }, lineJoin)) { }
/// <summary> /// Adds a new instance of the <see cref="DrawableStrokeLineJoin" /> class to the <see cref="Drawables" />. /// </summary> /// <param name="lineJoin">The line join.</param> /// <returns>The <see cref="Drawables" /> instance.</returns> public Drawables StrokeLineJoin(LineJoin lineJoin) { _drawables.Add(new DrawableStrokeLineJoin(lineJoin)); return(this); }
private static SvgStrokeLineJoin MapLineJoin(LineJoin lineJoin) { switch (lineJoin) { case LineJoin.Beveled: return SvgStrokeLineJoin.Bevel; case LineJoin.Miter: return SvgStrokeLineJoin.Miter; default: return SvgStrokeLineJoin.Round; } }
/// <summary> /// Draws multiple line segments defined by points (0,1) (2,3) (4,5) etc. /// This should have better performance than calling DrawLine for each segment. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">If set to <c>true</c> the shape will be aliased.</param> public override void DrawLineSegments(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { this.paint.Reset(); { this.SetStroke(stroke, thickness, dashArray, lineJoin, aliased); this.pts.Clear(); if (aliased) { foreach (var p in points) { this.pts.Add(this.ConvertAliased(p.X)); this.pts.Add(this.ConvertAliased(p.Y)); } } else { foreach (var p in points) { this.pts.Add(this.Convert(p.X)); this.pts.Add(this.Convert(p.Y)); } } this.canvas.DrawLines(this.pts.ToArray(), this.paint); } }
internal BaseStrokeContent(LottieDrawable lottieDrawable, BaseLayer layer, CapStyle cap, LineJoin join, float miterLimit, AnimatableIntegerValue opacity, AnimatableFloatValue width, List <AnimatableFloatValue> dashPattern, AnimatableFloatValue offset) { _lottieDrawable = lottieDrawable; _layer = layer; Paint.Style = Paint.PaintStyle.Stroke; Paint.StrokeCap = cap; Paint.StrokeJoin = join; Paint.StrokeMiter = miterLimit; _opacityAnimation = opacity.CreateAnimation(); _widthAnimation = width.CreateAnimation(); if (offset == null) { _dashPatternOffsetAnimation = null; } else { _dashPatternOffsetAnimation = offset.CreateAnimation(); } _dashPatternAnimations = new List <IBaseKeyframeAnimation <float?, float?> >(dashPattern.Count); _dashPatternValues = new float[dashPattern.Count]; for (var i = 0; i < dashPattern.Count; i++) { _dashPatternAnimations.Add(dashPattern[i].CreateAnimation()); } layer.AddAnimation(_opacityAnimation); layer.AddAnimation(_widthAnimation); for (var i = 0; i < _dashPatternAnimations.Count; i++) { layer.AddAnimation(_dashPatternAnimations[i]); } if (_dashPatternOffsetAnimation != null) { layer.AddAnimation(_dashPatternOffsetAnimation); } _opacityAnimation.ValueChanged += OnValueChanged; _widthAnimation.ValueChanged += OnValueChanged; for (var i = 0; i < dashPattern.Count; i++) { _dashPatternAnimations[i].ValueChanged += OnValueChanged; } if (_dashPatternOffsetAnimation != null) { _dashPatternOffsetAnimation.ValueChanged += OnValueChanged; } }
public LayerText(string content, Font font, int FontSize, Color textColor, int OutlineSize, Color OutlineColor, LineJoin OutlineStyle) { this.Content = content; this.Font = font; this.TextColor = textColor; this.OutlineColor = OutlineColor; this.OutlineSize = OutlineSize; this.OutlineStyle = OutlineStyle; this.FontSize = FontSize; StringFormat = new StringFormat(); StringFormat.Alignment = StringAlignment.Center; StringFormat.LineAlignment = StringAlignment.Center; StringFormat.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap; StringFormat.Trimming = StringTrimming.Character; HeightRate = WidthRate = 1; }
public void SetLineJoin(LineJoin value) { this.LineJoin = value; this.CallMethod <object>(LINE_JOIN_PROPERTY, value.ToString().ToLowerInvariant()); }
/// <summary> /// Adds a line. /// </summary>§ /// <param name="maxZoom"></param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="color">Color.</param> /// <param name="width">Width.</param> /// <param name="lineJoin"></param> /// <param name="dashes"></param> /// <param name="minZoom"></param> public virtual uint AddLine(float minZoom, float maxZoom, double[] x, double[] y, int color, double width, LineJoin lineJoin, int[] dashes) { return(this.AddLine(0, minZoom, maxZoom, x, y, color, width, lineJoin, dashes)); }
private void ExecuteDrawableStrokeLineJoin(XmlElement element, Collection <IDrawable> drawables) { LineJoin lineJoin_ = Variables.GetValue <LineJoin>(element, "lineJoin"); drawables.Add(new DrawableStrokeLineJoin(lineJoin_)); }
/// <summary> /// Draws a clipped polyline through the specified points. /// </summary> /// <param name="rc">The render context.</param> /// <param name="clippingRectangle">The clipping rectangle.</param> /// <param name="points">The points.</param> /// <param name="minDistSquared">The minimum line segment length (squared).</param> /// <param name="stroke">The stroke color.</param> /// <param name="strokeThickness">The stroke thickness.</param> /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param> /// <param name="lineJoin">The line join.</param> /// <param name="aliased">Set to <c>true</c> to draw as an aliased line.</param> /// <param name="outputBuffer">The output buffer.</param> /// <param name="pointsRendered">The points rendered callback.</param> public static void DrawClippedLine( this IRenderContext rc, OxyRect clippingRectangle, IList <ScreenPoint> points, double minDistSquared, OxyColor stroke, double strokeThickness, double[] dashArray, LineJoin lineJoin, bool aliased, List <ScreenPoint> outputBuffer = null, Action <IList <ScreenPoint> > pointsRendered = null) { var n = points.Count; if (n == 0) { return; } if (outputBuffer != null) { outputBuffer.Clear(); } else { outputBuffer = new List <ScreenPoint>(n); } // draws the points in the output buffer and calls the callback (if specified) Action drawLine = () => { EnsureNonEmptyLineIsVisible(outputBuffer); rc.DrawLine(outputBuffer, stroke, strokeThickness, dashArray, lineJoin, aliased); // Execute the 'callback' if (pointsRendered != null) { pointsRendered(outputBuffer); } }; var clipping = new CohenSutherlandClipping(clippingRectangle); if (n == 1 && clipping.IsInside(points[0])) { outputBuffer.Add(points[0]); } int lastPointIndex = 0; for (int i = 1; i < n; i++) { // Calculate the clipped version of previous and this point. var sc0 = points[i - 1]; var sc1 = points[i]; bool isInside = clipping.ClipLine(ref sc0, ref sc1); if (!isInside) { // the line segment is outside the clipping rectangle // keep the previous coordinate for minimum distance comparison continue; } // length calculation (inlined for performance) var dx = sc1.X - points[lastPointIndex].X; var dy = sc1.Y - points[lastPointIndex].Y; if ((dx * dx) + (dy * dy) > minDistSquared || outputBuffer.Count == 0 || i == n - 1) { // point comparison inlined for performance // ReSharper disable CompareOfFloatsByEqualityOperator if (sc0.X != points[lastPointIndex].X || sc0.Y != points[lastPointIndex].Y || outputBuffer.Count == 0) // ReSharper restore disable CompareOfFloatsByEqualityOperator { outputBuffer.Add(new ScreenPoint(sc0.X, sc0.Y)); } outputBuffer.Add(new ScreenPoint(sc1.X, sc1.Y)); lastPointIndex = i; } if (clipping.IsInside(points[i]) || outputBuffer.Count == 0) { continue; } // we are leaving the clipping region - render the line drawLine(); outputBuffer.Clear(); } if (outputBuffer.Count > 0) { drawLine(); } }
internal static extern GpStatus GdipGetPenLineJoin(GpPen pen, out LineJoin lineJoin);
public void SetLineJoin(LineJoin lineJoin) { SetStatus(GdiPlus.GdipSetPenLineJoin(nativePen, lineJoin)); }
/// <summary> /// Sets the stroke style. /// </summary> /// <param name="c">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join.</param> private void SetStroke(OxyColor c, double thickness, double[] dashArray = null, LineJoin lineJoin = LineJoin.Miter) { this.gctx.SetStrokeColor(c.ToCGColor()); this.gctx.SetLineWidth((float)thickness); this.gctx.SetLineJoin(lineJoin.Convert()); if (dashArray != null && dashArray.Length > 1) { var lengths = dashArray.Select(d => (nfloat)d).ToArray(); this.gctx.SetLineDash(0f, lengths); } else { this.gctx.SetLineDash(0f, new nfloat[] {}); } }
public void StrokeLineJoin(LineJoin value) { _NativeInstance.StrokeLineJoin(value); }
/// <summary> /// Sets the stroke style. /// </summary> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join.</param> /// <param name="aliased">Use aliased strokes if set to <c>true</c>.</param> private void SetStroke(OxyColor stroke, double thickness, double[] dashArray = null, LineJoin lineJoin = LineJoin.Miter, bool aliased = false) { this.paint.SetStyle(Paint.Style.Stroke); this.paint.Color = stroke.ToColor(); this.paint.StrokeWidth = this.Convert(thickness); this.paint.StrokeJoin = lineJoin.Convert(); if (dashArray != null) { var dashArrayF = dashArray.Select(this.Convert).ToArray(); this.paint.SetPathEffect(new DashPathEffect(dashArrayF, 0f)); } this.paint.AntiAlias = !aliased; }
internal static extern Status GdipGetPenLineJoin (IntPtr pen, out LineJoin lineJoin);
/// <summary> /// Draws the line using the MaxPolylinesPerLine and MinPointsPerPolyline properties. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The thickness.</param> /// <param name="dashArray">The dash array. Use <c>null</c> to get a solid line.</param> /// <param name="lineJoin">The line join.</param> /// <param name="aliased">Render aliased if set to <c>true</c>.</param> /// <remarks>See <a href="https://oxyplot.codeplex.com/discussions/456679">discussion</a>.</remarks> private void DrawLineBalanced(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { // balance the number of points per polyline and the number of polylines var numPointsPerPolyline = Math.Max(points.Count / MaxPolylinesPerLine, MinPointsPerPolyline); var polyline = CreateAndAdd <Polyline>(); SetStroke(polyline, stroke, thickness, lineJoin, dashArray, 0, aliased); var pc = new List <Point>(numPointsPerPolyline); var n = points.Count; double lineLength = 0; var dashPatternLength = (dashArray != null) ? dashArray.Sum() : 0; var last = new Point(); for (int i = 0; i < n; i++) { var p = aliased ? ToPixelAlignedPoint(points[i]) : ToPoint(points[i]); pc.Add(p); // alt. 1 if (dashArray != null) { if (i > 0) { var delta = p - last; var dist = Math.Sqrt((delta.X * delta.X) + (delta.Y * delta.Y)); lineLength += dist; } last = p; } // use multiple polylines with limited number of points to improve Avalonia performance if (pc.Count >= numPointsPerPolyline) { polyline.Points = pc; if (i < n - 1) { // alt.2 ////if (dashArray != null) ////{ //// lineLength += this.GetLength(polyline); ////} // start a new polyline at last point so there is no gap (it is not necessary to use the % operator) var dashOffset = dashPatternLength > 0 ? lineLength / thickness : 0; polyline = CreateAndAdd <Polyline>(); SetStroke(polyline, stroke, thickness, lineJoin, dashArray, dashOffset, aliased); pc = new List <Point>(numPointsPerPolyline) { pc.Last() }; } } } if (pc.Count > 1 || n == 1) { polyline.Points = pc; } }
internal static extern void cairo_set_line_join (IntPtr cr, LineJoin line_join);
/// <summary> /// Draws the line using the MaxPolylinesPerLine and MinPointsPerPolyline properties. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The thickness.</param> /// <param name="dashArray">The dash array. Use <c>null</c> to get a solid line.</param> /// <param name="lineJoin">The line join.</param> /// <param name="aliased">Render aliased if set to <c>true</c>.</param> /// <remarks>See <a href="https://oxyplot.codeplex.com/discussions/456679">discussion</a>.</remarks> private void DrawLineBalanced(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { DrawLineSegmentsByStreamGeometry(points, stroke, thickness, dashArray, lineJoin, aliased); /* // balance the number of points per polyline and the number of polylines * var numPointsPerPolyline = Math.Max(points.Count / MaxPolylinesPerLine, MinPointsPerPolyline); * * var polyline = this.CreateAndAdd<Polyline>(); * this.SetStroke(polyline, stroke, thickness, lineJoin, dashArray, 0, aliased); * var pc = new PointCollection(numPointsPerPolyline); * * var n = points.Count; * double lineLength = 0; * var dashPatternLength = (dashArray != null) ? dashArray.Sum() : 0; * var last = new Point(); * for (int i = 0; i < n; i++) * { * var p = aliased ? this.ToPixelAlignedPoint(points[i]) : this.ToPoint(points[i]); * pc.Add(p); * * // alt. 1 * if (dashArray != null) * { * if (i > 0) * { * var delta = p - last; * var dist = Math.Sqrt((delta.X * delta.X) + (delta.Y * delta.Y)); * lineLength += dist; * } * * last = p; * } * * // use multiple polylines with limited number of points to improve WPF performance * if (pc.Count >= numPointsPerPolyline) * { * polyline.Points = pc; * * if (i < n - 1) * { * // alt.2 * ////if (dashArray != null) * ////{ * //// lineLength += this.GetLength(polyline); * ////} * * // start a new polyline at last point so there is no gap (it is not necessary to use the % operator) * var dashOffset = dashPatternLength > 0 ? lineLength / thickness : 0; * polyline = this.CreateAndAdd<Polyline>(); * this.SetStroke(polyline, stroke, thickness, lineJoin, dashArray, dashOffset, aliased); * pc = new PointCollection(numPointsPerPolyline) { pc.Last() }; * } * } * } * * if (pc.Count > 1 || n == 1) * { * polyline.Points = pc; * }*/ }
/// <summary> /// Draws a polyline. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param> public override void DrawLine(IList<ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { this.paint.Reset(); { this.path.Reset(); { this.SetPath(points, aliased); this.SetStroke(stroke, thickness, dashArray, lineJoin, aliased); this.canvas.DrawPath(this.path, this.paint); } } }
/// <summary> /// Initializes a new instance of the <see cref="DrawableStrokeLineJoin"/> class. /// </summary> /// <param name="lineJoin">The line join.</param> public DrawableStrokeLineJoin(LineJoin lineJoin) { LineJoin = lineJoin; }
/// <summary> /// Draws a polygon. The polygon can have stroke and/or fill. /// </summary> /// <param name="points">The points.</param> /// <param name="fill">The fill color.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">If set to <c>true</c> the shape will be aliased.</param> public override void DrawPolygon(IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { this.paint.Reset(); { this.path.Reset(); { this.SetPath(points, aliased); this.path.Close(); if (fill.IsVisible()) { this.SetFill(fill); this.canvas.DrawPath(this.path, this.paint); } if (stroke.IsVisible()) { this.SetStroke(stroke, thickness, dashArray, lineJoin, aliased); this.canvas.DrawPath(this.path, this.paint); } } } }
public static extern void SetLineJoin(IntPtr handle, LineJoin value);
public static extern GpStatus GdipSetPenLineJoin(GpPen pen, LineJoin lineJoin);
/// <summary> /// Draws a collection of polygons, where all polygons have the same stroke and fill. /// This performs better than calling DrawPolygon multiple times. /// </summary> /// <param name="polygons">The polygons.</param> /// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the polygons will not be filled.</param> /// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the polygons will not be stroked.</param> /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param> /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param> public void DrawPolygons( IList <IList <ScreenPoint> > polygons, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { var usg = UseStreamGeometry; Path path = null; StreamGeometry streamGeometry = null; StreamGeometryContext sgc = null; PathGeometry pathGeometry = null; var count = 0; foreach (var polygon in polygons) { if (path == null) { path = CreateAndAdd <Path>(); SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased); if (!fill.IsUndefined()) { path.Fill = GetCachedBrush(fill); } if (usg) { streamGeometry = new StreamGeometry(); sgc = streamGeometry.Open(); sgc.SetFillRule(FillRule.NonZero); } else { pathGeometry = new PathGeometry { FillRule = FillRule.NonZero }; } } PathFigure figure = null; var first = true; foreach (var p in polygon) { var point = aliased ? ToPixelAlignedPoint(p) : ToPoint(p); if (first) { if (usg) { sgc.BeginFigure(point, !fill.IsUndefined()); } else { figure = new PathFigure { StartPoint = point, IsFilled = !fill.IsUndefined(), IsClosed = true }; pathGeometry.Figures.Add(figure); } first = false; } else { if (usg) { sgc.LineTo(point); } else { figure.Segments.Add(new LineSegment { Point = point }); } } } count++; // Must limit the number of figures, otherwise drawing errors... if (count > MaxFiguresPerGeometry) { if (usg) { sgc.Dispose(); path.Data = streamGeometry; } else { path.Data = pathGeometry; } path = null; count = 0; } } if (path != null) { if (usg) { sgc.Dispose(); path.Data = streamGeometry; } else { path.Data = pathGeometry; } } }
/// <summary> /// Creates the specified pen. /// </summary> /// <param name="color">The color.</param> /// <param name="thickness">The thickness.</param> /// <param name="lineStyle">The line style.</param> /// <param name="lineJoin">The line join.</param> /// <returns>A pen.</returns> public static OxyPen Create( OxyColor color, double thickness, LineStyle lineStyle = LineStyle.Solid, LineJoin lineJoin = LineJoin.Miter) { if (color.IsInvisible() || lineStyle == LineStyle.None || Math.Abs(thickness) < double.Epsilon) { return null; } return new OxyPen(color, thickness, lineStyle, lineJoin); }
public virtual void AcceptAttributeLineJoin(LineJoin lineJoin, T parameter) { // intentionally left blank }
private void _SetStrokeJoin(LineJoin lineJoin) { int status = SafeNativeMethods.Gdip.GdipSetCustomLineCapStrokeJoin(new HandleRef(this, nativeCap), lineJoin); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); }
public static void Should_ReturnLineJoinFromString(string lineJoinType) { var lineJoin = LineJoin.FromString(lineJoinType); Assert.Equal(lineJoinType, lineJoin.ToString()); }
/// <summary> /// Creates a new line2D. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="color"></param> /// <param name="width"></param> /// <param name="lineJoin"></param> /// <param name="minX"></param> /// <param name="maxX"></param> /// <param name="minY"></param> /// <param name="maxY"></param> public Line2D(double[] x, double[] y, int color, double width, LineJoin lineJoin, int[] dashes, int minX, int maxX, int minY, int maxY) : this() { this.X = x; this.Y = y; this.Color = color; this.Width = width; this.LineJoin = lineJoin; this.Dashes = dashes; MinX = minX; MaxX = maxX; MinY = minY; MaxY = maxY; this.MinZoom = float.MinValue; this.MaxZoom = float.MaxValue; }
public static void Should_ReturnDefaultLineJoin_IfStringDoesNotMatch() { var lineJoinType = "obviouslyNotAValidOne"; var lineJoin = LineJoin.FromString(lineJoinType); Assert.Equal(default, lineJoin);
/// <summary> /// Adds a line. /// </summary> /// <param name="maxZoom"></param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="color">Color.</param> /// <param name="width">Width.</param> /// <param name="minZoom"></param> /// <returns>The line.</returns> public override uint AddLine(int layer, float minZoom, float maxZoom, double[] x, double[] y, int color, double width, LineJoin lineJoin, int[] dashes) { // add the line but simplify it for higher zoom levels. float currentMaxZoom = float.MaxValue; for (int idx = 0; idx < _zoomLevelCutoffs.Count; idx++) { float currentMinZoom = _zoomLevelCutoffs[idx]; if (!(currentMinZoom >= maxZoom) && !(currentMaxZoom < minZoom)) { float thisMinZoom = System.Math.Max(currentMinZoom, minZoom); float thisMaxZoom = System.Math.Min(currentMaxZoom, maxZoom); // simplify the algorithm. double epsilon = this.CalculateSimplificationEpsilon(thisMaxZoom); double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y }, epsilon); double distance = epsilon * 2; if (simplified[0].Length == 2) { // check if the simplified version is smaller than epsilon. OsmSharp.Math.Primitives.PointF2D point1 = new OsmSharp.Math.Primitives.PointF2D( simplified[0][0], simplified[0][1]); OsmSharp.Math.Primitives.PointF2D point2 = new OsmSharp.Math.Primitives.PointF2D( simplified[1][0], simplified[0][1]); distance = point1.Distance(point2); } if (distance >= epsilon) { // add to the scene. if (_scenes[idx] == null) { _scenes[idx] = new Scene2DSimple(); } _scenes[idx].AddLine(layer, thisMinZoom, thisMaxZoom, simplified[0], simplified[1], color, width, lineJoin, dashes); } } currentMaxZoom = currentMinZoom; // move to the next cutoff. } return 0; }
public async Task SetLineJoinAsync(LineJoin value) { this.LineJoin = value; await this.BatchCallAsync(LINE_JOIN_PROPERTY, isMethodCall : false, value.ToString().ToLowerInvariant()); }