pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1586380 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
Date Thu, 10 Apr 2014 17:29:53 GMT
Author: tilman
Date: Thu Apr 10 17:29:52 2014
New Revision: 1586380

URL: http://svn.apache.org/r1586380
Log:
PDFBOX-2021: split "old" rendering and printing (renderPageToGraphics) to separate leaf methods

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=1586380&r1=1586379&r2=1586380&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 Thu Apr
10 17:29:52 2014
@@ -174,12 +174,14 @@ public class PDFRenderer
         PDPage page = document.getPage(pageIndex);
         // TODO need width/wight calculations? should these be in PageDrawer?
         PDRectangle cropBox = page.findCropBox();
-        renderPage(page, graphics, (int)cropBox.getWidth(), (int)cropBox.getHeight(), scale,
scale);
+        renderPageToGraphics(page, graphics, (int)cropBox.getWidth(), (int)cropBox.getHeight(),
scale, scale);
     }
 
     // renders a page to the given graphics
-    // TODO need to be able to override this
-    private void renderPage(PDPage page, Graphics2D graphics, int width, int height, float
scaleX,
+    // TODO 1: need to be able to override this
+    // TODO 2: merge this with private renderPage per DRY, fix regressions related to PDFBOX-2021
+    //      test rendering and printing of PDFBOX-758, PDFBOX-427, PDFBOX-1435 and PDFBOX-1693
+    private void renderPageToGraphics(PDPage page, Graphics2D graphics, int width, int height,
float scaleX,
                             float scaleY) throws IOException
     {
         graphics.clearRect(0, 0, width, height);
@@ -211,4 +213,41 @@ public class PDFRenderer
         drawer.drawPage(graphics, page, page.findCropBox());
         drawer.dispose();
     }
+    
+    // renders a page to the given graphics
+    // TODO need to be able to override this
+    private void renderPage(PDPage page, Graphics2D graphics, int width, int height, float
scaleX,
+                            float scaleY) throws IOException
+    {
+        graphics.clearRect(0, 0, width, height);
+        int rotationAngle = page.findRotation();
+        if (rotationAngle != 0)
+        {
+            int translateX = 0;
+            int translateY = 0;
+            switch (rotationAngle)
+            {
+                case 90:
+                translateX = width;
+                break;
+                case 270:
+                translateY = height;
+                    break;
+                case 180:
+                    translateX = width;
+                    translateY = height;
+                    break;
+            default:
+                break;
+            }
+            graphics.translate(translateX, translateY);
+            graphics.rotate((float) Math.toRadians(rotationAngle));
+        }
+        // TODO should we be passing the scale to PageDrawer rather than messing with Graphics?
+        graphics.scale(scaleX, scaleY);
+        PageDrawer drawer = new PageDrawer(this);   // TODO: need to make it easy to use
a custom PageDrawer
+        drawer.drawPage(graphics, page, page.findCropBox());
+        drawer.dispose();
+    }
+    
 }



Mime
View raw message