You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by ta...@marino.co.jp on 2014/08/26 10:56:40 UTC

Drawing vertical text like Identity-V encoding.

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

--



Re: Drawing vertical text like Identity-V encoding.

Posted by ta...@marino.co.jp.
Hi,

> Of course, looks interesting. Can you provide us with a sample pdf?
>
> Please create an issue on JIRA [1] and attach both the patch and the
> sample pdf to it.

I created an issue on JIRA.
https://issues.apache.org/jira/browse/PDFBOX-2294

Regards,
tani

On 2014/08/26 19:13, Andreas Lehmkühler wrote:
> Hi,
>
>>
>> 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.
> Of course, looks interesting. Can you provide us with a sample pdf?
>
> Please create an issue on JIRA [1] and attach both the patch and the
> sample pdf to it.
>
>
>> Regards,
>> tani
>
> BR
> Andreas Lehmkühler
>
> [1] https://issues.apache.org/jira/browse/PDFBOX
>
>
>>
>> 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
>>
>> --
>>
>>


Re: Drawing vertical text like Identity-V encoding.

Posted by Andreas Lehmkühler <an...@lehmi.de>.
Hi,


> tani@marino.co.jp hat am 26. August 2014 um 10:56 geschrieben:
>
>
> 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.
Of course, looks interesting. Can you provide us with a sample pdf?

Please create an issue on JIRA [1] and attach both the patch and the
sample pdf to it.


> Regards,
> tani

BR
Andreas Lehmkühler

[1] https://issues.apache.org/jira/browse/PDFBOX


>
> 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
>
> --
>
>