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
fa748a18
Commit
fa748a18
authored
Jan 12, 2019
by
mrbean-bremen
Committed by
mrbean-bremen
Jan 13, 2019
Browse files
Consider transformation for all svg element bounds
- fixes #331
parent
731a69e4
Changes
11
Hide whitespace changes
Inline
Side-by-side
Source/Basic Shapes/SvgImage.cs
View file @
fa748a18
...
...
@@ -88,9 +88,12 @@ namespace Svg
/// <value>The bounds.</value>
public
override
RectangleF
Bounds
{
get
{
return
new
RectangleF
(
this
.
Location
.
ToDeviceValue
(
null
,
this
),
new
SizeF
(
this
.
Width
.
ToDeviceValue
(
null
,
UnitRenderingType
.
Horizontal
,
this
),
this
.
Height
.
ToDeviceValue
(
null
,
UnitRenderingType
.
Vertical
,
this
)));
}
get
{
return
TransformedBounds
(
new
RectangleF
(
this
.
Location
.
ToDeviceValue
(
null
,
this
),
new
SizeF
(
this
.
Width
.
ToDeviceValue
(
null
,
UnitRenderingType
.
Horizontal
,
this
),
this
.
Height
.
ToDeviceValue
(
null
,
UnitRenderingType
.
Vertical
,
this
))));
}
}
/// <summary>
...
...
Source/Document Structure/SvgFragment.cs
View file @
fa748a18
...
...
@@ -238,7 +238,7 @@ namespace Svg
}
}
return
bounds
;
return
TransformedBounds
(
bounds
)
;
}
}
...
...
Source/Document Structure/SvgGroup.cs
View file @
fa748a18
...
...
@@ -47,8 +47,7 @@ namespace Svg
}
}
}
return
r
;
return
TransformedBounds
(
r
);
}
}
...
...
Source/Document Structure/SvgSwitch.cs
View file @
fa748a18
...
...
@@ -52,7 +52,7 @@ namespace Svg
}
}
return
r
;
return
TransformedBounds
(
r
)
;
}
}
...
...
Source/Document Structure/SvgSymbol.cs
View file @
fa748a18
...
...
@@ -74,7 +74,7 @@ namespace Svg.Document_Structure
}
}
return
r
;
return
TransformedBounds
(
r
)
;
}
}
...
...
Source/Extensibility/SvgForeignObject.cs
View file @
fa748a18
...
...
@@ -52,7 +52,7 @@ namespace Svg
}
}
return
r
;
return
TransformedBounds
(
r
)
;
}
}
...
...
Source/Painting/SvgMarker.cs
View file @
fa748a18
...
...
@@ -101,8 +101,14 @@ namespace Svg
{
var
path
=
this
.
Path
(
null
);
if
(
path
!=
null
)
{
if
(
Transforms
!=
null
&&
Transforms
.
Count
>
0
)
{
path
.
Transform
(
Transforms
.
GetMatrix
());
}
return
path
.
GetBounds
();
return
new
System
.
Drawing
.
RectangleF
();
}
return
new
RectangleF
();
}
}
...
...
Source/SvgElement.cs
View file @
fa748a18
...
...
@@ -362,6 +362,24 @@ namespace Svg
}
}
/// <summary>
/// Transforms the given rectangle with the set transformation, if any.
/// Can be applied to bounds calculated without considering the element transformation.
/// </summary>
/// <param name="bounds">The rectangle to be transformed.</param>
/// <returns>The transformed rectangle, or the original rectangle if no transformation exists.</returns>
protected
RectangleF
TransformedBounds
(
RectangleF
bounds
)
{
if
(
Transforms
!=
null
&&
Transforms
.
Count
>
0
)
{
var
path
=
new
GraphicsPath
();
path
.
AddRectangle
(
bounds
);
path
.
Transform
(
Transforms
.
GetMatrix
());
return
path
.
GetBounds
();
}
return
bounds
;
}
/// <summary>
/// Gets or sets the ID of the element.
/// </summary>
...
...
Source/Text/SvgTextBase.cs
View file @
fa748a18
...
...
@@ -220,7 +220,11 @@ namespace Svg
{
path
.
AddPath
(
elem
.
Path
(
null
),
false
);
}
return
path
.
GetBounds
();
if
(
Transforms
!=
null
&&
Transforms
.
Count
>
0
)
{
path
.
Transform
(
Transforms
.
GetMatrix
());
}
return
path
.
GetBounds
();
}
}
...
...
Tests/Svg.UnitTests/BoundsTests.cs
View file @
fa748a18
...
...
@@ -45,6 +45,24 @@ namespace Svg.UnitTests
AssertEqualBounds
(
"rects"
,
-
50f
,
9.5f
,
80
,
50.5f
);
}
[
TestMethod
]
public
void
TestTranslatedGroupBounds
()
{
AssertEqualBounds
(
"lines-translated"
,
-
12.5f
,
-
7
,
31
,
86
);
}
[
TestMethod
]
public
void
TestScaledGroupBounds
()
{
AssertEqualBounds
(
"lines-scaled"
,
19
,
-
81
,
62
,
172
);
}
[
TestMethod
]
public
void
TestRotatedGroupBounds
()
{
AssertEqualBounds
(
"lines-rotated"
,
-
45.5f
,
9.5f
,
86
,
31
);
}
private
void
AssertEqualBounds
(
string
elementId
,
float
x
,
float
y
,
float
width
,
float
height
)
{
const
float
Epsilon
=
0.01f
;
...
...
Tests/Svg.UnitTests/Resources/Issue281_Bounds/BoundsTest.svg
View file @
fa748a18
...
...
@@ -6,6 +6,21 @@
<line
id=
"line-xlate"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"translate(5, 5)"
/>
<line
id=
"line-xform"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"rotate(180), translate(-50, 0)"
/>
</g>
<g
id=
"lines-translated"
transform=
"translate(-22, 33.5)"
>
<line
id=
"line"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
/>
<line
id=
"line-xlate"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"translate(5, 5)"
/>
<line
id=
"line-xform"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"rotate(180), translate(-50, 0)"
/>
</g>
<g
id=
"lines-rotated"
transform=
"rotate(90)"
>
<line
id=
"line"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
/>
<line
id=
"line-xlate"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"translate(5, 5)"
/>
<line
id=
"line-xform"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"rotate(180), translate(-50, 0)"
/>
</g>
<g
id=
"lines-scaled"
transform=
"scale(2)"
>
<line
id=
"line"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
/>
<line
id=
"line-xlate"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"translate(5, 5)"
/>
<line
id=
"line-xform"
x1=
"10"
x2=
"30"
y1=
"20"
y2=
"40"
transform=
"rotate(180), translate(-50, 0)"
/>
</g>
<g
id=
"rects"
>
<rect
id=
"rect"
x=
"10"
y=
"30"
width=
"10"
height=
"20"
/>
<rect
id=
"rect-xlate"
x=
"10"
y=
"30"
width=
"10"
height=
"20"
transform=
"translate(10, 10)"
/>
...
...
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