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/03/25 22:35:42 UTC
svn commit: r1085566 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
Author: lehmi
Date: Fri Mar 25 21:35:42 2011
New Revision: 1085566
URL: http://svn.apache.org/viewvc?rev=1085566&view=rev
Log:
PDFBOX-758: fixed the rendering of rotated images
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java?rev=1085566&r1=1085565&r2=1085566&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java Fri Mar 25 21:35:42 2011
@@ -88,37 +88,18 @@ public class Invoke extends OperatorProc
log.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
- int pageRotation = page.findRotation();
-
+ float yScaling = ctm.getYScale();
+ float angle = (float)Math.acos(ctm.getValue(0, 0)/ctm.getXScale());
+ if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0)
+ angle = (-1)*angle;
+ ctm.setValue(2, 1, (float)(pageHeight - ctm.getYPosition() - Math.cos(angle)*yScaling));
+ ctm.setValue(2, 0, (float)(ctm.getXPosition() - Math.sin(angle)*yScaling));
+ // because of the moved 0,0-reference, we have to shear in the opposite direction
+ ctm.setValue(0, 1, (-1)*ctm.getValue(0, 1));
+ ctm.setValue(1, 0, (-1)*ctm.getValue(1, 0));
AffineTransform ctmAT = ctm.createAffineTransform();
ctmAT.scale(1f/imageWidth, 1f/imageHeight);
- Matrix rotationMatrix = new Matrix();
- rotationMatrix.setFromAffineTransform( ctmAT );
- // calculate the inverse rotation angle
- // scaleX = m00 = cos
- // shearX = m01 = -sin
- // tan = sin/cos
- double angle = Math.atan(ctmAT.getShearX()/ctmAT.getScaleX());
- Matrix translationMatrix = null;
- if (pageRotation == 0 || pageRotation == 180)
- {
- translationMatrix = Matrix.getTranslatingInstance((float)(Math.sin(angle)*ctm.getXScale()), (float)(pageHeight-2*ctm.getYPosition()-Math.cos(angle)*ctm.getYScale()));
- }
- else if (pageRotation == 90 || pageRotation == 270)
- {
- translationMatrix = Matrix.getTranslatingInstance((float)(Math.sin(angle)*ctm.getYScale()), (float)(pageHeight-2*ctm.getYPosition()));
- }
- rotationMatrix = rotationMatrix.multiply(translationMatrix);
- rotationMatrix.setValue(0, 1, (-1)*rotationMatrix.getValue(0, 1));
- rotationMatrix.setValue(1, 0, (-1)*rotationMatrix.getValue(1, 0));
-
- AffineTransform at = new AffineTransform(
- rotationMatrix.getValue(0,0),rotationMatrix.getValue(0,1),
- rotationMatrix.getValue(1,0),rotationMatrix.getValue(1,1),
- rotationMatrix.getValue(2,0),rotationMatrix.getValue(2,1)
- );
-
- drawer.drawImage( awtImage, at );
+ drawer.drawImage( awtImage, ctmAT );
}
catch( Exception e )
{