pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1649914 - in /pdfbox/trunk: examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/ examples/src/main/java/org/apache/pdfbox/examples/pdfa/ examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ pdfbox/src/main/java/org...
Date Tue, 06 Jan 2015 19:34:55 GMT
Author: jahewson
Date: Tue Jan  6 19:34:54 2015
New Revision: 1649914

URL: http://svn.apache.org/r1649914
Log:
PDFBOX-2590: Deprecate confusing Text Matrix APIs

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java
    pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java
Tue Jan  6 19:34:54 2015
@@ -53,7 +53,7 @@ public class SuperimposePage {
             PDFont font = PDType1Font.HELVETICA_BOLD;
             aContent.beginText();
             aContent.setFont(font, 12);
-            aContent.moveTextPositionByAmount(2, 5);
+            aContent.newLineAtOffset(2, 5);
             aContent.drawString("Import a pdf file:");
             aContent.endText();
             aContent.close();

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java Tue
Jan  6 19:34:54 2015
@@ -85,7 +85,7 @@ public class CreatePDFA
             PDPageContentStream contentStream = new PDPageContentStream(doc, page);
             contentStream.beginText();
             contentStream.setFont( font, 12 );
-            contentStream.moveTextPositionByAmount( 100, 700 );
+            contentStream.newLineAtOffset(100, 700);
             contentStream.drawString( message );
             contentStream.endText();
             contentStream.saveGraphicsState();

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java
Tue Jan  6 19:34:54 2015
@@ -25,6 +25,7 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
+import org.apache.pdfbox.util.Matrix;
 
 /**
  * This is an example of how to add a message to every page
@@ -71,8 +72,8 @@ public class AddMessageToEachPage
                 boolean rotate = rotation == 90 || rotation == 270;
                 float pageWidth = rotate ? pageSize.getHeight() : pageSize.getWidth();
                 float pageHeight = rotate ? pageSize.getWidth() : pageSize.getHeight();
-                double centeredXPosition = rotate ? pageHeight/2f : (pageWidth - stringWidth)/2f;
-                double centeredYPosition = rotate ? (pageWidth - stringWidth)/2f : pageHeight/2f;
+                float centerX = rotate ? pageHeight/2f : (pageWidth - stringWidth)/2f;
+                float centerY = rotate ? (pageWidth - stringWidth)/2f : pageHeight/2f;
                 // append the content to the existing stream
                 PDPageContentStream contentStream = new PDPageContentStream(doc, page, true,
true,true);
                 contentStream.beginText();
@@ -83,11 +84,11 @@ public class AddMessageToEachPage
                 if (rotate)
                 {
                     // rotate the text according to the page rotation
-                    contentStream.setTextRotation(Math.PI/2, centeredXPosition, centeredYPosition);
+                    contentStream.setTextMatrix(Matrix.getRotateInstance(Math.PI / 2, centerX,
centerY));
                 }
                 else
                 {
-                    contentStream.setTextTranslation(centeredXPosition, centeredYPosition);
+                    contentStream.setTextMatrix(Matrix.getTranslatingInstance(centerX, centerY));
                 }
                 contentStream.drawString( message );
                 contentStream.endText();

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java
Tue Jan  6 19:34:54 2015
@@ -100,9 +100,9 @@ public class Annotation
                 PDPageContentStream contentStream = new PDPageContentStream(document, page);
                 contentStream.beginText();
                 contentStream.setFont( font, 18 );
-                contentStream.moveTextPositionByAmount( inch, ph-inch-18);
+                contentStream.newLineAtOffset(inch, ph - inch - 18);
                 contentStream.drawString( "PDFBox" );
-                contentStream.moveTextPositionByAmount( 0,-(inch/2));
+                contentStream.newLineAtOffset(0, -(inch / 2));
                 contentStream.drawString( "Click Here" );
                 contentStream.endText();
 

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java
Tue Jan  6 19:34:54 2015
@@ -71,11 +71,11 @@ public class CreateLandscapePDF
             contentStream.concatenate2CTM(0, 1, -1, 0, pageWidth, 0);
             contentStream.setFont( font, fontSize );
             contentStream.beginText();
-            contentStream.moveTextPositionByAmount(startX, startY);
+            contentStream.newLineAtOffset(startX, startY);
             contentStream.drawString( message);
-            contentStream.moveTextPositionByAmount(0, 100);
+            contentStream.newLineAtOffset(0, 100);
             contentStream.drawString( message);
-            contentStream.moveTextPositionByAmount(100, 100);
+            contentStream.newLineAtOffset(100, 100);
             contentStream.drawString( message);
             contentStream.endText();
             

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
Tue Jan  6 19:34:54 2015
@@ -73,7 +73,7 @@ public class EmbeddedFiles
             PDPageContentStream contentStream = new PDPageContentStream(doc, page);
             contentStream.beginText();
             contentStream.setFont( font, 12 );
-            contentStream.moveTextPositionByAmount( 100, 700 );
+            contentStream.newLineAtOffset(100, 700);
             contentStream.drawString( "Go to Document->File Attachments to View Embedded
Files" );
             contentStream.endText();
             contentStream.close();

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java
Tue Jan  6 19:34:54 2015
@@ -48,7 +48,7 @@ public class EmbeddedFonts
         stream.setFont(font, 12);
         stream.setLeading(12 * 1.2);
 
-        stream.moveTextPositionByAmount(50, 600);
+        stream.newLineAtOffset(50, 600);
         stream.drawString("PDFBox Unicode with Embedded TrueType Font");
         stream.newLine();
 

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java
Tue Jan  6 19:34:54 2015
@@ -67,7 +67,7 @@ public class HelloWorld
             PDPageContentStream contentStream = new PDPageContentStream(doc, page);
             contentStream.beginText();
             contentStream.setFont( font, 12 );
-            contentStream.moveTextPositionByAmount( 100, 700 );
+            contentStream.newLineAtOffset(100, 700);
             contentStream.drawString( message );
             contentStream.endText();
             contentStream.close();

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
Tue Jan  6 19:34:54 2015
@@ -24,7 +24,6 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
 import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
 import org.apache.pdfbox.pdmodel.font.PDType0Font;
 
 /**
@@ -63,7 +62,7 @@ public class HelloWorldTTF
                     page);
             contentStream.beginText();
             contentStream.setFont(font, 12);
-            contentStream.moveTextPositionByAmount(100, 700);
+            contentStream.newLineAtOffset(100, 700);
             contentStream.drawString(message);
             contentStream.endText();
             contentStream.close();

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java
Tue Jan  6 19:34:54 2015
@@ -64,7 +64,7 @@ public class HelloWorldType1AfmPfb
                     page);
             contentStream.beginText();
             contentStream.setFont(font, 12);
-            contentStream.moveTextPositionByAmount(100, 700);
+            contentStream.newLineAtOffset(100, 700);
             contentStream.drawString(message);
             contentStream.endText();
             contentStream.close();

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java
Tue Jan  6 19:34:54 2015
@@ -24,6 +24,7 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
 import org.apache.pdfbox.pdmodel.font.PDFont;
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
+import org.apache.pdfbox.util.Matrix;
 
 /**
  * This is an example of how to use a text matrix.
@@ -95,10 +96,10 @@ public class UsingTextMatrix
             contentStream.setFont( font, fontSize );
             contentStream.beginText();
 
-            // text scaling
+            // text scaling and translation
             for (int i=0;i<10;i++)
             {
-                contentStream.setTextScaling(12+(i*6), 12+(i*6), 100, 100+i*50);
+                contentStream.setTextMatrix(new Matrix(12 + (i * 6), 0, 0, 12+(i*6), 100,
100+i*50));
                 contentStream.drawString( message + " " +i);
             }
             contentStream.endText();
@@ -115,16 +116,16 @@ public class UsingTextMatrix
 
             int i = 0;
             // text scaling combined with rotation 
-            contentStream.setTextMatrix(12, 0, 0, 12, centeredXPosition, centeredYPosition*1.5);
+            contentStream.setTextMatrix(new Matrix(12, 0, 0, 12, centeredXPosition, centeredYPosition*1.5f));
             contentStream.drawString( message + " " +i++);
 
-            contentStream.setTextMatrix(0, 18, -18, 0, centeredXPosition, centeredYPosition*1.5);
+            contentStream.setTextMatrix(new Matrix(0, 18, -18, 0, centeredXPosition, centeredYPosition*1.5f));
             contentStream.drawString( message + " " +i++);
 
-            contentStream.setTextMatrix(-24, 0, 0, -24, centeredXPosition, centeredYPosition*1.5);
+            contentStream.setTextMatrix(new Matrix(-24, 0, 0, -24, centeredXPosition, centeredYPosition*1.5f));
             contentStream.drawString( message + " " +i++);
 
-            contentStream.setTextMatrix(0, -30, 30, 0, centeredXPosition, centeredYPosition*1.5);
+            contentStream.setTextMatrix(new Matrix(0, -30, 30, 0, centeredXPosition, centeredYPosition*1.5f));
             contentStream.drawString( message + " " +i++);
 
             contentStream.endText();

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java
Tue Jan  6 19:34:54 2015
@@ -60,6 +60,7 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.graphics.PDXObject;
 import org.apache.pdfbox.pdmodel.graphics.image.PDInlineImage;
 import org.apache.pdfbox.util.Charsets;
+import org.apache.pdfbox.util.Matrix;
 
 /**
  * This class is a convenience for creating page content streams. You MUST call close() when
you
@@ -325,7 +326,7 @@ public class PDPageContentStream impleme
     }
 
     /**
-     * Set the font to draw text with.
+     * Set the font and font size to draw text with.
      *
      * @param font The font to use.
      * @param fontSize The font size to draw the text.
@@ -505,21 +506,63 @@ public class PDPageContentStream impleme
     }
 
     /**
+     * Sets the text leading.
+     *
+     * @param leading The leading in unscaled text units.
+     * @throws IOException If there is an error writing to the stream.
+     */
+    public void setLeading(double leading) throws IOException
+    {
+        appendRawCommands(leading);
+        appendRawCommands(SPACE);
+        appendRawCommands(SET_LEADING);
+    }
+
+    /**
+     * Move to the start of the next line of text. Requires the leading to have been set.
+     *
+     * @throws IOException If there is an error writing to the stream.
+     */
+    public void newLine() throws IOException
+    {
+        if (!inTextMode)
+        {
+            throw new IllegalStateException("Must call beginText() before newLine()");
+        }
+        appendRawCommands(NEW_LINE);
+    }
+
+    /**
      * The Td operator.
      * A current text matrix will be replaced with a new one (1 0 0 1 x y).
-     * @param x The x coordinate.
-     * @param y The y coordinate.
+     * @param tx The x translation.
+     * @param ty The y translation.
+     * @throws IOException If there is an error writing to the stream.
+     * @deprecated Use {@link #newLineAtOffset} instead.
+     */
+    @Deprecated
+    public void moveTextPositionByAmount(float tx, float ty) throws IOException
+    {
+        newLineAtOffset(tx, ty);
+    }
+
+    /**
+     * The Td operator.
+     * Move to the start of the next line, offset from the start of the current line by (tx,
ty).
+     *
+     * @param tx The x translation.
+     * @param ty The y translation.
      * @throws IOException If there is an error writing to the stream.
      */
-    public void moveTextPositionByAmount(float x, float y) throws IOException
+    public void newLineAtOffset(float tx, float ty) throws IOException
     {
         if (!inTextMode)
         {
-            throw new IOException("Error: must call beginText() before moveTextPositionByAmount");
+            throw new IOException("Error: must call beginText() before newLineAtOffset()");
         }
-        appendRawCommands(x);
+        appendRawCommands(tx);
         appendRawCommands(SPACE);
-        appendRawCommands(y);
+        appendRawCommands(ty);
         appendRawCommands(SPACE);
         appendRawCommands(MOVE_TEXT_POSITION);
     }
@@ -534,7 +577,9 @@ public class PDPageContentStream impleme
      * @param e The e value of the matrix.
      * @param f The f value of the matrix.
      * @throws IOException If there is an error writing to the stream.
+     * @deprecated Use {@link #setTextMatrix(Matrix)} instead.
      */
+    @Deprecated
     public void setTextMatrix(double a, double b, double c, double d, double e, double f)
throws IOException
     {
         if (!inTextMode)
@@ -557,11 +602,13 @@ public class PDPageContentStream impleme
     }
 
     /**
-    * The Tm operator. Sets the text matrix to the given values.
-    * A current text matrix will be replaced with the new one.
-    * @param matrix the transformation matrix
-    * @throws IOException If there is an error writing to the stream.
-    */
+     * The Tm operator. Sets the text matrix to the given values.
+     * A current text matrix will be replaced with the new one.
+     * @param matrix the transformation matrix
+     * @throws IOException If there is an error writing to the stream.
+     * @deprecated Use {@link #setTextMatrix(Matrix)} instead.
+     */
+    @Deprecated
     public void setTextMatrix(AffineTransform matrix) throws IOException
     {
         if (!inTextMode)
@@ -573,6 +620,23 @@ public class PDPageContentStream impleme
     }
 
     /**
+     * The Tm operator. Sets the text matrix to the given values.
+     * A current text matrix will be replaced with the new one.
+     *
+     * @param matrix the transformation matrix
+     * @throws IOException If there is an error writing to the stream.
+     */
+    public void setTextMatrix(Matrix matrix) throws IOException
+    {
+        if (!inTextMode)
+        {
+            throw new IOException("Error: must call beginText() before setTextMatrix");
+        }
+        appendMatrix(matrix.createAffineTransform());
+        appendRawCommands(SET_TEXT_MATRIX);
+    }
+
+    /**
      * The Tm operator. Sets the text matrix to the given scaling and translation values.
      * A current text matrix will be replaced with the new one.
      * @param sx The scaling factor in x-direction.
@@ -580,10 +644,12 @@ public class PDPageContentStream impleme
      * @param tx The translation value in x-direction.
      * @param ty The translation value in y-direction.
      * @throws IOException If there is an error writing to the stream.
+     * @deprecated Use {@link #setTextMatrix(Matrix)} instead.
      */
+    @Deprecated
     public void setTextScaling(double sx, double sy, double tx, double ty) throws IOException
     {
-        setTextMatrix(sx, 0, 0, sy, tx, ty);
+        setTextMatrix(new Matrix((float)sx, 0f, 0f, (float)sy, (float)tx, (float)ty));
     }
 
     /**
@@ -592,10 +658,12 @@ public class PDPageContentStream impleme
      * @param tx The translation value in x-direction.
      * @param ty The translation value in y-direction.
      * @throws IOException If there is an error writing to the stream.
+     * @deprecated Use {@link #setTextMatrix(Matrix)} instead.
      */
+    @Deprecated
     public void setTextTranslation(double tx, double ty) throws IOException
     {
-        setTextMatrix(1, 0, 0, 1, tx, ty);
+        setTextMatrix(Matrix.getTranslatingInstance((float)tx, (float)ty));
     }
 
     /**
@@ -605,12 +673,12 @@ public class PDPageContentStream impleme
      * @param tx The translation value in x-direction.
      * @param ty The translation value in y-direction.
      * @throws IOException If there is an error writing to the stream.
+     * @deprecated Use {@link #setTextMatrix(Matrix)} instead.
      */
+    @Deprecated
     public void setTextRotation(double angle, double tx, double ty) throws IOException
     {
-        double angleCos = Math.cos(angle);
-        double angleSin = Math.sin(angle);
-        setTextMatrix(angleCos, angleSin, -angleSin, angleCos, tx, ty);
+        setTextMatrix(Matrix.getRotateInstance(angle, (float)tx, (float)ty));
     }
 
     /**
@@ -691,33 +759,6 @@ public class PDPageContentStream impleme
     }
 
     /**
-     * Sets the text leading.
-     *
-     * @param leading The leading in unscaled text units.
-     * @throws IOException If there is an error writing to the stream.
-     */
-    public void setLeading(double leading) throws IOException
-    {
-        appendRawCommands(leading);
-        appendRawCommands(SPACE);
-        appendRawCommands(SET_LEADING);
-    }
-
-    /**
-     * Move to the start of the next line of text. Requires the leading to have been set.
-     *
-     * @throws IOException If there is an error writing to the stream.
-     */
-    public void newLine() throws IOException
-    {
-        if (!inTextMode)
-        {
-            throw new IllegalStateException("Must call beginText() before newLine()");
-        }
-        appendRawCommands(NEW_LINE);
-    }
-
-    /**
      * Set the stroking color space.  This will add the colorspace to the PDResources
      * if necessary.
      *

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java Tue Jan  6 19:34:54
2015
@@ -387,29 +387,25 @@ public final class Matrix implements Clo
     @Deprecated
     public Matrix extractScaling()
     {
-        Matrix retval = new Matrix();
-
-        retval.single[0] = this.single[0];
-        retval.single[4] = this.single[4];
-
-        return retval;
+        Matrix matrix = new Matrix();
+        matrix.single[0] = this.single[0];
+        matrix.single[4] = this.single[4];
+        return matrix;
     }
 
     /**
      * Convenience method to create a scaled instance.
      *
-     * @param x The xscale operator.
-     * @param y The yscale operator.
+     * @param sx The xscale operator.
+     * @param sy The yscale operator.
      * @return A new matrix with just the x/y scaling
      */
-    public static Matrix getScaleInstance( float x, float y)
+    public static Matrix getScaleInstance(float sx, float sy)
     {
-        Matrix retval = new Matrix();
-
-        retval.single[0] = x;
-        retval.single[4] = y;
-
-        return retval;
+        Matrix matrix = new Matrix();
+        matrix.single[0] = sx;
+        matrix.single[4] = sy;
+        return matrix;
     }
 
     /**
@@ -421,29 +417,48 @@ public final class Matrix implements Clo
     @Deprecated
     public Matrix extractTranslating()
     {
-        Matrix retval = new Matrix();
-
-        retval.single[6] = this.single[6];
-        retval.single[7] = this.single[7];
-
-        return retval;
+        Matrix matrix = new Matrix();
+        matrix.single[6] = this.single[6];
+        matrix.single[7] = this.single[7];
+        return matrix;
     }
 
     /**
      * Convenience method to create a translating instance.
      *
-     * @param x The x translating operator.
-     * @param y The y translating operator.
+     * @param tx The x translating operator.
+     * @param ty The y translating operator.
      * @return A new matrix with just the x/y translating.
      */
-    public static Matrix getTranslatingInstance( float x, float y)
+    public static Matrix getTranslatingInstance(float tx, float ty)
     {
-        Matrix retval = new Matrix();
+        Matrix matrix = new Matrix();
+        matrix.single[6] = tx;
+        matrix.single[7] = ty;
+        return matrix;
+    }
 
-        retval.single[6] = x;
-        retval.single[7] = y;
+    /**
+     * Convenience method to create a rotated instance.
+     *
+     * @param theta The angle of rotation measured in radians
+     * @param tx The x translation.
+     * @param ty The y translation.
+     * @return A new matrix with just the x/y translating.
+     */
+    public static Matrix getRotateInstance(double theta, float tx, float ty)
+    {
+        float cosTheta = (float)Math.cos(theta);
+        float sinTheta = (float)Math.sin(theta);
 
-        return retval;
+        Matrix matrix = new Matrix();
+        matrix.single[0] = cosTheta;
+        matrix.single[1] = sinTheta;
+        matrix.single[3] = -sinTheta;
+        matrix.single[4] = cosTheta;
+        matrix.single[6] = tx;
+        matrix.single[7] = ty;
+        return matrix;
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
Tue Jan  6 19:34:54 2015
@@ -68,7 +68,7 @@ public class TestFontEmbedding extends T
         stream.setFont(font, 12, subset);
 
         String text = "Unicode русский язык Tiếng Việt";
-        stream.moveTextPositionByAmount(50, 600);
+        stream.newLineAtOffset(50, 600);
         stream.drawString(text);
 
         stream.endText();

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java
Tue Jan  6 19:34:54 2015
@@ -110,13 +110,13 @@ public class TestOptionalContentGroups e
             contentStream.beginMarkedContentSequence(COSName.OC, mc0);
             contentStream.beginText();
             contentStream.setFont(font, 14);
-            contentStream.moveTextPositionByAmount(80, 700);
+            contentStream.newLineAtOffset(80, 700);
             contentStream.drawString("PDF 1.5: Optional Content Groups");
             contentStream.endText();
             font = PDType1Font.HELVETICA;
             contentStream.beginText();
             contentStream.setFont(font, 12);
-            contentStream.moveTextPositionByAmount(80, 680);
+            contentStream.newLineAtOffset(80, 680);
             contentStream.drawString("You should see a green textline, but no red text line.");
             contentStream.endText();
             contentStream.endMarkedContentSequence();
@@ -126,7 +126,7 @@ public class TestOptionalContentGroups e
             contentStream.setNonStrokingColor(Color.GREEN);
             contentStream.beginText();
             contentStream.setFont(font, 12);
-            contentStream.moveTextPositionByAmount(80, 600);
+            contentStream.newLineAtOffset(80, 600);
             contentStream.drawString(
                     "This is from an enabled layer. If you see this, that's good.");
             contentStream.endText();
@@ -137,7 +137,7 @@ public class TestOptionalContentGroups e
             contentStream.setNonStrokingColor(Color.RED);
             contentStream.beginText();
             contentStream.setFont(font, 12);
-            contentStream.moveTextPositionByAmount(80, 500);
+            contentStream.newLineAtOffset(80, 500);
             contentStream.drawString(
                     "This is from a disabled layer. If you see this, that's NOT good!");
             contentStream.endText();

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java Tue Jan
 6 19:34:54 2015
@@ -142,7 +142,7 @@ public class TestLayerUtility extends Te
             PDPageContentStream contentStream = new PDPageContentStream(doc, page, false,
false);
             PDFont font = PDType1Font.HELVETICA_BOLD;
             contentStream.beginText();
-            contentStream.moveTextPositionByAmount(50, 720);
+            contentStream.newLineAtOffset(50, 720);
             contentStream.setFont(font, 14);
             contentStream.drawString("Simple test document with text.");
             contentStream.endText();
@@ -150,10 +150,10 @@ public class TestLayerUtility extends Te
             contentStream.beginText();
             int fontSize = 12;
             contentStream.setFont(font, fontSize);
-            contentStream.moveTextPositionByAmount(50, 700);
+            contentStream.newLineAtOffset(50, 700);
             for (String line : text)
             {
-                contentStream.moveTextPositionByAmount(0, -fontSize * 1.2f);
+                contentStream.newLineAtOffset(0, -fontSize * 1.2f);
                 contentStream.drawString(line);
             }
             contentStream.endText();

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java Tue Jan  6 19:34:54
2015
@@ -148,8 +148,8 @@ public class TextToPDF
                         contentStream.setFont( font, fontSize );
                         contentStream.beginText();
                         y = page.getMediaBox().getHeight() - margin + height;
-                        contentStream.moveTextPositionByAmount(
-                            margin, y );
+                        contentStream.newLineAtOffset(
+                                margin, y);
 
                     }
                     //System.out.println( "Drawing string at " + x + "," + y );
@@ -158,7 +158,7 @@ public class TextToPDF
                     {
                         throw new IOException( "Error:Expected non-null content stream."
);
                     }
-                    contentStream.moveTextPositionByAmount( 0, -height);
+                    contentStream.newLineAtOffset(0, -height);
                     y -= height;
                     contentStream.drawString( nextLineToDraw.toString() );
                 }

Modified: pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java?rev=1649914&r1=1649913&r2=1649914&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java (original)
+++ pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java Tue Jan
 6 19:34:54 2015
@@ -39,7 +39,7 @@ public class TestPDFText2HTML extends Te
         PDPageContentStream contentStream = new PDPageContentStream(doc, page);
         contentStream.beginText();
         contentStream.setFont(font, 12);
-        contentStream.moveTextPositionByAmount(100, 700);
+        contentStream.newLineAtOffset(100, 700);
         contentStream.drawString(text);
         contentStream.endText();
         contentStream.close();



Mime
View raw message