pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1745766 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
Date Fri, 27 May 2016 15:41:25 GMT
Author: tilman
Date: Fri May 27 15:41:25 2016
New Revision: 1745766

URL: http://svn.apache.org/viewvc?rev=1745766&view=rev
Log:
PDFBOX-3359: defactor and refactor code to separate clearing for both cases, i.e. render to
graphics and render to image

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=1745766&r1=1745765&r2=1745766&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 Fri May
27 15:41:25 2016
@@ -135,8 +135,15 @@ public class PDFRenderer
         {
             g.setBackground(Color.WHITE);
         }
+        g.clearRect(0, 0, image.getWidth(), image.getHeight());
+        
+        transform(g, page, scale);
 
-        renderPage(page, g, image.getWidth(), image.getHeight(), scale, scale);
+        // the end-user may provide a custom PageDrawer
+        PageDrawerParameters parameters = new PageDrawerParameters(this, page);
+        PageDrawer drawer = createPageDrawer(parameters);
+        drawer.drawPage(g, page.getCropBox());       
+        
         g.dispose();
 
         return image;
@@ -165,22 +172,27 @@ public class PDFRenderer
     {
         PDPage page = document.getPage(pageIndex);
         // TODO need width/wight calculations? should these be in PageDrawer?
-        PDRectangle adjustedCropBox = page.getCropBox();
-        renderPage(page, graphics, (int)adjustedCropBox.getWidth(), (int)adjustedCropBox.getHeight(),
scale, scale);
+
+        transform(graphics, page, scale);
+
+        PDRectangle cropBox = page.getCropBox();
+        graphics.clearRect(0, 0, (int) cropBox.getWidth(), (int) cropBox.getHeight());
+
+        // the end-user may provide a custom PageDrawer
+        PageDrawerParameters parameters = new PageDrawerParameters(this, page);
+        PageDrawer drawer = createPageDrawer(parameters);
+        drawer.drawPage(graphics, cropBox);
     }
 
-    // renders a page to the given graphics
-    private void renderPage(PDPage page, Graphics2D graphics, int width, int height, float
scaleX,
-                            float scaleY) throws IOException
+    // scale rotate translate
+    private void transform(Graphics2D graphics, PDPage page, float scale)
     {
-        graphics.clearRect(0, 0, width, height);
+        graphics.scale(scale, scale);
 
-        graphics.scale(scaleX, scaleY);
         // TODO should we be passing the scale to PageDrawer rather than messing with Graphics?
-
-        PDRectangle cropBox = page.getCropBox();
         int rotationAngle = page.getRotation();
-        
+        PDRectangle cropBox = page.getCropBox();
+
         if (rotationAngle != 0)
         {
             float translateX = 0;
@@ -201,11 +213,6 @@ public class PDFRenderer
             graphics.translate(translateX, translateY);
             graphics.rotate((float) Math.toRadians(rotationAngle));
         }
-
-        // the end-user may provide a custom PageDrawer
-        PageDrawerParameters parameters = new PageDrawerParameters(this, page);
-        PageDrawer drawer = createPageDrawer(parameters);
-        drawer.drawPage(graphics, cropBox);
     }
 
     /**



Mime
View raw message