From 75efb0880c97b5d8802e2025037fe87c5503ec22 Mon Sep 17 00:00:00 2001 From: Tebjan Halm Date: Mon, 23 Mar 2015 12:01:59 +0100 Subject: [PATCH] Revert "Working on making this export valid SVG documents." --- Source/DataTypes/SvgAspectRatio.cs | 1 - Source/DataTypes/SvgColourInterpolation.cs | 19 +-- Source/DataTypes/SvgCoordinateUnits.cs | 4 - Source/DataTypes/SvgFontStyle.cs | 19 +-- Source/DataTypes/SvgFontVariant.cs | 6 +- Source/DataTypes/SvgFontWeight.cs | 63 ++------ Source/DataTypes/SvgMarkerUnits.cs | 8 +- Source/DataTypes/SvgOverflow.cs | 35 +--- Source/DataTypes/SvgTextDecoration.cs | 25 +-- Source/DataTypes/SvgTextLengthAdjust.cs | 14 +- Source/DataTypes/SvgTextPathMethod.cs | 10 +- Source/DataTypes/SvgTextPathSpacing.cs | 10 +- Source/Document Structure/SvgFragment.cs | 53 +++--- .../feColourMatrix/SvgColourMatrix.cs | 6 +- .../feColourMatrix/SvgColourMatrixType.cs | 10 +- Source/Painting/EnumConverters.cs | 152 +++++------------- Source/Painting/SvgGradientSpreadMethod.cs | 12 -- Source/Painting/SvgMarker.cs | 16 +- Source/Painting/SvgStrokeLineCap.cs | 12 +- Source/Painting/SvgStrokeLineJoin.cs | 9 -- Source/SvgAttributeCollection.cs | 11 +- Source/SvgDocument.cs | 18 +-- Source/SvgElement.cs | 40 +++-- Source/SvgElementStyle.cs | 28 ++-- Source/SvgExtentions.cs | 2 +- Source/Text/SvgFontFace.cs | 6 +- Source/Text/SvgTextAnchor.cs | 3 +- Source/Text/SvgTextBase.cs | 25 ++- Source/Text/SvgTextPath.cs | 4 +- 29 files changed, 187 insertions(+), 434 deletions(-) diff --git a/Source/DataTypes/SvgAspectRatio.cs b/Source/DataTypes/SvgAspectRatio.cs index 4de7213..77ae817 100644 --- a/Source/DataTypes/SvgAspectRatio.cs +++ b/Source/DataTypes/SvgAspectRatio.cs @@ -50,7 +50,6 @@ namespace Svg } - [TypeConverter(typeof(SvgPreserveAspectRatioConverter))] public enum SvgPreserveAspectRatio { xMidYMid, //default diff --git a/Source/DataTypes/SvgColourInterpolation.cs b/Source/DataTypes/SvgColourInterpolation.cs index ad17513..4d66653 100644 --- a/Source/DataTypes/SvgColourInterpolation.cs +++ b/Source/DataTypes/SvgColourInterpolation.cs @@ -1,26 +1,15 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; namespace Svg.DataTypes { - /// Specifies the color space for gradient interpolations, color animations and alpha compositing. - /// When a child element is blended into a background, the value of the ‘color-interpolation’ property on the child determines the type of blending, not the value of the ‘color-interpolation’ on the parent. For gradients which make use of the ‘xlink:href’ attribute to reference another gradient, the gradient uses the ‘color-interpolation’ property value from the gradient element which is directly referenced by the ‘fill’ or ‘stroke’ property. When animating colors, color interpolation is performed according to the value of the ‘color-interpolation’ property on the element being animated. - [TypeConverter(typeof(SvgColourInterpolationConverter))] public enum SvgColourInterpolation { - /// Indicates that the user agent can choose either the sRGB or linearRGB spaces for color interpolation. This option indicates that the author doesn't require that color interpolation occur in a particular color space. - Auto, - - /// Indicates that color interpolation should occur in the sRGB color space. - SRGB, - - /// Indicates that color interpolation should occur in the linearized RGB color space as described above. - LinearRGB, - - /// The value is inherited from the parent element. - Inherit + auto, + sRGB, + linearRGB, + inherit } } diff --git a/Source/DataTypes/SvgCoordinateUnits.cs b/Source/DataTypes/SvgCoordinateUnits.cs index e4b5a20..a17c83e 100644 --- a/Source/DataTypes/SvgCoordinateUnits.cs +++ b/Source/DataTypes/SvgCoordinateUnits.cs @@ -6,21 +6,17 @@ using System.ComponentModel; namespace Svg { - //TODO Need to split this enum into separate inherited enums for GradientCoordinateUnits, ClipPathCoordinateUnits, etc. as each should have its own converter since they have different defaults. /// /// Defines the various coordinate units certain SVG elements may use. /// [TypeConverter(typeof(SvgCoordinateUnitsConverter))] public enum SvgCoordinateUnits { - //TODO Inherit is not actually valid Inherit, - /// /// Indicates that the coordinate system of the owner element is to be used. /// ObjectBoundingBox, - /// /// Indicates that the coordinate system of the entire document is to be used. /// diff --git a/Source/DataTypes/SvgFontStyle.cs b/Source/DataTypes/SvgFontStyle.cs index 95708ab..2153f6b 100644 --- a/Source/DataTypes/SvgFontStyle.cs +++ b/Source/DataTypes/SvgFontStyle.cs @@ -1,26 +1,15 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; namespace Svg { - /// This is the descriptor for the style of a font and takes the same values as the 'font-style' property, except that a comma-separated list is permitted. - [TypeConverter(typeof(SvgFontStyleConverter))] - [Flags] public enum SvgFontStyle { - /// Indicates that the font-face supplies all styles (normal, oblique and italic). - All = (Normal | Oblique | Italic), - - /// Specifies a font that is classified as 'normal' in the UA's font database. - Normal = 1, - - /// Specifies a font that is classified as 'oblique' in the UA's font database. Fonts with Oblique, Slanted, or Incline in their names will typically be labeled 'oblique' in the font database. A font that is labeled 'oblique' in the UA's font database may actually have been generated by electronically slanting a normal font. - Oblique = 2, - - /// Specifies a font that is classified as 'italic' in the UA's font database, or, if that is not available, one labeled 'oblique'. Fonts with Italic, Cursive, or Kursiv in their names will typically be labeled 'italic' - Italic = 4 + normal, + italic, + oblique, + inherit } } diff --git a/Source/DataTypes/SvgFontVariant.cs b/Source/DataTypes/SvgFontVariant.cs index f1f81ac..40971b8 100644 --- a/Source/DataTypes/SvgFontVariant.cs +++ b/Source/DataTypes/SvgFontVariant.cs @@ -9,8 +9,8 @@ namespace Svg [TypeConverter(typeof(SvgFontVariantConverter))] public enum SvgFontVariant { - Normal, - Smallcaps, - Inherit + normal, + smallcaps, + inherit } } diff --git a/Source/DataTypes/SvgFontWeight.cs b/Source/DataTypes/SvgFontWeight.cs index 31773f1..55001f4 100644 --- a/Source/DataTypes/SvgFontWeight.cs +++ b/Source/DataTypes/SvgFontWeight.cs @@ -6,57 +6,22 @@ using System.ComponentModel; namespace Svg { - //TODO This should be split out to define an enum for the font face element and text element. - /// The weight of a face relative to others in the same font family. [TypeConverter(typeof(SvgFontWeightConverter))] - [Flags] public enum SvgFontWeight { - //TODO All Is not valid for text elements, but is is for font face elements. - /// All font weights. - All = (W100 | W200 | W300 | W400 | W500 | W600 | W700 | W800 | W900), - - //TODO Inherit Is not valid for font face elements, but is is for text elements. - /// The value is inherited from the parent element. - Inherit = 0, - - /// Same as . - Normal = W400, - - /// Same as . - Bold = W700, - - /// One font weight darker than the parent element. - Bolder = 512, - - /// One font weight lighter than the parent element. - Lighter = 1024, - - /// - W100 = 1, - - /// - W200 = 2, - - /// - W300 = 4, - - /// Same as . - W400 = 8, - - /// - W500 = 16, - - /// - W600 = 32, - - /// Same as . - W700 = 64, - - /// - W800 = 128, - - /// - W900 = 256 + inherit, + normal, + bold, + bolder, + lighter, + w100, + w200, + w300, + w400, // same as normal + w500, + w600, + w700, // same as bold + w800, + w900 } } diff --git a/Source/DataTypes/SvgMarkerUnits.cs b/Source/DataTypes/SvgMarkerUnits.cs index 1603bbb..9b0aa78 100644 --- a/Source/DataTypes/SvgMarkerUnits.cs +++ b/Source/DataTypes/SvgMarkerUnits.cs @@ -2,14 +2,10 @@ namespace Svg.DataTypes { - /// Defines the coordinate system for attributes ‘markerWidth’, ‘markerHeight’ and the contents of the ‘marker’. [TypeConverter(typeof(SvgMarkerUnitsConverter))] public enum SvgMarkerUnits { - /// If markerUnits="strokeWidth", ‘markerWidth’, ‘markerHeight’ and the contents of the ‘marker’ represent values in a coordinate system which has a single unit equal the size in user units of the current stroke width (see the ‘stroke-width’ property) in place for the graphic object referencing the marker. - StrokeWidth, - - /// If markerUnits="userSpaceOnUse", ‘markerWidth’, ‘markerHeight’ and the contents of the ‘marker’ represent values in the current user coordinate system in place for the graphic object referencing the marker (i.e., the user coordinate system for the element referencing the ‘marker’ element via a ‘marker’, ‘marker-start’, ‘marker-mid’ or ‘marker-end’ property). - UserSpaceOnUse + strokeWidth, + userSpaceOnUse } } diff --git a/Source/DataTypes/SvgOverflow.cs b/Source/DataTypes/SvgOverflow.cs index f5daa78..1d7ae83 100644 --- a/Source/DataTypes/SvgOverflow.cs +++ b/Source/DataTypes/SvgOverflow.cs @@ -1,39 +1,16 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; namespace Svg { - /// The ‘overflow’ property applies to elements that establish new viewports (e.g., ‘svg’ elements), ‘pattern’ elements and ‘marker’ elements. For all other elements, the property has no effect (i.e., a clipping rectangle is not created). - /// - /// The ‘overflow’ property has the same parameter values and has the same meaning as defined in CSS2 ([CSS2], section 11.1.1); however, the following additional points apply: - /// The ‘overflow’ property applies to elements that establish new viewports (e.g., ‘svg’ elements), ‘pattern’ elements and ‘marker’ elements. For all other elements, the property has no effect (i.e., a clipping rectangle is not created). - /// For those elements to which the ‘overflow’ property can apply, if the ‘overflow’ property has the value hidden or scroll, the effect is that a new clipping path in the shape of a rectangle is created. The result is equivalent to defining a ‘clipPath’ element whose content is a ‘rect’ element which defines the equivalent rectangle, and then specifying the of this ‘clipPath’ element on the ‘clip-path’ property for the given element. - /// If the ‘overflow’ property has a value other than hidden or scroll, the property has no effect (i.e., a clipping rectangle is not created). - /// Within SVG content, the value auto is equivalent to the value visible. - /// When an outermost svg element is embedded inline within a parent XML grammar which uses CSS layout ([CSS2], chapter 9) or XSL formatting [XSL], if the ‘overflow’ property has the value hidden or scroll, then the user agent will establish an initial clipping path equal to the bounds of the initial viewport; otherwise, the initial clipping path is set according to the clipping rules as defined in CSS2 ([CSS2], section 11.1.1). - /// When an outermost svg element is stand-alone or embedded inline within a parent XML grammar which does not use CSS layout or XSL formatting, the ‘overflow’ property on the outermost svg element is ignored for the purposes of visual rendering and the initial clipping path is set to the bounds of the initial viewport. - /// The initial value for ‘overflow’ as defined in [CSS2-overflow] is 'visible', and this applies also to the root ‘svg’ element; however, for child elements of an SVG document, SVG's user agent style sheet overrides this initial value and sets the ‘overflow’ property on elements that establish new viewports (e.g., ‘svg’ elements), ‘pattern’ elements and ‘marker’ elements to the value 'hidden'. - /// As a result of the above, the default behavior of SVG user agents is to establish a clipping path to the bounds of the initial viewport and to establish a new clipping path for each element which establishes a new viewport and each ‘pattern’ and ‘marker’ element. - /// - [TypeConverter(typeof(SvgOverflowConverter))] public enum SvgOverflow - { - /// The value is inherited from the parent element. - Inherit, - - /// The overflow is rendered - same as "visible". - Auto, - - /// Overflow is rendered. - Visible, - - /// Overflow is not rendered. - Hidden, - - /// Overflow causes a scrollbar to appear (horizontal, vertical or both). - Scroll + { + inherit, + auto, + visible, + hidden, + scroll } } diff --git a/Source/DataTypes/SvgTextDecoration.cs b/Source/DataTypes/SvgTextDecoration.cs index 42b46fa..50f9523 100644 --- a/Source/DataTypes/SvgTextDecoration.cs +++ b/Source/DataTypes/SvgTextDecoration.cs @@ -6,27 +6,14 @@ using System.ComponentModel; namespace Svg { - /// This property describes decorations that are added to the text of an element. Conforming SVG Viewers are not required to support the blink value. [TypeConverter(typeof(SvgTextDecorationConverter))] - [Flags] public enum SvgTextDecoration { - /// The value is inherited from the parent element. - Inherit = 0, - - /// The text is not decorated - None = 1, - - /// The text is underlined. - Underline = 2, - - /// The text is overlined. - Overline = 4, - - /// The text is struck through. - LineThrough = 8, - - /// The text will blink. - Blink = 16 + inherit, + none, + underline, + overline, + lineThrough, + blink } } diff --git a/Source/DataTypes/SvgTextLengthAdjust.cs b/Source/DataTypes/SvgTextLengthAdjust.cs index 7276e8c..ab68d3a 100644 --- a/Source/DataTypes/SvgTextLengthAdjust.cs +++ b/Source/DataTypes/SvgTextLengthAdjust.cs @@ -1,23 +1,13 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; namespace Svg { - /// Indicates the type of adjustments which the user agent shall make to make the rendered length of the text match the value specified on the ‘textLength’ attribute. - /// - /// The user agent is required to achieve correct start and end positions for the text strings, but the locations of intermediate glyphs are not predictable because user agents might employ advanced algorithms to stretch or compress text strings in order to balance correct start and end positioning with optimal typography. - /// Note that, for a text string that contains n characters, the adjustments to the advance values often occur only for n−1 characters (see description of attribute ‘textLength’), whereas stretching or compressing of the glyphs will be applied to all n characters. - /// - [TypeConverter(typeof(SvgTextLengthAdjustConverter))] public enum SvgTextLengthAdjust { - /// Indicates that only the advance values are adjusted. The glyphs themselves are not stretched or compressed. - Spacing, - - /// Indicates that the advance values are adjusted and the glyphs themselves stretched or compressed in one axis (i.e., a direction parallel to the inline-progression-direction). - SpacingAndGlyphs + spacing, + spacingAndGlyphs } } diff --git a/Source/DataTypes/SvgTextPathMethod.cs b/Source/DataTypes/SvgTextPathMethod.cs index a1ca800..64aac32 100644 --- a/Source/DataTypes/SvgTextPathMethod.cs +++ b/Source/DataTypes/SvgTextPathMethod.cs @@ -1,19 +1,13 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; namespace Svg { - /// Indicates the method by which text should be rendered along the path. - [TypeConverter(typeof(SvgTextPathMethodConverter))] public enum SvgTextPathMethod { - /// Indicates that the glyphs should be rendered using simple 2x3 transformations such that there is no stretching/warping of the glyphs. Typically, supplemental rotation, scaling and translation transformations are done for each glyph to be rendered. As a result, with align, fonts where the glyphs are designed to be connected (e.g., cursive fonts), the connections may not align properly when text is rendered along a path. - Align, - - /// Indicates that the glyph outlines will be converted into paths, and then all end points and control points will be adjusted to be along the perpendicular vectors from the path, thereby stretching and possibly warping the glyphs. With this approach, connected glyphs, such as in cursive scripts, will maintain their connections. - Stretch + align, + stretch } } diff --git a/Source/DataTypes/SvgTextPathSpacing.cs b/Source/DataTypes/SvgTextPathSpacing.cs index b988c09..e53d8fa 100644 --- a/Source/DataTypes/SvgTextPathSpacing.cs +++ b/Source/DataTypes/SvgTextPathSpacing.cs @@ -1,19 +1,13 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; namespace Svg { - /// Indicates how the user agent should determine the spacing between glyphs that are to be rendered along a path. - [TypeConverter(typeof(SvgTextPathSpacingConverter))] public enum SvgTextPathSpacing { - /// Indicates that the glyphs should be rendered exactly according to the spacing rules as specified in Text on a path layout rules. - Exact, - - /// Indicates that the user agent should use text-on-a-path layout algorithms to adjust the spacing between glyphs in order to achieve visually appealing results. - Auto + exact, + auto } } diff --git a/Source/Document Structure/SvgFragment.cs b/Source/Document Structure/SvgFragment.cs index ef8c813..6233669 100644 --- a/Source/Document Structure/SvgFragment.cs +++ b/Source/Document Structure/SvgFragment.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using System.Drawing.Drawing2D; -using System.Xml; namespace Svg { @@ -42,7 +41,7 @@ namespace Svg private SvgUnit _x; private SvgUnit _y; - + /// /// Gets or sets the position where the left point of the svg should start. /// @@ -52,10 +51,10 @@ namespace Svg get { return _x; } set { - if (_x != value) + if(_x != value) { _x = value; - OnAttributeChanged(new AttributeEventArgs { Attribute = "x", Value = value }); + OnAttributeChanged(new AttributeEventArgs{ Attribute = "x", Value = value }); } } } @@ -69,10 +68,10 @@ namespace Svg get { return _y; } set { - if (_y != value) + if(_y != value) { _y = value; - OnAttributeChanged(new AttributeEventArgs { Attribute = "y", Value = value }); + OnAttributeChanged(new AttributeEventArgs{ Attribute = "y", Value = value }); } } } @@ -116,7 +115,7 @@ namespace Svg get { return this.Attributes.GetAttribute("viewBox"); } set { this.Attributes["viewBox"] = value; } } - + /// /// Gets or sets the aspect of the viewport. /// @@ -163,9 +162,9 @@ namespace Svg { switch (this.Overflow) { - case SvgOverflow.Auto: - case SvgOverflow.Visible: - case SvgOverflow.Scroll: + case SvgOverflow.auto: + case SvgOverflow.visible: + case SvgOverflow.scroll: base.Render(renderer); break; default: @@ -186,29 +185,29 @@ namespace Svg break; } } - + /// /// Gets the for this element. /// /// public GraphicsPath Path { - get - { + get + { var path = new GraphicsPath(); AddPaths(this, path); - + return path; } } - + /// /// Gets the bounds of the svg element. /// /// The bounds. - public RectangleF Bounds - { + public RectangleF Bounds + { get { return this.Path.GetBounds(); @@ -247,7 +246,7 @@ namespace Svg } } - if (isWidthperc) + if (isWidthperc) { w = (bounds.Width + bounds.X) * (Width.Value * 0.01f); } @@ -255,11 +254,11 @@ namespace Svg { w = Width.ToDeviceValue(null, UnitRenderingType.Horizontal, this); } - if (isHeightperc) + if (isHeightperc) { h = (bounds.Height + bounds.Y) * (Height.Value * 0.01f); } - else + else { h = Height.ToDeviceValue(null, UnitRenderingType.Vertical, this); } @@ -283,20 +282,6 @@ namespace Svg return newObj; } - //Override the default behavior, writing out the namespaces. - protected override void WriteStartElement(XmlTextWriter writer) - { - base.WriteStartElement(writer); - foreach (var ns in SvgAttributeAttribute.Namespaces) - { - if (string.IsNullOrEmpty(ns.Key)) - writer.WriteAttributeString("xmlns", ns.Value); - else - writer.WriteAttributeString("xmlns:" + ns.Key, ns.Value); - } - - writer.WriteAttributeString("version", "1.1"); - } } } \ No newline at end of file diff --git a/Source/Filter Effects/feColourMatrix/SvgColourMatrix.cs b/Source/Filter Effects/feColourMatrix/SvgColourMatrix.cs index 8f8804d..18320c8 100644 --- a/Source/Filter Effects/feColourMatrix/SvgColourMatrix.cs +++ b/Source/Filter Effects/feColourMatrix/SvgColourMatrix.cs @@ -42,7 +42,7 @@ namespace Svg.FilterEffects float value; switch (this.Type) { - case SvgColourMatrixType.HueRotate: + case SvgColourMatrixType.hueRotate: value = (string.IsNullOrEmpty(this.Values) ? 0 : float.Parse(this.Values)); colorMatrixElements = new float[][] { new float[] {(float)(0.213 + Math.Cos(value) * +0.787 + Math.Sin(value) * -0.213), @@ -58,7 +58,7 @@ namespace Svg.FilterEffects new float[] {0, 0, 0, 0, 1} }; break; - case SvgColourMatrixType.LuminanceToAlpha: + case SvgColourMatrixType.luminanceToAlpha: colorMatrixElements = new float[][] { new float[] {0, 0, 0, 0, 0}, new float[] {0, 0, 0, 0, 0}, @@ -67,7 +67,7 @@ namespace Svg.FilterEffects new float[] {0, 0, 0, 0, 1} }; break; - case SvgColourMatrixType.Saturate: + case SvgColourMatrixType.saturate: value = (string.IsNullOrEmpty(this.Values) ? 1 : float.Parse(this.Values)); colorMatrixElements = new float[][] { new float[] {(float)(0.213+0.787*value), (float)(0.715-0.715*value), (float)(0.072-0.072*value), 0, 0}, diff --git a/Source/Filter Effects/feColourMatrix/SvgColourMatrixType.cs b/Source/Filter Effects/feColourMatrix/SvgColourMatrixType.cs index fe9694c..9941f63 100644 --- a/Source/Filter Effects/feColourMatrix/SvgColourMatrixType.cs +++ b/Source/Filter Effects/feColourMatrix/SvgColourMatrixType.cs @@ -1,17 +1,15 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; namespace Svg.FilterEffects { - [TypeConverter(typeof(EnumBaseConverter))] public enum SvgColourMatrixType { - Matrix, - Saturate, - HueRotate, - LuminanceToAlpha + matrix, + saturate, + hueRotate, + luminanceToAlpha } } diff --git a/Source/Painting/EnumConverters.cs b/Source/Painting/EnumConverters.cs index a9e98df..d048d14 100644 --- a/Source/Painting/EnumConverters.cs +++ b/Source/Painting/EnumConverters.cs @@ -66,29 +66,11 @@ namespace Svg //converts enums to lower case strings public class EnumBaseConverter : BaseConverter - where T : struct { - /// If specified, upon conversion, the default value will result in 'null'. - public T? DefaultValue { get; protected set;} - - /// Creates a new instance. - public EnumBaseConverter() { } - - /// Creates a new instance. - /// Specified the default value of the enum. - public EnumBaseConverter(T defaultValue) - { - this.DefaultValue = defaultValue; - } - - /// Attempts to convert the provided value to . public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value == null) { - if (this.DefaultValue.HasValue) - return this.DefaultValue.Value; - return Activator.CreateInstance(typeof(T)); } @@ -100,166 +82,112 @@ namespace Svg return (T)Enum.Parse(typeof(T), (string)value, true); } - /// Attempts to convert the value to the destination type. public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { - if (destinationType == typeof(string) && value is T) + if (destinationType == typeof(string)) { - //If the value id the default value, no need to write the attribute. - if (this.DefaultValue.HasValue && Enum.Equals(value, this.DefaultValue.Value)) - return null; - else - { - //SVG attributes should be camelCase. - string stringValue = ((T)value).ToString(); - - stringValue = string.Format("{0}{1}", stringValue[0].ToString().ToLower(), stringValue.Substring(1)); - - return stringValue; - } + return ((T)value).ToString().ToLower(); } return base.ConvertTo(context, culture, value, destinationType); } } + //implementation for fill-rule public sealed class SvgFillRuleConverter : EnumBaseConverter { - public SvgFillRuleConverter() : base(SvgFillRule.NonZero) { } - } - - public sealed class SvgColourInterpolationConverter : EnumBaseConverter - { - public SvgColourInterpolationConverter() : base(SvgColourInterpolation.SRGB) { } } + //implementaton for clip rule public sealed class SvgClipRuleConverter : EnumBaseConverter { - public SvgClipRuleConverter() : base(SvgClipRule.NonZero) { } } + //implementaton for clip rule public sealed class SvgTextAnchorConverter : EnumBaseConverter { - public SvgTextAnchorConverter() : base(SvgTextAnchor.Start) { } } public sealed class SvgStrokeLineCapConverter : EnumBaseConverter { - public SvgStrokeLineCapConverter() : base(SvgStrokeLineCap.Butt) { } } public sealed class SvgStrokeLineJoinConverter : EnumBaseConverter { - public SvgStrokeLineJoinConverter() : base(SvgStrokeLineJoin.Miter) { } } public sealed class SvgMarkerUnitsConverter : EnumBaseConverter { - public SvgMarkerUnitsConverter() : base(SvgMarkerUnits.StrokeWidth) { } - } - - public sealed class SvgFontStyleConverter : EnumBaseConverter - { - public SvgFontStyleConverter() : base(SvgFontStyle.All) { } - } - - public sealed class SvgOverflowConverter : EnumBaseConverter - { - public SvgOverflowConverter() : base(SvgOverflow.Auto) { } - } - - public sealed class SvgTextLengthAdjustConverter : EnumBaseConverter - { - public SvgTextLengthAdjustConverter() : base(SvgTextLengthAdjust.Spacing) { } - } - - public sealed class SvgTextPathMethodConverter : EnumBaseConverter - { - public SvgTextPathMethodConverter() : base(SvgTextPathMethod.Align) { } - } - - public sealed class SvgTextPathSpacingConverter : EnumBaseConverter - { - public SvgTextPathSpacingConverter() : base(SvgTextPathSpacing.Exact) { } } public sealed class SvgFontVariantConverter : EnumBaseConverter { - public SvgFontVariantConverter() : base(SvgFontVariant.Normal) { } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - if (value.ToString() == "small-caps") - return SvgFontVariant.Smallcaps; - + if (value.ToString() == "small-caps") return SvgFontVariant.smallcaps; return base.ConvertFrom(context, culture, value); } - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { - if (destinationType == typeof(string) && value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.Smallcaps) + if (destinationType == typeof(string) && value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.smallcaps) { return "small-caps"; } - return base.ConvertTo(context, culture, value, destinationType); } } public sealed class SvgCoordinateUnitsConverter : EnumBaseConverter { - //TODO Inherit is not actually valid. See TODO on SvgCoordinateUnits enum. - public SvgCoordinateUnitsConverter() : base(SvgCoordinateUnits.Inherit) { } - } - - public sealed class SvgGradientSpreadMethodConverter : EnumBaseConverter - { - public SvgGradientSpreadMethodConverter() : base(SvgGradientSpreadMethod.Pad) { } + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + if (value == null || value.ToString() == "") return SvgCoordinateUnits.Inherit; + return base.ConvertFrom(context, culture, value); + } + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { + if (destinationType == typeof(string) && value is SvgCoordinateUnits && (SvgCoordinateUnits)value == SvgCoordinateUnits.Inherit) + { + return null; + } + return base.ConvertTo(context, culture, value, destinationType); + } } public sealed class SvgTextDecorationConverter : EnumBaseConverter { - public SvgTextDecorationConverter() : base(SvgTextDecoration.None) { } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { - if (value.ToString() == "line-through") - return SvgTextDecoration.LineThrough; - + if (value.ToString() == "line-through") return SvgTextDecoration.lineThrough; return base.ConvertFrom(context, culture, value); } - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { - if (destinationType == typeof(string) && value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.LineThrough) + if (destinationType == typeof(string) && value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.lineThrough) { return "line-through"; } - return base.ConvertTo(context, culture, value, destinationType); } } public sealed class SvgFontWeightConverter : EnumBaseConverter { - //TODO Defaulting to Normal although it should be All if this is used on a font face. - public SvgFontWeightConverter() : base(SvgFontWeight.Normal) { } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { switch ((string)value) { - case "100": return SvgFontWeight.W100; - case "200": return SvgFontWeight.W200; - case "300": return SvgFontWeight.W300; - case "400": return SvgFontWeight.W400; - case "500": return SvgFontWeight.W500; - case "600": return SvgFontWeight.W600; - case "700": return SvgFontWeight.W700; - case "800": return SvgFontWeight.W800; - case "900": return SvgFontWeight.W900; + case "100": return SvgFontWeight.w100; + case "200": return SvgFontWeight.w200; + case "300": return SvgFontWeight.w300; + case "400": return SvgFontWeight.w400; + case "500": return SvgFontWeight.w500; + case "600": return SvgFontWeight.w600; + case "700": return SvgFontWeight.w700; + case "800": return SvgFontWeight.w800; + case "900": return SvgFontWeight.w900; } } return base.ConvertFrom(context, culture, value); @@ -270,15 +198,15 @@ namespace Svg { switch ((SvgFontWeight)value) { - case SvgFontWeight.W100: return "100"; - case SvgFontWeight.W200: return "200"; - case SvgFontWeight.W300: return "300"; - case SvgFontWeight.W400: return "400"; - case SvgFontWeight.W500: return "500"; - case SvgFontWeight.W600: return "600"; - case SvgFontWeight.W700: return "700"; - case SvgFontWeight.W800: return "800"; - case SvgFontWeight.W900: return "900"; + case SvgFontWeight.w100: return "100"; + case SvgFontWeight.w200: return "200"; + case SvgFontWeight.w300: return "300"; + case SvgFontWeight.w400: return "400"; + case SvgFontWeight.w500: return "500"; + case SvgFontWeight.w600: return "600"; + case SvgFontWeight.w700: return "700"; + case SvgFontWeight.w800: return "800"; + case SvgFontWeight.w900: return "900"; } } return base.ConvertTo(context, culture, value, destinationType); diff --git a/Source/Painting/SvgGradientSpreadMethod.cs b/Source/Painting/SvgGradientSpreadMethod.cs index 6c7453e..0041a6a 100644 --- a/Source/Painting/SvgGradientSpreadMethod.cs +++ b/Source/Painting/SvgGradientSpreadMethod.cs @@ -1,26 +1,14 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; namespace Svg { - /// Indicates what happens if the gradient starts or ends inside the bounds of the target rectangle. - /// - /// Possible values are: 'pad', which says to use the terminal colors of the gradient to fill the remainder of the target region, 'reflect', which says to reflect the gradient pattern start-to-end, end-to-start, start-to-end, etc. continuously until the target rectangle is filled, and repeat, which says to repeat the gradient pattern start-to-end, start-to-end, start-to-end, etc. continuously until the target region is filled. - /// If the attribute is not specified, the effect is as if a value of 'pad' were specified. - /// - [TypeConverter(typeof(SvgGradientSpreadMethodConverter))] public enum SvgGradientSpreadMethod { - /// Use the terminal colors of the gradient to fill the remainder of the target region. Pad, - - /// Reflect the gradient pattern start-to-end, end-to-start, start-to-end, etc. continuously until the target rectangle is filled. Reflect, - - /// Repeat the gradient pattern start-to-end, start-to-end, start-to-end, etc. continuously until the target region is filled. Repeat } } \ No newline at end of file diff --git a/Source/Painting/SvgMarker.cs b/Source/Painting/SvgMarker.cs index 6d5de60..dac9f1c 100644 --- a/Source/Painting/SvgMarker.cs +++ b/Source/Painting/SvgMarker.cs @@ -81,10 +81,10 @@ namespace Svg public SvgMarker() { - MarkerUnits = SvgMarkerUnits.StrokeWidth; + MarkerUnits = SvgMarkerUnits.strokeWidth; MarkerHeight = 3; MarkerWidth = 3; - Overflow = SvgOverflow.Hidden; + Overflow = SvgOverflow.hidden; } public override System.Drawing.Drawing2D.GraphicsPath Path(ISvgRenderer renderer) @@ -183,13 +183,13 @@ namespace Svg transMatrix.Rotate(Orient.Angle); switch (MarkerUnits) { - case SvgMarkerUnits.StrokeWidth: + case SvgMarkerUnits.strokeWidth: transMatrix.Translate(AdjustForViewBoxWidth(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this) * pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)), AdjustForViewBoxHeight(-RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this) * pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this))); break; - case SvgMarkerUnits.UserSpaceOnUse: + case SvgMarkerUnits.userSpaceOnUse: transMatrix.Translate(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this), -RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this)); break; @@ -224,10 +224,10 @@ namespace Svg Brush pBrush = pPath.Stroke.GetBrush(this, renderer, Opacity); switch (MarkerUnits) { - case SvgMarkerUnits.StrokeWidth: + case SvgMarkerUnits.strokeWidth: return (new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this) * pPath.StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this))); - case SvgMarkerUnits.UserSpaceOnUse: + case SvgMarkerUnits.userSpaceOnUse: return (new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this))); } return (new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this))); @@ -242,14 +242,14 @@ namespace Svg GraphicsPath pRet = Path(null).Clone() as GraphicsPath; switch (MarkerUnits) { - case SvgMarkerUnits.StrokeWidth: + case SvgMarkerUnits.strokeWidth: using (var transMatrix = new Matrix()) { transMatrix.Scale(AdjustForViewBoxWidth(pPath.StrokeWidth), AdjustForViewBoxHeight(pPath.StrokeWidth)); pRet.Transform(transMatrix); } break; - case SvgMarkerUnits.UserSpaceOnUse: + case SvgMarkerUnits.userSpaceOnUse: break; } return (pRet); diff --git a/Source/Painting/SvgStrokeLineCap.cs b/Source/Painting/SvgStrokeLineCap.cs index 5a7f75e..f937e7f 100644 --- a/Source/Painting/SvgStrokeLineCap.cs +++ b/Source/Painting/SvgStrokeLineCap.cs @@ -5,20 +5,12 @@ using System.ComponentModel; namespace Svg { - /// Specifies the shape to be used at the end of open subpaths when they are stroked. [TypeConverter(typeof(SvgStrokeLineCapConverter))] public enum SvgStrokeLineCap { - /// The value is inherited from the parent element. - Inherit, - - /// The ends of the subpaths are square but do not extend past the end of the subpath. Butt, - - /// The ends of the subpaths are rounded. Round, - - /// The ends of the subpaths are square. - Square + Square, + Inherit } } diff --git a/Source/Painting/SvgStrokeLineJoin.cs b/Source/Painting/SvgStrokeLineJoin.cs index e66730a..7af2288 100644 --- a/Source/Painting/SvgStrokeLineJoin.cs +++ b/Source/Painting/SvgStrokeLineJoin.cs @@ -5,20 +5,11 @@ using System.ComponentModel; namespace Svg { - /// Specifies the shape to be used at the corners of paths or basic shapes when they are stroked. [TypeConverter(typeof(SvgStrokeLineJoinConverter))] public enum SvgStrokeLineJoin { - /// The value is inherited from the parent element. - Inherit, - - /// The corners of the paths are joined sharply. Miter, - - /// The corners of the paths are rounded off. Round, - - /// The corners of the paths are "flattened". Bevel } } diff --git a/Source/SvgAttributeCollection.cs b/Source/SvgAttributeCollection.cs index a88c52b..ac09091 100644 --- a/Source/SvgAttributeCollection.cs +++ b/Source/SvgAttributeCollection.cs @@ -85,12 +85,13 @@ namespace Svg private bool IsInheritValue(object value) { return (value == null || - (value is SvgFontWeight && (SvgFontWeight)value == SvgFontWeight.Inherit) || - (value is SvgTextAnchor && (SvgTextAnchor)value == SvgTextAnchor.Inherit) || - (value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.Inherit) || - (value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.Inherit) || + (value is SvgFontStyle && (SvgFontStyle)value == SvgFontStyle.inherit) || + (value is SvgFontWeight && (SvgFontWeight)value == SvgFontWeight.inherit) || + (value is SvgTextAnchor && (SvgTextAnchor)value == SvgTextAnchor.inherit) || + (value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.inherit) || + (value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.inherit) || (value is XmlSpaceHandling && (XmlSpaceHandling)value == XmlSpaceHandling.inherit) || - (value is SvgOverflow && (SvgOverflow)value == SvgOverflow.Inherit) || + (value is SvgOverflow && (SvgOverflow)value == SvgOverflow.inherit) || (value == SvgColourServer.Inherit) || (value is string && (string)value == "inherit") ); diff --git a/Source/SvgDocument.cs b/Source/SvgDocument.cs index e19a2c9..b53e444 100644 --- a/Source/SvgDocument.cs +++ b/Source/SvgDocument.cs @@ -11,8 +11,6 @@ using System.Xml; using System.Linq; using ExCSS; using Svg.Css; -using System.Threading; -using System.Globalization; namespace Svg { @@ -477,7 +475,7 @@ namespace Svg renderer.ScaleTransform(bitmap.Width / size.Width, bitmap.Height / size.Height); //EO, 2014-12-05: Requested to ensure proper zooming out (reduce size). Otherwise it clip the image. - this.Overflow = SvgOverflow.Auto; + this.Overflow = SvgOverflow.auto; this.Render(renderer); } @@ -490,18 +488,6 @@ namespace Svg //Trace.TraceInformation("End Render"); } - public override void Write(XmlTextWriter writer) - { - //Save previous culture and switch to invariant for writing - var previousCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; - - base.Write(writer); - - //Switch culture back - Thread.CurrentThread.CurrentCulture = previousCulture; - } - public void Write(Stream stream) { @@ -513,7 +499,7 @@ namespace Svg if (!String.IsNullOrEmpty(this.ExternalCSSHref)) xmlWriter.WriteProcessingInstruction("xml-stylesheet", String.Format("type=\"text/css\" href=\"{0}\"", this.ExternalCSSHref)); - this.Write(xmlWriter); + this.WriteElement(xmlWriter); xmlWriter.Flush(); } diff --git a/Source/SvgElement.cs b/Source/SvgElement.cs index 38fe89a..d988bee 100644 --- a/Source/SvgElement.cs +++ b/Source/SvgElement.cs @@ -520,11 +520,16 @@ namespace Svg this.Render(renderer); } - /// Derrived classes may decide that the element should not be written. For example, the text element shouldn't be written if it's empty. - public virtual bool ShouldWriteElement() + public void WriteElement(XmlTextWriter writer) { - //Write any element who has a name. - return (this.ElementName != String.Empty); + //Save previous culture and switch to invariant for writing + var previousCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; + + this.Write(writer); + + //Switch culture back + Thread.CurrentThread.CurrentCulture = previousCulture; } protected virtual void WriteStartElement(XmlTextWriter writer) @@ -532,8 +537,18 @@ namespace Svg if (this.ElementName != String.Empty) { writer.WriteStartElement(this.ElementName); + if (this.ElementName == "svg") + { + foreach (var ns in SvgAttributeAttribute.Namespaces) + { + if (string.IsNullOrEmpty(ns.Key)) + writer.WriteAttributeString("xmlns", ns.Value); + else + writer.WriteAttributeString("xmlns:" + ns.Key, ns.Value); + } + writer.WriteAttributeString("version", "1.1"); + } } - this.WriteAttributes(writer); } @@ -557,12 +572,10 @@ namespace Svg (!attr.Attribute.InAttributeDictionary || _attributes.ContainsKey(attr.Attribute.Name))) { object propertyValue = attr.Property.GetValue(this); - string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string)); forceWrite = false; writeStyle = (attr.Attribute.Name == "fill"); - - if (writeStyle && (Parent != null)) + if ((attr.Attribute.Name == "fill") && (Parent != null)) { if(propertyValue == SvgColourServer.NotSet) continue; @@ -580,9 +593,9 @@ namespace Svg if (propertyValue != null) { var type = propertyValue.GetType(); - - //Only write the attribute's value if it is not the default value, not null/empty, or we're forcing the write. - if ((!string.IsNullOrEmpty(value) && !SvgDefaults.IsDefault(attr.Attribute.Name, value)) || forceWrite) + string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string)); + + if (!SvgDefaults.IsDefault(attr.Attribute.Name, value) || forceWrite) { if (writeStyle) { @@ -596,6 +609,7 @@ namespace Svg } else if(attr.Attribute.Name == "fill") //if fill equals null, write 'none' { + string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string)); if (writeStyle) { styles[attr.Attribute.Name] = value; @@ -662,9 +676,9 @@ namespace Svg return resolved; } - public virtual void Write(XmlTextWriter writer) + protected virtual void Write(XmlTextWriter writer) { - if (ShouldWriteElement()) + if (this.ElementName != String.Empty) { this.WriteStartElement(writer); this.WriteChildren(writer); diff --git a/Source/SvgElementStyle.cs b/Source/SvgElementStyle.cs index 7ce672e..837c2c9 100644 --- a/Source/SvgElementStyle.cs +++ b/Source/SvgElementStyle.cs @@ -173,7 +173,7 @@ namespace Svg [SvgAttribute("font-style", true)] public virtual SvgFontStyle FontStyle { - get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.All : (SvgFontStyle)this.Attributes["font-style"]; } + get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.inherit : (SvgFontStyle)this.Attributes["font-style"]; } set { this.Attributes["font-style"] = value; this.IsPathDirty = true; } } @@ -183,7 +183,7 @@ namespace Svg [SvgAttribute("font-variant", true)] public virtual SvgFontVariant FontVariant { - get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.Inherit : (SvgFontVariant)this.Attributes["font-variant"]; } + get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.inherit : (SvgFontVariant)this.Attributes["font-variant"]; } set { this.Attributes["font-variant"] = value; this.IsPathDirty = true; } } @@ -193,7 +193,7 @@ namespace Svg [SvgAttribute("text-decoration", true)] public virtual SvgTextDecoration TextDecoration { - get { return (this.Attributes["text-decoration"] == null) ? SvgTextDecoration.Inherit : (SvgTextDecoration)this.Attributes["text-decoration"]; } + get { return (this.Attributes["text-decoration"] == null) ? SvgTextDecoration.inherit : (SvgTextDecoration)this.Attributes["text-decoration"]; } set { this.Attributes["text-decoration"] = value; this.IsPathDirty = true; } } @@ -203,7 +203,7 @@ namespace Svg [SvgAttribute("font-weight", true)] public virtual SvgFontWeight FontWeight { - get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.Inherit : (SvgFontWeight)this.Attributes["font-weight"]; } + get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.inherit : (SvgFontWeight)this.Attributes["font-weight"]; } set { this.Attributes["font-weight"] = value; this.IsPathDirty = true; } } @@ -328,12 +328,12 @@ namespace Svg // Get the font-weight switch (this.FontWeight) { - //Note: Bold is not listed because it is = W700. - case SvgFontWeight.Bolder: - case SvgFontWeight.W600: - case SvgFontWeight.W700: - case SvgFontWeight.W800: - case SvgFontWeight.W900: + case SvgFontWeight.bold: + case SvgFontWeight.bolder: + case SvgFontWeight.w600: + case SvgFontWeight.w700: + case SvgFontWeight.w800: + case SvgFontWeight.w900: fontStyle |= System.Drawing.FontStyle.Bold; break; } @@ -341,8 +341,8 @@ namespace Svg // Get the font-style switch (this.FontStyle) { - case SvgFontStyle.Italic: - case SvgFontStyle.Oblique: + case SvgFontStyle.italic: + case SvgFontStyle.oblique: fontStyle |= System.Drawing.FontStyle.Italic; break; } @@ -350,10 +350,10 @@ namespace Svg // Get the text-decoration switch (this.TextDecoration) { - case SvgTextDecoration.LineThrough: + case SvgTextDecoration.lineThrough: fontStyle |= System.Drawing.FontStyle.Strikeout; break; - case SvgTextDecoration.Underline: + case SvgTextDecoration.underline: fontStyle |= System.Drawing.FontStyle.Underline; break; } diff --git a/Source/SvgExtentions.cs b/Source/SvgExtentions.cs index 333a4ba..9a93277 100644 --- a/Source/SvgExtentions.cs +++ b/Source/SvgExtentions.cs @@ -54,7 +54,7 @@ namespace Svg { using (XmlTextWriter xml = new XmlTextWriter(str)) { - elem.Write(xml); + elem.WriteElement(xml); result = str.ToString(); } diff --git a/Source/Text/SvgFontFace.cs b/Source/Text/SvgFontFace.cs index 1935280..e967729 100644 --- a/Source/Text/SvgFontFace.cs +++ b/Source/Text/SvgFontFace.cs @@ -84,7 +84,7 @@ namespace Svg [SvgAttribute("font-style")] public virtual SvgFontStyle FontStyle { - get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.All : (SvgFontStyle)this.Attributes["font-style"]; } + get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.inherit : (SvgFontStyle)this.Attributes["font-style"]; } set { this.Attributes["font-style"] = value; } } @@ -94,7 +94,7 @@ namespace Svg [SvgAttribute("font-variant")] public virtual SvgFontVariant FontVariant { - get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.Inherit : (SvgFontVariant)this.Attributes["font-variant"]; } + get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.inherit : (SvgFontVariant)this.Attributes["font-variant"]; } set { this.Attributes["font-variant"] = value; } } @@ -104,7 +104,7 @@ namespace Svg [SvgAttribute("font-weight")] public virtual SvgFontWeight FontWeight { - get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.Inherit : (SvgFontWeight)this.Attributes["font-weight"]; } + get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.inherit : (SvgFontWeight)this.Attributes["font-weight"]; } set { this.Attributes["font-weight"] = value; } } diff --git a/Source/Text/SvgTextAnchor.cs b/Source/Text/SvgTextAnchor.cs index f4dbf7d..162b22a 100644 --- a/Source/Text/SvgTextAnchor.cs +++ b/Source/Text/SvgTextAnchor.cs @@ -12,8 +12,7 @@ namespace Svg [TypeConverter(typeof(SvgTextAnchorConverter))] public enum SvgTextAnchor { - /// The value is inherited from the parent element. - Inherit, + inherit, /// /// The rendered characters are aligned such that the start of the text string is at the initial current text position. /// diff --git a/Source/Text/SvgTextBase.cs b/Source/Text/SvgTextBase.cs index 1a07ad6..a572c52 100644 --- a/Source/Text/SvgTextBase.cs +++ b/Source/Text/SvgTextBase.cs @@ -19,7 +19,7 @@ namespace Svg protected SvgUnitCollection _dx = new SvgUnitCollection(); private string _rotate; private List _rotations = new List(); - + /// /// Gets or sets the text to be rendered. /// @@ -36,7 +36,7 @@ namespace Svg [SvgAttribute("text-anchor", true)] public virtual SvgTextAnchor TextAnchor { - get { return (this.Attributes["text-anchor"] == null) ? SvgTextAnchor.Inherit : (SvgTextAnchor)this.Attributes["text-anchor"]; } + get { return (this.Attributes["text-anchor"] == null) ? SvgTextAnchor.inherit : (SvgTextAnchor)this.Attributes["text-anchor"]; } set { this.Attributes["text-anchor"] = value; this.IsPathDirty = true; } } @@ -143,7 +143,7 @@ namespace Svg { this._rotate = value; this._rotations.Clear(); - this._rotations.AddRange(from r in _rotate.Split(new char[] { ',', ' ', '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries) select float.Parse(r)); + this._rotations.AddRange(from r in _rotate.Split(new char[] {',', ' ', '\r', '\n', '\t'}, StringSplitOptions.RemoveEmptyEntries) select float.Parse(r)); this.IsPathDirty = true; OnAttributeChanged(new AttributeEventArgs { Attribute = "rotate", Value = value }); } @@ -167,7 +167,7 @@ namespace Svg [SvgAttribute("lengthAdjust", true)] public virtual SvgTextLengthAdjust LengthAdjust { - get { return (this.Attributes["lengthAdjust"] == null) ? SvgTextLengthAdjust.Spacing : (SvgTextLengthAdjust)this.Attributes["lengthAdjust"]; } + get { return (this.Attributes["lengthAdjust"] == null) ? SvgTextLengthAdjust.spacing : (SvgTextLengthAdjust)this.Attributes["lengthAdjust"]; } set { this.Attributes["lengthAdjust"] = value; this.IsPathDirty = true; } } @@ -230,14 +230,14 @@ namespace Svg /// The bounds. public override System.Drawing.RectangleF Bounds { - get + get { var path = this.Path(null); foreach (var elem in this.Children.OfType()) { path.AddPath(elem.Path(null), false); } - return path.GetBounds(); + return path.GetBounds(); } } @@ -296,9 +296,9 @@ namespace Svg public override GraphicsPath Path(ISvgRenderer renderer) { //if there is a TSpan inside of this text element then path should not be null (even if this text is empty!) - var nodes = GetContentNodes().Where(x => x is SvgContentNode && - string.IsNullOrEmpty(x.Content.Trim(new[] { '\r', '\n', '\t' }))); - + var nodes = GetContentNodes().Where(x => x is SvgContentNode && + string.IsNullOrEmpty(x.Content.Trim(new[] {'\r', '\n', '\t'}))); + if (_path == null || IsPathDirty || nodes.Count() == 1) { renderer = (renderer ?? SvgRenderer.FromNull()); @@ -365,7 +365,7 @@ namespace Svg var diff = (actLength - specLength); if (Math.Abs(diff) > 1.5) { - if (this.LengthAdjust == SvgTextLengthAdjust.Spacing) + if (this.LengthAdjust == SvgTextLengthAdjust.spacing) { origState.LetterSpacingAdjust = -1 * diff / (state.NumChars - origState.NumChars - 1); SetPath(origState, false); @@ -913,10 +913,5 @@ namespace Svg } } - /// Empty text elements are not legal - only write this element if it has children. - public override bool ShouldWriteElement() - { - return (this.HasChildren() || this.Nodes.Count > 0); - } } } diff --git a/Source/Text/SvgTextPath.cs b/Source/Text/SvgTextPath.cs index d109a44..e80b866 100644 --- a/Source/Text/SvgTextPath.cs +++ b/Source/Text/SvgTextPath.cs @@ -42,14 +42,14 @@ namespace Svg [SvgAttribute("method")] public virtual SvgTextPathMethod Method { - get { return (this.Attributes["method"] == null ? SvgTextPathMethod.Align : (SvgTextPathMethod)this.Attributes["method"]); } + get { return (this.Attributes["method"] == null ? SvgTextPathMethod.align : (SvgTextPathMethod)this.Attributes["method"]); } set { this.Attributes["method"] = value; } } [SvgAttribute("spacing")] public virtual SvgTextPathSpacing Spacing { - get { return (this.Attributes["spacing"] == null ? SvgTextPathSpacing.Exact : (SvgTextPathSpacing)this.Attributes["spacing"]); } + get { return (this.Attributes["spacing"] == null ? SvgTextPathSpacing.exact : (SvgTextPathSpacing)this.Attributes["spacing"]); } set { this.Attributes["spacing"] = value; } } -- GitLab