Dienstag, 24. Mai 2011

Getting complex text layout into libass

Unfortunately, libass's rendering model doesn't make it easy to plug-in contextual transforms that are needed for complex text layout. Currently, for every subtitle event, a lot of  processing is done per-glyph before line breaking, positioning, etc. take place. However, the complex text layout engine needs runs of text. Let's look again at the text layout pipeline:

  1. Split up text into runs according to style (font, size, decoration).
  2. Split up runs further according to text direction (depending on script and language).
  3. Shape runs that need it.
  4. Break lines.
  5. Reorder lines into visual order
Step 1 is currently not done with runs, style is strictly applied per glyph. This is not without problems, for example it makes text decorations (underline, strike-through) hard to implement correctly and positioning after certain style changes is hard to get right (from italic to non-italic style). Moreover, this requires inter-glyph blending later on in the rendering pipeline.

My plan is to completely refactor the main rendering loop from individual glyphs to runs to get rid of these problems. Obviously, the other advantage of it is that it makes plugging complex text layout into rendering much easier.

What about the next steps? Steps 2 and 5, BiDi transformation, will be handled by fribidi. Step 3, text shaping, will be handled by the new harfbuzz-ng library. Step 4 is going to be handled by liblinebreak plus support code in libass.

As a first step, I will implement a simple standalone renderer for steps 2-5. I'm using the hb-view program from harfbuzz-ng as the base.

Update: added step 5, reordering.

Keine Kommentare:

Kommentar veröffentlichen