Exemple #1
0
        /// <inheritdoc/>
        public override void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray,
            OxyPlot.LineJoin lineJoin)
        {
            if (points.Count < 2)
            {
                return;
            }

            this.SetSmoothingMode(this.ShouldUseAntiAliasingForLine(edgeRenderingMode, points));

            var pts = this.ToPoints(points);

            if (fill.IsVisible())
            {
                this.g.FillPolygon(this.GetCachedBrush(fill), pts);
            }

            if (stroke.IsInvisible() || thickness <= 0)
            {
                return;
            }

            var pen = this.GetCachedPen(stroke, thickness, dashArray, lineJoin);

            this.g.DrawPolygon(pen, pts);
        }
Exemple #2
0
 /// <inheritdoc/>
 public abstract void DrawLine(
     IList <ScreenPoint> points,
     OxyColor stroke,
     double thickness,
     EdgeRenderingMode edgeRenderingMode,
     double[] dashArray,
     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="edgeRenderingMode">The edge rendering mode. This is not supported and will be ignored.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        public override void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray,
            LineJoin lineJoin)
        {
            this.doc.SetColor(stroke);
            this.SetLineWidth(thickness);
            if (dashArray != null)
            {
                this.SetLineDashPattern(dashArray, 0);
            }

            this.doc.SetLineJoin(Convert(lineJoin));
            var h = this.doc.PageHeight;

            this.doc.MoveTo(points[0].X, h - points[0].Y);
            for (int i = 1; i < points.Count; i++)
            {
                this.doc.LineTo(points[i].X, h - points[i].Y);
            }

            this.doc.Stroke(false);
            if (dashArray != null)
            {
                this.doc.ResetLineDashPattern();
            }
        }
Exemple #4
0
        /// <summary>
        /// Draws a clipped ellipse.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="clippingRectangle">The clipping rectangle.</param>
        /// <param name="rect">The rectangle.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <param name="n">The number of points around the ellipse.</param>
        public static void DrawClippedEllipse(
            this IRenderContext rc,
            OxyRect clippingRectangle,
            OxyRect rect,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            int n = 100)
        {
            if (rc.SetClip(clippingRectangle))
            {
                rc.DrawEllipse(rect, fill, stroke, thickness, edgeRenderingMode);
                rc.ResetClip();
                return;
            }

            var    points = new ScreenPoint[n];
            double cx     = (rect.Left + rect.Right) / 2;
            double cy     = (rect.Top + rect.Bottom) / 2;
            double rx     = (rect.Right - rect.Left) / 2;
            double ry     = (rect.Bottom - rect.Top) / 2;

            for (int i = 0; i < n; i++)
            {
                double a = Math.PI * 2 * i / (n - 1);
                points[i] = new ScreenPoint(cx + (rx * Math.Cos(a)), cy + (ry * Math.Sin(a)));
            }

            rc.DrawClippedPolygon(clippingRectangle, points, 4, fill, stroke, thickness, edgeRenderingMode);
        }
Exemple #5
0
        /// <summary>
        /// Draws the line.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke.</param>
        /// <param name="thickness">The thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join.</param>
        /// <param name="aliased">if set to <c>true</c> [aliased].</param>
        public override void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray,
            OxyPlot.LineJoin lineJoin)
        {
            if (stroke.IsVisible() && thickness > 0 && points.Count >= 2)
            {
                // g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; // TODO: Smoothing modes
                this.g.Save();
                this.g.SetSourceColor(stroke);
                this.g.LineJoin  = lineJoin.ToLineJoin();
                this.g.LineWidth = thickness;
                if (dashArray != null)
                {
                    this.g.SetDash(dashArray, 0);
                }

                bool aliased = !ShouldUseAntiAliasingForLine(edgeRenderingMode, points);
                this.g.MoveTo(points[0].ToPointD(aliased));
                foreach (var point in points.Skip(1))
                {
                    this.g.LineTo(point.ToPointD(aliased));
                }

                this.g.Stroke();
                this.g.Restore();
            }
        }
