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:05 UTC
svn commit: r1814631 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
Author: tilman
Date: Wed Nov 8 20:00:05 2017
New Revision: 1814631
URL: http://svn.apache.org/viewvc?rev=1814631&view=rev
Log:
PDFBOX-3992: show text with positioning, by backslash47 and Dan Fickling
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java?rev=1814631&r1=1814630&r2=1814631&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java Wed Nov 8 20:00:05 2017
@@ -385,6 +385,41 @@ public final class PDPageContentStream i
}
/**
+ * 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.
@@ -392,6 +427,19 @@ public final class PDPageContentStream i
*/
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()");
@@ -416,9 +464,6 @@ public final class PDPageContentStream i
}
COSWriter.writeString(font.encode(text), output);
- write(" ");
-
- writeOperator("Tj");
}
/**