diff --git a/Source/DataTypes/SvgAspectRatio.cs b/Source/DataTypes/SvgAspectRatio.cs index 4de72132ba2fddc25d4a0c942fd8391941662550..77ae817adac6f154100000e244d9ff7ca8477da7 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 ad175135323c40169ef563fc81e4f8036ed8d5df..4d666539b6d8dbaa202c62954a54a5bd3fdc3d08 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 e4b5a205225b2115bf7104b9abcfe021d3fa94fa..a17c83ee9c9d5aaaa8319335fd10c3e81979f200 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 95708ab37d556d34fa70b668a7aa09e1aba5fa59..2153f6b2e3fab7630d0b8b1acfed1eb2f5c1fb8e 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 f1f81ac589b1d0ea5ec5a980d9d41a52c147acb5..40971b83cb6d73b2f91b6d648a48ecb0e9155d5e 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 31773f109f659b5836b31ccb5ba6adbbe6056caa..55001f4d03630557c5bbf3cd301a1691c04d20ca 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 1603bbbc32572b6839e104f7c973a98e883e6bef..9b0aa7869e57b88675b725cd341b739735583caf 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 f5daa78475a8f5b5ca62596a38dd895864f6d0f5..1d7ae83185c3f0e84f335eb9b6a27006f3b93ad7 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 42b46fa056a0c00bfefb20266dcf17d817c06aa4..50f9523247a7c8dad3b0e40cfb1100ca4015cec9 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 7276e8cecb91584c5740889bbc1c71c4e53187cc..ab68d3ac4d6332a146debc1d371e752856aca8ac 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 a1ca8001a5046f0f13340e091fd121c829e1104b..64aac329c3858057259d62c1ecbfe5f1cc78a1d8 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 b988c09d79a589804acfb7183ba25c114f0c5272..e53d8fa35d74e1e58f474a392ffc437fcd4124e6 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 ef8c813196b7281f7a70b943f618c300f55b5ef6..6233669f1a7bb36380946ff58be2a839de40da9b 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 8f8804d14d494ad423ca23946f3f26bae84f6d38..18320c843687bdc2e2799b9bd19481abb6a13ce4 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 fe9694cc194a85c7a9aec60d7e597755a2661fb6..9941f6373250723034b71ec479c815702ea7956b 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 a9e98dfdfc2b63ec2715a745691c2f2e59eb5b72..d048d142697ac7f74c8b5ba21066f6418609ab70 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 6c7453e3ac4b803e08413e2ea2558b7ae500b04a..0041a6a9443db2be06dc40c933ba0220c5dd2e02 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 6d5de60e8bc9490113e090e83b7bb5d8520afcb5..dac9f1ca358bd44bde48bbb632f2337450ca2bae 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 5a7f75ed60297850ea7a6675c7362c206307ece8..f937e7f778fe366a34cdb46e440c9a2c24f64421 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 e66730a6a2945f688c1fd3b06fed69ac2c3917d4..7af2288ae07950cce802fec03ab44d83fb2f59b0 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 a88c52b3e2a84802ac976fce613560e7389ea85a..ac09091079282828eabc9ceaff7fd6237b2d8cff 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 e19a2c9d0765c2d1a2dee373e736c60128f95d60..b53e44429fd9d506ebfd12e4dd2bc2791c88d775 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 38fe89ae5a5e358daa7709a4351196d25dd8a481..d988bee8bc51ab486e9c7dd707b197a7d096ae06 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 7ce672e0f457b4b50973a99c4422236b216dcfef..837c2c944c90685b62c92fd701e32bec9be110e6 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 333a4bace6091996811e3930efde7974906ecda7..9a93277e6db3ba45e3bf1a1cacbda828e655e701 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 1935280662e98125b2fb3c164f7f1fa922e2d146..e9677290fa26a80c77e892c40aa4afc43cd8e3c8 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 f4dbf7d382de9bb0a2b13466ca626a0446be8779..162b22a45fe09dd5e4c4d52641943876a25462b2 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 1a07ad636cdafc0772dce2d330809ba66d0268e5..a572c52c6aa88b70b3fc3b7fd21e2fbf96ccad3b 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 d109a44efd43e9f4120efee4a51bd68c23efae5b..e80b866a3403c8a705c7a8226f7a4b07f1eaa0e0 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; } }