Skip to content

Commit 1ffa4d5

Browse files
committed
Fix behavior for svg containing elements with zero or negative stroke-width
DEVSIX-6270
1 parent 457ddde commit 1ffa4d5

File tree

16 files changed

+39
-7
lines changed

16 files changed

+39
-7
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,16 @@ private StrokeProperties calculateStrokeProperties(SvgDrawContext context) {
695695
if (!SvgConstants.Values.NONE.equalsIgnoreCase(strokeRawValue)) {
696696
String strokeWidthRawValue = getAttribute(SvgConstants.Attributes.STROKE_WIDTH);
697697

698-
// 1 px = 0,75 pt
699-
float strokeWidth = 0.75f;
700-
698+
float strokeWidth = -1;
701699
if (strokeWidthRawValue != null) {
702700
strokeWidth = parseHorizontalLength(strokeWidthRawValue, context);
703701
}
704702

703+
if (strokeWidth < 0) {
704+
// Default: 1 px = 0,75 pt
705+
strokeWidth = 0.75f;
706+
}
707+
705708
float generalOpacity = getOpacity();
706709
float strokeOpacity = getOpacityByAttributeName(SvgConstants.Attributes.STROKE_OPACITY, generalOpacity);
707710

@@ -719,8 +722,10 @@ private StrokeProperties calculateStrokeProperties(SvgDrawContext context) {
719722
SvgStrokeParameterConverter.convertStrokeDashParameters(strokeDashArrayRawValue,
720723
strokeDashOffsetRawValue, getCurrentFontSize(context), context);
721724

722-
doStroke = true;
723-
return new StrokeProperties(strokeColor, strokeWidth, strokeOpacity, lineDashParameters);
725+
if (strokeWidth > 0) {
726+
doStroke = true;
727+
return new StrokeProperties(strokeColor, strokeWidth, strokeOpacity, lineDashParameters);
728+
}
724729
}
725730
return null;
726731
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This file is part of the iText (R) project.
2525
import com.itextpdf.test.ITextTest;
2626

2727
import java.io.IOException;
28+
2829
import org.junit.jupiter.api.BeforeAll;
2930
import org.junit.jupiter.api.Tag;
3031
import org.junit.jupiter.api.Test;
@@ -103,14 +104,24 @@ public void strokeAttributesTest() throws IOException, InterruptedException {
103104
convertAndCompare(SOURCE_FOLDER, DESTINATION_FOLDER, "stroke-attributes");
104105
}
105106

107+
@Test
108+
public void zeroStrokeWidthTest() throws IOException, InterruptedException {
109+
convertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "zeroStrokeWidth");
110+
}
111+
112+
@Test
113+
public void negativeStrokeWidthTest() throws IOException, InterruptedException {
114+
convertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "negativeStrokeWidth");
115+
}
116+
106117
@Test
107118
public void heightWidthZeroTest() throws IOException, InterruptedException {
108-
convertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER,"heightWidthZero");
119+
convertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "heightWidthZero");
109120
}
110121

111122
@Test
112123
public void heightWidthNegativeTest() throws IOException, InterruptedException {
113-
convertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER,"heightWidthNegative");
124+
convertAndCompareSinglePage(SOURCE_FOLDER, DESTINATION_FOLDER, "heightWidthNegative");
114125
}
115126

116127
@Test
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)