You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2017/11/08 20:00:10 UTC
svn commit: r1814632 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox:
contentstream/PDAbstractContentStream.java pdmodel/PDPageContentStream.java
Author: tilman
Date: Wed Nov 8 20:00:10 2017
New Revision: 1814632
URL: http://svn.apache.org/viewvc?rev=1814632&view=rev
Log:
PDFBOX-3992: show text with positioning, by backslash47 and Dan Fickling
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDAbstractContentStream.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDAbstractContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDAbstractContentStream.java?rev=1814632&r1=1814631&r2=1814632&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDAbstractContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDAbstractContentStream.java Wed Nov 8 20:00:10 2017
@@ -244,6 +244,41 @@ public abstract class PDAbstractContentS
}
/**
+ * Shows the given text at the location specified by the current text matrix with the given
+ * interspersed positioning. This allows the user to efficiently position each glyph or sequence
+ * of glyphs.
+ *
+ * @param textWithPositioningArray An array consisting of String and Float types. Each String is
+ * output to the page using the current text matrix. Using the default coordinate system, each
+ * interspersed number adjusts the current text matrix by translating to the left or down for
+ * horizontal and vertical text respectively. The number is expressed in thousands of a text
+ * space unit, and may be negative.
+ *
+ * @throws IOException if an io exception occurs.
+ */
+ public void showTextWithPositioning(Object[] textWithPositioningArray) throws IOException
+ {
+ write("[");
+ for (Object obj : textWithPositioningArray)
+ {
+ if (obj instanceof String)
+ {
+ showTextInternal((String) obj);
+ }
+ else if (obj instanceof Float)
+ {
+ writeOperand(((Float) obj).floatValue());
+ }
+ else
+ {
+ throw new IllegalArgumentException("Argument must consist of array of Float and String types");
+ }
+ }
+ write("] ");
+ writeOperator("TJ");
+ }
+
+ /**
* Shows the given text at the location specified by the current text matrix.
*
* @param text The Unicode text to show.
@@ -251,6 +286,19 @@ public abstract class PDAbstractContentS
*/
public void showText(String text) throws IOException
{
+ showTextInternal(text);
+ write(" ");
+ writeOperator("Tj");
+ }
+
+ /**
+ * Outputs a string using the correct encoding and subsetting as required.
+ *
+ * @text The Unicode text to show.
+ * @throws IOException If an io exception occurs.
+ */
+ protected void showTextInternal(String text) throws IOException
+ {
if (!inTextMode)
{
throw new IllegalStateException("Must call beginText() before showText()");
@@ -275,9 +323,6 @@ public abstract class PDAbstractContentS
}
COSWriter.writeString(font.encode(text), output);
- write(" ");
-
- writeOperator("Tj");
}
/**
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java?rev=1814632&r1=1814631&r2=1814632&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java Wed Nov 8 20:00:10 2017
@@ -22,6 +22,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Stack;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.contentstream.PDAbstractContentStream;
@@ -331,13 +332,12 @@ public final class PDPageContentStream e
}
/**
- * Shows the given text at the location specified by the current text matrix.
+ * Outputs a string using the correct encoding and subsetting as required.
*
- * @param text The Unicode text to show.
+ * @text The Unicode text to show.
* @throws IOException If an io exception occurs.
*/
- @Override
- public void showText(String text) throws IOException
+ protected void showTextInternal(String text) throws IOException
{
if (!isInTextMode())
{
@@ -362,11 +362,7 @@ public final class PDPageContentStream e
}
}
-
COSWriter.writeString(font.encode(text), getOutput());
- write(" ");
-
- writeOperator("Tj");
}
/**