PhilterPaper / Perl-PDF-Builder

Extended version of the popular PDF::API2 Perl-based PDF library for creating, reading, and modifying PDF documents
https://www.catskilltech.com/FreeSW/product/PDF%2DBuilder/title/PDF%3A%3ABuilder/freeSW_full
Other
6 stars 7 forks source link

How to write perpendicular Japanese text? #144

Closed PhilterPaper closed 3 years ago

PhilterPaper commented 3 years ago

Kurt steuber wrote:

Dear Phil,

In the textlabel command ($width = $txt->textlabel($x,$y, $font, $size, $text, %opts) I find an option -rotate => $deg With this I could rotate my text by 90 degrees. But I would like to format a Japanese text the normal way, this means all characters remain upright but in a perpendicular row (which is normal in Japan :-) ) Placing the characters by single character strings below each other does not work either, since at least the interpunctation marks (brackets, full stop, quotes etc) have to be different in a perpendicular line. For instance brackets are indeed rotated by 90 degrees, full stops are placed in the upper right corner instead etc. I attach an image of a text sample where you can see that the comma is not correctly placed.

Greetings Kurt

perpendicular_line
PhilterPaper commented 3 years ago

Phil Perry replied:

I think textlabel is set up strictly for left-to-right text, and the whole thing can be rotated at some angle. To get vertical text with unrotated characters and proper punctuation will be very difficult. Have you tried HarfBuzz::Shaper support in PDF::Builder? The example for it shows some Chinese text in vertical mode -- no punctuation there, but you should try it anyway to see if it does the job for you. That might be a lot easier than trying to bend textlabel() to handle this.

PhilterPaper commented 3 years ago

Phil Perry replied:

Note: be careful choosing your .ttf or .otf CJK font file. Some do not permit embedding the font at all (requiring that the recipient have their own copy); some insist on embedding the entire font file (your PDF gets really huge); and some will permit embedding of a subset. Try to choose one that does the subset, as it will minimize the size of your PDF file.

PhilterPaper commented 3 years ago

With no response from the OP, I'll assume that HarfBuzz::Shaper does the job. If not, this ticket can be reopened.

PhilterPaper commented 3 years ago

By the way, Kurt, if HarfBuzz::Shaper does the job for you, and you have any nice tricks for using it for vertical mode CJK texts, please feel free to share so I can update and expand the documentation!

PhilterPaper commented 2 years ago

Just a note that I finally got around to trying this with CJK text (in Chinese) to see if punctuation was rotated in vertical mode -- it was. I'm not sure if the period is quite right (may be a font issue), but ( and ) certainly are correct. This should be in the next release's examples/HarfBuzz.pl. Anyway, this should work for your purposes, so I'll keep this ticket closed. Let me know if you experience problems using it.

PhilterPaper commented 7 months ago

Vertical writing: see https://www.mail-archive.com/search?l=harfbuzz@lists.freedesktop.org&q=subject:%22%5C%5BHarfBuzz%5C%5D+vertical+text+for+RTL+scripts%5C%3F%22&o=newest&f=1 for some discussion on this (using HarfBuzz).