зеркало из https://github.com/wieslawsoltes/SVG.git
* 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:
Родитель
3034b3d38a
Коммит
fafb144492
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче