@@ -54,7 +54,10 @@ This file is part of the iText (R) project.
54
54
import com .itextpdf .kernel .geom .Rectangle ;
55
55
import com .itextpdf .kernel .geom .Subpath ;
56
56
import com .itextpdf .kernel .pdf .PdfArray ;
57
+ import com .itextpdf .kernel .pdf .PdfDocument ;
58
+ import com .itextpdf .kernel .pdf .PdfIndirectReference ;
57
59
import com .itextpdf .kernel .pdf .PdfNumber ;
60
+ import com .itextpdf .kernel .pdf .PdfStream ;
58
61
import com .itextpdf .kernel .pdf .PdfTextArray ;
59
62
import com .itextpdf .kernel .pdf .canvas .PdfCanvasConstants ;
60
63
import com .itextpdf .kernel .pdf .canvas .parser .clipper .ClipperBridge ;
@@ -71,6 +74,7 @@ This file is part of the iText (R) project.
71
74
import com .itextpdf .kernel .pdf .canvas .parser .data .ImageRenderInfo ;
72
75
import com .itextpdf .kernel .pdf .canvas .parser .data .PathRenderInfo ;
73
76
import com .itextpdf .kernel .pdf .canvas .parser .data .TextRenderInfo ;
77
+ import com .itextpdf .kernel .pdf .xobject .PdfImageXObject ;
74
78
import org .apache .commons .imaging .ImageFormats ;
75
79
import org .apache .commons .imaging .ImageInfo ;
76
80
import org .apache .commons .imaging .ImageReadException ;
@@ -120,8 +124,6 @@ public PdfCleanUpFilter(List<Rectangle> regions) {
120
124
121
125
/**
122
126
* Generic class representing the result of filtering an object of type T
123
- *
124
- * @param <T>
125
127
*/
126
128
static class FilterResult <T > {
127
129
private boolean isModified ;
@@ -143,8 +145,6 @@ boolean isModified() {
143
145
144
146
/**
145
147
* Get the result after filtering
146
- *
147
- * @return
148
148
*/
149
149
T getFilterResult () {
150
150
return filterResult ;
@@ -155,7 +155,6 @@ T getFilterResult() {
155
155
* Filter a TextRenderInfo object
156
156
*
157
157
* @param text the TextRenderInfo to be filtered
158
- * @return
159
158
*/
160
159
FilterResult <PdfArray > filterText (TextRenderInfo text ) {
161
160
PdfTextArray textArray = new PdfTextArray ();
@@ -177,24 +176,34 @@ FilterResult<PdfArray> filterText(TextRenderInfo text) {
177
176
return new FilterResult <PdfArray >(true , textArray );
178
177
}
179
178
179
+ FilteredImagesCache .FilteredImageKey createFilteredImageKey (ImageRenderInfo image , PdfDocument document ) {
180
+ return FilteredImagesCache .createFilteredImageKey (image , getImageAreasToBeCleaned (image ), document );
181
+ }
182
+
180
183
/**
181
184
* Filter an ImageRenderInfo object
182
185
*
183
186
* @param image the ImageRenderInfo object to be filtered
184
- * @return
185
187
*/
186
188
FilterResult <ImageData > filterImage (ImageRenderInfo image ) {
187
- List <Rectangle > areasToBeCleaned = getImageAreasToBeCleaned (image );
188
- if (areasToBeCleaned == null ) {
189
+ return filterImage (image , getImageAreasToBeCleaned (image ));
190
+ }
191
+
192
+ FilterResult <ImageData > filterImage (FilteredImagesCache .FilteredImageKey imageKey ) {
193
+ return filterImage (imageKey .getImageRenderInfo (), imageKey .getCleanedAreas ());
194
+ }
195
+
196
+ FilterResult <ImageData > filterImage (ImageRenderInfo image , List <Rectangle > imageAreasToBeCleaned ) {
197
+ if (imageAreasToBeCleaned == null ) {
189
198
return new FilterResult <>(true , null );
190
- } else if (areasToBeCleaned .isEmpty ()) {
191
- return new FilterResult <>(false , ImageDataFactory . create ( image . getImage (). getImageBytes ()) );
199
+ } else if (imageAreasToBeCleaned .isEmpty ()) {
200
+ return new FilterResult <>(false , null );
192
201
}
193
202
194
203
byte [] filteredImageBytes ;
195
204
try {
196
205
byte [] originalImageBytes = image .getImage ().getImageBytes ();
197
- filteredImageBytes = processImage (originalImageBytes , areasToBeCleaned );
206
+ filteredImageBytes = processImage (originalImageBytes , imageAreasToBeCleaned );
198
207
} catch (Exception e ) {
199
208
throw new RuntimeException (e );
200
209
}
@@ -206,7 +215,6 @@ FilterResult<ImageData> filterImage(ImageRenderInfo image) {
206
215
* Filter a PathRenderInfo object
207
216
*
208
217
* @param path the PathRenderInfo object to be filtered
209
- * @return
210
218
*/
211
219
com .itextpdf .kernel .geom .Path filterStrokePath (PathRenderInfo path ) {
212
220
PdfArray dashPattern = path .getLineDashPattern ();
@@ -220,7 +228,6 @@ com.itextpdf.kernel.geom.Path filterStrokePath(PathRenderInfo path) {
220
228
* Filter a PathRenderInfo object
221
229
*
222
230
* @param path the PathRenderInfo object to be filtered
223
- * @return
224
231
*/
225
232
com .itextpdf .kernel .geom .Path filterFillPath (PathRenderInfo path , int fillingRule ) {
226
233
return filterFillPath (path .getPath (), path .getCtm (), fillingRule );
@@ -230,7 +237,6 @@ com.itextpdf.kernel.geom.Path filterFillPath(PathRenderInfo path, int fillingRul
230
237
* Returns whether the given TextRenderInfo object needs to be cleaned up
231
238
*
232
239
* @param renderInfo the input TextRenderInfo object
233
- * @return
234
240
*/
235
241
private boolean isTextNotToBeCleaned (TextRenderInfo renderInfo ) {
236
242
Point [] textRect = getTextRectangle (renderInfo );
@@ -402,7 +408,6 @@ private void cleanImage(BufferedImage image, List<Rectangle> areasToBeCleaned) {
402
408
* Get the bytes of the BufferedImage (in JPG format)
403
409
*
404
410
* @param image input image
405
- * @return
406
411
*/
407
412
private byte [] getJPGBytes (BufferedImage image ) {
408
413
ByteArrayOutputStream outputStream = null ;
@@ -465,10 +470,7 @@ private com.itextpdf.kernel.geom.Path filterStrokePath(com.itextpdf.kernel.geom.
465
470
/**
466
471
* Note: this method will close all unclosed subpaths of the passed path.
467
472
*
468
- * @param path path
469
- * @param ctm ctm
470
473
* @param fillingRule If the subpath is contour, pass any value.
471
- * @return filterFillPath
472
474
*/
473
475
private com .itextpdf .kernel .geom .Path filterFillPath (com .itextpdf .kernel .geom .Path path , Matrix ctm , int fillingRule ) {
474
476
path .closeAllSubpaths ();
@@ -570,7 +572,6 @@ private static List<Subpath> convertToSquares(List<Subpath> degenerateSubpaths,
570
572
* Approximates a given Path with a List of Point objects
571
573
*
572
574
* @param path input path
573
- * @return
574
575
*/
575
576
private static List <Point > getPathApproximation (com .itextpdf .kernel .geom .Path path ) {
576
577
List <Point > approx = new ArrayList <Point >() {
@@ -634,7 +635,6 @@ private static Point[] getRotatedSquareVertices(Point[] orthogonalSquareVertices
634
635
*
635
636
* @param center center of the circle
636
637
* @param radius radius of the circle
637
- * @return
638
638
*/
639
639
private static BezierCurve [] approximateCircle (Point center , double radius ) {
640
640
// The circle is split into 4 sectors. Arc of each sector
@@ -693,7 +693,6 @@ private Point[] transformPoints(Matrix transformationMatrix, boolean inverse, Po
693
693
* Get the bounding box of a TextRenderInfo object
694
694
*
695
695
* @param renderInfo input TextRenderInfo object
696
- * @return
697
696
*/
698
697
private Point [] getTextRectangle (TextRenderInfo renderInfo ) {
699
698
LineSegment ascent = renderInfo .getAscentLine ();
@@ -711,7 +710,6 @@ private Point[] getTextRectangle(TextRenderInfo renderInfo) {
711
710
* Convert a Rectangle object into 4 Points
712
711
*
713
712
* @param rect input Rectangle
714
- * @return
715
713
*/
716
714
private Point [] getRectangleVertices (Rectangle rect ) {
717
715
Point [] points = {
@@ -731,7 +729,6 @@ private Point[] getRectangleVertices(Rectangle rect) {
731
729
* @param p2 second Point
732
730
* @param p3 third Point
733
731
* @param p4 fourth Point
734
- * @return
735
732
*/
736
733
private Rectangle getAsRectangle (Point p1 , Point p2 , Point p3 , Point p4 ) {
737
734
List <Double > xs = Arrays .asList (p1 .getX (), p2 .getX (), p3 .getX (), p4 .getX ());
@@ -750,7 +747,6 @@ private Rectangle getAsRectangle(Point p1, Point p2, Point p3, Point p4) {
750
747
*
751
748
* @param rect1 first Rectangle
752
749
* @param rect2 second Rectangle
753
- * @return
754
750
*/
755
751
private Rectangle getRectanglesIntersection (Rectangle rect1 , Rectangle rect2 ) {
756
752
float x1 = Math .max (rect1 .getLeft (), rect2 .getLeft ());
0 commit comments