Commit 2d6d72e7 authored by ubbn's avatar ubbn
Browse files

To consider stroke width for boundary. Fix to #175

parent 7eff50ac
......@@ -100,15 +100,24 @@ namespace Svg
/// </summary>
public override GraphicsPath Path(ISvgRenderer renderer)
{
if (this._path == null || this.IsPathDirty)
if ((this._path == null || this.IsPathDirty) && base.StrokeWidth > 0)
{
float halfStrokeWidth = base.StrokeWidth / 2;
// If it is to render, don't need to consider stroke width.
// i.e stroke width only to be considered when calculating boundary
if (renderer != null)
{
halfStrokeWidth = 0;
this.IsPathDirty = false;
}
_path = new GraphicsPath();
_path.StartFigure();
var center = this.Center.ToDeviceValue(renderer, this);
var radius = this.Radius.ToDeviceValue(renderer, UnitRenderingType.Other, this);
var radius = this.Radius.ToDeviceValue(renderer, UnitRenderingType.Other, this) + halfStrokeWidth;
_path.AddEllipse(center.X - radius, center.Y - radius, 2 * radius, 2 * radius);
_path.CloseFigure();
this.IsPathDirty = false;
}
return _path;
}
......
......@@ -104,16 +104,25 @@ namespace Svg
/// <value></value>
public override GraphicsPath Path(ISvgRenderer renderer)
{
if (this._path == null || this.IsPathDirty)
if ((this._path == null || this.IsPathDirty) && base.StrokeWidth > 0)
{
float halfStrokeWidth = base.StrokeWidth / 2;
// If it is to render, don't need to consider stroke width.
// i.e stroke width only to be considered when calculating boundary
if (renderer != null)
{
halfStrokeWidth = 0;
this.IsPathDirty = false;
}
var center = SvgUnit.GetDevicePoint(this._centerX, this._centerY, renderer, this);
var radius = SvgUnit.GetDevicePoint(this._radiusX, this._radiusY, renderer, this);
var radius = SvgUnit.GetDevicePoint(this._radiusX + halfStrokeWidth, this._radiusY + halfStrokeWidth, renderer, this);
this._path = new GraphicsPath();
_path.StartFigure();
_path.AddEllipse(center.X - radius.X, center.Y - radius.Y, 2 * radius.X, 2 * radius.Y);
_path.CloseFigure();
this.IsPathDirty = false;
}
return _path;
}
......
......@@ -126,7 +126,7 @@ namespace Svg
public override System.Drawing.Drawing2D.GraphicsPath Path(ISvgRenderer renderer)
{
if (this._path == null || this.IsPathDirty)
if ((this._path == null || this.IsPathDirty) && base.StrokeWidth > 0)
{
PointF start = new PointF(this.StartX.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this),
this.StartY.ToDeviceValue(renderer, UnitRenderingType.Vertical, this));
......@@ -134,9 +134,23 @@ namespace Svg
this.EndY.ToDeviceValue(renderer, UnitRenderingType.Vertical, this));
this._path = new GraphicsPath();
// If it is to render, don't need to consider stroke width.
// i.e stroke width only to be considered when calculating boundary
if (renderer != null)
{
this._path.AddLine(start, end);
this.IsPathDirty = false;
}
else
{ // only when calculating boundary
_path.StartFigure();
var radius = base.StrokeWidth / 2;
_path.AddEllipse(start.X - radius, start.Y - radius, 2 * radius, 2 * radius);
_path.AddEllipse(end.X - radius, end.Y - radius, 2 * radius, 2 * radius);
_path.CloseFigure();
}
}
return this._path;
}
......
......@@ -65,7 +65,7 @@ namespace Svg
public override GraphicsPath Path(ISvgRenderer renderer)
{
if (this._path == null || this.IsPathDirty)
if ((this._path == null || this.IsPathDirty) && base.StrokeWidth > 0)
{
this._path = new GraphicsPath();
this._path.StartFigure();
......@@ -77,6 +77,15 @@ namespace Svg
{
var endPoint = SvgUnit.GetDevicePoint(points[i], points[i + 1], renderer, this);
// If it is to render, don't need to consider stroke width.
// i.e stroke width only to be considered when calculating boundary
if (renderer == null)
{
var radius = base.StrokeWidth / 2;
_path.AddEllipse(endPoint.X - radius, endPoint.Y - radius, 2 * radius, 2 * radius);
continue;
}
//first line
if (_path.PointCount == 0)
{
......@@ -94,6 +103,7 @@ namespace Svg
}
this._path.CloseFigure();
if (renderer != null)
this.IsPathDirty = false;
}
return this._path;
......
......@@ -48,7 +48,7 @@ namespace Svg
private GraphicsPath _Path;
public override GraphicsPath Path(ISvgRenderer renderer)
{
if (_Path == null || this.IsPathDirty)
if ((_Path == null || this.IsPathDirty) && base.StrokeWidth > 0)
{
_Path = new GraphicsPath();
......@@ -59,6 +59,13 @@ namespace Svg
PointF endPoint = new PointF(Points[i].ToDeviceValue(renderer, UnitRenderingType.Horizontal, this),
Points[i + 1].ToDeviceValue(renderer, UnitRenderingType.Vertical, this));
if (renderer == null)
{
var radius = base.StrokeWidth / 2;
_Path.AddEllipse(endPoint.X - radius, endPoint.Y - radius, 2 * radius, 2 * radius);
continue;
}
// TODO: Remove unrequired first line
if (_Path.PointCount == 0)
{
......@@ -74,6 +81,7 @@ namespace Svg
{
Trace.TraceError("Error rendering points: " + exc.Message);
}
if (renderer != null)
this.IsPathDirty = false;
}
return _Path;
......
......@@ -176,13 +176,25 @@ namespace Svg
/// </summary>
public override GraphicsPath Path(ISvgRenderer renderer)
{
if (_path == null || IsPathDirty)
if ((_path == null || IsPathDirty) && base.StrokeWidth > 0)
{
float halfStrokeWidth = base.StrokeWidth / 2;
// If it is to render, don't need to consider stroke
if (renderer != null)
{
halfStrokeWidth = 0;
this.IsPathDirty = false;
}
// If the corners aren't to be rounded just create a rectangle
if (CornerRadiusX.Value == 0.0f && CornerRadiusY.Value == 0.0f)
{
var rectangle = new RectangleF(Location.ToDeviceValue(renderer, this),
SvgUnit.GetDeviceSize(this.Width, this.Height, renderer, this));
// Starting location which take consideration of stroke width
SvgPoint strokedLocation = new SvgPoint(Location.X - halfStrokeWidth, Location.Y - halfStrokeWidth);
var rectangle = new RectangleF(strokedLocation.ToDeviceValue(renderer, this),
SvgUnit.GetDeviceSize(this.Width + halfStrokeWidth * 2, this.Height + halfStrokeWidth * 2, renderer, this));
_path = new GraphicsPath();
_path.StartFigure();
......@@ -253,7 +265,6 @@ namespace Svg
// Close
_path.CloseFigure();
}
IsPathDirty = false;
}
return _path;
}
......
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