@@ -49,7 +49,6 @@ This file is part of the iText (R) project.
49
49
import com .itextpdf .kernel .PdfException ;
50
50
import com .itextpdf .kernel .colors .Color ;
51
51
import com .itextpdf .kernel .colors .gradients .AbstractLinearGradientBuilder ;
52
- import com .itextpdf .kernel .colors .gradients .StrategyBasedLinearGradientBuilder ;
53
52
import com .itextpdf .kernel .font .PdfFont ;
54
53
import com .itextpdf .kernel .geom .AffineTransform ;
55
54
import com .itextpdf .kernel .geom .Point ;
@@ -538,7 +537,8 @@ public void drawBackground(DrawContext drawContext) {
538
537
// for gradient uses width and height = 1. For all othe cases the logic left as it was.
539
538
Rectangle imageRectangle ;
540
539
if (backgroundXObject == null ) {
541
- backgroundXObject = createXObject (backgroundImage .getLinearGradientBuilder (), backgroundArea , drawContext .getDocument ());
540
+ backgroundXObject = AbstractRenderer .createXObject (backgroundImage .getLinearGradientBuilder (),
541
+ backgroundArea , drawContext .getDocument ());
542
542
imageRectangle = new Rectangle (backgroundArea .getX (), backgroundArea .getTop () - backgroundXObject .getHeight (),1 , 1 );
543
543
} else {
544
544
imageRectangle = new Rectangle (backgroundArea .getX (), backgroundArea .getTop () - backgroundXObject .getHeight (),
@@ -575,20 +575,26 @@ public void drawBackground(DrawContext drawContext) {
575
575
}
576
576
}
577
577
578
- public PdfFormXObject createXObject (AbstractLinearGradientBuilder linearGradientBuilder ,
578
+ /**
579
+ * Create a {@link PdfFormXObject} with the given area and containing a linear gradient inside.
580
+ *
581
+ * @param linearGradientBuilder the linear gradient builder
582
+ * @param xObjectArea the result object area
583
+ * @param document the pdf document
584
+ * @return the xObject with a specified area and a linear gradient
585
+ */
586
+ public static PdfFormXObject createXObject (AbstractLinearGradientBuilder linearGradientBuilder ,
579
587
Rectangle xObjectArea , PdfDocument document ) {
580
- if (linearGradientBuilder == null ) {
581
- return null ;
582
- }
583
588
Rectangle formBBox = new Rectangle (0 , 0 , xObjectArea .getWidth (), xObjectArea .getHeight ());
584
- PdfFormXObject xObject = null ;
585
- Color gradientColor = linearGradientBuilder .buildColor (formBBox , null );
586
- if (gradientColor != null ) {
587
- xObject = new PdfFormXObject (formBBox );
588
- new PdfCanvas (xObject , document )
589
- .setColor (gradientColor , true )
590
- .rectangle (formBBox )
591
- .fill ();
589
+ PdfFormXObject xObject = new PdfFormXObject (formBBox );
590
+ if (linearGradientBuilder != null ) {
591
+ Color gradientColor = linearGradientBuilder .buildColor (formBBox , null );
592
+ if (gradientColor != null ) {
593
+ new PdfCanvas (xObject , document )
594
+ .setColor (gradientColor , true )
595
+ .rectangle (formBBox )
596
+ .fill ();
597
+ }
592
598
}
593
599
return xObject ;
594
600
}
0 commit comments