@@ -46,6 +46,7 @@ This file is part of the iText (R) project.
46
46
import com .itextpdf .kernel .pdf .xobject .PdfFormXObject ;
47
47
import com .itextpdf .kernel .pdf .xobject .PdfImageXObject ;
48
48
import com .itextpdf .kernel .pdf .xobject .PdfXObject ;
49
+ import com .itextpdf .layout .property .BackgroundRepeat .BackgroundRepeatValue ;
49
50
50
51
public class BackgroundImage {
51
52
@@ -54,26 +55,30 @@ public class BackgroundImage {
54
55
protected PdfXObject image ;
55
56
56
57
/**
57
- * Whether the background repeats in the x dimension .
58
+ * Whether the background-repeat value is not {@link BackgroundRepeatValue#NO_REPEAT} for X axis .
58
59
*
59
- * @deprecated Replace this field with {@link BackgroundRepeat} instance.
60
+ * @deprecated replace this field with {@link BackgroundRepeat} instance
60
61
*/
61
62
@ Deprecated
62
63
protected boolean repeatX ;
63
64
64
65
/**
65
- * Whether the background repeats in the y dimension .
66
+ * Whether the background-repeat value is not {@link BackgroundRepeatValue#NO_REPEAT} for Y axis .
66
67
*
67
- * @deprecated Replace this field with {@link BackgroundRepeat} instance.
68
+ * @deprecated replace this field with {@link BackgroundRepeat} instance
68
69
*/
69
70
@ Deprecated
70
71
protected boolean repeatY ;
72
+
71
73
protected AbstractLinearGradientBuilder linearGradientBuilder ;
72
74
73
75
private BlendMode blendMode = DEFAULT_BLEND_MODE ;
74
76
75
- private BackgroundPosition position ;
76
- private BackgroundSize backgroundSize ;
77
+ private BackgroundRepeat repeat ;
78
+
79
+ private final BackgroundPosition position ;
80
+
81
+ private final BackgroundSize backgroundSize ;
77
82
78
83
/**
79
84
* Creates a new {@link BackgroundImage} instance.
@@ -89,8 +94,9 @@ protected BackgroundImage(PdfXObject image, BackgroundRepeat repeat, BackgroundP
89
94
BackgroundSize backgroundSize , AbstractLinearGradientBuilder linearGradientBuilder ,
90
95
BlendMode blendMode ) {
91
96
this .image = image ;
92
- this .repeatX = repeat .isRepeatX ();
93
- this .repeatY = repeat .isRepeatY ();
97
+ this .repeatX = !repeat .isNoRepeatOnXAxis ();
98
+ this .repeatY = !repeat .isNoRepeatOnYAxis ();
99
+ this .repeat = repeat ;
94
100
this .position = position ;
95
101
this .backgroundSize = backgroundSize ;
96
102
this .linearGradientBuilder = linearGradientBuilder ;
@@ -181,8 +187,9 @@ public BackgroundImage(final PdfFormXObject image) {
181
187
*/
182
188
@ Deprecated
183
189
public BackgroundImage (final PdfImageXObject image , final boolean repeatX , final boolean repeatY ) {
184
- this (image , new BackgroundRepeat (repeatX , repeatY ), new BackgroundPosition (), new BackgroundSize (),
185
- null , DEFAULT_BLEND_MODE );
190
+ 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 );
186
193
}
187
194
188
195
/**
@@ -195,8 +202,9 @@ public BackgroundImage(final PdfImageXObject image, final boolean repeatX, final
195
202
*/
196
203
@ Deprecated
197
204
public BackgroundImage (final PdfFormXObject image , final boolean repeatX , final boolean repeatY ) {
198
- this (image , new BackgroundRepeat (repeatX , repeatY ), new BackgroundPosition (), new BackgroundSize (),
199
- null , DEFAULT_BLEND_MODE );
205
+ 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 );
200
208
}
201
209
202
210
/**
@@ -221,8 +229,8 @@ public BackgroundImage(final AbstractLinearGradientBuilder linearGradientBuilder
221
229
*/
222
230
@ Deprecated
223
231
public BackgroundImage (final AbstractLinearGradientBuilder linearGradientBuilder , final BlendMode blendMode ) {
224
- this (null , new BackgroundRepeat (false , false ), new BackgroundPosition (), new BackgroundSize ()
225
- , linearGradientBuilder , blendMode );
232
+ this (null , new BackgroundRepeat (BackgroundRepeatValue . NO_REPEAT ), new BackgroundPosition (),
233
+ new BackgroundSize () , linearGradientBuilder , blendMode );
226
234
}
227
235
228
236
public PdfImageXObject getImage () {
@@ -250,10 +258,12 @@ public boolean isBackgroundSpecified() {
250
258
return image instanceof PdfFormXObject || image instanceof PdfImageXObject || linearGradientBuilder != null ;
251
259
}
252
260
261
+ @ Deprecated
253
262
public boolean isRepeatX () {
254
263
return repeatX ;
255
264
}
256
265
266
+ @ Deprecated
257
267
public boolean isRepeatY () {
258
268
return repeatY ;
259
269
}
@@ -301,6 +311,23 @@ public float getHeight() {
301
311
return (float ) image .getHeight ();
302
312
}
303
313
314
+ /**
315
+ * Gets image {@link BackgroundRepeat} instance.
316
+ *
317
+ * @return the image background repeat
318
+ */
319
+ public BackgroundRepeat getRepeat () {
320
+ // Remove this if-blocks after removing repeatX and repeatY
321
+ if (repeatX == repeat .isNoRepeatOnXAxis ()) {
322
+ repeat = new BackgroundRepeat (repeatX ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT , repeat .getYAxisRepeat ());
323
+ }
324
+ if (repeatY == repeat .isNoRepeatOnYAxis ()) {
325
+ repeat = new BackgroundRepeat (repeat .getXAxisRepeat (), repeatY ? BackgroundRepeatValue .REPEAT : BackgroundRepeatValue .NO_REPEAT );
326
+ }
327
+
328
+ return repeat ;
329
+ }
330
+
304
331
/**
305
332
* Get the image's blend mode.
306
333
*
@@ -349,7 +376,7 @@ public Builder setImage(PdfXObject image) {
349
376
*/
350
377
public Builder setLinearGradientBuilder (AbstractLinearGradientBuilder linearGradientBuilder ) {
351
378
this .linearGradientBuilder = linearGradientBuilder ;
352
- this .repeat = new BackgroundRepeat (false , false );
379
+ this .repeat = new BackgroundRepeat (BackgroundRepeatValue . NO_REPEAT );
353
380
this .image = null ;
354
381
return this ;
355
382
}
0 commit comments