monoceres
monoceres

Reputation: 4770

How to find column width for vertical text with FreeType / HarfBuzz

I'm currently rendering text with FreeType + Harfbuzz and am now trying to introduce vertical text rendering (mainly for east asian scripts).

The issue I'm facing is that I can't figure out how wide a column of text should be. For horizontal text we can find out the line height with ascent - descent, but since these values are not provided in the case of vertical text ('ascent' / 'descent' is simple the left and right part of the glyph respectively) I have no idea how wide my text columns should be.

I tried using bbox width for the font, but the box changes drastically between different fonts, giving no good info.

Upvotes: 3

Views: 393

Answers (1)

Phantom
Phantom

Reputation: 37

I think this site may be useful :

https://freetype.org/freetype2/docs/glyphs/glyphs-3.html#:~:text=Each%20layout%20uses%20a%20different%20convention%20for%20glyph,vertical%20layout%2C%20glyphs%20are%20centered%20around%20the%20baseline%3A

I think it might be a case of trial and error, however you could also try these steps:

  1. Get a run of vertical text and feed it into Harfbuzz to get the glyphs and glyph positions

  2. Take the resulting glyph positions and adjust them using the values from hb_font_subtract_glyph_origin_for_direction

  3. The top-side bearing from the vmtx table should be subtracted from the y-position of each glyph

  4. The maximum y extent of each glyph should then be subtracted from the y- position of each glyph

  5. The x position should be further adjusted by vertTypoDescender from the vmtx table if I want a central baseline

  6. Draw the glyphs at those positions

Upvotes: 0

Related Questions