[HarfBuzz] Harfbuzz with linebreaking

Adam Twardoch (List) list.adam at twardoch.com
Mon Jun 13 23:44:12 UTC 2016


Both XeTeX and Mozilla Firefox have opensource code which uses HarfBuzz for line setting but combines it with other techniques to perform paragraph-level line breaking, hyphenation and justification. 

In a way, FreeType takes a font, glyph ids and their positions, and delivers an image. HarfBuzz takes a font and plain Unicode text, and delivers glyph ids and their positions in a line. 

But "something else" (e.g. code that needs to be written) would be needed for paragraphs. 

Paragraph setting is not at all easy, and can be done in a number of ways. If your paragraphs are always left-aligned, rectangular, and don't use hyphenation, then it’s easy. But if they need to wrap around graphics or use freeform margins, use hyphenation, multiple fonts etc. — the code needs to deal with situations that are completely out of scope for HarfBuzz. Yes, even setting one word in bold or italic would require the paragraph composer code to be aware of multiple fonts and some kind of “markup” or “rich text” — something that HarfBuzz doesn’t do and isn’t intended for. 

Best,
Adam

Sent from my mobile phone.

> On 13.06.2016, at 17:00, Kelvin Ma <kelvinsthirteen at gmail.com> wrote:
> 
> So I’ve not received an answer to this anywhere, so, how do I typeset paragraphs with Harfbuzz? How do I use the ‘safe-to-break’ iterator?
> 
> Because it sounds like right now I’d have to shape the *entire* paragraph as one line, then find the last shaped glyph that falls before the cutoff point, then iterate backwards from the character corresponding to the glyph following *that*, on each breakpoint, reshaping the whole line each time until something fits. Then I’d have to do that all over again for the second line until the entire paragraph is shaped. So to typeset 5 lines of text I’d have to shape about 22 lines of text. To typeset a 20 line paragraph I’d have to shape about 240 lines of text.
> 
> Surely this is not how harfbuzz expects users to use it?
> 
> (Asking because I need harfbuzz for my typesetter app)
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/harfbuzz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/harfbuzz/attachments/20160614/e295d01c/attachment-0001.html>


More information about the HarfBuzz mailing list