* Path and Bounds are now available for SvgFragment

* SvgDocument can calculate its size in percentage
* SvgTransform collection can return all matrices multiplied
This commit is contained in:
Tebjan Halm 2011-12-02 01:13:40 +01:00
Родитель 3034b3d38a
Коммит fafb144492
4 изменённых файлов: 64 добавлений и 4 удалений

Просмотреть файл

@ -84,9 +84,22 @@ namespace Svg
AddPaths(this, path);
return path;
return path;
}
}
/// <summary>
/// Gets the bounds of the svg element.
/// </summary>
/// <value>The bounds.</value>
public RectangleF Bounds
{
get
{
return this.Path.GetBounds();
}
}
/// <summary>
/// Initializes a new instance of the <see cref="SvgFragment"/> class.

Просмотреть файл

@ -283,7 +283,21 @@ namespace Svg
public RectangleF GetDimensions()
{
return new RectangleF(0, 0, Width.ToDeviceValue(), Height.ToDeviceValue());
var w = Width.ToDeviceValue();
var h = Height.ToDeviceValue();
RectangleF bounds = new RectangleF();
var isWidthperc = Width.Type == SvgUnitType.Percentage;
var isHeightperc = Height.Type == SvgUnitType.Percentage;
if(isWidthperc || isHeightperc)
{
bounds = this.Bounds; //do just one call to the recursive bounds property
if(isWidthperc) w = (bounds.Width + bounds.X) * (w * 0.01f);
if(isHeightperc) h = (bounds.Height + bounds.Y) * (h * 0.01f);
}
return new RectangleF(0, 0, w, h);
}
/// <summary>

Просмотреть файл

@ -418,7 +418,17 @@ namespace Svg
if (c is SvgVisualElement)
{
var cp = ((SvgVisualElement)c).Path;
if (cp != null) path.AddPath(cp, false);
if (cp != null)
{
cp = (GraphicsPath)cp.Clone();
if(c.Transforms != null)
cp.Transform(c.Transforms.GetMatrix());
path.AddPath(cp, false);
}
}
AddPaths(c, path);

Просмотреть файл

@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
@ -9,5 +10,27 @@ namespace Svg.Transforms
[TypeConverter(typeof(SvgTransformConverter))]
public class SvgTransformCollection : List<SvgTransform>
{
/// <summary>
/// Multiplies all matrices
/// </summary>
/// <returns>The result of all transforms</returns>
public Matrix GetMatrix()
{
var transformMatrix = new Matrix();
// Return if there are no transforms
if (this.Count == 0)
{
return transformMatrix;
}
foreach (SvgTransform transformation in this)
{
transformMatrix.Multiply(transformation.Matrix);
}
return transformMatrix;
}
}
}