Skip to content

Commit 8a7f840

Browse files
committed
SVG: Fix handling of the invalid fill-opacity and stroke-opacity values
DEVSIX-2678, DEVSIX-2679
1 parent ac9e726 commit 8a7f840

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,10 @@ private float getOpacityByAttributeName(String attributeName, float generalOpaci
568568
float opacityValue;
569569
if (CssTypesValidationUtils.isPercentageValue(opacityStr)) {
570570
opacityValue = CssDimensionParsingUtils.parseRelativeValue(opacityStr, 1f);
571+
} else if (CssTypesValidationUtils.isNumber(opacityStr)) {
572+
opacityValue = (float) CssDimensionParsingUtils.parseFloat(opacityStr);
571573
} else {
572-
opacityValue = Float.valueOf(opacityStr);
574+
opacityValue = 1;
573575
}
574576
opacity *= opacityValue;
575577
}

svg/src/test/java/com/itextpdf/svg/renderers/OpacityTest.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ public void testRGBA() throws IOException, InterruptedException {
6363
}
6464

6565
@Test
66-
//TODO DEVSIX-2678 SVG: Displaying invalid value of fill-opacity incorrectly
67-
public void testFillOpacityWithComma() {
68-
Assertions.assertThrows(NumberFormatException.class,
69-
() -> convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "testFillOpacityWithComma")
70-
);
66+
public void testFillOpacityWithComma() throws IOException, InterruptedException {
67+
convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "testFillOpacityWithComma");
7168
}
7269

7370
@Test
@@ -76,17 +73,13 @@ public void testFillOpacityWithPercents() throws IOException, InterruptedExcepti
7673
}
7774

7875
@Test
79-
//TODO: update after DEVSIX-2678 fix
8076
public void testFillOpacity() throws IOException, InterruptedException {
8177
convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svg_fill_opacity");
8278
}
8379

8480
@Test
85-
//TODO DEVSIX-2679
8681
public void testStrokeOpacityWithComma() throws IOException, InterruptedException {
87-
Assertions.assertThrows(Exception.class,
88-
() -> convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "testStrokeOpacityWithComma")
89-
);
82+
convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "testStrokeOpacityWithComma");
9083
}
9184

9285
@Test
@@ -95,7 +88,6 @@ public void testStrokeOpacityWithPercents() throws IOException, InterruptedExcep
9588
}
9689

9790
@Test
98-
//TODO: update after DEVSIX-2679 fix
9991
public void testStrokeOpacity() throws IOException, InterruptedException {
10092
convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "svg_stroke_opacity");
10193
}
Lines changed: 12 additions & 0 deletions
Loading
Lines changed: 9 additions & 9 deletions
Loading

0 commit comments

Comments
 (0)