Commit 6f96b730 authored by mrbean-bremen's avatar mrbean-bremen Committed by mrbean-bremen
Browse files

Partly fixed marker appearance

- fixed stroke and fill color (taken from marker or from included path)
- added missing scaling for markerUnits="strokeWidth"
- fixed initial value of "orient" to be "0"
- fixes 2 of the W3C tests
parent fecffa78
...@@ -76,6 +76,7 @@ namespace SVGViewer ...@@ -76,6 +76,7 @@ namespace SVGViewer
else else
outputDir = System.IO.Path.GetDirectoryName(svgDoc.BaseUri.LocalPath); outputDir = System.IO.Path.GetDirectoryName(svgDoc.BaseUri.LocalPath);
svgImage.Image.Save(System.IO.Path.Combine(outputDir, "output.png")); svgImage.Image.Save(System.IO.Path.Combine(outputDir, "output.png"));
// svgDoc.Write(System.IO.Path.Combine(outputDir, "output.svg"));
} }
} }
} }
...@@ -12,6 +12,8 @@ namespace Svg ...@@ -12,6 +12,8 @@ namespace Svg
get get
{ {
var path = this.Path(null); var path = this.Path(null);
if (path != null)
{
if (Transforms != null && Transforms.Count > 0) if (Transforms != null && Transforms.Count > 0)
{ {
path = (GraphicsPath)path.Clone(); path = (GraphicsPath)path.Clone();
...@@ -19,6 +21,8 @@ namespace Svg ...@@ -19,6 +21,8 @@ namespace Svg
} }
return path.GetBounds(); return path.GetBounds();
} }
return new System.Drawing.RectangleF();
}
} }
} }
} }
...@@ -15,7 +15,13 @@ namespace Svg ...@@ -15,7 +15,13 @@ namespace Svg
public SvgOrient() public SvgOrient()
{ {
IsAuto = true; IsAuto = false;
Angle = 0;
}
public SvgOrient(bool isAuto)
{
IsAuto = isAuto;
} }
public SvgOrient(float angle) public SvgOrient(float angle)
......
...@@ -21,7 +21,7 @@ namespace Svg.DataTypes ...@@ -21,7 +21,7 @@ namespace Svg.DataTypes
switch (value.ToString()) switch (value.ToString())
{ {
case "auto": case "auto":
return (new SvgOrient()); return (new SvgOrient(true));
default: default:
float fTmp = float.MinValue; float fTmp = float.MinValue;
if(!float.TryParse(value.ToString(), out fTmp)) if(!float.TryParse(value.ToString(), out fTmp))
......
...@@ -7,7 +7,7 @@ using Svg.DataTypes; ...@@ -7,7 +7,7 @@ using Svg.DataTypes;
namespace Svg namespace Svg
{ {
[SvgElement("marker")] [SvgElement("marker")]
public class SvgMarker : SvgVisualElement, ISvgViewPort public class SvgMarker : SvgPathBasedElement, ISvgViewPort
{ {
private SvgOrient _svgOrient = new SvgOrient(); private SvgOrient _svgOrient = new SvgOrient();
...@@ -79,6 +79,37 @@ namespace Svg ...@@ -79,6 +79,37 @@ namespace Svg
set { this.Attributes["markerUnits"] = value; } set { this.Attributes["markerUnits"] = value; }
} }
/// <summary>
/// If not set set in the marker, consider the attribute in the drawing element.
/// </summary>
public override SvgPaintServer Fill
{
get
{
var path = this.Children.FirstOrDefault(x => x is SvgVisualElement);
if (path != null)
{
return path.Fill;
}
return base.Fill;
}
}
/// <summary>
/// If not set set in the marker, consider the attribute in the drawing element.
/// </summary>
public override SvgPaintServer Stroke
{
get {
var path = this.Children.FirstOrDefault(x => x is SvgVisualElement);
if (path != null)
{
return path.Stroke;
}
return base.Stroke;
}
}
public SvgMarker() public SvgMarker()
{ {
MarkerUnits = SvgMarkerUnits.StrokeWidth; MarkerUnits = SvgMarkerUnits.StrokeWidth;
...@@ -95,23 +126,6 @@ namespace Svg ...@@ -95,23 +126,6 @@ namespace Svg
return null; return null;
} }
public override System.Drawing.RectangleF Bounds
{
get
{
var path = this.Path(null);
if (path != null)
{
if (Transforms != null && Transforms.Count > 0)
{
path.Transform(Transforms.GetMatrix());
}
return path.GetBounds();
}
return new RectangleF();
}
}
public override SvgElement DeepCopy() public override SvgElement DeepCopy()
{ {
return DeepCopy<SvgMarker>(); return DeepCopy<SvgMarker>();
...@@ -199,10 +213,12 @@ namespace Svg ...@@ -199,10 +213,12 @@ namespace Svg
case SvgMarkerUnits.StrokeWidth: case SvgMarkerUnits.StrokeWidth:
if (ViewBox.Width > 0 && ViewBox.Height > 0) if (ViewBox.Width > 0 && ViewBox.Height > 0)
{ {
transMatrix.Scale(MarkerWidth, MarkerHeight);
var strokeWidth = pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this);
transMatrix.Translate(AdjustForViewBoxWidth(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this) * transMatrix.Translate(AdjustForViewBoxWidth(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this) *
pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)), strokeWidth),
AdjustForViewBoxHeight(-RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this) * AdjustForViewBoxHeight(-RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this) *
pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this))); strokeWidth));
} }
else else
{ {
...@@ -244,13 +260,14 @@ namespace Svg ...@@ -244,13 +260,14 @@ namespace Svg
/// <returns></returns> /// <returns></returns>
private Pen CreatePen(SvgVisualElement pPath, ISvgRenderer renderer) private Pen CreatePen(SvgVisualElement pPath, ISvgRenderer renderer)
{ {
if (pPath.Stroke == null) return null; if (this.Stroke == null) return null;
Brush pBrush = pPath.Stroke.GetBrush(this, renderer, Opacity); Brush pBrush = this.Stroke.GetBrush(this, renderer, Opacity);
switch (MarkerUnits) switch (MarkerUnits)
{ {
case SvgMarkerUnits.StrokeWidth: case SvgMarkerUnits.StrokeWidth:
return (new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this) * // TODO: have to multiply with marker stroke width if it is not inherted from the
pPath.StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this))); // same ancestor as owner path stroke width
return (new Pen(pBrush, pPath.StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this)));
case SvgMarkerUnits.UserSpaceOnUse: case SvgMarkerUnits.UserSpaceOnUse:
return (new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this))); return (new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this)));
} }
......
...@@ -21,7 +21,7 @@ namespace Svg.UnitTests ...@@ -21,7 +21,7 @@ namespace Svg.UnitTests
{ {
protected override string TestResource { get { return GetFullResourceString("Issue212_MakerEnd.OperatingPlan.svg"); } } protected override string TestResource { get { return GetFullResourceString("Issue212_MakerEnd.OperatingPlan.svg"); } }
protected override int ExpectedSize { get { return 5000; } } //5321 //5410 protected override int ExpectedSize { get { return 4300; } } // original image has 4314 bytes
[TestMethod] [TestMethod]
......
...@@ -47,6 +47,8 @@ painting-fill-01-t ...@@ -47,6 +47,8 @@ painting-fill-01-t
painting-fill-02-t painting-fill-02-t
painting-fill-03-t painting-fill-03-t
painting-fill-05-b painting-fill-05-b
painting-marker-01-f
painting-marker-06-f
painting-stroke-01-t painting-stroke-01-t
painting-stroke-02-t painting-stroke-02-t
painting-stroke-04-t painting-stroke-04-t
......
...@@ -53,6 +53,8 @@ painting-fill-02-t.svg ...@@ -53,6 +53,8 @@ painting-fill-02-t.svg
painting-fill-03-t.svg painting-fill-03-t.svg
painting-fill-04-t.svg painting-fill-04-t.svg
painting-fill-05-b.svg painting-fill-05-b.svg
painting-marker-01-f.svg
painting-marker-06-f.svg
painting-stroke-01-t.svg painting-stroke-01-t.svg
painting-stroke-02-t.svg painting-stroke-02-t.svg
painting-stroke-04-t.svg painting-stroke-04-t.svg
......
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