Exemple #6
0
 /// <summary>
 /// Draws a list of markers.
 /// </summary>
 /// <param name="rc">The render context.</param>
 /// <param name="markerPoints">The marker points.</param>
 /// <param name="clippingRectangle">The clipping rectangle.</param>
 /// <param name="markerType">Type of the marker.</param>
 /// <param name="markerOutline">The marker outline.</param>
 /// <param name="markerSize">Size of the marker.</param>
 /// <param name="markerFill">The marker fill.</param>
 /// <param name="markerStroke">The marker stroke.</param>
 /// <param name="markerStrokeThickness">The marker stroke thickness.</param>
 /// <param name="edgeRenderingMode">The edge rendering mode.</param>
 /// <param name="resolution">The resolution.</param>
 /// <param name="binOffset">The bin Offset.</param>
 public static void DrawMarkers(
     this IRenderContext rc,
     IList <ScreenPoint> markerPoints,
     OxyRect clippingRectangle,
     MarkerType markerType,
     IList <ScreenPoint> markerOutline,
     double markerSize,
     OxyColor markerFill,
     OxyColor markerStroke,
     double markerStrokeThickness,
     EdgeRenderingMode edgeRenderingMode,
     int resolution        = 0,
     ScreenPoint binOffset = new ScreenPoint())
 {
     DrawMarkers(
         rc,
         clippingRectangle,
         markerPoints,
         markerType,
         markerOutline,
         new[] { markerSize },
         markerFill,
         markerStroke,
         markerStrokeThickness,
         edgeRenderingMode,
         resolution,
         binOffset);
 }
Exemple #7
0
        /// <summary>
        /// Draws the clipped rectangle.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="clippingRectangle">The clipping rectangle.</param>
        /// <param name="rect">The rectangle to draw.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        public static void DrawClippedRectangle(
            this IRenderContext rc,
            OxyRect clippingRectangle,
            OxyRect rect,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode)
        {
            if (rc.SetClip(clippingRectangle))
            {
                rc.DrawRectangle(rect, fill, stroke, thickness, edgeRenderingMode);
                rc.ResetClip();
                return;
            }

            var clippedRect = ClipRect(rect, clippingRectangle);

            if (clippedRect == null)
            {
                return;
            }

            rc.DrawRectangle(clippedRect.Value, fill, stroke, thickness, edgeRenderingMode);
        }
Exemple #8
0
        /// <summary>
        /// Draws clipped line segments.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="clippingRectangle">The clipping rectangle.</param>
        /// <param name="points">The points defining the line segments. Lines are drawn from point 0 to 1, point 2 to 3 and so on.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="strokeThickness">The stroke thickness.</param>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param>
        /// <param name="lineJoin">The line join.</param>
        public static void DrawClippedLineSegments(
            this IRenderContext rc,
            OxyRect clippingRectangle,
            IList <ScreenPoint> points,
            OxyColor stroke,
            double strokeThickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray,
            LineJoin lineJoin)
        {
            if (rc.SetClip(clippingRectangle))
            {
                rc.DrawLineSegments(points, stroke, strokeThickness, edgeRenderingMode, dashArray, lineJoin);
                rc.ResetClip();
                return;
            }

            var clipping = new CohenSutherlandClipping(clippingRectangle);

            var clippedPoints = new List <ScreenPoint>(points.Count);

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                var s0 = points[i];
                var s1 = points[i + 1];
                if (clipping.ClipLine(ref s0, ref s1))
                {
                    clippedPoints.Add(s0);
                    clippedPoints.Add(s1);
                }
            }

            rc.DrawLineSegments(clippedPoints, stroke, strokeThickness, edgeRenderingMode, dashArray, lineJoin);
        }
Exemple #9
0
        /// <inheritdoc/>
        public void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray = null,
            LineJoin lineJoin  = LineJoin.Miter)
        {
            if (!fill.IsVisible() && !(stroke.IsVisible() || thickness <= 0) || points.Count < 2)
            {
                return;
            }

            var path         = this.GetPath();
            var actualPoints = this.GetActualPoints(points, thickness, edgeRenderingMode);

            AddPoints(actualPoints, path);
            path.Close();

            if (fill.IsVisible())
            {
                var paint = this.GetFillPaint(fill, edgeRenderingMode);
                this.SkCanvas.DrawPath(path, paint);
            }

            if (stroke.IsVisible() && thickness > 0)
            {
                var paint = this.GetLinePaint(stroke, thickness, edgeRenderingMode, dashArray, lineJoin);
                this.SkCanvas.DrawPath(path, paint);
            }
        }
Exemple #10
0
 /// <summary>
 /// Gets a <see cref="SKPaint"/> containing information needed to render the fill of a shape.
 /// </summary>
 /// <remarks>
 /// This modifies and returns the local <see cref="paint"/> instance.
 /// </remarks>
 /// <param name="fillColor">The fill color.</param>
 /// <param name="edgeRenderingMode">The edge rendering mode.</param>
 /// <returns>The paint.</returns>
 private SKPaint GetFillPaint(OxyColor fillColor, EdgeRenderingMode edgeRenderingMode)
 {
     this.paint.Color       = fillColor.ToSKColor();
     this.paint.Style       = SKPaintStyle.Fill;
     this.paint.IsAntialias = this.ShouldUseAntiAliasing(edgeRenderingMode);
     this.paint.PathEffect  = null;
     return(this.paint);
 }
Exemple #11
0
 /// <summary>
 /// Writes a polyline.
 /// </summary>
 /// <param name="pts">The points.</param>
 /// <param name="style">The style.</param>
 /// <param name="edgeRenderingMode">The edge rendering mode.</param>
 public void WritePolyline(IEnumerable <ScreenPoint> pts, string style, EdgeRenderingMode edgeRenderingMode)
 {
     // http://www.w3.org/TR/SVG/shapes.html#PolylineElement
     this.WriteStartElement("polyline");
     this.WriteAttributeString("points", this.PointsToString(pts));
     this.WriteAttributeString("style", style);
     this.WriteEdgeRenderingModeAttribute(edgeRenderingMode);
     this.WriteEndElement();
 }
        /// <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="edgeRenderingMode">The edge rendering mode. This is not supported and will be ignored.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        public override void DrawPolygon(
            IList <ScreenPoint> points,
            OxyColor fill,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray,
            LineJoin lineJoin)
        {
            var isStroked = stroke.IsVisible() && thickness > 0;
            var isFilled  = fill.IsVisible();

            if (!isStroked && !isFilled)
            {
                return;
            }

            var h = this.doc.PageHeight;

            this.doc.MoveTo(points[0].X, h - points[0].Y);
            for (int i = 1; i < points.Count; i++)
            {
                this.doc.LineTo(points[i].X, h - points[i].Y);
            }

            if (isStroked)
            {
                this.doc.SetColor(stroke);
                this.SetLineWidth(thickness);
                if (dashArray != null)
                {
                    this.SetLineDashPattern(dashArray, 0);
                }

                this.doc.SetLineJoin(Convert(lineJoin));
                if (isFilled)
                {
                    this.doc.SetFillColor(fill);
                    this.doc.FillAndStroke();
                }
                else
                {
                    this.doc.Stroke();
                }

                if (dashArray != null)
                {
                    this.doc.ResetLineDashPattern();
                }
            }
            else
            {
                this.doc.SetFillColor(fill);
                this.doc.Fill();
            }
        }
Exemple #13
0
        /// <summary>
        /// Draws the plot to a cairo context within the specified bounds.
        /// </summary>
        /// <param name="cr">The cairo context to use for drawing.</param>
        void DrawPlot(Cairo.Context cr)
        {
            try
            {
                lock (this.invalidateLock)
                {
                    if (this.isModelInvalidated)
                    {
                        if (this.model != null)
                        {
                            ((IPlotModel)this.model).Update(this.updateDataFlag);
                            this.updateDataFlag = false;
                        }

                        this.isModelInvalidated = false;
                    }
                }

                lock (this.renderingLock)
                {
                    EdgeRenderingMode edgeRenderingMode = EdgeRenderingMode.Automatic.GetActual(EdgeRenderingMode.Adaptive);
                    this.renderContext.SetGraphicsTarget(cr);
                    if (this.model != null)
                    {
                        OxyRect rect = new OxyRect(0, 0, Allocation.Width, Allocation.Height);
                        if (!this.model.Background.IsUndefined())
                        {
                            this.renderContext.DrawRectangle(rect, this.model.Background, OxyColors.Undefined, 0, edgeRenderingMode);
                        }

                        ((IPlotModel)this.model).Render(this.renderContext, rect);
                    }

                    if (this.zoomRectangle.HasValue)
                    {
                        this.renderContext.DrawRectangle(this.zoomRectangle.Value, OxyColor.FromArgb(0x40, 0xFF, 0xFF, 0x00), OxyColors.Transparent, 1.0, edgeRenderingMode);
                    }
                }
            }
            catch (Exception paintException)
            {
                var trace = new StackTrace(paintException);
                Debug.WriteLine(paintException);
                Debug.WriteLine(trace);

                // using (var font = new Font("Arial", 10))
                {
                    // int width; int height;
                    // this.GetSizeRequest(out width, out height);
                    Debug.Assert(false, "OxyPlot paint exception: " + paintException.Message);

                    // g.ResetTransform();
                    // g.DrawString(, font, Brushes.Red, width / 2, height / 2, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Draws the line segments.
        /// </summary>
        /// <param name="rc">The render context.</param>
        /// <param name="points">The points.</param>
        /// <param name="pen">The pen.</param>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        public static void DrawLineSegments(
            this IRenderContext rc, IList <ScreenPoint> points, OxyPen pen, EdgeRenderingMode edgeRenderingMode)
        {
            if (pen == null)
            {
                return;
            }

            rc.DrawLineSegments(points, pen.Color, pen.Thickness, edgeRenderingMode, pen.ActualDashArray, pen.LineJoin);
        }
Exemple #15
0
 /// <summary>
 /// Gets a <see cref="SKPaint"/> containing information needed to render a stroke.
 /// </summary>
 /// <remarks>
 /// This modifies and returns the local <see cref="paint"/> instance.
 /// </remarks>
 /// <param name="strokeColor">The stroke color.</param>
 /// <param name="strokeThickness">The stroke thickness.</param>
 /// <param name="edgeRenderingMode">The edge rendering mode.</param>
 /// <returns>The paint.</returns>
 private SKPaint GetStrokePaint(OxyColor strokeColor, double strokeThickness, EdgeRenderingMode edgeRenderingMode)
 {
     this.paint.Color       = strokeColor.ToSKColor();
     this.paint.Style       = SKPaintStyle.Stroke;
     this.paint.IsAntialias = this.ShouldUseAntiAliasing(edgeRenderingMode);
     this.paint.StrokeWidth = this.GetActualThickness(strokeThickness, edgeRenderingMode);
     this.paint.PathEffect  = null;
     this.paint.StrokeJoin  = SKStrokeJoin.Miter;
     return(this.paint);
 }
        /// <summary>
        /// Draws a collection of rectangles, where all have the same stroke and fill.
        /// This performs better than calling DrawRectangle multiple times.
        /// </summary>
        /// <param name="rectangles">The rectangles.</param>
        /// <param name="fill">The fill color. If set to <c>OxyColors.Undefined</c>, the rectangles will not be filled.</param>
        /// <param name="stroke">The stroke color. If set to <c>OxyColors.Undefined</c>, the rectangles will not be stroked.</param>
        /// <param name="thickness">The stroke thickness (in device independent units, 1/96 inch).</param>
        public override void DrawRectangles(IList <OxyRect> rectangles,
                                            OxyColor fill,
                                            OxyColor stroke,
                                            double thickness,
                                            EdgeRenderingMode edgeRenderingMode)
        {
            var polys = rectangles.Select(r => RectangleToPolygon(r)).ToList();

            DrawPolygons(polys, fill, stroke, thickness, edgeRenderingMode, null, LineJoin.Miter);
        }
 /// <inheritdoc/>
 public override void DrawLine(
     IList <ScreenPoint> points,
     OxyColor stroke,
     double thickness,
     EdgeRenderingMode edgeRenderingMode,
     double[] dashArray,
     LineJoin lineJoin)
 {
     this.w.WritePolyline(points, this.w.CreateStyle(OxyColors.Undefined, stroke, thickness, dashArray, lineJoin), edgeRenderingMode);
 }
        ///<inheritdoc/>
        public void DrawLineSegments(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray,
            LineJoin lineJoin)
        {
            if (this.UseStreamGeometry)
            {
                this.DrawLineSegmentsByStreamGeometry(points, stroke, thickness, edgeRenderingMode, dashArray, lineJoin);
                return;
            }

            Path         path         = null;
            PathGeometry pathGeometry = null;

            int count = 0;

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                if (path == null)
                {
                    path = this.CreateAndAdd <Path>();
                    this.SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0);
                    pathGeometry = new PathGeometry();
                }

                var actualPoints = this.GetActualPoints(new[] { points[i], points[i + 1] }, path.StrokeThickness, edgeRenderingMode).ToList();

                var figure = new PathFigure {
                    StartPoint = actualPoints[0], IsClosed = false
                };
                figure.Segments.Add(new LineSegment(actualPoints[1], true)
                {
                    IsSmoothJoin = false
                });
                pathGeometry.Figures.Add(figure);

                count++;

                // Must limit the number of figures, otherwise drawing errors...
                if (count > MaxFiguresPerGeometry || dashArray != null)
                {
                    path.Data = pathGeometry;
                    path      = null;
                    count     = 0;
                }
            }

            if (path != null)
            {
                path.Data = pathGeometry;
            }
        }
