Skip to content

Commit f942189

Browse files
committed
Make the CSS API more convenient to use
1 parent 80e7849 commit f942189

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/main/java/com/itextpdf/html2pdf/css/CssNestedAtRule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,9 @@ public String toString() {
142142
sb.append("\n}");
143143
return sb.toString();
144144
}
145+
146+
public String getRuleParameters() {
147+
return ruleParameters;
148+
}
149+
145150
}

src/main/java/com/itextpdf/html2pdf/css/CssRuleSet.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public class CssRuleSet extends CssStatement {
6969
private List<CssDeclaration> importantDeclarations;
7070

7171
/**
72-
* Creates a new {@link CssRuleSet}.
72+
* Creates a new {@link CssRuleSet} from selector and raw list of declarations.
73+
* The declarations are split into normal and important under the hood.
74+
* To construct the {@link CssRuleSet} instance from normal and important declarations, see
75+
* {@link #CssRuleSet(ICssSelector, List, List)}
7376
*
7477
* @param selector the CSS selector
7578
* @param declarations the CSS declarations
@@ -78,7 +81,13 @@ public CssRuleSet(ICssSelector selector, List<CssDeclaration> declarations) {
7881
this.selector = selector;
7982
this.normalDeclarations = new ArrayList<>();
8083
this.importantDeclarations = new ArrayList<>();
81-
splitDeclarationsIntoNormalAndImportant(declarations);
84+
splitDeclarationsIntoNormalAndImportant(declarations, normalDeclarations, importantDeclarations);
85+
}
86+
87+
public CssRuleSet(ICssSelector selector, List<CssDeclaration> normalDeclarations, List<CssDeclaration> importantDeclarations) {
88+
this.selector = selector;
89+
this.normalDeclarations = normalDeclarations;
90+
this.importantDeclarations = importantDeclarations;
8291
}
8392

8493
/* (non-Javadoc)
@@ -151,7 +160,7 @@ public List<CssDeclaration> getImportantDeclarations() {
151160
*
152161
* @param declarations the declarations
153162
*/
154-
private void splitDeclarationsIntoNormalAndImportant(List<CssDeclaration> declarations) {
163+
private static void splitDeclarationsIntoNormalAndImportant(List<CssDeclaration> declarations, List<CssDeclaration> normalDeclarations, List<CssDeclaration> importantDeclarations) {
155164
for (CssDeclaration declaration : declarations) {
156165
int exclIndex = declaration.getExpression().indexOf('!');
157166
if (exclIndex > 0 && importantMatcher.matcher(declaration.getExpression()).matches()) {

0 commit comments

Comments
 (0)