You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Aaron Madlon-Kay <aa...@madlon-kay.com> on 2017/10/30 13:08:10 UTC

Creating vertical text

Hello.

I’m attempting to use PDFBox to create a PDF with vertical Japanese text. I understand that PDFBox doesn’t support this out of the box, so depending on the scope of the missing functionality I may try to implement it myself. If the dev ML is more appropriate for this, please let me know.

I have obtained 90% of what I want by forcing my font to be loaded as Identity-V rather than Identity-H: this successfully makes the text render vertically. In particular I am referring to supplying COSName.IDENTITY_V in place of IDENTITY_H on this line:
https://github.com/apache/pdfbox/blob/f548ef7ea50f8e60685f5461ed4504751f766c4b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java#L73

The remaining 10% is that vertical glyphs are not used when appropriate: for instance U+30FC is a horizontal line normally, but has a vertical alternative glyph. I understand that the association between default and vertical glyphs is stored in the ‘vert’ subtable of the GSUB table.

My question: What do I need to do to get the ‘vert’ glyphs used as appropriate? Do I need to parse the table and do the pivoting myself when writing out the PDF? Or am I simply missing some bit of metadata about the embedded font that should be there?

Additional details:

- The font I’m using is IPA Gothic (TTF version): http://ipafont.ipa.go.jp/old/ipafont/download.html#en
- A sample output with incorrect horizontal glyphs: https://drive.google.com/file/d/0B5OoSoZGclLTVUpyMUY3WnU5RDg/view?usp=sharing
  - The horizontal line characters (U+2015, U+30FC) are incorrect and should be vertical. Yes, I have confirmed in e.g. FontForge that the font has ‘vert’ substitutions for these characters.
  - The sample is large (4.4 MB) because the entire font is embedded, just to illustrate that the problem isn’t(?) due to subsetting
- I’m working off of trunk, r1813370 / cd71c32b

Thank you for any advice you can offer.

-Aaron
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Creating vertical text

Posted by Aaron Madlon-Kay <aa...@madlon-kay.com>.
I received some spot-on advice from PDFBox contributor John Hewson, so I wanted to share it in case anyone else has the same issue:

> John Hewson wrote:
> 
> …
> 
> First of all, Identity-V seems like the right approach. PDFBox should be able to handle the basics of vertical text layout using that. However, as you say advanced OpenType features such as GSUB are not supported in PDFBox. That’s because OpenType is not supported in PDF* as it’s too new. So it’s up to the program/library which generates the PDF to apply the positioning or substitution itself and place the correct glyph on the page. PDFBox doesn’t implement that functionality, because it’s pretty complex - though we’d certainly like to!
> 
> * not entirely true, but PDF viewers have very limited support for it.
> 
> The way OpenType Layout works is that there are various abstract "features” which are identified by “tags” such as “vert”. These are simply used as keys to turn on/off various positioning or substitutions, which can be found in the GSUB and GPOS tables, respectively. So when an application wants, say, the vertical version of a font, it enables the “vert” feature by applying all the relevant substitutions/positionings. This could be as simple as a substitution rule which switches a horizontal glyph for a vertical one, or a complex state machine for some Indic language. In the case of “vert”, it’s going to be the former.
> 
> Given that GSUB and GPOS support are not coming to PDFBox anytime soon and assuming that you are just wanting to use a limited set of vertical fonts then I’d recommend “freezing” the “vert” feature into the font. This means creating a special subset of the font which already has the positioning and substitutions applied to the glyphs themselves. The resulting font won’t have any need for GSUB or GPOS tables for “vert” any more, and will only support vertical writing. You can find a tool for generating such fonts here: https://github.com/twardoch/fonttools-utils/tree/master/pyftfeatfreeze
> 
> For debugging, if you’re looking for a tool to inspect the table inside fonts, I recommend the free DTL OTMaster Light available here: http://fontmaster.nl, Microsoft’s OpenType spec is also helpful: https://www.microsoft.com/en-us/Typography/OpenTypeSpecification.aspx


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org