pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r720169 - in /incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox: pdfviewer/ pdmodel/font/ util/
Date Mon, 24 Nov 2008 11:29:27 GMT
Author: jukka
Date: Mon Nov 24 03:29:27 2008
New Revision: 720169

URL: http://svn.apache.org/viewvc?rev=720169&view=rev
Log:
PDFBOX-363: Fixed Page rotation

Patch by Andreas Lehmkühler.

Modified:
    incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
    incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
    incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
    incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
    incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
    incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
    incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
    incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/TextPosition.java

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java?rev=720169&r1=720168&r2=720169&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfviewer/PageDrawer.java Mon Nov
24 03:29:27 2008
@@ -153,8 +153,20 @@
                 //need to implement....
             }
             PDFont font = text.getFont();
-            font.drawString( text.getCharacter(), graphics, text.getFontSize(), text.getXScale(),
text.getYScale(),
-                             text.getX(), text.getY() );
+
+            Matrix textPos = text.getTextPos().copy();
+            float x = textPos.getXPosition();
+            // the 0,0-reference has to be moved from the lower left (PDF) to the upper left
(AWT-graphics)
+            float y = pageSize.height - textPos.getYPosition();
+    		// Set translation to 0,0. We only need the scaling and shearing
+            textPos.setValue(2, 0, 0);
+            textPos.setValue(2, 1, 0);
+            AffineTransform at = textPos.createAffineTransform();
+    		// If there is a rotation, we have to add a additional rotation by 180°. 
+    		// Don't no why.yet. I guess there is a problem with clockwise- and counterclockwise-rotation
+            if (at.getShearX() != 0 || at.getShearY() != 0)
+            	at.quadrantRotate(2);
+            font.drawString( text.getCharacter(), graphics, text.getFontSize(), at, x, y
);
         }
         catch( IOException io )
         {

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=720169&r1=720168&r2=720169&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Mon
Nov 24 03:29:27 2008
@@ -17,6 +17,7 @@
 package org.apache.pdfbox.pdmodel.font;
 
 import java.awt.Graphics;
+import java.awt.geom.AffineTransform;
 
 import java.io.IOException;
 
@@ -88,8 +89,7 @@
     /**
      * {@inheritDoc}
      */
-    public void drawString( String string, Graphics g, float fontSize,
-        float xScale, float yScale, float x, float y )
+    public void drawString( String string, Graphics g, float fontSize, AffineTransform at,
float x, float y )
     {
         throw new RuntimeException( "Not yet implemented" );
     }

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java?rev=720169&r1=720168&r2=720169&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDFont.java Mon Nov
24 03:29:27 2008
@@ -47,6 +47,7 @@
 import org.apache.pdfbox.util.ResourceLoader;
 
 import java.awt.Graphics;
+import java.awt.geom.AffineTransform;
 
 import java.io.BufferedReader;
 import java.io.InputStream;
@@ -218,15 +219,14 @@
      * @param string The string to draw.
      * @param g The graphics to draw onto.
      * @param fontSize The size of the font to draw.
-     * @param xScale The x scaling percent.
-     * @param yScale The y scaling percent.
+     * @param at The transformation matrix with all infos for scaling and shearing of the
font.
      * @param x The x coordinate to draw at.
      * @param y The y coordinate to draw at.
      *
      * @throws IOException If there is an error drawing the specific string.
      */
     public abstract void drawString( String string, Graphics g, float fontSize,
-        float xScale, float yScale, float x, float y ) throws IOException;
+        AffineTransform at, float x, float y ) throws IOException;
 
     /**
      * Used for multibyte encodings.

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java?rev=720169&r1=720168&r2=720169&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
(original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDSimpleFont.java
Mon Nov 24 03:29:27 2008
@@ -17,6 +17,7 @@
 package org.apache.pdfbox.pdmodel.font;
 
 import java.awt.Graphics;
+import java.awt.geom.AffineTransform;
 
 import java.io.IOException;
 
@@ -66,8 +67,7 @@
     /**
      * {@inheritDoc}
      */
-    public void drawString( String string, Graphics g, float fontSize,
-        float xScale, float yScale, float x, float y ) throws IOException
+    public void drawString( String string, Graphics g, float fontSize, AffineTransform at,
float x, float y ) throws IOException
     {
         System.err.println( "Not yet implemented:" + getClass().getName() );
     }

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java?rev=720169&r1=720168&r2=720169&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
(original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.java
Mon Nov 24 03:29:27 2008
@@ -320,8 +320,7 @@
     /**
      * {@inheritDoc}
      */
-    public void drawString( String string, Graphics g, float fontSize,
-        float xScale, float yScale, float x, float y ) throws IOException
+    public void drawString( String string, Graphics g, float fontSize, AffineTransform at,
float x, float y ) throws IOException
     {
         PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary)getFontDescriptor();
         if( awtFont == null )
@@ -356,8 +355,6 @@
                 throw new WrappedIOException( f );
             }
         }
-        AffineTransform at = new AffineTransform();
-        at.scale( xScale, yScale );
         Graphics2D g2d = (Graphics2D)g;
         g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON
);
         g2d.setFont( awtFont.deriveFont( at ).deriveFont( fontSize ) );

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=720169&r1=720168&r2=720169&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Mon
Nov 24 03:29:27 2008
@@ -17,6 +17,7 @@
 package org.apache.pdfbox.pdmodel.font;
 
 import java.awt.Graphics;
+import java.awt.geom.AffineTransform;
 
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -55,11 +56,10 @@
     /**
      * {@inheritDoc}
      */
-    public void drawString( String string, Graphics g, float fontSize,
-        float xScale, float yScale, float x, float y ) throws IOException
+    public void drawString( String string, Graphics g, float fontSize, AffineTransform at,
float x, float y ) throws IOException
     {
         //throw new RuntimeException( "Not yet implemented" );
-        super.drawString(string, g, fontSize, xScale, yScale, x, y);
+        super.drawString(string, g, fontSize, at, x, y);
         logger().info("Called Type1Font.drawString since Type0 is not yet implemented");
     }
 

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java?rev=720169&r1=720168&r2=720169&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/font/PDType1Font.java Mon
Nov 24 03:29:27 2008
@@ -181,8 +181,7 @@
     /**
      * {@inheritDoc}
      */
-    public void drawString( String string, Graphics g, float fontSize,
-        float xScale, float yScale, float x, float y ) throws IOException
+    public void drawString( String string, Graphics g, float fontSize, AffineTransform at,
float x, float y ) throws IOException
     {
         if( awtFont == null )
         {
@@ -269,9 +268,6 @@
 		}
             }
         }
-        AffineTransform at = new AffineTransform();
-        at.scale( xScale, yScale );
-
         Graphics2D g2d = (Graphics2D)g;
         g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON
);
         g2d.setFont( awtFont.deriveFont( at ).deriveFont( fontSize ) );

Modified: incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/TextPosition.java
URL: http://svn.apache.org/viewvc/incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/TextPosition.java?rev=720169&r1=720168&r2=720169&view=diff
==============================================================================
--- incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/TextPosition.java (original)
+++ incubator/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/TextPosition.java Mon Nov
24 03:29:27 2008
@@ -111,6 +111,15 @@
     }
 
     /**
+     * Return the Matrix textPos stored in this object
+     *  
+     * @return The Matrix containing all infos of the starting textposition
+     */
+    public Matrix getTextPos() {
+    	return textPos;
+    }
+
+    /**
      * Return the direction/orientation of the string in this object
      * based on its text matrix.
      * @return The direction of the text (0, 90, 180, or 270)



Mime
View raw message