20
20
package com .openhtmltopdf .css .parser .property ;
21
21
22
22
import java .util .ArrayList ;
23
+ import java .util .Arrays ;
24
+ import java .util .Collections ;
23
25
import java .util .List ;
24
26
25
27
import com .openhtmltopdf .css .constants .CSSName ;
29
31
import com .openhtmltopdf .css .parser .FSRGBColor ;
30
32
import com .openhtmltopdf .css .parser .PropertyValue ;
31
33
import com .openhtmltopdf .css .sheet .PropertyDeclaration ;
34
+ import com .openhtmltopdf .util .WebDoc ;
35
+ import com .openhtmltopdf .util .WebDocLocations ;
32
36
37
+ @ WebDoc (WebDocLocations .CSS_BACKGROUND_PROPERTIES )
33
38
public class BackgroundPropertyBuilder extends AbstractPropertyBuilder {
34
39
// [<'background-color'> || <'background-image'> || <'background-repeat'> ||
35
40
// <'background-attachment'> || <'background-position'>] | inherit
@@ -93,18 +98,18 @@ public List<PropertyDeclaration> buildDeclarations(
93
98
}
94
99
95
100
backgroundRepeat = new PropertyDeclaration (
96
- CSSName .BACKGROUND_REPEAT , value , important , origin );
101
+ CSSName .BACKGROUND_REPEAT , new PropertyValue ( Collections . singletonList ( value )) , important , origin );
97
102
}
98
103
99
104
if (PrimitivePropertyBuilders .BACKGROUND_ATTACHMENTS .get (ident .FS_ID )) {
100
105
if (backgroundAttachment != null ) {
101
106
throw new CSSParseException ("A background-attachment value cannot be set twice" , -1 );
102
107
}
103
-
108
+
104
109
backgroundAttachment = new PropertyDeclaration (
105
- CSSName .BACKGROUND_ATTACHMENT , value , important , origin );
110
+ CSSName .BACKGROUND_ATTACHMENT , new PropertyValue ( Collections . singletonList ( value )) , important , origin );
106
111
}
107
-
112
+
108
113
if (ident == IdentValue .TRANSPARENT ) {
109
114
if (backgroundColor != null ) {
110
115
throw new CSSParseException ("A background-color value cannot be set twice" , -1 );
@@ -118,11 +123,13 @@ public List<PropertyDeclaration> buildDeclarations(
118
123
if (backgroundImage != null ) {
119
124
throw new CSSParseException ("A background-image value cannot be set twice" , -1 );
120
125
}
121
-
126
+
127
+ List <PropertyValue > bgImages = Collections .singletonList (value );
128
+
122
129
backgroundImage = new PropertyDeclaration (
123
- CSSName .BACKGROUND_IMAGE , value , important , origin );
130
+ CSSName .BACKGROUND_IMAGE , new PropertyValue ( bgImages ) , important , origin );
124
131
}
125
-
132
+
126
133
if (PrimitivePropertyBuilders .BACKGROUND_POSITIONS .get (ident .FS_ID )) {
127
134
processingBackgroundPosition = true ;
128
135
}
@@ -137,9 +144,11 @@ public List<PropertyDeclaration> buildDeclarations(
137
144
if (backgroundImage != null ) {
138
145
throw new CSSParseException ("A background-image value cannot be set twice" , -1 );
139
146
}
140
-
147
+
148
+ List <PropertyValue > bgImages = Collections .singletonList (value );
149
+
141
150
backgroundImage = new PropertyDeclaration (
142
- CSSName .BACKGROUND_IMAGE , value , important , origin );
151
+ CSSName .BACKGROUND_IMAGE , new PropertyValue ( bgImages ) , important , origin );
143
152
}
144
153
145
154
if (processingBackgroundPosition || isLength (value ) || type == CSSPrimitiveValue .CSS_PERCENTAGE ) {
@@ -167,38 +176,34 @@ public List<PropertyDeclaration> buildDeclarations(
167
176
backgroundColor = new PropertyDeclaration (
168
177
CSSName .BACKGROUND_COLOR , new PropertyValue (IdentValue .TRANSPARENT ), important , origin );
169
178
}
170
-
179
+
171
180
if (backgroundImage == null ) {
181
+ List <PropertyValue > bgImages = Collections .singletonList (new PropertyValue (IdentValue .NONE ));
182
+
172
183
backgroundImage = new PropertyDeclaration (
173
- CSSName .BACKGROUND_IMAGE , new PropertyValue (IdentValue . NONE ), important , origin );
184
+ CSSName .BACKGROUND_IMAGE , new PropertyValue (bgImages ), important , origin );
174
185
}
175
-
186
+
176
187
if (backgroundRepeat == null ) {
177
188
backgroundRepeat = new PropertyDeclaration (
178
- CSSName .BACKGROUND_REPEAT , new PropertyValue (IdentValue .REPEAT ), important , origin );
189
+ CSSName .BACKGROUND_REPEAT , new PropertyValue (Collections . singletonList ( new PropertyValue ( IdentValue .REPEAT )) ), important , origin );
179
190
}
180
-
191
+
181
192
if (backgroundAttachment == null ) {
182
193
backgroundAttachment = new PropertyDeclaration (
183
- CSSName .BACKGROUND_ATTACHMENT , new PropertyValue (IdentValue .SCROLL ), important , origin );
184
-
194
+ CSSName .BACKGROUND_ATTACHMENT , new PropertyValue (Collections .singletonList (new PropertyValue (IdentValue .SCROLL ))), important , origin );
185
195
}
186
-
196
+
187
197
if (backgroundPosition == null ) {
188
198
List <PropertyValue > v = new ArrayList <>(2 );
189
199
v .add (new PropertyValue (CSSPrimitiveValue .CSS_PERCENTAGE , 0.0f , "0%" ));
190
200
v .add (new PropertyValue (CSSPrimitiveValue .CSS_PERCENTAGE , 0.0f , "0%" ));
191
201
backgroundPosition = new PropertyDeclaration (
192
202
CSSName .BACKGROUND_POSITION , new PropertyValue (v ), important , origin );
193
203
}
194
-
195
- result = new ArrayList <>(5 );
196
- result .add (backgroundColor );
197
- result .add (backgroundImage );
198
- result .add (backgroundRepeat );
199
- result .add (backgroundAttachment );
200
- result .add (backgroundPosition );
201
-
202
- return result ;
204
+
205
+ return Arrays .asList (
206
+ backgroundColor , backgroundImage , backgroundRepeat ,
207
+ backgroundAttachment , backgroundPosition );
203
208
}
204
209
}
0 commit comments