@@ -80,29 +80,26 @@ public class BackgroundImage {
80
80
81
81
private final BackgroundSize backgroundSize ;
82
82
83
+ private final BackgroundBox backgroundClip ;
84
+
85
+ private final BackgroundBox backgroundOrigin ;
86
+
83
87
/**
84
- * Creates a new {@link BackgroundImage} instance.
88
+ * Creates a copy of passed {@link BackgroundImage} instance.
85
89
*
86
- * @param image background-image property. {@link PdfXObject} instance.
87
- * @param repeat background-repeat property. {@link BackgroundRepeat} instance.
88
- * @param position background-position property. {@link BackgroundPosition} instance.
89
- * @param backgroundSize background-size property. {@link BackgroundSize} instance.
90
- * @param linearGradientBuilder background-image property. {@link AbstractLinearGradientBuilder} instance.
91
- * @param blendMode the image's blend mode. {@link BlendMode} instance.
90
+ * @param backgroundImage {@link BackgroundImage} for cloning
92
91
*/
93
- protected BackgroundImage (PdfXObject image , BackgroundRepeat repeat , BackgroundPosition position ,
94
- BackgroundSize backgroundSize , AbstractLinearGradientBuilder linearGradientBuilder ,
95
- BlendMode blendMode ) {
96
- this .image = image ;
97
- this .repeatX = !repeat .isNoRepeatOnXAxis ();
98
- this .repeatY = !repeat .isNoRepeatOnYAxis ();
99
- this .repeat = repeat ;
100
- this .position = position ;
101
- this .backgroundSize = backgroundSize ;
102
- this .linearGradientBuilder = linearGradientBuilder ;
103
- if (blendMode != null ) {
104
- this .blendMode = blendMode ;
105
- }
92
+ public BackgroundImage (BackgroundImage backgroundImage ) {
93
+ this (backgroundImage .getImage () == null ? (PdfXObject ) backgroundImage .getForm () : backgroundImage .getImage (),
94
+ backgroundImage .getRepeat (),
95
+ backgroundImage .getBackgroundPosition (),
96
+ backgroundImage .getBackgroundSize (),
97
+ backgroundImage .getLinearGradientBuilder (),
98
+ backgroundImage .getBlendMode (),
99
+ backgroundImage .getBackgroundClip (),
100
+ backgroundImage .getBackgroundOrigin ());
101
+ repeatX = backgroundImage .isRepeatX ();
102
+ repeatY = backgroundImage .isRepeatY ();
106
103
}
107
104
108
105
/**
@@ -115,7 +112,8 @@ protected BackgroundImage(PdfXObject image, BackgroundRepeat repeat, BackgroundP
115
112
*/
116
113
@ Deprecated
117
114
public BackgroundImage (final PdfImageXObject image , final BackgroundRepeat repeat , final BlendMode blendMode ) {
118
- this (image , repeat , new BackgroundPosition (), new BackgroundSize (), null , blendMode );
115
+ this (image , repeat , new BackgroundPosition (), new BackgroundSize (), null , blendMode ,
116
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
119
117
}
120
118
121
119
/**
@@ -128,7 +126,8 @@ public BackgroundImage(final PdfImageXObject image, final BackgroundRepeat repea
128
126
*/
129
127
@ Deprecated
130
128
public BackgroundImage (final PdfFormXObject image , final BackgroundRepeat repeat , final BlendMode blendMode ) {
131
- this (image , repeat , new BackgroundPosition (), new BackgroundSize (), null , blendMode );
129
+ this (image , repeat , new BackgroundPosition (), new BackgroundSize (), null , blendMode ,
130
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
132
131
}
133
132
134
133
/**
@@ -140,7 +139,8 @@ public BackgroundImage(final PdfFormXObject image, final BackgroundRepeat repeat
140
139
*/
141
140
@ Deprecated
142
141
public BackgroundImage (final PdfImageXObject image , final BackgroundRepeat repeat ) {
143
- this (image , repeat , new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE );
142
+ this (image , repeat , new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE ,
143
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
144
144
}
145
145
146
146
/**
@@ -152,7 +152,8 @@ public BackgroundImage(final PdfImageXObject image, final BackgroundRepeat repea
152
152
*/
153
153
@ Deprecated
154
154
public BackgroundImage (final PdfFormXObject image , final BackgroundRepeat repeat ) {
155
- this (image , repeat , new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE );
155
+ this (image , repeat , new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE ,
156
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
156
157
}
157
158
158
159
/**
@@ -163,7 +164,8 @@ public BackgroundImage(final PdfFormXObject image, final BackgroundRepeat repeat
163
164
*/
164
165
@ Deprecated
165
166
public BackgroundImage (final PdfImageXObject image ) {
166
- this (image , new BackgroundRepeat (), new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE );
167
+ this (image , new BackgroundRepeat (), new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE ,
168
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
167
169
}
168
170
169
171
/**
@@ -174,7 +176,8 @@ public BackgroundImage(final PdfImageXObject image) {
174
176
*/
175
177
@ Deprecated
176
178
public BackgroundImage (final PdfFormXObject image ) {
177
- this (image , new BackgroundRepeat (), new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE );
179
+ this (image , new BackgroundRepeat (), new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE ,
180
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
178
181
}
179
182
180
183
/**
@@ -188,8 +191,9 @@ public BackgroundImage(final PdfFormXObject image) {
188
191
@ Deprecated
189
192
public BackgroundImage (final PdfImageXObject image , final boolean repeatX , final boolean repeatY ) {
190
193
this (image , new BackgroundRepeat (repeatX ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT ,
191
- repeatY ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT ), new BackgroundPosition (),
192
- new BackgroundSize (), null , DEFAULT_BLEND_MODE );
194
+ repeatY ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT ),
195
+ new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE ,
196
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
193
197
}
194
198
195
199
/**
@@ -203,8 +207,9 @@ public BackgroundImage(final PdfImageXObject image, final boolean repeatX, final
203
207
@ Deprecated
204
208
public BackgroundImage (final PdfFormXObject image , final boolean repeatX , final boolean repeatY ) {
205
209
this (image , new BackgroundRepeat (repeatX ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT ,
206
- repeatY ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT ), new BackgroundPosition (),
207
- new BackgroundSize (), null , DEFAULT_BLEND_MODE );
210
+ repeatY ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT ),
211
+ new BackgroundPosition (), new BackgroundSize (), null , DEFAULT_BLEND_MODE ,
212
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
208
213
}
209
214
210
215
/**
@@ -230,7 +235,8 @@ public BackgroundImage(final AbstractLinearGradientBuilder linearGradientBuilder
230
235
@ Deprecated
231
236
public BackgroundImage (final AbstractLinearGradientBuilder linearGradientBuilder , final BlendMode blendMode ) {
232
237
this (null , new BackgroundRepeat (BackgroundRepeatValue .NO_REPEAT ), new BackgroundPosition (),
233
- new BackgroundSize (), linearGradientBuilder , blendMode );
238
+ new BackgroundSize (), linearGradientBuilder , blendMode ,
239
+ BackgroundBox .BORDER_BOX , BackgroundBox .PADDING_BOX );
234
240
}
235
241
236
242
public PdfImageXObject getImage () {
@@ -241,6 +247,37 @@ public PdfFormXObject getForm() {
241
247
return image instanceof PdfFormXObject ? (PdfFormXObject ) image : null ;
242
248
}
243
249
250
+ /**
251
+ * Creates a new {@link BackgroundImage} instance.
252
+ *
253
+ * @param image background-image property. {@link PdfXObject} instance.
254
+ * @param repeat background-repeat property. {@link BackgroundRepeat} instance.
255
+ * @param position background-position property. {@link BackgroundPosition} instance.
256
+ * @param backgroundSize background-size property. {@link BackgroundSize} instance.
257
+ * @param linearGradientBuilder background-image property. {@link AbstractLinearGradientBuilder} instance.
258
+ * @param blendMode the image's blend mode. {@link BlendMode} instance.
259
+ * @param clip background-clip property. {@link BackgroundBox} instance.
260
+ * @param origin background-origin property. {@link BackgroundBox} instance.
261
+ */
262
+ private BackgroundImage (PdfXObject image , BackgroundRepeat repeat , BackgroundPosition position ,
263
+ BackgroundSize backgroundSize , AbstractLinearGradientBuilder linearGradientBuilder ,
264
+ BlendMode blendMode , BackgroundBox clip , BackgroundBox origin ) {
265
+ this .image = image ;
266
+ if (repeat != null ) {
267
+ this .repeatX = !repeat .isNoRepeatOnXAxis ();
268
+ this .repeatY = !repeat .isNoRepeatOnYAxis ();
269
+ }
270
+ this .repeat = repeat ;
271
+ this .position = position ;
272
+ this .backgroundSize = backgroundSize ;
273
+ this .linearGradientBuilder = linearGradientBuilder ;
274
+ if (blendMode != null ) {
275
+ this .blendMode = blendMode ;
276
+ }
277
+ this .backgroundClip = clip ;
278
+ this .backgroundOrigin = origin ;
279
+ }
280
+
244
281
/**
245
282
* Gets background-position.
246
283
*
@@ -319,10 +356,12 @@ public float getHeight() {
319
356
public BackgroundRepeat getRepeat () {
320
357
// Remove this if-blocks after removing repeatX and repeatY
321
358
if (repeatX == repeat .isNoRepeatOnXAxis ()) {
322
- repeat = new BackgroundRepeat (repeatX ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT , repeat .getYAxisRepeat ());
359
+ repeat = new BackgroundRepeat (repeatX ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT ,
360
+ repeat .getYAxisRepeat ());
323
361
}
324
362
if (repeatY == repeat .isNoRepeatOnYAxis ()) {
325
- repeat = new BackgroundRepeat (repeat .getXAxisRepeat (), repeatY ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT );
363
+ repeat = new BackgroundRepeat (repeat .getXAxisRepeat (),
364
+ repeatY ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT );
326
365
}
327
366
328
367
return repeat ;
@@ -337,6 +376,24 @@ public BlendMode getBlendMode() {
337
376
return blendMode ;
338
377
}
339
378
379
+ /**
380
+ * Gets background-clip.
381
+ *
382
+ * @return {@link BackgroundBox}
383
+ */
384
+ public BackgroundBox getBackgroundClip () {
385
+ return backgroundClip ;
386
+ }
387
+
388
+ /**
389
+ * Gets background-origin.
390
+ *
391
+ * @return {@link BackgroundBox}
392
+ */
393
+ public BackgroundBox getBackgroundOrigin () {
394
+ return backgroundOrigin ;
395
+ }
396
+
340
397
/**
341
398
* {@link BackgroundImage} builder class.
342
399
*/
@@ -348,6 +405,8 @@ public static class Builder {
348
405
private BackgroundRepeat repeat = new BackgroundRepeat ();
349
406
private BlendMode blendMode = DEFAULT_BLEND_MODE ;
350
407
private BackgroundSize backgroundSize = new BackgroundSize ();
408
+ private BackgroundBox clip = BackgroundBox .BORDER_BOX ;
409
+ private BackgroundBox origin = BackgroundBox .PADDING_BOX ;
351
410
352
411
public Builder () {
353
412
}
@@ -429,13 +488,36 @@ public Builder setBackgroundSize(BackgroundSize backgroundSize) {
429
488
return this ;
430
489
}
431
490
491
+ /**
492
+ * Sets background-clip.
493
+ *
494
+ * @param clip {@link BackgroundBox} to be set.
495
+ * @return this {@link Builder}.
496
+ */
497
+ public Builder setBackgroundClip (BackgroundBox clip ) {
498
+ this .clip = clip ;
499
+ return this ;
500
+ }
501
+
502
+ /**
503
+ * Sets background-origin.
504
+ *
505
+ * @param origin {@link BackgroundBox} to be set.
506
+ * @return this {@link Builder}.
507
+ */
508
+ public Builder setBackgroundOrigin (BackgroundBox origin ) {
509
+ this .origin = origin ;
510
+ return this ;
511
+ }
512
+
432
513
/**
433
514
* Builds new {@link BackgroundImage} using set fields.
434
515
*
435
516
* @return new {@link BackgroundImage}.
436
517
*/
437
518
public BackgroundImage build () {
438
- return new BackgroundImage (image , repeat , position , backgroundSize , linearGradientBuilder , blendMode );
519
+ return new BackgroundImage (image , repeat , position , backgroundSize , linearGradientBuilder , blendMode , clip ,
520
+ origin );
439
521
}
440
522
}
441
523
}
0 commit comments