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
else
outputDir = System.IO.Path.GetDirectoryName(svgDoc.BaseUri.LocalPath);
svgImage.Image.Save(System.IO.Path.Combine(outputDir, "output.png"));
// svgDoc.Write(System.IO.Path.Combine(outputDir, "output.svg"));
}
}
}
......@@ -12,12 +12,16 @@ namespace Svg
get
{
var path = this.Path(null);
if (Transforms != null && Transforms.Count > 0)
if (path != null)
{
path = (GraphicsPath)path.Clone();
path.Transform(Transforms.GetMatrix());
if (Transforms != null && Transforms.Count > 0)
{
path = (GraphicsPath)path.Clone();
path.Transform(Transforms.GetMatrix());
}
return path.GetBounds();
}
return path.GetBounds();
return new System.Drawing.RectangleF();
}
}
}
......
......@@ -15,10 +15,16 @@ namespace Svg
public SvgOrient()
{
IsAuto = true;
IsAuto = false;
Angle = 0;
}
public SvgOrient(float angle)
public SvgOrient(bool isAuto)
{
IsAuto = isAuto;
}
public SvgOrient(float angle)
{
Angle = angle;
}
......
......@@ -21,7 +21,7 @@ namespace Svg.DataTypes
switch (value.ToString())
{
case "auto":
return (new SvgOrient());
return (new SvgOrient(true));
default:
float fTmp = float.MinValue;
if(!float.TryParse(value.ToString(), out fTmp))
......
......@@ -7,7 +7,7 @@ using Svg.DataTypes;
namespace Svg
{
[SvgElement("marker")]
public class SvgMarker : SvgVisualElement, ISvgViewPort
public class SvgMarker : SvgPathBasedElement, ISvgViewPort
{
private SvgOrient _svgOrient = new SvgOrient();
......@@ -79,6 +79,37 @@ namespace Svg
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()
{
MarkerUnits = SvgMarkerUnits.StrokeWidth;
......@@ -95,23 +126,6 @@ namespace Svg
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()
{
return DeepCopy<SvgMarker>();
......@@ -199,10 +213,12 @@ namespace Svg
case SvgMarkerUnits.StrokeWidth:
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) *
pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)),
strokeWidth),
AdjustForViewBoxHeight(-RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this) *
pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)));
strokeWidth));
}
else
{
......@@ -244,13 +260,14 @@ namespace Svg
/// <returns></returns>
private Pen CreatePen(SvgVisualElement pPath, ISvgRenderer renderer)
{
if (pPath.Stroke == null) return null;
Brush pBrush = pPath.Stroke.GetBrush(this, renderer, Opacity);
if (this.Stroke == null) return null;
Brush pBrush = this.Stroke.GetBrush(this, renderer, Opacity);
switch (MarkerUnits)
{
case SvgMarkerUnits.StrokeWidth:
return (new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this) *
pPath.StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this)));
// TODO: have to multiply with marker stroke width if it is not inherted from the
// same ancestor as owner path stroke width
return (new Pen(pBrush, pPath.StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this)));
case SvgMarkerUnits.UserSpaceOnUse:
return (new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this)));
}
......
......@@ -21,7 +21,7 @@ namespace Svg.UnitTests
{
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]
......
......@@ -47,6 +47,8 @@ painting-fill-01-t
painting-fill-02-t
painting-fill-03-t
painting-fill-05-b
painting-marker-01-f
painting-marker-06-f
painting-stroke-01-t
painting-stroke-02-t
painting-stroke-04-t
......
......@@ -53,6 +53,8 @@ painting-fill-02-t.svg
painting-fill-03-t.svg
painting-fill-04-t.svg
painting-fill-05-b.svg
painting-marker-01-f.svg
painting-marker-06-f.svg
painting-stroke-01-t.svg
painting-stroke-02-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