Skip to content

Commit 9094fb0

Browse files
author
Dmitry Radchuk
committed
Fix rx/ry handling of Ellipse and Rectangle svg objects
DEVSIX-3119, DEVSIX-3121
1 parent 4c7964a commit 9094fb0

File tree

8 files changed

+16
-10
lines changed

8 files changed

+16
-10
lines changed

svg/src/main/java/com/itextpdf/svg/renderers/impl/EllipseSvgNodeRenderer.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,16 @@ protected boolean setParameters() {
8181
*/
8282
protected boolean setParameters(SvgDrawContext context) {
8383
initCenter(context);
84-
rx = parseHorizontalLength(getAttribute(SvgConstants.Attributes.RX), context);
85-
ry = parseVerticalLength(getAttribute(SvgConstants.Attributes.RY), context);
84+
String rxValue = getAttribute(SvgConstants.Attributes.RX);
85+
String ryValue = getAttribute(SvgConstants.Attributes.RY);
86+
rx = parseHorizontalLength(rxValue, context);
87+
ry = parseVerticalLength(ryValue, context);
88+
if (rxValue == null) {
89+
rx = ry;
90+
}
91+
if (ryValue == null) {
92+
ry = rx;
93+
}
8694
return rx > 0.0F && ry > 0.0F;
8795
}
8896

svg/src/main/java/com/itextpdf/svg/renderers/impl/RectangleSvgNodeRenderer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ private void setParameters(SvgDrawContext context) {
117117
height = parseVerticalLength(getAttribute(SvgConstants.Attributes.HEIGHT), context);
118118

119119
if (attributesAndStyles.containsKey(SvgConstants.Attributes.RX)) {
120-
rx = checkRadius(parseHorizontalLength(getAttribute(SvgConstants.Attributes.RX), context), width);
121-
rxPresent = true;
120+
float rawRadius =parseHorizontalLength(getAttribute(SvgConstants.Attributes.RX), context);
121+
rx = checkRadius(rawRadius, width);
122+
rxPresent = rawRadius >= 0.0f;
122123
}
123124
if (attributesAndStyles.containsKey(SvgConstants.Attributes.RY)) {
124-
ry = checkRadius(parseVerticalLength(getAttribute(SvgConstants.Attributes.RY), context), height);
125-
ryPresent = true;
125+
float rawRadius = parseVerticalLength(getAttribute(SvgConstants.Attributes.RY), context);
126+
ry = checkRadius(rawRadius, height);
127+
ryPresent = rawRadius >= 0.0f;
126128
}
127129
}
128130

svg/src/test/java/com/itextpdf/svg/renderers/impl/EllipseSvgNodeRendererIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,11 @@ public void ellipseCyAbsentTest() throws IOException, InterruptedException, java
8282
}
8383

8484
@Test
85-
//TODO: update cmp_ when DEVSIX-3119
8685
public void ellipseRxAbsentTest() throws IOException, InterruptedException, java.io.IOException {
8786
convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseRxAbsent");
8887
}
8988

9089
@Test
91-
//TODO: update cmp_ when DEVSIX-3119
9290
public void ellipseRyAbsentTest() throws IOException, InterruptedException, java.io.IOException {
9391
convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "ellipseRyAbsent");
9492
}

svg/src/test/java/com/itextpdf/svg/renderers/impl/RectangleSvgNodeRendererIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,11 @@ public void basicEllipticalHeightCappedRoundedRectangleTest() throws IOException
9595
}
9696

9797
@Test
98-
//TODO change cmp-file after DEVSIX-3121 fixed
9998
public void basicEllipticalNegativeWidthRoundedRectangleTest() throws IOException, InterruptedException {
10099
convertAndCompare(sourceFolder, destinationFolder, "basicEllipticalNegativeWidthRoundedRectangle");
101100
}
102101

103102
@Test
104-
//TODO change cmp-file after DEVSIX-3121 fixed
105103
public void basicEllipticalNegativeHeightRoundedRectangleTest() throws IOException, InterruptedException {
106104
convertAndCompare(sourceFolder, destinationFolder, "basicEllipticalNegativeHeightRoundedRectangle");}
107105

0 commit comments

Comments
 (0)