Commit d604cc8d authored by davescriven's avatar davescriven
Browse files

- Adding initial support for Write functionality. Units & Transforms mostly....

- Adding initial support for Write functionality. Units & Transforms mostly. Enums still need work. Needs support for an IsDirty concept so that that every possible attribute isn't written.
parent c552f74b
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Globalization;
namespace Svg
{
......@@ -172,12 +173,6 @@ namespace Svg
return base.GetHashCode();
}
/// <summary>
/// Returns the fully qualified type name of this instance.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"/> containing a fully qualified type name.
/// </returns>
public override string ToString()
{
string type = string.Empty;
......@@ -207,7 +202,7 @@ namespace Svg
break;
}
return string.Concat(this.Value.ToString(), type);
return string.Concat(this.Value.ToString(CultureInfo.InvariantCulture), type);
}
/// <summary>
......
......@@ -72,9 +72,31 @@ namespace Svg
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
return ((SvgUnit)value).ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
\ No newline at end of file
......@@ -108,5 +108,39 @@ namespace Svg
return base.ConvertFrom(context, culture, value);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var viewBox = (SvgViewBox)value;
return string.Format("{0}, {1}, {2}, {3}",
viewBox.MinX.ToString(CultureInfo.InvariantCulture), viewBox.MinY.ToString(CultureInfo.InvariantCulture),
viewBox.MinX.ToString(CultureInfo.InvariantCulture), viewBox.MinY.ToString(CultureInfo.InvariantCulture));
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Globalization;
namespace Svg
{
......@@ -50,13 +52,40 @@ namespace Svg
colour = string.Format(culture, "#{0}{0}{1}{1}{2}{2}", colour[1], colour[2], colour[3]);
return base.ConvertFrom(context, culture, colour);
}
else
{
return base.ConvertFrom(context, culture, value);
}
}
return base.ConvertFrom(context, culture, value);
}
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var colour = (Color)value;
return ColorTranslator.ToHtml(colour);
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Drawing;
using System.Globalization;
namespace Svg
{
......@@ -34,14 +35,58 @@ namespace Svg
}
else // Otherwise try and parse as colour
{
SvgColourServer server = new SvgColourServer((Color)_colourConverter.ConvertFrom(value.Trim()));
return server;
return new SvgColourServer((Color)_colourConverter.ConvertFrom(value.Trim()));
}
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return SvgPaintServerFactory.Create((string)value, (SvgDocument)context);
}
if (value is string)
{
return SvgPaintServerFactory.Create((string)value, (SvgDocument)context);
}
return base.ConvertFrom(context, culture, value);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var colourServer = value as SvgColourServer;
if (colourServer != null)
{
return new SvgColourConverter().ConvertTo(colourServer.Colour, typeof(string));
}
if (value != null)
{
return string.Format(CultureInfo.InvariantCulture, "url(#{0})", ((SvgPaintServer)value).ID);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
......@@ -12,10 +13,15 @@
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
......@@ -28,7 +34,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
......@@ -40,6 +45,7 @@
<DefineConstants>TRACE;DEBUG;REFLECTION</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
......@@ -50,6 +56,7 @@
<WarningLevel>4</WarningLevel>
<CodeAnalysisRules>
</CodeAnalysisRules>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.JScript" />
......@@ -148,6 +155,11 @@
<Compile Include="Web\SvgHandler.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
......@@ -163,6 +175,11 @@
<ProductName>.NET Framework 3.5</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\svg11.dtd" />
......
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
......@@ -4,8 +4,9 @@ using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml;
using System.Linq;
using Svg.Transforms;
using System.Reflection;
namespace Svg
{
......@@ -27,7 +28,20 @@ namespace Svg
/// </summary>
protected internal string ElementName
{
get { return this._elementName; }
get
{
if (string.IsNullOrEmpty(this._elementName))
{
var attr = TypeDescriptor.GetAttributes(this).OfType<SvgElementAttribute>().SingleOrDefault();
if (attr != null)
{
this._elementName = attr.ElementName;
}
}
return this._elementName;
}
internal set { this._elementName = value; }
}
......@@ -297,7 +311,25 @@ namespace Svg
protected virtual void WriteAttributes(XmlTextWriter writer)
{
var attributes = from PropertyDescriptor a in TypeDescriptor.GetProperties(this)
let attribute = a.Attributes[typeof(SvgAttributeAttribute)] as SvgAttributeAttribute
where attribute != null
select new { Property = a, Attribute = attribute };
foreach (var attr in attributes)
{
if (attr.Property.Converter.CanConvertTo(typeof(string)))
{
object propertyValue = attr.Property.GetValue(this);
if (propertyValue != null)
{
string value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
writer.WriteAttributeString(attr.Attribute.Name, attr.Attribute.NameSpace, value);
}
}
}
}
protected virtual void Write(XmlTextWriter writer)
......
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using System.Globalization;
namespace Svg.Transforms
{
......@@ -34,6 +35,12 @@ namespace Svg.Transforms
}
}
public override string WriteToString()
{
return string.Format(CultureInfo.InvariantCulture, "matrix({0}, {1}, {2}, {3}, {4}, {5})",
this.points[0], this.points[1], this.points[2], this.points[3], this.points[4], this.points[5]);
}
public SvgMatrix(List<float> m)
{
this.points = m;
......
......@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using System.Globalization;
namespace Svg.Transforms
{
......@@ -37,6 +38,11 @@ namespace Svg.Transforms
}
}
public override string WriteToString()
{
return string.Format(CultureInfo.InvariantCulture, "rotate({0}, {1}, {2})", this.Angle, this.CenterX, this.CenterY);
}
public SvgRotate(float angle)
{
this.Angle = angle;
......
......@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using System.Globalization;
namespace Svg.Transforms
{
......@@ -32,6 +33,11 @@ namespace Svg.Transforms
}
}
public override string WriteToString()
{
return string.Format(CultureInfo.InvariantCulture, "scale({0}, {1})", this.X, this.Y);
}
public SvgScale(float x) : this(x, x) { }
public SvgScale(float x, float y)
......
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using System.Globalization;
namespace Svg.Transforms
{
......@@ -35,6 +36,11 @@ namespace Svg.Transforms
}
}
public override string WriteToString()
{
return string.Format(CultureInfo.InvariantCulture, "shear({0}, {1})", this.X, this.Y);
}
public SvgShear(float x) : this(x, x) { }
public SvgShear(float x, float y)
......
using System;
using System.Drawing.Drawing2D;
using System.Globalization;
namespace Svg.Transforms
{
......@@ -24,6 +25,11 @@ namespace Svg.Transforms
}
}
public override string WriteToString()
{
return string.Format(CultureInfo.InvariantCulture, "skew({0}, {1})", this.AngleX, this.AngleY);
}
public SvgSkew(float x, float y)
{
AngleX = x;
......
......@@ -9,5 +9,6 @@ namespace Svg.Transforms
public abstract class SvgTransform
{
public abstract Matrix Matrix { get; }
public abstract string WriteToString();
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Linq;
namespace Svg.Transforms
{
......@@ -164,5 +165,40 @@ namespace Svg.Transforms
return base.ConvertFrom(context, culture, value);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var transforms = value as SvgTransformCollection;
if (transforms != null)
{
return string.Join(",", transforms.Select(t => t.WriteToString()).ToArray());
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
namespace Svg.Transforms
{
......@@ -31,6 +32,11 @@ namespace Svg.Transforms
}
}
public override string WriteToString()
{
return string.Format(CultureInfo.InvariantCulture, "translate({0}, {1})", this.X, this.Y);
}
public SvgTranslate(float x, float y)
{
this.x = x;
......
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