Skip to content

Commit aed7ccc

Browse files
Minor fixes in CompareTool
1 parent 377b7eb commit aed7ccc

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

kernel/src/main/java/com/itextpdf/kernel/utils/CompareTool.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ This file is part of the iText (R) project.
6565
import com.itextpdf.kernel.pdf.ReaderProperties;
6666
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
6767
import com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation;
68+
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
6869
import com.itextpdf.kernel.xmp.PdfConst;
6970
import com.itextpdf.kernel.xmp.XMPConst;
7071
import com.itextpdf.kernel.xmp.XMPException;
@@ -852,7 +853,7 @@ private String listDiffPagesAsString(List<Integer> diffPages) {
852853
}
853854
}
854855
sb.append("]");
855-
return diffPages.toString();
856+
return sb.toString();
856857
}
857858

858859
private void createIgnoredAreasPdfs(String outPath, Map<Integer, List<Rectangle>> ignoredAreas) throws IOException {
@@ -867,28 +868,17 @@ private void createIgnoredAreasPdfs(String outPath, Map<Integer, List<Rectangle>
867868
List<Rectangle> rectangles = entry.getValue();
868869

869870
if (rectangles != null && !rectangles.isEmpty()) {
870-
//drawing rectangles manually, because we don't want to create dependency on itextpdf.canvas module for itextpdf.kernel
871-
PdfStream outStream = getPageContentStream(pdfOutDoc.getPage(pageNumber));
872-
PdfStream cmpStream = getPageContentStream(pdfCmpDoc.getPage(pageNumber));
873-
874-
outStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("q\n"));
875-
outStream.getOutputStream().writeFloats(new float[]{0.0f, 0.0f, 0.0f}).writeSpace().writeBytes(ByteUtils.getIsoBytes("rg\n"));
876-
cmpStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("q\n"));
877-
cmpStream.getOutputStream().writeFloats(new float[]{0.0f, 0.0f, 0.0f}).writeSpace().writeBytes(ByteUtils.getIsoBytes("rg\n"));
871+
PdfCanvas outCanvas = new PdfCanvas(pdfOutDoc.getPage(pageNumber));
872+
PdfCanvas cmpCanvas = new PdfCanvas(pdfCmpDoc.getPage(pageNumber));
878873

874+
outCanvas.saveState();
875+
cmpCanvas.saveState();
879876
for (Rectangle rect : rectangles) {
880-
outStream.getOutputStream().writeFloats(new float[]{rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()}).
881-
writeSpace().
882-
writeBytes(ByteUtils.getIsoBytes("re\n")).
883-
writeBytes(ByteUtils.getIsoBytes("f\n"));
884-
885-
cmpStream.getOutputStream().writeFloats(new float[]{rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()}).
886-
writeSpace().
887-
writeBytes(ByteUtils.getIsoBytes("re\n")).
888-
writeBytes(ByteUtils.getIsoBytes("f\n"));
877+
outCanvas.rectangle(rect).fill();
878+
cmpCanvas.rectangle(rect).fill();
889879
}
890-
outStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("Q\n"));
891-
cmpStream.getOutputStream().writeBytes(ByteUtils.getIsoBytes("Q\n"));
880+
outCanvas.restoreState();
881+
cmpCanvas.restoreState();
892882
}
893883
}
894884

@@ -898,11 +888,6 @@ private void createIgnoredAreasPdfs(String outPath, Map<Integer, List<Rectangle>
898888
init(outPath + ignoredAreasPrefix + outPdfName, outPath + ignoredAreasPrefix + cmpPdfName);
899889
}
900890

901-
private PdfStream getPageContentStream(PdfPage page) {
902-
PdfStream stream = page.getContentStream(page.getContentStreamCount() - 1);
903-
return stream.getOutputStream() == null ? page.newContentStreamAfter() : stream;
904-
}
905-
906891
private void prepareOutputDirs(String outPath, String differenceImagePrefix) {
907892
File[] imageFiles;
908893
File[] cmpImageFiles;

0 commit comments

Comments
 (0)