Commit 9eccb205 authored by davescriven's avatar davescriven
Browse files

- Fixed "#7522 support rotate(angle,cx,cy)". Added new properties and a new...

- Fixed "#7522 support rotate(angle,cx,cy)". Added new properties and a new constructor overload to   SvgRotate in order to support the optional parameters.
- Removed redundant code from SvgElementFactory.
parent edc594e1
......@@ -159,16 +159,14 @@ namespace Svg
{
var properties = TypeDescriptor.GetProperties(element.GetType(), new SvgAttributeAttribute[] { new SvgAttributeAttribute(attributeName) });
PropertyDescriptor descriptor = null;
TypeConverter converter = null;
if (properties.Count > 0)
{
descriptor = properties[0];
converter = (properties[0].Converter != null) ? properties[0].Converter : TypeDescriptor.GetConverter(descriptor.PropertyType);
try
{
descriptor.SetValue(element, converter.ConvertFrom(document, CultureInfo.InvariantCulture, attributeValue));
descriptor.SetValue(element, descriptor.Converter.ConvertFrom(document, CultureInfo.InvariantCulture, attributeValue));
}
catch
{
......
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
namespace Svg.Transforms
{
public sealed class SvgRotate : SvgTransform
{
private float angle;
public float Angle
{
get { return this.angle; }
set { this.angle = value; }
get;
set;
}
public float CenterX
{
get;
set;
}
public float CenterY
{
get;
set;
}
public override System.Drawing.Drawing2D.Matrix Matrix
public override Matrix Matrix
{
get
{
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
Matrix matrix = new Matrix();
matrix.Translate(this.CenterX, this.CenterY);
matrix.Rotate(this.Angle);
matrix.Translate(-this.CenterX, -this.CenterY);
return matrix;
}
}
public SvgRotate(float angle)
{
this.angle = angle;
this.Angle = angle;
}
public SvgRotate(float angle, float centerX, float centerY)
: this(angle)
{
this.CenterX = centerX;
this.CenterY = centerY;
}
}
}
\ No newline at end of file
......@@ -69,8 +69,26 @@ namespace Svg.Transforms
transformList.Add(new SvgTranslate(x, y));
break;
case "rotate":
float angle = float.Parse(contents, NumberStyles.Float, CultureInfo.InvariantCulture);
transformList.Add(new SvgRotate(angle));
string[] args = contents.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (args.Length != 1 && args.Length != 3)
{
throw new FormatException("Rotate transforms must be in the format 'rotate(angle [cx cy ])'");
}
float angle = float.Parse(args[0], NumberStyles.Float, CultureInfo.InvariantCulture);
if (args.Length == 0)
{
transformList.Add(new SvgRotate(angle));
}
else
{
float cx = float.Parse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture);
float cy = float.Parse(args[2], NumberStyles.Float, CultureInfo.InvariantCulture);
transformList.Add(new SvgRotate(angle, cx, cy));
}
break;
case "scale":
string[] scales = contents.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
......
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