From bc1d94f4cac9df38ac68c0b89fdd61c901bc531c Mon Sep 17 00:00:00 2001 From: Tebjan Halm Date: Sat, 24 Dec 2011 04:56:06 +0100 Subject: [PATCH] * path tag writing works now * added few enum converters --- Source/Painting/EnumConverters.cs | 13 ++++++++- Source/Painting/SvgPatternServer.cs | 11 ++++++++ Source/Paths/SvgArcSegment.cs | 7 +++++ Source/Paths/SvgClosePathSegment.cs | 6 ++++ Source/Paths/SvgCubicCurveSegment.cs | 2 +- Source/Paths/SvgLineSegment.cs | 6 ++++ Source/Paths/SvgMoveToSegment.cs | 6 ++++ Source/Paths/SvgPathBuilder.cs | 35 +++++++++++++++++++++++- Source/Paths/SvgQuadraticCurveSegment.cs | 6 ++++ 9 files changed, 89 insertions(+), 3 deletions(-) diff --git a/Source/Painting/EnumConverters.cs b/Source/Painting/EnumConverters.cs index 6dfc1b0..3e4ab87 100644 --- a/Source/Painting/EnumConverters.cs +++ b/Source/Painting/EnumConverters.cs @@ -95,5 +95,16 @@ namespace Svg //implementaton for clip rule public sealed class SvgClipRuleConverter : EnumBaseConverter { - } + } + + //implementaton for clip rule + public sealed class SvgTextAnchorConverter : EnumBaseConverter + { + } + + //implementaton for preserve aspect ratio + public sealed class SvgPreserverAspectRatioConverter : EnumBaseConverter + { + } + } diff --git a/Source/Painting/SvgPatternServer.cs b/Source/Painting/SvgPatternServer.cs index 95764e8..1bd3454 100644 --- a/Source/Painting/SvgPatternServer.cs +++ b/Source/Painting/SvgPatternServer.cs @@ -31,6 +31,17 @@ namespace Svg get { return this._viewBox; } set { this._viewBox = value; } } + + /// + /// Gets or sets the aspect of the viewport. + /// + /// + [SvgAttribute("preserveAspectRatio")] + public SvgAspectRatio AspectRatio + { + get; + set; + } /// /// Gets or sets the width of the pattern. diff --git a/Source/Paths/SvgArcSegment.cs b/Source/Paths/SvgArcSegment.cs index 011d3e7..f0e2488 100644 --- a/Source/Paths/SvgArcSegment.cs +++ b/Source/Paths/SvgArcSegment.cs @@ -152,6 +152,13 @@ namespace Svg.Pathing startY = (float)endpointY; } } + + public override string ToString() + { + var arcFlag = this.Size == SvgArcSize.Large ? "1" : "0"; + var sweepFlag = this.Sweep == SvgArcSweep.Positive ? "1" : "0"; + return "A" + this.RadiusX.ToString() + " " + this.RadiusY.ToString() + " " + this.Angle.ToString() + " " + arcFlag + " " + sweepFlag + " " + this.End.ToSvgString(); + } } [Flags] diff --git a/Source/Paths/SvgClosePathSegment.cs b/Source/Paths/SvgClosePathSegment.cs index 43b567b..3f028d0 100644 --- a/Source/Paths/SvgClosePathSegment.cs +++ b/Source/Paths/SvgClosePathSegment.cs @@ -10,5 +10,11 @@ namespace Svg.Pathing { graphicsPath.CloseFigure(); } + + public override string ToString() + { + return "z"; + } + } } diff --git a/Source/Paths/SvgCubicCurveSegment.cs b/Source/Paths/SvgCubicCurveSegment.cs index b9950a4..b977949 100644 --- a/Source/Paths/SvgCubicCurveSegment.cs +++ b/Source/Paths/SvgCubicCurveSegment.cs @@ -37,7 +37,7 @@ namespace Svg.Pathing public override string ToString() { - return String.Format("C {0} {1} {2}", this.FirstControlPoint, this.SecondControlPoint, this.End); + return "C" + this.FirstControlPoint.ToSvgString() + " " + this.SecondControlPoint.ToSvgString() + " " + this.End.ToSvgString(); } } } diff --git a/Source/Paths/SvgLineSegment.cs b/Source/Paths/SvgLineSegment.cs index 9a04fdb..61ed708 100644 --- a/Source/Paths/SvgLineSegment.cs +++ b/Source/Paths/SvgLineSegment.cs @@ -17,5 +17,11 @@ namespace Svg.Pathing { graphicsPath.AddLine(this.Start, this.End); } + + public override string ToString() + { + return "L" + this.End.ToSvgString(); + } + } } \ No newline at end of file diff --git a/Source/Paths/SvgMoveToSegment.cs b/Source/Paths/SvgMoveToSegment.cs index 6d44fc5..e9e1e3c 100644 --- a/Source/Paths/SvgMoveToSegment.cs +++ b/Source/Paths/SvgMoveToSegment.cs @@ -17,5 +17,11 @@ namespace Svg.Pathing { graphicsPath.StartFigure(); } + + public override string ToString() + { + return "M" + this.Start.ToSvgString(); + } + } } diff --git a/Source/Paths/SvgPathBuilder.cs b/Source/Paths/SvgPathBuilder.cs index 1a0b46b..5e86d03 100644 --- a/Source/Paths/SvgPathBuilder.cs +++ b/Source/Paths/SvgPathBuilder.cs @@ -4,11 +4,19 @@ using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Globalization; - +using System.Linq; using Svg.Pathing; namespace Svg { + public static class PointFExtensions + { + public static string ToSvgString(this PointF p) + { + return p.X.ToString() + " " + p.Y.ToString(); + } + } + internal class SvgPathBuilder : TypeConverter { /// @@ -256,6 +264,31 @@ namespace Svg } return base.ConvertFrom(context, culture, value); + } + + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == typeof(string)) + { + var paths = value as SvgPathSegmentList; + + if (paths != null) + { + return string.Join(" ", paths.Select(p => p.ToString()).ToArray()); + } + } + + return base.ConvertTo(context, culture, value, destinationType); + } + + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + { + if (destinationType == typeof(string)) + { + return true; + } + + return base.CanConvertTo(context, destinationType); } } } \ No newline at end of file diff --git a/Source/Paths/SvgQuadraticCurveSegment.cs b/Source/Paths/SvgQuadraticCurveSegment.cs index d7c88f5..4ed7f5b 100644 --- a/Source/Paths/SvgQuadraticCurveSegment.cs +++ b/Source/Paths/SvgQuadraticCurveSegment.cs @@ -48,5 +48,11 @@ namespace Svg.Pathing { graphicsPath.AddBezier(this.Start, this.FirstControlPoint, this.SecondControlPoint, this.End); } + + public override string ToString() + { + return "Q" + this.ControlPoint.ToSvgString() + " " + this.End.ToSvgString(); + } + } } -- GitLab