[HarfBuzz] Interaction between shaping and line-breaking

Behdad Esfahbod behdad at behdad.org
Wed Aug 21 12:15:04 PDT 2013


On 13-08-21 07:03 AM, James Clark wrote:
> I've just started looking at HarfBuzz and I'm trying to get a better
> understanding of how it would work as part of a complete text formatting
> system.  In particular I would like to understand how line-breaking is
> supposed to interact with HarfBuzz's shaping.
> 
> Suppose, for example, I have a paragraph whose content is "This is difficult."
>  I'm guessing that the first step is to get HarfBuzz to shape the entire
> content.  Now let's suppose that I've decided to break this as:
> 
>   This is dif-
>   ficult.
> 
> In general, this may require reshaping: for example, difficult might have used
> an "ffi" ligature.  I can of course do this reshaping just by passing "This is
> dif-" and "ficult" again to the Harfbuzz shaper. However, apart from being
> inefficient, that would not be workable if I want to do Knuth-Plass style
> optimized line-breaking.

Right.  We plan to provide API that allows for more efficient handling of such
cases, but it's not currently there.


> Given that I have already shaped "This is difficult.", I would hope that there
> would be some way to figure out how many characters on each side of the break
> I need to reshape.

That's exactly what I like to provide.


>  For example, probably in this case it is enough to just
> reshape the "f-" before and "fi" after the break.  However, I don't see how I
> can figure this out from the information that HarfBuzz supplies.  I can think
> of various heuristics (eg stopping at whitespace) but I can't think of
> algorithm for doing this that will be correct regardless of the font.

You currently can't :(.  Well, there's something Firefox does, which is use
some hb-ot API to figure out whether the space character participates in any
GSUB/GPOS rules, and if it doesn't then it knows that it's safe to break at
space and reconstruct the line from cached shaped words.


> James

HTH,

-- 
behdad
http://behdad.org/



More information about the HarfBuzz mailing list