/// <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); }
/// <summary> /// Creates a style. /// </summary> /// <param name="fill">The fill color.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness (in user units).</param> /// <param name="dashArray">The line dash array.</param> /// <param name="lineJoin">The line join type.</param> /// <returns>A style string.</returns> public string CreateStyle( OxyColor fill, OxyColor stroke, double thickness, double[] dashArray = null, LineJoin lineJoin = LineJoin.Miter) { // http://oreilly.com/catalog/svgess/chapter/ch03.html var style = new StringBuilder(); if (fill.IsInvisible()) { style.AppendFormat("fill:none;"); } else { style.AppendFormat("fill:{0};", this.ColorToString(fill)); if (fill.A != 0xFF) { style.AppendFormat(CultureInfo.InvariantCulture, "fill-opacity:{0};", fill.A / 255.0); } } if (stroke.IsInvisible()) { style.AppendFormat("stroke:none;"); } else { string formatString = "stroke:{0};stroke-width:{1:" + this.NumberFormat + "}"; style.AppendFormat(CultureInfo.InvariantCulture, formatString, this.ColorToString(stroke), thickness); switch (lineJoin) { case LineJoin.Round: style.AppendFormat(";stroke-linejoin:round"); break; case LineJoin.Bevel: style.AppendFormat(";stroke-linejoin:bevel"); break; } if (stroke.A != 0xFF) { style.AppendFormat(CultureInfo.InvariantCulture, ";stroke-opacity:{0}", stroke.A / 255.0); } if (dashArray != null && dashArray.Length > 0) { style.Append(";stroke-dasharray:"); for (int i = 0; i < dashArray.Length; i++) { style.AppendFormat( CultureInfo.InvariantCulture, "{0}{1}", i > 0 ? "," : string.Empty, dashArray[i]); } } } return(style.ToString()); }
/// <summary> /// Draws the polygon from the specified points. 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, OxyPlot.LineJoin lineJoin, bool aliased) { if (points.Count < 2) { return; } this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; var pts = this.ToPoints(points); if (fill.IsVisible()) { this.g.FillPolygon(fill.ToBrush(), pts); } if (stroke.IsInvisible() || thickness <= 0) { return; } using (var pen = this.CreatePen(stroke, thickness)) { if (dashArray != null) { pen.DashPattern = this.ToFloatArray(dashArray); } switch (lineJoin) { case OxyPlot.LineJoin.Round: pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; break; case OxyPlot.LineJoin.Bevel: pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel; break; // The default LineJoin is Miter } this.g.DrawPolygon(pen, pts); } }
/// <summary> /// Draws the rectangle. /// </summary> /// <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> public override void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness) { if (fill.IsVisible() || stroke.IsInvisible()) { this.GroundTruth[KeyRectangle].Add(new RectangleF((float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height)); } if (fill.IsVisible()) { this.g.FillRectangle( this.GetCachedBrush(fill), (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height); } if (stroke.IsInvisible() || thickness <= 0) { return; } using (var pen = this.CreatePen(stroke, thickness)) { this.g.DrawRectangle(pen, (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height); } }
/// <summary> /// Draws the rectangle. /// </summary> /// <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> public override void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness) { if (fill.IsVisible()) { this.g.FillRectangle( this.GetCachedBrush(fill), (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height); } if (stroke.IsInvisible() || thickness <= 0) { return; } var pen = this.GetCachedPen(stroke, thickness); this.g.DrawRectangle(pen, (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height); }
/// <summary> /// Draws the polyline from the specified points. /// </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, OxyPlot.LineJoin lineJoin, bool aliased) { if (stroke.IsInvisible() || thickness <= 0 || points.Count < 2) { return; } this.g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; var pen = this.GetCachedPen(stroke, thickness, dashArray, lineJoin); this.g.DrawLines(pen, this.ToPoints(points)); }
/// <inheritdoc/> public override void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness, EdgeRenderingMode edgeRenderingMode) { this.SetSmoothingMode(this.ShouldUseAntiAliasingForRect(edgeRenderingMode)); if (fill.IsVisible()) { this.g.FillRectangle( this.GetCachedBrush(fill), (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height); } if (stroke.IsInvisible() || thickness <= 0) { return; } var pen = this.GetCachedPen(stroke, thickness); this.g.DrawRectangle(pen, (float)rect.Left, (float)rect.Top, (float)rect.Width, (float)rect.Height); }
/// <inheritdoc/> public override void DrawLine( IList <ScreenPoint> points, OxyColor stroke, double thickness, EdgeRenderingMode edgeRenderingMode, double[] dashArray, OxyPlot.LineJoin lineJoin) { if (stroke.IsInvisible() || thickness <= 0 || points.Count < 2) { return; } this.SetSmoothingMode(this.ShouldUseAntiAliasingForLine(edgeRenderingMode, points)); var pen = this.GetCachedPen(stroke, thickness, dashArray, lineJoin); this.g.DrawLines(pen, this.ToPoints(points)); }
/// <summary> /// Sets the stroke properties of the specified shape. /// </summary> /// <param name="shape">The shape.</param> /// <param name="stroke">The stroke.</param> /// <param name="thickness">The thickness.</param> /// <param name="lineJoin">The line join.</param> /// <param name="dashArray">The dash array.</param> /// <param name="aliased">The aliased.</param> // ReSharper disable UnusedParameter.Local private void SetStroke( Shape shape, OxyColor stroke, double thickness, LineJoin lineJoin = LineJoin.Miter, double[] dashArray = null, bool aliased = false) { if (stroke.IsInvisible() || thickness <= 0) { return; } shape.Stroke = this.GetCachedBrush(stroke); switch (lineJoin) { case LineJoin.Round: shape.StrokeLineJoin = PenLineJoin.Round; break; case LineJoin.Bevel: shape.StrokeLineJoin = PenLineJoin.Bevel; break; // The default StrokeLineJoin is Miter } if (!thickness.Equals(1.0)) { // default values is 1 shape.StrokeThickness = thickness; } if (dashArray != null) { shape.StrokeDashArray = CreateDashArrayCollection(dashArray); } // shape.UseLayoutRounding = aliased; }
/// <summary> /// Draws the polyline from the specified points. /// </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.IsInvisible() || thickness <= 0) { return; } this.g.SmoothingMode = aliased ? XSmoothingMode.None : XSmoothingMode.HighQuality; var pen = new XPen(ToColor(stroke), (float)thickness); if (dashArray != null) { pen.DashPattern = dashArray; } switch (lineJoin) { case LineJoin.Round: pen.LineJoin = XLineJoin.Round; break; case LineJoin.Bevel: pen.LineJoin = XLineJoin.Bevel; break; // The default LineJoin is Miter } this.g.DrawLines(pen, ToPoints(points)); }
/// <inheritdoc/> public override void DrawLine( IList <ScreenPoint> points, OxyColor stroke, double thickness, EdgeRenderingMode edgeRenderingMode, double[] dashArray, LineJoin lineJoin) { if (stroke.IsInvisible() || thickness <= 0) { return; } this.SetSmoothingMode(this.ShouldUseAntiAliasingForLine(edgeRenderingMode, points)); var pen = new XPen(ToColor(stroke), (float)thickness); if (dashArray != null) { pen.DashPattern = dashArray; } switch (lineJoin) { case LineJoin.Round: pen.LineJoin = XLineJoin.Round; break; case LineJoin.Bevel: pen.LineJoin = XLineJoin.Bevel; break; // The default LineJoin is Miter } this.g.DrawLines(pen, ToPoints(points)); }
/// <summary> /// Converts an <see cref="OxyColor" /> to a <see cref="Color" />. /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The converted color.</returns> public static SKColor ToSKColor(this OxyColor color) { return(color.IsInvisible() ? new SKColor(0, 0, 0, 0) : new SKColor(color.R, color.G, color.B, color.A)); }
/// <summary> /// Converts an <see cref="OxyColor" /> to a <see cref="Color" />. /// </summary> /// <param name="color">The color to convert.</param> /// <returns>The converted color.</returns> public static SKColor ToColor(this OxyColor color) { return(color.IsInvisible() ? SKColors.Transparent : new SKColor(color.R, color.G, color.B, color.A)); }
/// <summary> /// The draw text. /// </summary> /// <param name="p">The p.</param> /// <param name="text">The text.</param> /// <param name="fill">The fill.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">The font size.</param> /// <param name="fontWeight">The font weight.</param> /// <param name="rotate">The rotate.</param> /// <param name="halign">The horizontal alignment.</param> /// <param name="valign">The vertical alignment.</param> /// <param name="maxSize">The maximum size of the text.</param> public void DrawText( ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, OxyPlot.HorizontalAlignment halign, OxyPlot.VerticalAlignment valign, OxySize?maxSize) { if (fill.IsInvisible() || string.IsNullOrEmpty(text)) { return; } var tb = new TextBlock { Text = text, Foreground = fill.ToBrush() }; // tb.SetValue(TextOptions.TextHintingModeProperty, TextHintingMode.Animated); if (fontFamily != null) { tb.FontFamily = new FontFamily(fontFamily); } if (fontSize > 0) { tb.FontSize = fontSize; } tb.FontWeight = GetFontWeight(fontWeight); tb.Measure(new Size(1000, 1000)); double dx = 0; if (halign == OxyPlot.HorizontalAlignment.Center) { dx = -tb.ActualWidth / 2; } if (halign == OxyPlot.HorizontalAlignment.Right) { dx = -tb.ActualWidth; } double dy = 0; if (valign == OxyPlot.VerticalAlignment.Middle) { dy = -tb.ActualHeight / 2; } if (valign == OxyPlot.VerticalAlignment.Bottom) { dy = -tb.ActualHeight; } var transform = new TransformGroup(); transform.Children.Add(new TranslateTransform { X = (int)dx, Y = (int)dy }); if (!rotate.Equals(0.0)) { transform.Children.Add(new RotateTransform { Angle = rotate }); } transform.Children.Add(new TranslateTransform { X = (int)p.X, Y = (int)p.Y }); tb.RenderTransform = transform; if (this.clip.HasValue) { // add a clipping container that is not rotated var c = new Canvas(); c.Children.Add(tb); this.Add(c); } else { this.Add(tb); } }
/// <summary> /// Draws the polyline from the specified points. /// </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.IsInvisible() || thickness <= 0) { return; } this.g.SmoothingMode = aliased ? XSmoothingMode.None : XSmoothingMode.HighQuality; var pen = new XPen(ToColor(stroke), (float)thickness); if (dashArray != null) { pen.DashPattern = dashArray; } switch (lineJoin) { case LineJoin.Round: pen.LineJoin = XLineJoin.Round; break; case LineJoin.Bevel: pen.LineJoin = XLineJoin.Bevel; break; // The default LineJoin is Miter } this.g.DrawLines(pen, ToPoints(points)); }
/// <summary> /// The draw text. /// </summary> /// <param name="p">The p.</param> /// <param name="text">The text.</param> /// <param name="fill">The fill.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">The font size.</param> /// <param name="fontWeight">The font weight.</param> /// <param name="rotate">The rotate.</param> /// <param name="halign">The horizontal alignment.</param> /// <param name="valign">The vertical alignment.</param> /// <param name="maxSize">The maximum size of the text.</param> public void DrawText( ScreenPoint p, string text, OxyColor fill, string fontFamily, double fontSize, double fontWeight, double rotate, OxyPlot.HorizontalAlignment halign, OxyPlot.VerticalAlignment valign, OxySize? maxSize) { if (fill.IsInvisible() || string.IsNullOrEmpty(text)) { return; } var tb = new TextBlock { Text = text, Foreground = fill.ToBrush() }; // tb.SetValue(TextOptions.TextHintingModeProperty, TextHintingMode.Animated); if (fontFamily != null) { tb.FontFamily = new FontFamily(fontFamily); } if (fontSize > 0) { tb.FontSize = fontSize; } tb.FontWeight = GetFontWeight(fontWeight); tb.Measure(new Size(1000, 1000)); double dx = 0; if (halign == OxyPlot.HorizontalAlignment.Center) { dx = -tb.ActualWidth / 2; } if (halign == OxyPlot.HorizontalAlignment.Right) { dx = -tb.ActualWidth; } double dy = 0; if (valign == OxyPlot.VerticalAlignment.Middle) { dy = -tb.ActualHeight / 2; } if (valign == OxyPlot.VerticalAlignment.Bottom) { dy = -tb.ActualHeight; } var transform = new TransformGroup(); transform.Children.Add(new TranslateTransform { X = (int)dx, Y = (int)dy }); if (!rotate.Equals(0.0)) { transform.Children.Add(new RotateTransform { Angle = rotate }); } transform.Children.Add(new TranslateTransform { X = (int)p.X, Y = (int)p.Y }); tb.RenderTransform = transform; if (this.clip.HasValue) { // add a clipping container that is not rotated var c = new Canvas(); c.Children.Add(tb); this.Add(c); } else { this.Add(tb); } }
/// <summary> /// Writes text. /// </summary> /// <param name="position">The position.</param> /// <param name="text">The text.</param> /// <param name="fill">The text color.</param> /// <param name="fontFamily">The font family.</param> /// <param name="fontSize">The font size (in user units).</param> /// <param name="fontWeight">The font weight.</param> /// <param name="rotate">The rotation angle.</param> /// <param name="halign">The horizontal alignment.</param> /// <param name="valign">The vertical alignment.</param> public void WriteText( ScreenPoint position, string text, OxyColor fill, string fontFamily = null, double fontSize = 10, double fontWeight = FontWeights.Normal, double rotate = 0, HorizontalAlignment halign = HorizontalAlignment.Left, VerticalAlignment valign = VerticalAlignment.Top) { // http://www.w3.org/TR/SVG/text.html this.WriteStartElement("text"); // WriteAttributeString("x", position.X); // WriteAttributeString("y", position.Y); string baselineAlignment = "hanging"; if (valign == VerticalAlignment.Middle) { baselineAlignment = "middle"; } if (valign == VerticalAlignment.Bottom) { baselineAlignment = "baseline"; } this.WriteAttributeString("dominant-baseline", baselineAlignment); string textAnchor = "start"; if (halign == HorizontalAlignment.Center) { textAnchor = "middle"; } if (halign == HorizontalAlignment.Right) { textAnchor = "end"; } this.WriteAttributeString("text-anchor", textAnchor); string fmt = "translate({0:" + this.NumberFormat + "},{1:" + this.NumberFormat + "})"; string transform = string.Format(CultureInfo.InvariantCulture, fmt, position.X, position.Y); if (Math.Abs(rotate) > 0) { transform += string.Format(CultureInfo.InvariantCulture, " rotate({0})", rotate); } this.WriteAttributeString("transform", transform); if (fontFamily != null) { this.WriteAttributeString("font-family", fontFamily); } if (fontSize > 0) { this.WriteAttributeString("font-size", fontSize); } if (fontWeight > 0) { this.WriteAttributeString("font-weight", fontWeight); } if (fill.IsInvisible()) { this.WriteAttributeString("fill", "none"); } else { this.WriteAttributeString("fill", this.ColorToString(fill)); if (fill.A != 0xFF) { this.WriteAttributeString("fill-opacity", fill.A / 255.0); } } this.WriteClipPathAttribute(); // WriteAttributeString("style", style); this.WriteString(text); this.WriteEndElement(); }
/// <summary> /// Sets the stroke properties of the specified shape. /// </summary> /// <param name="shape">The shape.</param> /// <param name="stroke">The stroke.</param> /// <param name="thickness">The thickness.</param> /// <param name="lineJoin">The line join.</param> /// <param name="dashArray">The dash array.</param> /// <param name="aliased">The aliased.</param> // ReSharper disable UnusedParameter.Local private void SetStroke( Shape shape, OxyColor stroke, double thickness, OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter, double[] dashArray = null, bool aliased = false) { if (stroke.IsInvisible() || thickness <= 0) { return; } shape.Stroke = this.GetCachedBrush(stroke); switch (lineJoin) { case OxyPenLineJoin.Round: shape.StrokeLineJoin = PenLineJoin.Round; break; case OxyPenLineJoin.Bevel: shape.StrokeLineJoin = PenLineJoin.Bevel; break; // The default StrokeLineJoin is Miter } if (!thickness.Equals(1.0)) { // default values is 1 shape.StrokeThickness = thickness; } if (dashArray != null) { shape.StrokeDashArray = CreateDashArrayCollection(dashArray); } // shape.UseLayoutRounding = aliased; }