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
4edc3ea2
Commit
4edc3ea2
authored
Jan 01, 2019
by
mrbean-bremen
Committed by
mrbean-bremen
Jan 02, 2019
Browse files
Added handling of rounded caps for dashed lines using dasharray
- fixes #191
parent
1653f010
Changes
2
Hide whitespace changes
Inline
Side-by-side
Source/Basic Shapes/SvgVisualElement.cs
View file @
4edc3ea2
...
...
@@ -256,10 +256,27 @@ namespace Svg
// handle odd dash arrays by repeating them once
this
.
StrokeDashArray
.
AddRange
(
this
.
StrokeDashArray
);
}
/* divide by stroke width - GDI behaviour that I don't quite understand yet.*/
pen
.
DashPattern
=
this
.
StrokeDashArray
.
ConvertAll
(
u
=>
((
u
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Other
,
this
)
<=
0
)
?
1
:
u
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Other
,
this
))
/
((
strokeWidth
<=
0
)
?
1
:
strokeWidth
)).
ToArray
();
if
(
this
.
StrokeLineCap
==
SvgStrokeLineCap
.
Round
)
{
// to handle round caps, we have to adapt the dash pattern
// by increasing the dash length by the stroke width - GDI draws the rounded
// edge inside the dash line, SVG draws it outside the line
var
pattern
=
new
float
[
pen
.
DashPattern
.
Length
];
int
offset
=
1
;
// the values are already normalized to dash width
for
(
int
i
=
0
;
i
<
pen
.
DashPattern
.
Length
;
i
++)
{
pattern
[
i
]
=
pen
.
DashPattern
[
i
]
+
offset
;
offset
*=
-
1
;
// increase dash length, decrease spaces
}
pen
.
DashPattern
=
pattern
;
pen
.
DashCap
=
DashCap
.
Round
;
}
if
(
this
.
StrokeDashOffset
!=
null
&&
this
.
StrokeDashOffset
.
Value
!=
0
)
{
pen
.
DashOffset
=
((
this
.
StrokeDashOffset
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Other
,
this
)
<=
0
)
?
1
:
this
.
StrokeDashOffset
.
ToDeviceValue
(
renderer
,
UnitRenderingType
.
Other
,
this
))
/
...
...
Tests/Svg.UnitTests/PassingTests.csv
View file @
4edc3ea2
...
...
@@ -174,6 +174,7 @@ __issue-109-01
__issue-116-01
__issue-123-01
__issue-143-01
__issue-191-01
__issue-202-01
__issue-214-01
__issue-227-01
...
...
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