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
Show whitespace changes
Inline
Side-by-side
Source/Basic Shapes/SvgCircle.cs
View file @
2d6d72e7
...
@@ -100,15 +100,24 @@ namespace Svg
...
@@ -100,15 +100,24 @@ namespace Svg
/// </summary>
/// </summary>
public
override
GraphicsPath
Path
(
ISvgRenderer
renderer
)
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
=
new
GraphicsPath
();
_path
.
StartFigure
();
_path
.
StartFigure
();
var
center
=
this
.
Center
.
ToDeviceValue
(
renderer
,
this
);
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
.
AddEllipse
(
center
.
X
-
radius
,
center
.
Y
-
radius
,
2
*
radius
,
2
*
radius
);
_path
.
CloseFigure
();
_path
.
CloseFigure
();
this
.
IsPathDirty
=
false
;
}
}
return
_path
;
return
_path
;
}
}
...
...
Source/Basic Shapes/SvgEllipse.cs
View file @
2d6d72e7
...
@@ -104,16 +104,25 @@ namespace Svg
...
@@ -104,16 +104,25 @@ namespace Svg
/// <value></value>
/// <value></value>
public
override
GraphicsPath
Path
(
ISvgRenderer
renderer
)
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
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
();
this
.
_path
=
new
GraphicsPath
();
_path
.
StartFigure
();
_path
.
StartFigure
();
_path
.
AddEllipse
(
center
.
X
-
radius
.
X
,
center
.
Y
-
radius
.
Y
,
2
*
radius
.
X
,
2
*
radius
.
Y
);
_path
.
AddEllipse
(
center
.
X
-
radius
.
X
,
center
.
Y
-
radius
.
Y
,
2
*
radius
.
X
,
2
*
radius
.
Y
);
_path
.
CloseFigure
();
_path
.
CloseFigure
();
this
.
IsPathDirty
=
false
;
}
}
return
_path
;
return
_path
;
}
}
...
...
Source/Basic Shapes/SvgLine.cs
View file @
2d6d72e7
...
@@ -126,7 +126,7 @@ namespace Svg
...
@@ -126,7 +126,7 @@ namespace Svg
public
override
System
.
Drawing
.
Drawing2D
.
GraphicsPath
Path
(
ISvgRenderer
renderer
)
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
),
PointF
start
=
new
PointF
(
this
.
StartX
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Horizontal
,
this
),
this
.
StartY
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Vertical
,
this
));
this
.
StartY
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Vertical
,
this
));
...
@@ -134,9 +134,23 @@ namespace Svg
...
@@ -134,9 +134,23 @@ namespace Svg
this
.
EndY
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Vertical
,
this
));
this
.
EndY
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Vertical
,
this
));
this
.
_path
=
new
GraphicsPath
();
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
.
_path
.
AddLine
(
start
,
end
);
this
.
IsPathDirty
=
false
;
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
;
return
this
.
_path
;
}
}
...
...
Source/Basic Shapes/SvgPolygon.cs
View file @
2d6d72e7
...
@@ -65,7 +65,7 @@ namespace Svg
...
@@ -65,7 +65,7 @@ namespace Svg
public
override
GraphicsPath
Path
(
ISvgRenderer
renderer
)
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
=
new
GraphicsPath
();
this
.
_path
.
StartFigure
();
this
.
_path
.
StartFigure
();
...
@@ -77,6 +77,15 @@ namespace Svg
...
@@ -77,6 +77,15 @@ namespace Svg
{
{
var
endPoint
=
SvgUnit
.
GetDevicePoint
(
points
[
i
],
points
[
i
+
1
],
renderer
,
this
);
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
//first line
if
(
_path
.
PointCount
==
0
)
if
(
_path
.
PointCount
==
0
)
{
{
...
@@ -94,6 +103,7 @@ namespace Svg
...
@@ -94,6 +103,7 @@ namespace Svg
}
}
this
.
_path
.
CloseFigure
();
this
.
_path
.
CloseFigure
();
if
(
renderer
!=
null
)
this
.
IsPathDirty
=
false
;
this
.
IsPathDirty
=
false
;
}
}
return
this
.
_path
;
return
this
.
_path
;
...
...
Source/Basic Shapes/SvgPolyline.cs
View file @
2d6d72e7
...
@@ -48,7 +48,7 @@ namespace Svg
...
@@ -48,7 +48,7 @@ namespace Svg
private
GraphicsPath
_Path
;
private
GraphicsPath
_Path
;
public
override
GraphicsPath
Path
(
ISvgRenderer
renderer
)
public
override
GraphicsPath
Path
(
ISvgRenderer
renderer
)
{
{
if
(
_Path
==
null
||
this
.
IsPathDirty
)
if
(
(
_Path
==
null
||
this
.
IsPathDirty
)
&&
base
.
StrokeWidth
>
0
)
{
{
_Path
=
new
GraphicsPath
();
_Path
=
new
GraphicsPath
();
...
@@ -59,6 +59,13 @@ namespace Svg
...
@@ -59,6 +59,13 @@ namespace Svg
PointF
endPoint
=
new
PointF
(
Points
[
i
].
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Horizontal
,
this
),
PointF
endPoint
=
new
PointF
(
Points
[
i
].
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Horizontal
,
this
),
Points
[
i
+
1
].
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Vertical
,
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
// TODO: Remove unrequired first line
if
(
_Path
.
PointCount
==
0
)
if
(
_Path
.
PointCount
==
0
)
{
{
...
@@ -74,6 +81,7 @@ namespace Svg
...
@@ -74,6 +81,7 @@ namespace Svg
{
{
Trace
.
TraceError
(
"Error rendering points: "
+
exc
.
Message
);
Trace
.
TraceError
(
"Error rendering points: "
+
exc
.
Message
);
}
}
if
(
renderer
!=
null
)
this
.
IsPathDirty
=
false
;
this
.
IsPathDirty
=
false
;
}
}
return
_Path
;
return
_Path
;
...
...
Source/Basic Shapes/SvgRectangle.cs
View file @
2d6d72e7
...
@@ -176,13 +176,25 @@ namespace Svg
...
@@ -176,13 +176,25 @@ namespace Svg
/// </summary>
/// </summary>
public
override
GraphicsPath
Path
(
ISvgRenderer
renderer
)
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 the corners aren't to be rounded just create a rectangle
if
(
CornerRadiusX
.
Value
==
0.0f
&&
CornerRadiusY
.
Value
==
0.0f
)
if
(
CornerRadiusX
.
Value
==
0.0f
&&
CornerRadiusY
.
Value
==
0.0f
)
{
{
var
rectangle
=
new
RectangleF
(
Location
.
ToDeviceValue
(
renderer
,
this
),
// Starting location which take consideration of stroke width
SvgUnit
.
GetDeviceSize
(
this
.
Width
,
this
.
Height
,
renderer
,
this
));
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
=
new
GraphicsPath
();
_path
.
StartFigure
();
_path
.
StartFigure
();
...
@@ -253,7 +265,6 @@ namespace Svg
...
@@ -253,7 +265,6 @@ namespace Svg
// Close
// Close
_path
.
CloseFigure
();
_path
.
CloseFigure
();
}
}
IsPathDirty
=
false
;
}
}
return
_path
;
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