Exemple #19
0
        /// <summary>
        /// Gets the stroke thickness that should actually be used for rendering, taking into account DPI scaling and snapping if necessary.
        /// </summary>
        /// <param name="strokeThickness">The stroke thickness.</param>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <returns>The actual stroke thickness.</returns>
        private float GetActualThickness(double strokeThickness, EdgeRenderingMode edgeRenderingMode)
        {
            var scaledThickness = this.Convert(strokeThickness);

            if (edgeRenderingMode == EdgeRenderingMode.PreferSharpness)
            {
                scaledThickness = Snap(scaledThickness, 0);
            }

            return(scaledThickness);
        }
        /// <summary>
        /// Draws 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 (in device independent units, 1/96 inch).</param>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <param name="dashArray">The dash array (in device independent units, 1/96 inch).</param>
        /// <param name="lineJoin">The line join type.</param>
        public override void DrawLineSegments(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray,
            LineJoin lineJoin)
        {
            if (UseStreamGeometry)
            {
                DrawLineSegmentsByStreamGeometry(points, stroke, thickness, edgeRenderingMode, dashArray, lineJoin);
                return;
            }

            bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed;

            Path         path         = null;
            PathGeometry pathGeometry = null;

            var count = 0;

            for (int i = 0; i + 1 < points.Count; i += 2)
            {
                if (path == null)
                {
                    path = CreateAndAdd <Path>();
                    SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0);
                    pathGeometry = new PathGeometry();
                }

                var figure = new PathFigure {
                    StartPoint = ToPoint(points[i], aliased), IsClosed = false
                };
                figure.Segments.Add(new LineSegment {
                    Point = ToPoint(points[i + 1], aliased)
                });
                pathGeometry.Figures.Add(figure);

                count++;

                // Must limit the number of figures, otherwise drawing errors...
                if (count > MaxFiguresPerGeometry || dashArray != null)
                {
                    path.Data = pathGeometry;
                    path      = null;
                    count     = 0;
                }
            }

            if (path != null)
            {
                path.Data = pathGeometry;
            }
        }
