<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 13, 2014 at 5:48 AM, Behdad Esfahbod <span dir="ltr"><<a href="mailto:behdad@behdad.org" target="_blank">behdad@behdad.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><br>
</div>In short: You shape the whole paragraph using HarfBuzz, then create a<br>
line-break iterator with ICU and walk the text and glyph string together and<br>
find the best break opportunity to fill the line. That can be<br>
mid-HarfBuzz-cluster. After that, you reshape the line, but can continue with<br>
the original shaped-paragraph for the next lines.<br>
<br>
Can be made twice faster, yes. We're not quite there yet.<br></blockquote><div><br></div><div>You have hinted before that you have something cooking here. I am very curious what it is. I am interested less in the potential speed-up, and more in the ability to do Knuth/Plass line-breaking correctly (which, of course, requires you to be able to determine the exact lengths of lines between each pair of potential breakpoints, before deciding which breakpoints to use).</div>
<div><br></div><div>In a little experimental project I've been working on (in pure JS, so not using harfbuzz at the moment), I have been playing with the following approach. I maintain two flags on each glyph:</div>
<div>
<br></div><div>- affectedByPreceding - true iff the shaping of this glyph, or any glyph following this glyph, has been affected by any glyph preceding this glyph;</div><div><br></div><div><div>- affectedByFollowing - true iff the shaping of this glyph, or any glyph preceding this glyph, has been affected by any glyph following this glyph.</div>
</div><div><br></div><div>If affectedByPreceding is false on a glyph, then that glyph and the following glyphs have been shaped just as if there was nothing before that glyph. Similarly, if affectedByFollowing is false on a glyph, then that glyph and the preceding glyphs have been shaped just as if there were nothing after the glyph.</div>
<div><br></div><div>As lookups modify the glyph sequence, then these flags are set based on the kind of lookup and the context. I can then use these flags to determine how much of the line, if any, needs to be reshaped. For example, if the first character after a line-break has the affectedByPreceding flag false, then I don't need to do any reshaping of the start of the line after the line-break.</div>
<div><br></div><div>This approach is not perfect: I can come up with artificial examples where it will fail (in the sense of giving a different result from reshaping the entire line). But it seems to work OK, at least for the simple examples I've tried.</div>
<div><br></div><div>So I was wondering whether your approach was similar to this, or whether you are doing something completely different (such as some sort of static analysis of the tables?).</div><div><br></div><div>James</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div>