Truly independent web browser
LibGfx: Don’t drop clusters that start with a default-ignorable
sideshowbarkerc24972e49292
diff --git a/Libraries/LibGfx/TextLayout.cpp b/Libraries/LibGfx/TextLayout.cppindex 75445bdb719..83ca902481a 100644--- a/Libraries/LibGfx/TextLayout.cpp+++ b/Libraries/LibGfx/TextLayout.cpp@@ -514,10 +514,8 @@ static ShapedGlyphs build_origin_relative_shape(Utf16View const& string, Font coauto first_trailing_whitespace_offset = string.length_in_code_units() - trailing_whitespace.length_in_code_units;auto is_right_to_left = hb_buffer_get_direction(buffer) == HB_DIRECTION_RTL;- auto glyph_length_in_code_units = [&](auto index) -> size_t {+ auto cluster_length_in_code_units = [&](auto index) -> size_t {auto starting_offset = glyph_info[index].cluster;- if (index > 0 && glyph_info[index - 1].cluster == starting_offset)- return 0;if (is_right_to_left) {for (size_t i = index; i-- > 0;) {if (auto offset = glyph_info[i].cluster; offset != starting_offset)@@ -533,17 +531,32 @@ static ShapedGlyphs build_origin_relative_shape(Utf16View const& string, Font coreturn string.length_in_code_units() - starting_offset;};+ auto glyph_length_in_code_units = [&](auto index) -> size_t {+ if (index > 0 && glyph_info[index - 1].cluster == glyph_info[index].cluster)+ return 0;+ return cluster_length_in_code_units(index);+ };++ // A glyph is left unpainted only when everything in its cluster is default-ignorable. A cluster that merely starts+ // with one, such as a Hangul syllable whose initial is the choseong filler, still shows its other characters.auto should_paint_glyph = [&](auto index) {auto starting_offset = glyph_info[index].cluster;if (starting_offset >= string.length_in_code_units())return true;- return !Unicode::code_point_has_default_ignorable_code_point_property(string.code_point_at(starting_offset));+ for (auto code_point : string.substring_view(starting_offset, cluster_length_in_code_units(index))) {+ if (!Unicode::code_point_has_default_ignorable_code_point_property(code_point))+ return true;+ }+ return false;};// NB: HarfBuzz positions glyphs in font space, where y grows upward, so its y offsets and advances are negated// for our coordinates, where y grows downward.+ bool should_paint = true;for (size_t i = 0; i < glyph_count; ++i) {- bool should_paint = should_paint_glyph(i);+ // Every glyph of a cluster gets the same answer, so it's worked out once, at the cluster's first glyph.+ if (i == 0 || glyph_info[i - 1].cluster != glyph_info[i].cluster)+ should_paint = should_paint_glyph(i);auto position = point- FloatPoint { 0, metrics.ascent }+ FloatPoint { positions[i].x_offset, -positions[i].y_offset } / text_shaping_resolution;diff --git a/Tests/LibWeb/Assets/NotoSansKR-jamo-subset.otf b/Tests/LibWeb/Assets/NotoSansKR-jamo-subset.otfnew file mode 100644index 00000000000..ecf895bdaf5Binary files /dev/null and b/Tests/LibWeb/Assets/NotoSansKR-jamo-subset.otf differdiff --git a/Tests/LibWeb/Text/expected/hangul-syllable-with-choseong-filler.txt b/Tests/LibWeb/Text/expected/hangul-syllable-with-choseong-filler.txtnew file mode 100644index 00000000000..082ad978582--- /dev/null+++ b/Tests/LibWeb/Text/expected/hangul-syllable-with-choseong-filler.txt@@ -0,0 +1,3 @@+syllable with a filler initial has a width: true+syllable with a kiyeok initial has a width: true+lone filler has no width: truediff --git a/Tests/LibWeb/Text/input/hangul-syllable-with-choseong-filler.html b/Tests/LibWeb/Text/input/hangul-syllable-with-choseong-filler.htmlnew file mode 100644index 00000000000..9d5a1835079--- /dev/null+++ b/Tests/LibWeb/Text/input/hangul-syllable-with-choseong-filler.html@@ -0,0 +1,28 @@+<!DOCTYPE html>+<meta charset="utf-8">+<style>+ @font-face {+ font-family: "Noto Sans KR jamo";+ src: url("../../Assets/NotoSansKR-jamo-subset.otf");+ }+ span {+ font: 40px "Noto Sans KR jamo";+ }+</style>+<!-- U+115F HANGUL CHOSEONG FILLER, then U+1193 HANGUL JUNGSEONG U-I -->+<span id="filler">ᅟᆓ</span>+<!-- U+1100 HANGUL CHOSEONG KIYEOK, then U+1193 -->+<span id="kiyeok">ᄀᆓ</span>+<!-- U+115F alone -->+<span id="lone-filler">ᅟ</span>+<script src="include.js"></script>+<script>+ asyncTest(async done => {+ await document.fonts.ready;+ const width = id => document.getElementById(id).getBoundingClientRect().width;+ println(`syllable with a filler initial has a width: ${width("filler") > 0}`);+ println(`syllable with a kiyeok initial has a width: ${width("kiyeok") > 0}`);+ println(`lone filler has no width: ${width("lone-filler") === 0}`);+ done();+ });+</script>