Exemple #21
0
        /// <summary>
        /// Returns a value indicating whether anti-aliasing should be used for the given edge rendering mode.
        /// </summary>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <returns>true if anti-aliasing should be used; false otherwise.</returns>
        protected virtual bool ShouldUseAntiAliasingForRect(EdgeRenderingMode edgeRenderingMode)
        {
            switch (edgeRenderingMode)
            {
            case EdgeRenderingMode.PreferGeometricAccuracy:
                return(true);

            default:
                return(false);
            }
        }
        /// <summary>
        /// Snaps a stroke thickness to device pixels if required by the edge rendering mode.
        /// </summary>
        /// <param name="strokeThickness">The stroke thickness.</param>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <returns>The processed stroke thickness.</returns>
        private double GetActualStrokeThickness(double strokeThickness, EdgeRenderingMode edgeRenderingMode)
        {
            switch (edgeRenderingMode)
            {
            case EdgeRenderingMode.PreferSharpness:
                return(PixelLayout.SnapStrokeThickness(strokeThickness, this.DpiScale));

            default:
                return(strokeThickness);
            }
        }
Exemple #23
0
        /// <summary>
        /// Returns a value indicating whether anti-aliasing should be used for the given edge rendering mode.
        /// </summary>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <returns>true if anti-aliasing should be used; false otherwise.</returns>
        protected virtual bool ShouldUseAntiAliasingForEllipse(EdgeRenderingMode edgeRenderingMode)
        {
            switch (edgeRenderingMode)
            {
            case EdgeRenderingMode.PreferSpeed:
                return(false);

            default:
                return(true);
            }
        }
        /// <summary>
        /// Snaps a rectangle to device pixels if required by the edge rendering mode.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <param name="strokeThickness">The stroke thickness.</param>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <returns>The processed rectangle.</returns>
        private Rect GetActualRect(OxyRect rect, double strokeThickness, EdgeRenderingMode edgeRenderingMode)
        {
            switch (edgeRenderingMode)
            {
            case EdgeRenderingMode.PreferGeometricAccuracy:
            case EdgeRenderingMode.PreferSpeed:
                return(ToRect(rect));

            default:
                return(PixelLayout.Snap(ToRect(rect), strokeThickness, this.VisualOffset, this.DpiScale));
            }
        }
        /// <inheritdoc/>
        public override void DrawLine(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray,
            LineJoin lineJoin)
        {
            var xckdPoints = this.Distort(points);

            this.rc.DrawLine(xckdPoints, stroke, thickness * this.ThicknessScale, edgeRenderingMode, dashArray, lineJoin);
        }
