Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
2d6d72e7
Commit
2d6d72e7
authored
Jul 28, 2015
by
ubbn
Browse files
To consider stroke width for boundary. Fix to #175
parent
7eff50ac
Changes
6
Hide whitespace changes
Inline
Side-by-side
Source/Basic Shapes/SvgCircle.cs
View file @
2d6d72e7
...
...
@@ -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
);
_path
.
AddEllipse
(
center
.
X
-
radius
,
center
.
Y
-
radius
,
2
*
radius
,
2
*
radius
);
var
center
=
this
.
Center
.
ToDeviceValue
(
renderer
,
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
;
}
...
...
Source/Basic Shapes/SvgEllipse.cs
View file @
2d6d72e7
...
...
@@ -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
;
}
...
...
Source/Basic Shapes/SvgLine.cs
View file @
2d6d72e7
...
...
@@ -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,8 +134,22 @@ namespace Svg
this
.
EndY
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Vertical
,
this
));
this
.
_path
=
new
GraphicsPath
();
this
.
_path
.
AddLine
(
start
,
end
);
this
.
IsPathDirty
=
false
;
// 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
;
}
...
...
Source/Basic Shapes/SvgPolygon.cs
View file @
2d6d72e7
...
...
@@ -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,7 +103,8 @@ namespace Svg
}
this
.
_path
.
CloseFigure
();
this
.
IsPathDirty
=
false
;
if
(
renderer
!=
null
)
this
.
IsPathDirty
=
false
;
}
return
this
.
_path
;
}
...
...
Source/Basic Shapes/SvgPolyline.cs
View file @
2d6d72e7
...
...
@@ -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,7 +81,8 @@ namespace Svg
{
Trace
.
TraceError
(
"Error rendering points: "
+
exc
.
Message
);
}
this
.
IsPathDirty
=
false
;
if
(
renderer
!=
null
)
this
.
IsPathDirty
=
false
;
}
return
_Path
;
}
...
...
Source/Basic Shapes/SvgRectangle.cs
View file @
2d6d72e7
...
...
@@ -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
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment