Skip to content

Commit 317ff08

Browse files
author
dmitry.radchuk
committed
Fix border and background shorthand parsing
DEVSIX-7028
1 parent 6137d49 commit 317ff08

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

styled-xml-parser/src/main/java/com/itextpdf/styledxmlparser/css/resolve/shorthand/impl/AbstractBorderShorthandResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This file is part of the iText (R) project.
4343
package com.itextpdf.styledxmlparser.css.resolve.shorthand.impl;
4444

4545
import com.itextpdf.commons.utils.MessageFormatUtil;
46+
import com.itextpdf.styledxmlparser.css.util.CssUtils;
4647
import com.itextpdf.styledxmlparser.logs.StyledXmlParserLogMessageConstant;
4748
import com.itextpdf.styledxmlparser.css.CommonCssConstants;
4849
import com.itextpdf.styledxmlparser.css.CssDeclaration;
@@ -94,7 +95,7 @@ public List<CssDeclaration> resolveShorthand(String shorthandExpression) {
9495
new CssDeclaration(colorPropName, shorthandExpression));
9596
}
9697

97-
String[] props = shorthandExpression.split("\\s+");
98+
List<String> props = CssUtils.extractShorthandProperties(shorthandExpression).get(0);
9899

99100
String borderColorValue = null;
100101
String borderStyleValue = null;

styled-xml-parser/src/main/java/com/itextpdf/styledxmlparser/css/resolve/shorthand/impl/AbstractBoxShorthandResolver.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This file is part of the iText (R) project.
4343
package com.itextpdf.styledxmlparser.css.resolve.shorthand.impl;
4444

4545
import com.itextpdf.commons.utils.MessageFormatUtil;
46+
import com.itextpdf.styledxmlparser.css.util.CssUtils;
4647
import com.itextpdf.styledxmlparser.logs.StyledXmlParserLogMessageConstant;
4748
import com.itextpdf.styledxmlparser.css.CommonCssConstants;
4849
import com.itextpdf.styledxmlparser.css.CssDeclaration;
@@ -90,17 +91,17 @@ public abstract class AbstractBoxShorthandResolver implements IShorthandResolver
9091
*/
9192
@Override
9293
public List<CssDeclaration> resolveShorthand(String shorthandExpression) {
93-
String[] props = shorthandExpression.split("\\s+");
94+
List<String> props = CssUtils.extractShorthandProperties(shorthandExpression).get(0);
9495
List<CssDeclaration> resolvedDecl = new ArrayList<>();
9596
String topProperty = MessageFormatUtil.format(_0_TOP_1, getPrefix(), getPostfix());
9697
String rightProperty = MessageFormatUtil.format(_0_RIGHT_1, getPrefix(), getPostfix());
9798
String bottomProperty = MessageFormatUtil.format(_0_BOTTOM_1, getPrefix(), getPostfix());
9899
String leftProperty = MessageFormatUtil.format(_0_LEFT_1, getPrefix(), getPostfix());
99-
if (props.length == 1) {
100-
resolvedDecl.add(new CssDeclaration(topProperty, props[0]));
101-
resolvedDecl.add(new CssDeclaration(rightProperty, props[0]));
102-
resolvedDecl.add(new CssDeclaration(bottomProperty, props[0]));
103-
resolvedDecl.add(new CssDeclaration(leftProperty, props[0]));
100+
if (props.size() == 1) {
101+
resolvedDecl.add(new CssDeclaration(topProperty, props.get(0)));
102+
resolvedDecl.add(new CssDeclaration(rightProperty, props.get(0)));
103+
resolvedDecl.add(new CssDeclaration(bottomProperty, props.get(0)));
104+
resolvedDecl.add(new CssDeclaration(leftProperty, props.get(0)));
104105
} else {
105106
for (String prop : props) {
106107
if (CommonCssConstants.INHERIT.equals(prop) || CommonCssConstants.INITIAL.equals(prop)) {
@@ -111,21 +112,21 @@ public List<CssDeclaration> resolveShorthand(String shorthandExpression) {
111112
return Collections.<CssDeclaration>emptyList();
112113
}
113114
}
114-
if (props.length == 2) {
115-
resolvedDecl.add(new CssDeclaration(topProperty, props[0]));
116-
resolvedDecl.add(new CssDeclaration(rightProperty, props[1]));
117-
resolvedDecl.add(new CssDeclaration(bottomProperty, props[0]));
118-
resolvedDecl.add(new CssDeclaration(leftProperty, props[1]));
119-
} else if (props.length == 3) {
120-
resolvedDecl.add(new CssDeclaration(topProperty, props[0]));
121-
resolvedDecl.add(new CssDeclaration(rightProperty, props[1]));
122-
resolvedDecl.add(new CssDeclaration(bottomProperty, props[2]));
123-
resolvedDecl.add(new CssDeclaration(leftProperty, props[1]));
124-
} else if (props.length == 4) {
125-
resolvedDecl.add(new CssDeclaration(topProperty, props[0]));
126-
resolvedDecl.add(new CssDeclaration(rightProperty, props[1]));
127-
resolvedDecl.add(new CssDeclaration(bottomProperty, props[2]));
128-
resolvedDecl.add(new CssDeclaration(leftProperty, props[3]));
115+
if (props.size() == 2) {
116+
resolvedDecl.add(new CssDeclaration(topProperty, props.get(0)));
117+
resolvedDecl.add(new CssDeclaration(rightProperty, props.get(1)));
118+
resolvedDecl.add(new CssDeclaration(bottomProperty, props.get(0)));
119+
resolvedDecl.add(new CssDeclaration(leftProperty, props.get(1)));
120+
} else if (props.size() == 3) {
121+
resolvedDecl.add(new CssDeclaration(topProperty, props.get(0)));
122+
resolvedDecl.add(new CssDeclaration(rightProperty, props.get(1)));
123+
resolvedDecl.add(new CssDeclaration(bottomProperty, props.get(2)));
124+
resolvedDecl.add(new CssDeclaration(leftProperty, props.get(1)));
125+
} else if (props.size() == 4) {
126+
resolvedDecl.add(new CssDeclaration(topProperty, props.get(0)));
127+
resolvedDecl.add(new CssDeclaration(rightProperty, props.get(1)));
128+
resolvedDecl.add(new CssDeclaration(bottomProperty, props.get(2)));
129+
resolvedDecl.add(new CssDeclaration(leftProperty, props.get(3)));
129130
}
130131
}
131132
return resolvedDecl;

styled-xml-parser/src/main/java/com/itextpdf/styledxmlparser/css/resolve/shorthand/impl/BackgroundShorthandResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ private static boolean processAllSpecifiedProperties(List<String> props,
233233
boolean propertyProcessedCorrectly = true;
234234
for (final String value : props) {
235235
final int slashCharInd = value.indexOf('/');
236-
if (slashCharInd > 0 && slashCharInd < value.length() - 1 && !slashEncountered && !value.contains("url(")) {
236+
if (slashCharInd > 0 && slashCharInd < value.length() - 1 && !slashEncountered && !value.contains("url(")
237+
&& !value.contains("device-cmyk(")) {
237238
slashEncountered = true;
238239
propertyProcessedCorrectly = processValueWithSlash(value, slashCharInd, resolvedProps, usedTypes);
239240
} else {

0 commit comments

Comments
 (0)