Hi,
I understand that PDFToImage currently doesn't support drawing
vertical text like Identity-V encoding. But I had to use it,
so I tried to let it work with modification as show below.
Even though I don't know whether this code is proper or not, I
could make image files with vertical text PDF file.
I'm happy if this information is something useful.
Regards,
tani
diff --git a/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
b/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
index ec1ed4a..0aae1b7 100644
--- a/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
+++ b/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
@@ -330,7 +330,16 @@ public class PDFStreamEngine
Matrix adjMatrix = new Matrix();
adjustment =- (adjustment / 1000) * horizontalScaling * fontsize;
// TODO vertical writing mode
- adjMatrix.setValue( 2, 0, adjustment );
+ //
+ // TODO: This is workaround for vertical writing mode by tani.
+ // Check pdfbox official improvement.
+ //
+ if (getGraphicsState().getTextState().getFont().getCMap() != null
+ &&
getGraphicsState().getTextState().getFont().getCMap().getWMode() == 1) {
+ adjMatrix.setValue( 2, 1, adjustment ); // Adjust only Y axis.
+ } else {
+ adjMatrix.setValue( 2, 0, adjustment );
+ }
showAdjustedTextRun(strings.get(i), adjMatrix);
}
}
@@ -472,9 +481,18 @@ public class PDFStreamEngine
float ty = 0;
// reset the matrix instead of creating a new one
td.reset();
- td.setValue(2, 0, tx);
- td.setValue(2, 1, ty);
-
+ //
+ // TODO: This is workaround for vertical writing mode by tani.
+ // Check pdfbox official improvement.
+ //
+ if (getGraphicsState().getTextState().getFont().getCMap() != null
+ &&
getGraphicsState().getTextState().getFont().getCMap().getWMode() == 1) {
+ td.setValue(2, 1, -tx); // Adjust only Y axis.
+ } else {
+ td.setValue(2, 0, tx);
+ td.setValue(2, 1, ty);
+ }
+
// The text matrix gets updated after each glyph is placed. The
updated
// version will have the X and Y coordinates for the next glyph.
// textMatrixEnd contains the coordinates of the end of the last
glyph without
@@ -488,7 +506,16 @@ public class PDFStreamEngine
// add some spacing to the text matrix (see comment above)
tx = (charHorizontalDisplacementText * fontSizeText +
characterSpacingText +
spacingText) * horizontalScalingText;
- td.setValue(2, 0, tx);
+ //
+ // TODO: This is workaround for vertical writing mode by tani.
+ // Check pdfbox official improvement.
+ //
+ if (getGraphicsState().getTextState().getFont().getCMap() != null
+ &&
getGraphicsState().getTextState().getFont().getCMap().getWMode() == 1) {
+ td.setValue(2, 1, -tx); // Adjust only Y axis.
+ } else {
+ td.setValue(2, 0, tx);
+ }
td.multiply(textMatrix, textMatrix);
// determine the width of this character
--