Commit e4aae797 authored by Vadim Zaslavsky's avatar Vadim Zaslavsky Committed by mrbean-bremen
Browse files

Basic support of CSS text-transform

parent 4c1fff6c
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Svg
{
/// <summary>This property describes transformations that are added to the text of an element.</summary>
[TypeConverter(typeof(SvgTextTransformationConverter))]
[Flags]
public enum SvgTextTransformation
{
/// <summary>The value is inherited from the parent element.</summary>
Inherit = 0,
/// <summary>The text is not transformed.</summary>
None = 1,
/// <summary>First letter of each word of the text is converted to uppercase.</summary>
Capitalize = 2,
/// <summary>The text is converted to uppercase.</summary>
Uppercase = 4,
/// <summary>The text is converted to lowercase.</summary>
Lowercase = 8
}
}
...@@ -300,6 +300,11 @@ namespace Svg ...@@ -300,6 +300,11 @@ namespace Svg
} }
} }
public sealed class SvgTextTransformationConverter : EnumBaseConverter<SvgTextTransformation>
{
public SvgTextTransformationConverter() : base(SvgTextTransformation.None) { }
}
public static class Enums public static class Enums
{ {
[CLSCompliant(false)] [CLSCompliant(false)]
......
...@@ -104,6 +104,7 @@ ...@@ -104,6 +104,7 @@
<Compile Include="Clipping and Masking\SvgMask.cs" /> <Compile Include="Clipping and Masking\SvgMask.cs" />
<Compile Include="DataTypes\ISvgSupportsCoordinateUnits.cs" /> <Compile Include="DataTypes\ISvgSupportsCoordinateUnits.cs" />
<Compile Include="DataTypes\SvgPointCollection.cs" /> <Compile Include="DataTypes\SvgPointCollection.cs" />
<Compile Include="DataTypes\SvgTextTransformation.cs" />
<Compile Include="DataTypes\SvgTextDecoration.cs" /> <Compile Include="DataTypes\SvgTextDecoration.cs" />
<Compile Include="DataTypes\SvgTextLengthAdjust.cs" /> <Compile Include="DataTypes\SvgTextLengthAdjust.cs" />
<Compile Include="DataTypes\SvgTextPathMethod.cs" /> <Compile Include="DataTypes\SvgTextPathMethod.cs" />
......
...@@ -217,6 +217,7 @@ namespace Svg ...@@ -217,6 +217,7 @@ namespace Svg
case "text-anchor": case "text-anchor":
case "text-decoration": case "text-decoration":
case "text-rendering": case "text-rendering":
case "text-transform":
case "unicode-bidi": case "unicode-bidi":
case "visibility": case "visibility":
case "word-spacing": case "word-spacing":
......
...@@ -249,6 +249,16 @@ namespace Svg ...@@ -249,6 +249,16 @@ namespace Svg
set { this.Attributes["font-weight"] = value; this.IsPathDirty = true; } set { this.Attributes["font-weight"] = value; this.IsPathDirty = true; }
} }
/// <summary>
/// Refers to the text transformation.
/// </summary>
[SvgAttribute("text-transform", true)]
public virtual SvgTextTransformation TextTransformation
{
get { return (SvgTextTransformation)(this.Attributes["text-transform"] ?? SvgTextTransformation.Inherit); }
set { this.Attributes["text-transform"] = value; this.IsPathDirty = true; }
}
private enum FontParseState private enum FontParseState
{ {
fontStyle, fontStyle,
......
...@@ -8,7 +8,8 @@ using System.Drawing.Drawing2D; ...@@ -8,7 +8,8 @@ using System.Drawing.Drawing2D;
using System.Drawing.Text; using System.Drawing.Text;
using Svg.DataTypes; using Svg.DataTypes;
using System.Linq; using System.Linq;
using System.Globalization;
namespace Svg namespace Svg
{ {
public abstract class SvgTextBase : SvgVisualElement public abstract class SvgTextBase : SvgVisualElement
...@@ -393,12 +394,13 @@ namespace Svg ...@@ -393,12 +394,13 @@ namespace Svg
private static readonly Regex MultipleSpaces = new Regex(@" {2,}", RegexOptions.Compiled); private static readonly Regex MultipleSpaces = new Regex(@" {2,}", RegexOptions.Compiled);
/// <summary> /// <summary>
/// Prepare the text according to the whitespace handling rules. <see href="http://www.w3.org/TR/SVG/text.html">SVG Spec</see>. /// Prepare the text according to the whitespace handling rules and text transformations. <see href="http://www.w3.org/TR/SVG/text.html">SVG Spec</see>.
/// </summary> /// </summary>
/// <param name="value">Text to be prepared</param> /// <param name="value">Text to be prepared</param>
/// <returns>Prepared text</returns> /// <returns>Prepared text</returns>
protected string PrepareText(string value) protected string PrepareText(string value)
{ {
value = ApplyTransformation(value);
if (this.SpaceHandling == XmlSpaceHandling.preserve) if (this.SpaceHandling == XmlSpaceHandling.preserve)
{ {
return value.Replace('\t', ' ').Replace("\r\n", " ").Replace('\r', ' ').Replace('\n', ' '); return value.Replace('\t', ' ').Replace("\r\n", " ").Replace('\r', ' ').Replace('\n', ' ');
...@@ -410,6 +412,23 @@ namespace Svg ...@@ -410,6 +412,23 @@ namespace Svg
} }
} }
private string ApplyTransformation(string value)
{
switch (this.TextTransformation)
{
case SvgTextTransformation.Capitalize:
return value.ToUpper();
case SvgTextTransformation.Uppercase:
return value.ToUpper();
case SvgTextTransformation.Lowercase:
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(value);
}
return value;
}
[SvgAttribute("onchange")] [SvgAttribute("onchange")]
public event EventHandler<StringArg> Change; public event EventHandler<StringArg> Change;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment