You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2011/08/10 08:03:13 UTC
svn commit: r1156038 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
Author: lehmi
Date: Wed Aug 10 06:03:13 2011
New Revision: 1156038
URL: http://svn.apache.org/viewvc?rev=1156038&view=rev
Log:
PDFBOX-744: rotate graphics when rendering a page with a given rotation based on the proposed patch
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java?rev=1156038&r1=1156037&r2=1156038&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java Wed Aug 10 06:03:13 2011
@@ -714,35 +714,28 @@ public class PDPage implements COSObject
int heightPx = Math.round(heightPt * scaling);
//TODO The following reduces accuracy. It should really be a Dimension2D.Float.
Dimension pageDimension = new Dimension( (int)widthPt, (int)heightPt );
-
- BufferedImage retval = new BufferedImage( widthPx, heightPx, imageType );
+ BufferedImage retval = null;
+ float rotation = (float)Math.toRadians(findRotation());
+ if (rotation != 0)
+ {
+ retval = new BufferedImage( heightPx, widthPx, imageType );
+ }
+ else
+ {
+ retval = new BufferedImage( widthPx, heightPx, imageType );
+ }
Graphics2D graphics = (Graphics2D)retval.getGraphics();
graphics.setBackground( TRANSPARENT_WHITE );
graphics.clearRect( 0, 0, retval.getWidth(), retval.getHeight() );
+ if (rotation != 0)
+ {
+ graphics.translate(retval.getWidth(), 0.0f);
+ graphics.rotate(rotation);
+ }
graphics.scale( scaling, scaling );
PageDrawer drawer = new PageDrawer();
drawer.drawPage( graphics, this, pageDimension );
- //TODO This could be done directly by manipulating the transformation matrix before painting.
- //That could result in a better image quality.
- try
- {
- int rotation = findRotation();
- if (rotation == 90 || rotation == 270)
- {
- int w = retval.getWidth();
- int h = retval.getHeight();
- BufferedImage rotatedImg = new BufferedImage(w, h, retval.getType());
- Graphics2D g = rotatedImg.createGraphics();
- g.rotate(Math.toRadians(rotation), w/2, h/2);
- g.drawImage(retval, null, 0, 0);
- }
- }
- catch (ImagingOpException e)
- {
- log.warn("Unable to rotate page image", e);
- }
-
return retval;
}