Exemple #26
0
        /// <inheritdoc/>
        public void DrawLineSegments(
            IList <ScreenPoint> points,
            OxyColor stroke,
            double thickness,
            EdgeRenderingMode edgeRenderingMode,
            double[] dashArray = null,
            LineJoin lineJoin  = LineJoin.Miter)
        {
            if (points.Count < 2 || !stroke.IsVisible() || thickness <= 0)
            {
                return;
            }

            var paint = this.GetLinePaint(stroke, thickness, edgeRenderingMode, dashArray, lineJoin);

            var skPoints = new SKPoint[points.Count];

            switch (edgeRenderingMode)
            {
            case EdgeRenderingMode.Automatic when this.RendersToPixels:
            case EdgeRenderingMode.Adaptive when this.RendersToPixels:
            case EdgeRenderingMode.PreferSharpness when this.RendersToPixels:
                var snapOffset = this.GetSnapOffset(thickness, edgeRenderingMode);
                for (var i = 0; i < points.Count - 1; i += 2)
                {
                    var p1 = points[i];
                    var p2 = points[i + 1];
                    if (RenderContextBase.IsStraightLine(p1, p2))
                    {
                        skPoints[i]     = this.ConvertSnap(p1, snapOffset);
                        skPoints[i + 1] = this.ConvertSnap(p2, snapOffset);
                    }
                    else
                    {
                        skPoints[i]     = this.Convert(p1);
                        skPoints[i + 1] = this.Convert(p2);
                    }
                }

                break;

            default:
                for (var i = 0; i < points.Count; i += 2)
                {
                    skPoints[i]     = this.Convert(points[i]);
                    skPoints[i + 1] = this.Convert(points[i + 1]);
                }

                break;
            }

            this.SkCanvas.DrawPoints(SKPointMode.Lines, skPoints, paint);
        }
Exemple #27
0
 /// <summary>
 /// Writes a line.
 /// </summary>
 /// <param name="p1">The first point.</param>
 /// <param name="p2">The second point.</param>
 /// <param name="style">The style.</param>
 /// <param name="edgeRenderingMode">The edge rendering mode.</param>
 public void WriteLine(ScreenPoint p1, ScreenPoint p2, string style, EdgeRenderingMode edgeRenderingMode)
 {
     // http://www.w3.org/TR/SVG/shapes.html#LineElement
     // http://www.w3schools.com/svg/svg_line.asp
     this.WriteStartElement("line");
     this.WriteAttributeString("x1", p1.X);
     this.WriteAttributeString("y1", p1.Y);
     this.WriteAttributeString("x2", p2.X);
     this.WriteAttributeString("y2", p2.Y);
     this.WriteAttributeString("style", style);
     this.WriteEdgeRenderingModeAttribute(edgeRenderingMode);
     this.WriteEndElement();
 }
Exemple #28
0
 /// <inheritdoc/>
 public virtual void DrawLineSegments(
     IList <ScreenPoint> points,
     OxyColor stroke,
     double thickness,
     EdgeRenderingMode edgeRenderingMode,
     double[] dashArray,
     LineJoin lineJoin)
 {
     for (int i = 0; i + 1 < points.Count; i += 2)
     {
         this.DrawLine(new[] { points[i], points[i + 1] }, stroke, thickness, edgeRenderingMode, dashArray, lineJoin);
     }
 }
Exemple #29
0
 /// <inheritdoc/>
 public virtual void DrawPolygons(
     IList <IList <ScreenPoint> > polygons,
     OxyColor fill,
     OxyColor stroke,
     double thickness,
     EdgeRenderingMode edgeRenderingMode,
     double[] dashArray,
     LineJoin lineJoin)
 {
     foreach (var polygon in polygons)
     {
         this.DrawPolygon(polygon, fill, stroke, thickness, edgeRenderingMode, dashArray, lineJoin);
     }
 }
Exemple #30
0
        /// <summary>
        /// Returns a value indicating whether anti-aliasing should be used for the given edge rendering mode.
        /// </summary>
        /// <param name="edgeRenderingMode">The edge rendering mode.</param>
        /// <param name="points">The points.</param>
        /// <returns>true if anti-aliasing should be used; false otherwise.</returns>
        protected virtual bool ShouldUseAntiAliasingForLine(EdgeRenderingMode edgeRenderingMode, IList <ScreenPoint> points)
        {
            switch (edgeRenderingMode)
            {
            case EdgeRenderingMode.PreferSpeed:
            case EdgeRenderingMode.PreferSharpness:
            case EdgeRenderingMode.Automatic when IsStraightLine(points):
            case EdgeRenderingMode.Adaptive when IsStraightLine(points):
                return(false);

            default:
                return(true);
            }
        }