Author: tilman Date: Sun Jan 9 12:11:32 2022 New Revision: 1896862 URL: http://svn.apache.org/viewvc?rev=1896862&view=rev Log: PDFBOX-4892: optimize, as suggested by valerybokov
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java?rev=1896862&r1=1896861&r2=1896862&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java Sun Jan 9 12:11:32 2022 @@ -278,9 +278,9 @@ public class PDFRenderer { PDPage page = pageTree.get(pageIndex); - PDRectangle cropbBox = page.getCropBox(); - float widthPt = cropbBox.getWidth(); - float heightPt = cropbBox.getHeight(); + PDRectangle cropBox = page.getCropBox(); + float widthPt = cropBox.getWidth(); + float heightPt = cropBox.getHeight(); // PDFBOX-4306 avoid single blank pixel line on the right or on the bottom int widthPx = (int) Math.max(Math.floor(widthPt * scale), 1); @@ -334,7 +334,7 @@ public class PDFRenderer } g.clearRect(0, 0, image.getWidth(), image.getHeight()); - transform(g, page, scale, scale); + transform(g, page.getRotation(), cropBox, scale, scale); // the end-user may provide a custom PageDrawer RenderingHints actualRenderingHints = @@ -442,9 +442,8 @@ public class PDFRenderer PDPage page = pageTree.get(pageIndex); // TODO need width/height calculations? should these be in PageDrawer? - transform(graphics, page, scaleX, scaleY); - PDRectangle cropBox = page.getCropBox(); + transform(graphics, page.getRotation(), cropBox, scaleX, scaleY); graphics.clearRect(0, 0, (int) cropBox.getWidth(), (int) cropBox.getHeight()); // the end-user may provide a custom PageDrawer @@ -469,15 +468,13 @@ public class PDFRenderer } // scale rotate translate - private void transform(Graphics2D graphics, PDPage page, float scaleX, float scaleY) + private void transform(Graphics2D graphics, int rotationAngle, PDRectangle cropBox, float scaleX, float scaleY) { graphics.scale(scaleX, scaleY); // TODO should we be passing the scale to PageDrawer rather than messing with Graphics? - int rotationAngle = page.getRotation(); if (rotationAngle != 0) { - PDRectangle cropBox = page.getCropBox(); float translateX = 0; float translateY = 0; switch (rotationAngle)