[HarfBuzz] Ligatures and color changes

Behdad Esfahbod behdad at behdad.org
Tue Feb 19 14:34:40 PST 2013


Hi Lóránt,

On 02/19/2013 12:20 PM, Lóránt Pintér wrote:
> Hi,
> 
> I have a problem with half-colored ligatures, like "(5) mfim" in the image:

Right.  That's one of the harder issues of text rendering.

> I figured out two ways to do this, but neither is good enough:
> 
>   * I can shape each color range separately, but then I lose the kerning
>     between them, breaking (6)

Yes.  Best to not do this.

>   * I can tell HarfBuzz to disable ligatures for the last of the first
>     character of each color range, but then it breaks (2) or (3) and (4).

Right.  This is a limitation of HarfBuzz currently, that you can't turn off a
pair-wise feature on one pair only, since changing the "liga" bit on one
character affects it in both directions.

I haven't been able to find a satisfactory fix for this yet.  I'll think about it.


> Is there maybe a way to tell HarfBuzz to ignore ligatures if they span that
> color boundary? Or is there maybe a way to (quickly) assess if "liga" would be
> applied to a range of characters?

We don't have a good answer for this right now.  The way I want to eventually
fix this in Pango is different: it is to pain the ligature glyph half in each
color.  I think you can do the same using <canvas>.  Just use a gradient with
a sharp color switch for the ligature.  It's a royal pain, but I think that's
the most desirable rendering.  I may be wrong.

As for *where* to cut the ligature, here's what you need:

  * Count the number of cursor positions *inside* the ligature.  For the "fi"
ligature it's one.  And we have one cursor position before the ligature, so in
this case we need to cut it in two pieces,

  * The common heuristic then is to cut the advance width of the ligature
(well, cluster really) into two equal pieces.  If you want to be fancy, you
can call hb_ot_layout_get_ligature_carets(), and if the number of carets
matches what you expect (1 in this case I believe?), you can use the returned
caret positions instead of equally dividing the ligature.  I haven't seen
anyone implementing this though, as it gives very marginal improvements over
the heuristic.

Hope that helps,
behdad

> Thanks.
> 
> -- 
> 
> *Lóránt Pintér*
> 
> Developer at Prezi <http://prezi.com>
> 
> 
> 
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/harfbuzz
> 

-- 
behdad
http://behdad.org/



More information about the HarfBuzz mailing list