diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/CmykColor.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/CmykColor.cs deleted file mode 100644 index 26a91e1..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/CmykColor.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using System.Globalization; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - /// - /// Represents a color in the CMYK color space - /// - public struct CmykColor : IEquatable - { - /// - /// Gets a color with CMYK values of (0, 0, 0, 100) - /// - public static readonly CmykColor Black = new CmykColor(0, 0, 0, 100); - - /// - /// Gets a color with CMYK values of (0, 0, 0, 0) - /// - public static readonly CmykColor White = new CmykColor(0, 0, 0, 0); - - /// - /// Gets a color with CMYK values of (100, 0, 0, 0) - /// - public static readonly CmykColor Cyan = new CmykColor(100, 0, 0, 0); - - /// - /// Gets a color with CMYK values of (0, 100, 0, 0) - /// - public static readonly CmykColor Magenta = new CmykColor(0, 100, 0, 0); - - /// - /// Gets a color with CMYK values of (0, 0, 100, 0) - /// - public static readonly CmykColor Yellow = new CmykColor(0, 0, 100, 0); - - /// - /// Gets the Cyan component (0-100) - /// - public readonly byte C; - - /// - /// Gets the Magenta component (0-100) - /// - public readonly byte M; - - /// - /// Gets the Yellow component (0-100) - /// - public readonly byte Y; - - /// - /// Gets the Black component (0-100) - /// - public readonly byte K; - - /// - /// Creates a new instance of - /// - /// cyan channel intensity between 0..100 - /// magenta channel intensity between 0..100 - /// yellow channel intensity between 0..100 - /// black channel intensity between 0..100 - public CmykColor(byte c, byte m, byte y, byte k) - { - C = EnsureValidIntensity(c); - M = EnsureValidIntensity(m); - Y = EnsureValidIntensity(y); - K = EnsureValidIntensity(k); - } - - /// - /// Creates a new instance of from the values in the specified string - /// - public CmykColor(string color) - { - if (string.IsNullOrWhiteSpace(color)) throw new ArgumentException(nameof(color)); - if (color.StartsWith("#")) - { - C = byte.Parse(color.Substring(1, 2), NumberStyles.HexNumber); - M = byte.Parse(color.Substring(3, 2), NumberStyles.HexNumber); - Y = byte.Parse(color.Substring(5, 2), NumberStyles.HexNumber); - K = byte.Parse(color.Substring(7, 2), NumberStyles.HexNumber); - } - else if (color.StartsWith("(") && color.EndsWith(")")) - { - var values = color.Substring(1, color.Length - 2).Split(','); - if (values.Length != 4) - { - throw new ArgumentException($"Expected (C,M,Y,K) but got '{color}'", nameof(color)); - } - C = byte.Parse(values[0]); - M = byte.Parse(values[1]); - Y = byte.Parse(values[2]); - K = byte.Parse(values[3]); - } - else - { - throw new ArgumentException("Invalid color, expected hex or value encoded (e.g. '#B8BDB900', '(72, 74, 73, 0)')", nameof(color)); - } - } - - /// - /// Returns the hash code for the color structure - /// - public override int GetHashCode() - { - unchecked - { - var hashCode = C.GetHashCode(); - hashCode = (hashCode * 397) ^ M.GetHashCode(); - hashCode = (hashCode * 397) ^ Y.GetHashCode(); - hashCode = (hashCode * 397) ^ K.GetHashCode(); - return hashCode; - } - } - - /// - /// Indicates whether the specified color is equal to the current color. - /// - public bool Equals(CmykColor other) => C == other.C && M == other.M && Y == other.Y && K == other.K; - - /// - /// Indicates whether the specified object is equal to the current color. - /// - public override bool Equals(object obj) => !ReferenceEquals(null, obj) && obj is CmykColor cmyk && Equals(cmyk); - - /// - /// Compares two colors for exact equality - /// - public static bool operator ==(CmykColor left, CmykColor right) => left.Equals(right); - - /// - /// Compares two colors for inequality - /// - public static bool operator !=(CmykColor left, CmykColor right) => !left.Equals(right); - - /// - /// Returns the string representation of the color - /// - public override string ToString() => $"#{C:x2}{M:x2}{Y:x2}{K:x2}"; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static byte EnsureValidIntensity(byte value) => value <= 100 ? value : throw new ArgumentOutOfRangeException(nameof(value), $"channel intensity should be between 0..100 but got {value}"); - } -} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Color.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Color.cs deleted file mode 100644 index 9b9d6cb..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Color.cs +++ /dev/null @@ -1,231 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - /// - /// Represents a color in multiple color spaces - /// - [DataContract] - public struct Color : IEquatable - { - /// - /// Gets the system defined No color - /// - public static readonly Color NoColor = new Color(); - - /// - /// Gets the system defined Black color - /// - public static readonly Color Black = new Color(EquinoxLabs.SVGSharpie.DynamicPDF.RgbColor.Black, EquinoxLabs.SVGSharpie.DynamicPDF.CmykColor.Black); - - /// - /// Gets the system defined White color - /// - public static readonly Color White = new Color(EquinoxLabs.SVGSharpie.DynamicPDF.RgbColor.White, EquinoxLabs.SVGSharpie.DynamicPDF.CmykColor.White); - - /// - /// Gets the color in the RGB color space - /// - [DataMember] - public RgbColor? RgbColor { get; private set; } - - /// - /// Gets the color in the CMYK color space - /// - [DataMember] - public CmykColor? CmykColor { get; private set; } - - /// - /// Gets the color in the Spot color space - /// - [DataMember] - public SpotColor? SpotColor { get; private set; } - - /// - /// Gets a value indicating whether the current color is empty (no values specified) - /// - [IgnoreDataMember] - public bool IsNone => !RgbColor.HasValue && !CmykColor.HasValue && !SpotColor.HasValue; - - /// - /// Creates a new instance color with just an RGB representation - /// - public Color(RgbColor rgb) - { - RgbColor = rgb; - CmykColor = null; - SpotColor = null; - } - - /// - /// Creates a new instance color with just a CMYK representation - /// - public Color(CmykColor cmyk) - { - RgbColor = null; - CmykColor = cmyk; - SpotColor = null; - } - - /// - /// Creates a new instance color with RGB, CMYK and Spot representations - /// - public Color(RgbColor? rgb, CmykColor? cmyk = null, SpotColor? spot = null) - { - RgbColor = rgb; - CmykColor = cmyk; - SpotColor = spot; - } - - /// - /// Creates a new instance color from the specified string representation - /// - public Color(string color) - { - if (color == null) throw new ArgumentNullException(nameof(color)); - RgbColor = null; - CmykColor = null; - SpotColor = null; - - if (color.StartsWith("#")) - { - RgbColor = new RgbColor(color); - return; - } - - void ParseColorSpace(ref Color self, string space) - { - var pair = space.Split(ColorSpaceValueSplitChars, StringSplitOptions.RemoveEmptyEntries); - var colorSpace = pair[0]; - var colorValue = pair.Length == 2 ? pair[1] : string.Empty; - if (pair.Length != 2) - { - var index = space.IndexOf("(", StringComparison.OrdinalIgnoreCase); - if (index < 0) - { - throw new Exception($"Invalid color space value '{space}'"); - } - colorSpace = space.Substring(0, index); - colorValue = space.Substring(index); - } - if (ColorSpaceInitializers.TryGetValue(colorSpace.ToLowerInvariant(), out var initializer)) - { - initializer(ref self, colorValue); - } - else - { - throw new ArgumentException($"Invalid color space prefix '{colorSpace}', expected one of [{RgbSpacePrefix}, {CmykSpacePrefix}, {SpotSpacePrefix}]"); - } - } - - var builder = new StringBuilder(); - var scope = 0; - for (var i = 0; i < color.Length; i++) - { - var c = color[i]; - if (c == ColorSpaceSplitChar && scope == 0) - { - var space = builder.ToString(); - ParseColorSpace(ref this, space); - builder.Clear(); - } - else if (!char.IsWhiteSpace(c)) - { - if (c == '(') scope++; - else if (c == ')') scope--; - builder.Append(c); - } - } - if (builder.Length > 0) - { - ParseColorSpace(ref this, builder.ToString()); - } - } - - /// - /// Returns the string representation of the current color - /// - public override string ToString() - { - var builder = new StringBuilder(); - if (RgbColor.HasValue && !CmykColor.HasValue && !SpotColor.HasValue) - { - return RgbColor.Value.ToString(); - } - if (RgbColor.HasValue) - { - builder.Append(RgbSpacePrefix).Append(ColorSpaceValueSplitChar).Append(RgbColor.Value); - } - if (CmykColor.HasValue) - { - if (builder.Length > 0) builder.Append(ColorSpaceSplitChar); - builder.Append(CmykSpacePrefix).Append(ColorSpaceValueSplitChar).Append(CmykColor.Value); - } - if (SpotColor.HasValue) - { - if (builder.Length > 0) builder.Append(ColorSpaceSplitChar); - builder.Append(SpotSpacePrefix).Append(ColorSpaceValueSplitChar).Append(SpotColor.Value); - } - return builder.ToString(); - } - - /// - /// Indicates whether the specified color is equal to the current color. - /// - public bool Equals(Color other) => RgbColor.Equals(other.RgbColor) && CmykColor.Equals(other.CmykColor) && SpotColor.Equals(other.SpotColor); - - /// - /// Indicates whether the specified object is equal to the current color. - /// - public override bool Equals(object obj) => !ReferenceEquals(null, obj) && obj is Color color && Equals(color); - - /// - /// Compares two colors for exact equality - /// - public static bool operator ==(Color left, Color right) => left.Equals(right); - - /// - /// Compares two colors for inequality - /// - public static bool operator !=(Color left, Color right) => !left.Equals(right); - - /// - /// Returns the hash code for the color structure - /// - public override int GetHashCode() - { - unchecked - { - // ReSharper disable once NonReadonlyMemberInGetHashCode - var hashCode = RgbColor.GetHashCode(); - // ReSharper disable once NonReadonlyMemberInGetHashCode - hashCode = (hashCode * 397) ^ CmykColor.GetHashCode(); - // ReSharper disable once NonReadonlyMemberInGetHashCode - hashCode = (hashCode * 397) ^ SpotColor.GetHashCode(); - return hashCode; - } - } - - private const string RgbSpacePrefix = "rgb"; - private const string CmykSpacePrefix = "cmyk"; - private const string SpotSpacePrefix = "spot"; - - private const char ColorSpaceSplitChar = ','; - private const char ColorSpaceValueSplitChar = ':'; - private static readonly char[] ColorSpaceValueSplitChars = { ColorSpaceValueSplitChar }; - - private delegate void ColorSpaceInitializerDelegate(ref Color self, string value); - - private static readonly Dictionary ColorSpaceInitializers = new Dictionary - { - { RgbSpacePrefix, (ref Color self, string value) => self.RgbColor = new RgbColor(value) }, - { CmykSpacePrefix, (ref Color self, string value) => self.CmykColor = new CmykColor(value) }, - { SpotSpacePrefix, (ref Color self, string value) => self.SpotColor = new SpotColor(value) } - }; - } -} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/ColorExtensions.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/ColorExtensions.cs deleted file mode 100644 index 6608263..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/ColorExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -using ceTe.DynamicPDF; -using Color = EquinoxLabs.SVGSharpie.DynamicPDF.Color; -using PdfColor = ceTe.DynamicPDF.Color; -using PdfCmykColor = ceTe.DynamicPDF.CmykColor; -using PdfSpotColor = ceTe.DynamicPDF.SpotColor; -using PdfSpotkColorInk = ceTe.DynamicPDF.SpotColorInk; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - internal static class ColorExtensions - { - public static PdfColor ToPdfColor(this Color color, PdfSpotColor spotColorInk) - { - return DynamicPdfColorConverter.ToPdfColor(color, spotColorInk); - } - - public static PdfColor ToPdfColor(this SvgColor color, PdfSpotColor spotColorOverride) - { - if (spotColorOverride != null) - { - return spotColorOverride; - } - return new ceTe.DynamicPDF.RgbColor(color.R, color.G, color.B); - } - } -} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/ClippingGroup.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/ClippingGroup.cs similarity index 93% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/ClippingGroup.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/ClippingGroup.cs index ee169fe..cf7095c 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/ClippingGroup.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/ClippingGroup.cs @@ -1,9 +1,8 @@ using ceTe.DynamicPDF; using ceTe.DynamicPDF.IO; using ceTe.DynamicPDF.PageElements; -using Rectangle = EquinoxLabs.SVGSharpie.DynamicPDF.Rectangle; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { /// /// Draws a rectangular clipping group around the child elements. All children will be clipped to the @@ -18,8 +17,9 @@ namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements /// the clipping rectangle to which the child elements will be clipped /// the child elements to add to the clipping group public ClippingGroup(Rectangle clippingRectangle, params PageElement[] children) - : this(clippingRectangle.X, clippingRectangle.Y, clippingRectangle.Right, clippingRectangle.Bottom, children) + : this(clippingRectangle.X, clippingRectangle.Y, clippingRectangle.X + clippingRectangle.Width, clippingRectangle.Y + clippingRectangle.Height, children) { + } /// diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/CloseSubPath.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/CloseSubPath.cs similarity index 83% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/CloseSubPath.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/CloseSubPath.cs index 657734b..96f580f 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/CloseSubPath.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/CloseSubPath.cs @@ -1,7 +1,7 @@ using ceTe.DynamicPDF.IO; using ceTe.DynamicPDF.PageElements; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { /// /// Represents a 'closepath' sub path command and writes the PDF 'h' operator diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/CustomPath.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/CustomPath.cs similarity index 98% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/CustomPath.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/CustomPath.cs index dd58a88..3d8f19e 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/CustomPath.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/CustomPath.cs @@ -2,7 +2,7 @@ using ceTe.DynamicPDF.IO; using ceTe.DynamicPDF.PageElements; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { /// /// Customized PDF path renderer, the base doesn't support fill rules other than non-zero diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/HorizontalAlignment.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/HorizontalAlignment.cs new file mode 100644 index 0000000..09f8518 --- /dev/null +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/HorizontalAlignment.cs @@ -0,0 +1,25 @@ +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core +{ + /// + /// Describes how a child element is horizontally positioned or stretched within a parent elements layout + /// + public enum HorizontalAlignment + { + /// + /// An element aligned to the left of the layout slot for the parent element. + /// + Left, + /// + /// An element aligned to the center of the layout slot for the parent element. + /// + Center, + /// + /// An element aligned to the right of the layout slot for the parent element. + /// + Right, + /// + /// An element stretched to fill the entire layout slot of the parent element. + /// + Stretch + } +} \ No newline at end of file diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/MoveSubPath.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/MoveSubPath.cs similarity index 91% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/MoveSubPath.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/MoveSubPath.cs index 590d2a2..77c40ca 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/MoveSubPath.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/MoveSubPath.cs @@ -1,7 +1,7 @@ using ceTe.DynamicPDF.IO; using ceTe.DynamicPDF.PageElements; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { /// /// Represents a 'moveto' sub path command, when added to a , is used to diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Rectangle.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Rectangle.cs new file mode 100644 index 0000000..8f3b797 --- /dev/null +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Rectangle.cs @@ -0,0 +1,46 @@ +using System.Runtime.Serialization; + +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core +{ + /// + /// Describes the width, height and location of a rectangle + /// + [DataContract] + public struct Rectangle + { + /// + /// Gets or sets the x-axis value of the left side of the rectangle. + /// + [DataMember(Name = "X")] + public double X { get; set; } + + /// + /// Gets or sets the y-axis value of the top side of the rectangle. + /// + [DataMember(Name = "Y")] + public double Y { get; set; } + + /// + /// Gets or sets the width of the rectangle + /// + [DataMember] + public double Width { get; set; } + + /// + /// Gets or sets the height of the rectangle + /// + [DataMember] + public double Height { get; set; } + + /// + /// Initializes a new instance of the Rectangle structure that has the specified x-coordinate, y-coordinate, width, and height. + /// + public Rectangle(double x, double y, double width, double height) + { + X = x; + Y = y; + Width = width; + Height = height; + } + } +} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/Circle.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/Circle.cs similarity index 94% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/Circle.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/Circle.cs index 0ce0308..0cafeb8 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/Circle.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/Circle.cs @@ -1,6 +1,6 @@ using System; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements.Shading +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core.Shading { internal struct Circle : IEquatable { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/GradientColorStop.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/GradientColorStop.cs similarity index 94% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/GradientColorStop.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/GradientColorStop.cs index 49ec720..41fccc8 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/GradientColorStop.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/GradientColorStop.cs @@ -2,7 +2,7 @@ using ceTe.DynamicPDF; using PdfColor = ceTe.DynamicPDF.Color; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements.Shading +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core.Shading { internal struct GradientColorStop : IEquatable { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/GradientShadingColor.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/GradientShadingColor.cs similarity index 99% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/GradientShadingColor.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/GradientShadingColor.cs index 29b5547..565b6e8 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/GradientShadingColor.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/GradientShadingColor.cs @@ -6,7 +6,7 @@ using ceTe.DynamicPDF; using ceTe.DynamicPDF.IO; using PdfColor = ceTe.DynamicPDF.Color; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements.Shading +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core.Shading { internal abstract class GradientShadingColor : GradientShadingColor, IEquatable where T : GradientShadingColor diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/LinearGradientShadingColor.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/LinearGradientShadingColor.cs similarity index 97% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/LinearGradientShadingColor.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/LinearGradientShadingColor.cs index 4b250e1..7e9efc7 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/LinearGradientShadingColor.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/LinearGradientShadingColor.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Drawing; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements.Shading +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core.Shading { internal sealed class LinearGradientShadingColor : GradientShadingColor { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/RadialGradientShadingColor.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/RadialGradientShadingColor.cs similarity index 96% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/RadialGradientShadingColor.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/RadialGradientShadingColor.cs index f1cad99..7621ccd 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/RadialGradientShadingColor.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/RadialGradientShadingColor.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Drawing; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements.Shading +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core.Shading { internal sealed class RadialGradientShadingColor : GradientShadingColor { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/ShadingType.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/ShadingType.cs similarity index 82% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/ShadingType.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/ShadingType.cs index 6ef2e6f..b982913 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/Shading/ShadingType.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/Shading/ShadingType.cs @@ -1,4 +1,4 @@ -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements.Shading +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core.Shading { internal enum ShadingType { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgClipPathMaskWriterVisitor.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgClipPathMaskWriterVisitor.cs similarity index 97% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgClipPathMaskWriterVisitor.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgClipPathMaskWriterVisitor.cs index 196f929..47d3fb6 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgClipPathMaskWriterVisitor.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgClipPathMaskWriterVisitor.cs @@ -1,12 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using ceTe.DynamicPDF; using ceTe.DynamicPDF.IO; -using EquinoxLabs.SVGSharpie; using PdfSpotColor = ceTe.DynamicPDF.SpotColor; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { internal sealed class SvgClipPathMaskWriterVisitor : SvgElementVisitor { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgClipPathPageElement.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgClipPathPageElement.cs similarity index 94% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgClipPathPageElement.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgClipPathPageElement.cs index ae04b79..dfd4a1a 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgClipPathPageElement.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgClipPathPageElement.cs @@ -1,10 +1,9 @@ using System; using ceTe.DynamicPDF; using ceTe.DynamicPDF.IO; -using EquinoxLabs.SVGSharpie; using PdfSpotColor = ceTe.DynamicPDF.SpotColor; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { internal sealed class SvgClipPathPageElement : PageElement { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgElementToDynamicPdfElementConverter.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgElementToDynamicPdfElementConverter.cs similarity index 98% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgElementToDynamicPdfElementConverter.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgElementToDynamicPdfElementConverter.cs index d779baa..d365607 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgElementToDynamicPdfElementConverter.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgElementToDynamicPdfElementConverter.cs @@ -3,12 +3,10 @@ using System.Collections.Generic; using System.Linq; using ceTe.DynamicPDF; using ceTe.DynamicPDF.PageElements; -using EquinoxLabs.SVGSharpie; -using EquinoxLabs.SVGSharpie.DynamicPDF; using EquinoxLabs.SVGSharpie.DynamicPDF.Extensions; using PdfSpotColor = ceTe.DynamicPDF.SpotColor; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { /// /// diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/SvgPageElement.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPageElement.cs similarity index 89% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/SvgPageElement.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPageElement.cs index 08cfbf8..6324b61 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/SvgPageElement.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPageElement.cs @@ -2,10 +2,9 @@ using ceTe.DynamicPDF; using ceTe.DynamicPDF.IO; using ceTe.DynamicPDF.PageElements; -using EquinoxLabs.SVGSharpie; using PdfSpotColor = ceTe.DynamicPDF.SpotColor; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { /// /// Represents a DynamicPdf graphical where the @@ -29,7 +28,7 @@ namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements public PdfSpotColor SpotColorOveride { get; set; } - public SvgPageElement(SvgDocument svgDocument, EquinoxLabs.SVGSharpie.DynamicPDF.Rectangle bounds, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Center, VerticalAlignment verticalAlignment = VerticalAlignment.Center) + public SvgPageElement(SvgDocument svgDocument, Rectangle bounds, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Center, VerticalAlignment verticalAlignment = VerticalAlignment.Center) : this(svgDocument, (float)bounds.X, (float)bounds.Y, (float)bounds.Width, (float)bounds.Height, horizontalAlignment, verticalAlignment) { } diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgPaintServerToDynamicPdfColorConverter.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPaintServerToDynamicPdfColorConverter.cs similarity index 96% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgPaintServerToDynamicPdfColorConverter.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPaintServerToDynamicPdfColorConverter.cs index b7b4835..393772e 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgPaintServerToDynamicPdfColorConverter.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPaintServerToDynamicPdfColorConverter.cs @@ -2,15 +2,12 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; -//using PNI.Apollo.Render.Services.DynamicPdf.Extensions; -using PNI.Apollo.Render.Services.DynamicPdf.PageElements.Shading; -using EquinoxLabs.SVGSharpie; +using EquinoxLabs.SVGSharpie.DynamicPDF.Extensions; using Color = ceTe.DynamicPDF.Color; -using EquinoxLabs.SVGSharpie.DynamicPDF; -using ceTe.DynamicPDF; +using EquinoxLabs.SVGSharpie.DynamicPDF.Core.Shading; using PdfSpotColor = ceTe.DynamicPDF.SpotColor; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { internal sealed class SvgPaintServerToDynamicPdfColorConverter { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgPathSegToDynamicPdfPathsConverter.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPathSegToDynamicPdfPathsConverter.cs similarity index 96% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgPathSegToDynamicPdfPathsConverter.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPathSegToDynamicPdfPathsConverter.cs index 9750d8d..df840ec 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/SvgPathSegToDynamicPdfPathsConverter.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/SvgPathSegToDynamicPdfPathsConverter.cs @@ -3,12 +3,10 @@ using System.Collections.Generic; using System.Linq; using ceTe.DynamicPDF; using ceTe.DynamicPDF.PageElements; -//using PNI.Apollo.Render.Services.DynamicPdf.Extensions; -using EquinoxLabs.SVGSharpie; -using EquinoxLabs.SVGSharpie.DynamicPDF; using PdfSpotColor = ceTe.DynamicPDF.SpotColor; +using EquinoxLabs.SVGSharpie.DynamicPDF.Extensions; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { /// /// Transforms path segments composed only of , diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/VectorElementPdfPageViewport.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/VectorElementPdfPageViewport.cs similarity index 63% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/VectorElementPdfPageViewport.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/VectorElementPdfPageViewport.cs index fe93f1a..dc9c64b 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/PageElements/Svg/VectorElementPdfPageViewport.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/VectorElementPdfPageViewport.cs @@ -1,53 +1,8 @@ using System; using System.Drawing; -namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core { - public enum VerticalAlignment - { - /// - /// The child element is aligned to the top of the parent's layout slot. - /// - Top, - /// - /// The child element is aligned to the center of the parent's layout slot. - /// - Center, - /// - /// The child element is aligned to the bottom of the parent's layout slot. - /// - Bottom, - /// - /// The child element is stretched to fill the parent's layout slot. - /// - Stretch - } - - - /// - /// Describes how a child element is horizontally positioned or stretched within a parent elements layout - /// - public enum HorizontalAlignment - { - /// - /// An element aligned to the left of the layout slot for the parent element. - /// - Left, - /// - /// An element aligned to the center of the layout slot for the parent element. - /// - Center, - /// - /// An element aligned to the right of the layout slot for the parent element. - /// - Right, - /// - /// An element stretched to fill the entire layout slot of the parent element. - /// - Stretch - } - - internal sealed class VectorElementPdfPageViewport { /// @@ -80,11 +35,6 @@ namespace PNI.Apollo.Render.Services.DynamicPdf.PageElements /// public bool ClippingGroupRequired { get; } - //public VectorElementPdfPageViewport(float contentWidth, float contentHeight, VectorElement element) - // : this(contentWidth, contentHeight, (float)element.Bounds.X, (float)element.Bounds.Y, (float)element.Bounds.Width, (float)element.Bounds.Height, element.HorizontalAlignment, element.VerticalAlignment) - //{ - //} - public VectorElementPdfPageViewport(float contentWidth, float contentHeight, float x, float y, float width, float height, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment) { ScaleX = width / contentWidth; diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/VerticalAlignment.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/VerticalAlignment.cs new file mode 100644 index 0000000..22f97c1 --- /dev/null +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Core/VerticalAlignment.cs @@ -0,0 +1,22 @@ +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Core +{ + public enum VerticalAlignment + { + /// + /// The child element is aligned to the top of the parent's layout slot. + /// + Top, + /// + /// The child element is aligned to the center of the parent's layout slot. + /// + Center, + /// + /// The child element is aligned to the bottom of the parent's layout slot. + /// + Bottom, + /// + /// The child element is stretched to fill the parent's layout slot. + /// + Stretch + } +} \ No newline at end of file diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/DynamicPdfColorConverter.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/DynamicPdfColorConverter.cs deleted file mode 100644 index 95b54e9..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/DynamicPdfColorConverter.cs +++ /dev/null @@ -1,41 +0,0 @@ -using ceTe.DynamicPDF; -using Color = EquinoxLabs.SVGSharpie.DynamicPDF.Color; -using PdfColor = ceTe.DynamicPDF.Color; -using PdfCmykColor = ceTe.DynamicPDF.CmykColor; -using PdfSpotColor = ceTe.DynamicPDF.SpotColor; -using PdfSpotkColorInk = ceTe.DynamicPDF.SpotColorInk; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - /// - /// Provides functionality to convert from the render langue color to the DynamicPdf color structure - /// - internal static class DynamicPdfColorConverter - { - public static PdfColor ToPdfColor(Color color, PdfSpotColor spotColorOverride) - { - if (spotColorOverride != null) - { - return spotColorOverride; - } - if (color.SpotColor != null) - { - var spotColorName = color.SpotColor.Value.InkName; - var cmyk = color.CmykColor.GetValueOrDefault(); - var cmykAlternate = new PdfCmykColor(cmyk.C / 100f, cmyk.M / 100f, cmyk.Y / 100f, cmyk.K / 100f); - return new PdfSpotColor(100, new PdfSpotkColorInk(spotColorName, cmykAlternate)); - } - if (color.CmykColor != null) - { - var cmyk = color.CmykColor.GetValueOrDefault(); - return new PdfCmykColor(cmyk.C / 100f, cmyk.M / 100f, cmyk.Y / 100f, cmyk.K / 100f); - } - if (color.RgbColor != null) - { - var rgb = color.RgbColor.Value; - return new ceTe.DynamicPDF.RgbColor(rgb.R, rgb.G, rgb.B); - } - return null; - } - } -} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/EquinoxLabs.SVGSharpie.DynamicPDF.csproj b/src/EquinoxLabs.SVGSharpie.DynamicPDF/EquinoxLabs.SVGSharpie.DynamicPDF.csproj index 6363de5..b03fff9 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/EquinoxLabs.SVGSharpie.DynamicPDF.csproj +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/EquinoxLabs.SVGSharpie.DynamicPDF.csproj @@ -31,6 +31,16 @@ + + + + + + + + + + diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/CollectionExtensions.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/CollectionExtensions.cs similarity index 96% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/CollectionExtensions.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/CollectionExtensions.cs index 1f3fd89..5bda155 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/CollectionExtensions.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/CollectionExtensions.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EquinoxLabs.SVGSharpie.DynamicPDF.Extensions { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/ColorExtensions.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/ColorExtensions.cs new file mode 100644 index 0000000..03ea5a0 --- /dev/null +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/ColorExtensions.cs @@ -0,0 +1,18 @@ +using PdfColor = ceTe.DynamicPDF.Color; +using PdfRgbColor = ceTe.DynamicPDF.RgbColor; +using PdfSpotColor = ceTe.DynamicPDF.SpotColor; + +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Extensions +{ + internal static class ColorExtensions + { + public static PdfColor ToPdfColor(this SvgColor color, PdfSpotColor spotColorOverride) + { + if (spotColorOverride != null) + { + return spotColorOverride; + } + return new PdfRgbColor(color.R, color.G, color.B); + } + } +} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/DynamicPdfPageElementExtensions.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/DynamicPdfPageElementExtensions.cs similarity index 83% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/DynamicPdfPageElementExtensions.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/DynamicPdfPageElementExtensions.cs index 4e1bc20..5763e11 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/DynamicPdfPageElementExtensions.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/DynamicPdfPageElementExtensions.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using ceTe.DynamicPDF; using ceTe.DynamicPDF.PageElements; -namespace EquinoxLabs.SVGSharpie.DynamicPDF +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Extensions { internal static class DynamicPdfPageElementExtensions { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/SvgEnumConversionExtensions.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/SvgEnumConversionExtensions.cs similarity index 91% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/SvgEnumConversionExtensions.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/SvgEnumConversionExtensions.cs index c046a51..729f91b 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/SvgEnumConversionExtensions.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Extensions/SvgEnumConversionExtensions.cs @@ -1,12 +1,7 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using ceTe.DynamicPDF; -using EquinoxLabs.SVGSharpie; -namespace EquinoxLabs.SVGSharpie.DynamicPDF +namespace EquinoxLabs.SVGSharpie.DynamicPDF.Extensions { internal static class SvgEnumConversionExtensions { diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Point.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Point.cs deleted file mode 100644 index 00884f1..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Point.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - /// - /// Defines a point in a two-dimensional plane using a pair of x- and y- coordinates. - /// - [DataContract] - public struct Point : IEquatable - { - /// - /// Represents a Point that has and values set to zero. - /// - public static readonly Point Empty = new Point(); - - /// - /// Gets or sets the x-coordinate of this Point. - /// - [DataMember] - public double X { get; set; } - - /// - /// Gets or sets the y-coordinate of this Point. - /// - [DataMember] - public double Y { get; set; } - - /// - /// Gets a value indicating whether this Point is empty (both X and Y are 0, otherwise false) - /// - public bool IsEmpty => - Math.Abs(X) < double.Epsilon && - Math.Abs(Y) < double.Epsilon; - - /// - /// Gets a value indicating whether both the x- and y- axis coordinates are the same - /// - public bool IsUniform => - Math.Abs(X - Y) < double.Epsilon; - - /// - /// Initializes a new instance of the Point class with the specified coordinates. - /// - /// The horizontal position of the point. - /// The vertical position of the point. - public Point(double x, double y) - { - X = x; - Y = y; - } - - /// - /// Returns a value indicating whether this instance and the specified object represent the same value. - /// - public bool Equals(Point other) => X.Equals(other.X) && Y.Equals(other.Y); - - /// - /// Returns a value indicating whether this instance and the specified object represent the same value. - /// - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - return obj is Point && Equals((Point)obj); - } - - public override int GetHashCode() - { - unchecked - { - return (X.GetHashCode() * 397) ^ Y.GetHashCode(); - } - } - - /// - /// Returns a value indicating whether the two specified points represent the same value. - /// - public static bool operator ==(Point left, Point right) => left.Equals(right); - - /// - /// Returns a value indicating whether the two specified points do not represent the same value. - /// - public static bool operator !=(Point left, Point right) => !left.Equals(right); - } -} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Rectangle.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Rectangle.cs deleted file mode 100644 index c1c458b..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Rectangle.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - /// - /// Describes the width, height and location of a rectangle - /// - [DataContract] - public struct Rectangle - { - /// - /// Gets a special value that represents a rectangle with no position or area. - /// - public static Rectangle Empty { get; } - - /// - /// Gets or sets the x-axis value of the left side of the rectangle. - /// - [DataMember(Name = "Left")] - public double X { get; set; } - - /// - /// Gets or sets the y-axis value of the top side of the rectangle. - /// - [DataMember(Name = "Top")] - public double Y { get; set; } - - /// - /// Gets or sets the width of the rectangle - /// - [DataMember] - public double Width { get; set; } - - /// - /// Gets or sets the height of the rectangle - /// - [DataMember] - public double Height { get; set; } - - /// - /// Gets or sets the size of the rectangle - /// - [IgnoreDataMember] - public Size Size - { - get => new Size(Width, Height); - set - { - Width = value.Width; - Height = value.Height; - } - } - - /// - /// Gets a value indicating whether the current rectangle is the rectangle - /// - public bool IsEmpty => - double.IsPositiveInfinity(X) && - double.IsPositiveInfinity(Y) && - double.IsNegativeInfinity(Width) && - double.IsNegativeInfinity(Height); - - /// - /// Gets the x-axis value of the left side of the rectangle. - /// - [IgnoreDataMember] - public double Left => X; - - /// - /// Gets the y-axis value of the top side of the rectangle. - /// - [IgnoreDataMember] - public double Top => Y; - - /// - /// Gets the x-axis value of the right side of the rectangle. - /// - [IgnoreDataMember] - public double Right => X + Width; - - /// - /// Gets the y-axis value of the bottom of the rectangle. - /// - [IgnoreDataMember] - public double Bottom => Y + Height; - - /// - /// Gets the top left point of the rectangle. - /// - [IgnoreDataMember] - public Point TopLeft => new Point(Left, Top); - - /// - /// Gets the top right point of the rectangle. - /// - [IgnoreDataMember] - public Point TopRight => new Point(Right, Top); - - /// - /// Gets the bottom left point of the rectangle. - /// - [IgnoreDataMember] - public Point BottomLeft => new Point(Left, Bottom); - - /// - /// Gets the bottom right point of the rectangle. - /// - [IgnoreDataMember] - public Point BottomRight => new Point(Right, Bottom); - - static Rectangle() - { - Empty = new Rectangle - { - X = double.PositiveInfinity, - Y = double.PositiveInfinity, - Width = double.NegativeInfinity, - Height = double.NegativeInfinity - }; - } - - /// - /// Initializes a new instance of the Rectangle structure that has the specified x-coordinate, y-coordinate, width, and height. - /// - public Rectangle(double x, double y, double width, double height) - { - X = x; - Y = y; - Width = width; - Height = height; - } - - /// - /// Initializes a new instance of the Rectangle structure that has the specified width, and height and is located at (0,0). - /// - public Rectangle(double width, double height) - : this(0, 0, width, height) - { - } - - /// - /// Initializes a new instance of the Rectangle structure that has the specified size and is located at (0,0). - /// - public Rectangle(Size size) - : this(size.Width, size.Height) - { - } - } -} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/SvgImageRenderer.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Renderer.cs similarity index 84% rename from src/EquinoxLabs.SVGSharpie.DynamicPDF/SvgImageRenderer.cs rename to src/EquinoxLabs.SVGSharpie.DynamicPDF/Renderer.cs index d296a10..5a53df1 100644 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/SvgImageRenderer.cs +++ b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Renderer.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ceTe.DynamicPDF; -using PNI.Apollo.Render.Services.DynamicPdf.PageElements; +using ceTe.DynamicPDF; +using EquinoxLabs.SVGSharpie.DynamicPDF.Core; using PdfSpotColor = ceTe.DynamicPDF.SpotColor; namespace EquinoxLabs.SVGSharpie.DynamicPDF { - public static class SvgImageRenderer + public static class Renderer { public static PageElement CreateSvgImagePageElement(SvgDocument document, Rectangle bounds, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, PdfSpotColor spotColorInk) diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/RgbColor.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/RgbColor.cs deleted file mode 100644 index 2e63b77..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/RgbColor.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - /// - /// Represents a color in the RGB color space - /// - public struct RgbColor : IEquatable - { - /// - /// Gets a color with the RGB value of #000000 - /// - public static readonly RgbColor Black = new RgbColor(0, 0, 0); - - /// - /// Gets a color with the RGB value of #FFFFFF - /// - public static readonly RgbColor White = new RgbColor(255, 255, 255); - - /// - /// Gets a color with the RGB value of #FF0000 - /// - public static readonly RgbColor Red = new RgbColor(255, 0, 0); - - /// - /// Gets a color with the RGB value of #00FF00 - /// - public static readonly RgbColor Green = new RgbColor(0, 255, 0); - - /// - /// Gets a color with the RGB value of #0000FF - /// - public static readonly RgbColor Blue = new RgbColor(0, 0, 255); - - /// - /// Gets the Red component - /// - public readonly byte R; - - /// - /// Gets the Green component - /// - public readonly byte G; - - /// - /// Gets the Blue component - /// - public readonly byte B; - - /// - /// Creates a new instance of with the specified channel intensities - /// - public RgbColor(byte r, byte g, byte b) - { - R = r; - G = g; - B = b; - } - - /// - /// Creates a new instance of from the specified string value - /// - public RgbColor(string color) - { - if (string.IsNullOrWhiteSpace(color)) throw new ArgumentException(nameof(color)); - if (color.StartsWith("#")) - { - int HexCharToNumber(char c) - { - if (c >= '0' && c <= '9') return c - '0'; - if (c >= 'a' && c <= 'f') return c - 'a' + 10; - if (c >= 'A' && c <= 'F') return c - 'A' + 10; - throw new Exception($"Invalid character '{c}' in color '{color}'"); - } - - byte HexStrToByte(string str, int index) => (byte)(HexCharToNumber(str[index]) * 16 + HexCharToNumber(str[index + 1])); - - R = HexStrToByte(color, 1); - G = HexStrToByte(color, 3); - B = HexStrToByte(color, 5); - } - else if (color.StartsWith("(") && color.EndsWith(")")) - { - var values = color.Substring(1, color.Length - 2).Split(','); - if (values.Length != 3) - { - throw new ArgumentException($"Expected (R,G,B) but got '{color}'", nameof(color)); - } - R = byte.Parse(values[0]); - G = byte.Parse(values[1]); - B = byte.Parse(values[2]); - } - else - { - throw new ArgumentException($"Invalid color, expected hex or value encoded (e.g. '#7248BD', '(114, 72,189)') got '{color}'", nameof(color)); - } - } - - /// - /// Returns the hash code for the color structure - /// - public override int GetHashCode() - { - unchecked - { - var hashCode = R.GetHashCode(); - hashCode = (hashCode * 397) ^ G.GetHashCode(); - hashCode = (hashCode * 397) ^ B.GetHashCode(); - return hashCode; - } - } - - /// - /// Indicates whether the specified color is equal to the current color. - /// - public bool Equals(RgbColor other) => R == other.R && G == other.G && B == other.B; - - /// - /// Indicates whether the specified object is equal to the current color. - /// - public override bool Equals(object obj) => !ReferenceEquals(null, obj) && obj is RgbColor rgb && Equals(rgb); - - /// - /// Compares two colors for exact equality - /// - public static bool operator ==(RgbColor left, RgbColor right) => left.Equals(right); - - /// - /// Compares two colors for inequality - /// - public static bool operator !=(RgbColor left, RgbColor right) => !left.Equals(right); - - /// - /// Returns the color encoded as a hex string (e.g. '#ccffa0') - /// - public override string ToString() => $"#{R:x2}{G:x2}{B:x2}"; - } -} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Size.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/Size.cs deleted file mode 100644 index 8b92ad6..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/Size.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - /// - /// Describes the size of an object - /// - [DataContract] - public struct Size - { - private double _width; - private double _height; - - /// - /// Gets a special size that represents a size with no area - /// - public static Size Empty { get; } - - /// - /// Gets a value indicating whether the current size is the size - /// - public bool IsEmpty => double.IsNegativeInfinity(_width) && double.IsNegativeInfinity(_height); - - /// - /// Gets or sets the width of the current size - /// - [DataMember] - public double Width - { - get => _width; - set - { - if (value < 0) - { - throw new ArgumentOutOfRangeException(); - } - _width = value; - } - } - - /// - /// Gets or sets the height of the current size - /// - [DataMember] - public double Height - { - get => _height; - set - { - if (value < 0) - { - throw new ArgumentOutOfRangeException(); - } - _height = value; - } - } - - static Size() - { - Empty = new Size - { - _width = double.NegativeInfinity, - _height = double.NegativeInfinity - }; - } - - public Size(double width, double height) - { - if (width < 0) { - throw new ArgumentOutOfRangeException(nameof(width)); - } - if (height < 0) - { - throw new ArgumentOutOfRangeException(nameof(height)); - } - _width = width; - _height = height; - } - } -} diff --git a/src/EquinoxLabs.SVGSharpie.DynamicPDF/SpotColor.cs b/src/EquinoxLabs.SVGSharpie.DynamicPDF/SpotColor.cs deleted file mode 100644 index 9b73194..0000000 --- a/src/EquinoxLabs.SVGSharpie.DynamicPDF/SpotColor.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EquinoxLabs.SVGSharpie.DynamicPDF -{ - /// - /// Describes the type of spot color - /// - public enum SpotColorType - { - /// - /// Pantone proprietary color space - /// - Pantone, - - /// - /// - /// - Generic - } - - /// - /// Represents a spot color, composed of a type and a descriptor specific to that type - /// - public struct SpotColor : IEquatable - { - /// - /// Gets the type of the spot color - /// - public readonly SpotColorType SpotColorType; - - /// - /// Gets the ink name of the spot color - /// - public readonly string InkName; - - /// - /// Creates a new instance of spot color of a specific type and descriptor - /// - public SpotColor(SpotColorType spotColorType, string inkName) - { - SpotColorType = spotColorType; - InkName = inkName ?? throw new ArgumentNullException(nameof(inkName)); - } - - /// - /// Creates a new instance of spot color by parsing the specified color string - /// - /// string representation to parse the type and descriptor from - public SpotColor(string color) - { - if (color == null) throw new ArgumentNullException(nameof(color)); - if (color.StartsWith("(") && color.EndsWith(")")) - { - color = color.Substring(1, color.Length - 2); - } - var splitIndex = color.IndexOf('-'); - if (splitIndex < 0) - { - throw new ArgumentException(nameof(color)); - } - var spotColorTypeStr = color.Substring(0, splitIndex); - if (!Enum.TryParse(spotColorTypeStr, true, out SpotColorType)) - { - throw new ArgumentException($"Invalid spot color type '{spotColorTypeStr}'", nameof(color)); - } - InkName = color.Substring(splitIndex + 1); - if (string.IsNullOrWhiteSpace(InkName)) - { - throw new ArgumentException("Missing spot color value", nameof(color)); - } - } - - /// - /// Returns the string representation of the color - /// - public override string ToString() => $"{SpotColorType}-{InkName}"; - - /// - /// Indicates whether the specified color is equal to the current color. - /// - public bool Equals(SpotColor other) => SpotColorType == other.SpotColorType && string.Equals(InkName, other.InkName); - - /// - /// Indicates whether the specified object is equal to the current color. - /// - public override bool Equals(object obj) => !ReferenceEquals(null, obj) && obj is SpotColor spot && Equals(spot); - - /// - /// Returns the hash code for the color structure - /// - public override int GetHashCode() - { - unchecked - { - return ((int)SpotColorType * 397) ^ (InkName != null ? InkName.GetHashCode() : 0); - } - } - - /// - /// Compares two colors for exact equality - /// - public static bool operator ==(SpotColor left, SpotColor right) => left.Equals(right); - - /// - /// Compares two colors for inequality - /// - public static bool operator !=(SpotColor left, SpotColor right) => !left.Equals(right); - } -} diff --git a/tests/EquinoxLabs.SVGSharpie.DynamicPDF.Tests/UnitTests.cs b/tests/EquinoxLabs.SVGSharpie.DynamicPDF.Tests/UnitTests.cs index 7d483be..90dca87 100644 --- a/tests/EquinoxLabs.SVGSharpie.DynamicPDF.Tests/UnitTests.cs +++ b/tests/EquinoxLabs.SVGSharpie.DynamicPDF.Tests/UnitTests.cs @@ -1,11 +1,11 @@ -using System; using System.Diagnostics; using System.IO; using ceTe.DynamicPDF; -using ceTe.DynamicPDF.PageElements; using Xunit; using PdfSpotColorInk = ceTe.DynamicPDF.SpotColorInk; using PdfSpotColor = ceTe.DynamicPDF.SpotColor; +using EquinoxLabs.SVGSharpie.DynamicPDF.Core; +using Rectangle = EquinoxLabs.SVGSharpie.DynamicPDF.Core.Rectangle; namespace EquinoxLabs.SVGSharpie.DynamicPDF.Tests { @@ -25,7 +25,7 @@ namespace EquinoxLabs.SVGSharpie.DynamicPDF.Tests var spotColor = new PdfSpotColor(1, spotColorInk); Page page = new Page( PageSize.Letter, PageOrientation.Portrait, 54.0f ); var svgDocument = SvgDocument.Parse(File.ReadAllText(svgFilePath)); - var pageElement = SvgImageRenderer.CreateSvgImagePageElement(svgDocument, new Rectangle(0, 0, 300, 300), PNI.Apollo.Render.Services.DynamicPdf.PageElements.HorizontalAlignment.Center, PNI.Apollo.Render.Services.DynamicPdf.PageElements.VerticalAlignment.Center, spotColor); + var pageElement = Renderer.CreateSvgImagePageElement(svgDocument, new Rectangle(0, 0, 300, 300), HorizontalAlignment.Center, VerticalAlignment.Center, spotColor); page.Elements.Add(pageElement); document.Pages.Add(page); document.Draw(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(svgFilePath), System.IO.Path.GetFileNameWithoutExtension(svgFilePath) + ".pdf"));