Integrated: 8270265: LineBreakMeasurer calculates incorrect line breaks with zero-width characters
Daniel Gredler
dgredler at openjdk.org
Thu Mar 13 20:30:06 UTC 2025
On Wed, 12 Feb 2025 23:53:43 GMT, Daniel Gredler <dgredler at openjdk.org> wrote:
> When a string contains zero-width characters, `LineBreakMeasurer` calculates line breaks incorrectly.
>
> The root cause appears to be that `LineBreakMeasurer` eventually calls into `StandardGlyphVector.getGlyphInfo()`, which derives the glyph advances from the glyph IDs. However, HarfBuzz's default treatment of zero-width characters is to provide the glyph ID of the space character (`U+0020`) combined with an artificial zero advance (not the font's space glyph advance). Unaware of HarfBuzz's sleight of hand, `StandardGlyphVector.getGlyphInfo()` retrieves the actual advances of the space glyph (since that was the glyph ID returned) and provides these back up the call chain to `LineBreakMeasurer` et al.
>
> I think the correct fix is to use `hb_buffer_set_invisible_glyph` to register `0xFFFF` as the invisible glyph ID with HarfBuzz (matching `CharToGlyphMapper.INVISIBLE_GLYPH_ID`).
>
> I haven't seen any unwanted side effects, but there is a risk, since this is changing the global HarfBuzz configuration.
>
> For more information on HarfBuzz's behavior in this area, see: https://harfbuzz.github.io/setting-buffer-properties.html
This pull request has now been integrated.
Changeset: 7fc776e2
Author: Daniel Gredler <dgredler at openjdk.org>
Committer: Phil Race <prr at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/7fc776e2ace920a3b1b319c021e6d3d440305b5e
Stats: 23 lines in 6 files changed: 13 ins; 1 del; 9 mod
8270265: LineBreakMeasurer calculates incorrect line breaks with zero-width characters
Reviewed-by: achung, prr
-------------
PR: https://git.openjdk.org/jdk/pull/23603
More information about the client-libs-dev
mailing list