What I need is something to bridge that gap between the 1-line of unbroken
text that harfbuzz generates, and the fragments I need to be able to
assemble a multi-line paragraph.

What Freetype does is give me images of individual letters, which I can
then put together to make words and sentences, because words and sentences
are made up of individual letters. But I cannot do that with harfbuzz
because its output is one line of text, whereas I need smaller pieces that
I can use to build a paragraph. The only way to get these pieces is to find
the spots in the shaped text where the whole line can be shaped in two
pieces with an identical result. This requires knowledge of all the glyph
shaping rules and opentype features, which is why it sounds like it can
*only* be HarfBuzz’s responsibility.

There is only one “workaround” I’ve seen (the mozilla one) where it simply
assumes each space-separated word is a fragment that will not affect the
shaping of its neighbors. But this only works for justified text; in many
fonts the space is kerned with letters such as T and L.

On Mon, Jun 13, 2016 at 7:44 PM, Adam Twardoch (List) <
list.a...@twardoch.com> wrote:

> 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 <kelvinsthirt...@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
> <https://github.com/kelvin13/Knockout>)
>
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/harfbuzz
>
>
_______________________________________________
HarfBuzz mailing list
HarfBuzz@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/harfbuzz

Reply via email to