Truly independent web browser
LibWeb: Treat small kana and Hangul jamo as letters for `word-break`
Tim Ledbetter04a991a4c502
diff --git a/Libraries/LibUnicode/CharacterTypes.cpp b/Libraries/LibUnicode/CharacterTypes.cppindex 9816028e739..a095a643adc 100644--- a/Libraries/LibUnicode/CharacterTypes.cpp+++ b/Libraries/LibUnicode/CharacterTypes.cpp@@ -515,7 +515,7 @@ BidiClass bidirectional_class(u32 code_point)return char_direction_to_bidi_class(direction);}-static LineBreakClass resolved_line_break_class(u32 code_point, bool allow_conditional_japanese_starters)+LineBreakClass line_break_class(u32 code_point){auto icu_code_point = static_cast<UChar32>(code_point);auto icu_line_break = static_cast<ULineBreak>(u_getIntPropertyValue(icu_code_point, UCHAR_LINE_BREAK));@@ -530,6 +530,10 @@ static LineBreakClass resolved_line_break_class(u32 code_point, bool allow_condicase U_LB_H2:case U_LB_H3:return LineBreakClass::Ideographic;+ case U_LB_JL:+ case U_LB_JV:+ case U_LB_JT:+ return LineBreakClass::HangulJamo;case U_LB_AMBIGUOUS:return LineBreakClass::Ambiguous;case U_LB_COMPLEX_CONTEXT:@@ -545,17 +549,12 @@ static LineBreakClass resolved_line_break_class(u32 code_point, bool allow_condicase U_LB_COMBINING_MARK:return LineBreakClass::CombiningMark;case U_LB_CONDITIONAL_JAPANESE_STARTER:- return allow_conditional_japanese_starters ? LineBreakClass::Ideographic : LineBreakClass::Other;+ return LineBreakClass::ConditionalJapaneseStarter;default:return LineBreakClass::Other;}}-LineBreakClass line_break_class(u32 code_point)-{- return resolved_line_break_class(code_point, false);-}-// 22.2.2.7.3 Canonicalize ( rer, ch ), https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-chu32 canonicalize(u32 code_point, bool unicode_mode){@@ -781,7 +780,7 @@ bool unicode_code_point_matches_range_ignoring_case(u32, u32, u32, bool);u32 unicode_get_case_closure(u32, u32*, u32);u8 unicode_layout_bidirectional_class(u32);-u8 unicode_layout_line_break_class(u32, bool);+u8 unicode_layout_line_break_class(u32);bool unicode_layout_code_point_has_emoji_property(u32);}@@ -983,9 +982,9 @@ extern "C" u8 unicode_layout_bidirectional_class(u32 code_point)return to_underlying(Unicode::bidirectional_class(code_point));}-extern "C" u8 unicode_layout_line_break_class(u32 code_point, bool allow_conditional_japanese_starters)+extern "C" u8 unicode_layout_line_break_class(u32 code_point){- return to_underlying(Unicode::resolved_line_break_class(code_point, allow_conditional_japanese_starters));+ return to_underlying(Unicode::line_break_class(code_point));}extern "C" bool unicode_layout_code_point_has_emoji_property(u32 code_point)diff --git a/Libraries/LibUnicode/CharacterTypes.h b/Libraries/LibUnicode/CharacterTypes.hindex b61885e0c61..b042b29b16e 100644--- a/Libraries/LibUnicode/CharacterTypes.h+++ b/Libraries/LibUnicode/CharacterTypes.h@@ -76,12 +76,14 @@ enum class BidiClass {BidiClass bidirectional_class(u32 code_point);enum class LineBreakClass {- Alphabetic, // AL- Numeric, // NU- Ideographic, // ID- Ambiguous, // AI- ComplexContext, // SA- CombiningMark, // CM+ Alphabetic, // AL+ Numeric, // NU+ Ideographic, // ID+ Ambiguous, // AI+ ComplexContext, // SA+ CombiningMark, // CM+ ConditionalJapaneseStarter, // CJ+ HangulJamo, // JL, JV, JTOther,};diff --git a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs b/Libraries/LibWeb/Rust/src/layout/text_chunker.rsindex 8f1fb404392..7534f0f0311 100644--- a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs+++ b/Libraries/LibWeb/Rust/src/layout/text_chunker.rs@@ -162,7 +162,7 @@ unsafe extern "C" {end: *mut usize,);safe fn unicode_layout_bidirectional_class(code_point: u32) -> u8;- safe fn unicode_layout_line_break_class(code_point: u32, allow_conditional_japanese_starters: bool) -> u8;+ safe fn unicode_layout_line_break_class(code_point: u32) -> u8;safe fn unicode_layout_code_point_has_emoji_property(code_point: u32) -> bool;}@@ -174,10 +174,12 @@ mod line_break_class {pub(super) const AMBIGUOUS: u8 = 3;pub(super) const COMPLEX_CONTEXT: u8 = 4;pub(super) const COMBINING_MARK: u8 = 5;+ pub(super) const CONDITIONAL_JAPANESE_STARTER: u8 = 6;+ pub(super) const HANGUL_JAMO: u8 = 7;}-fn line_break_class(code_point: u32, allow_conditional_japanese_starters: bool) -> u8 {- unicode_layout_line_break_class(code_point, allow_conditional_japanese_starters)+fn line_break_class(code_point: u32) -> u8 {+ unicode_layout_line_break_class(code_point)}// Classifies a code point for direction-run splitting: strong LTR/RTL, direction-neutral Common, or ContextDependent@@ -287,7 +289,7 @@ mod unicode_test_stubs {}#[unsafe(no_mangle)]- extern "C" fn unicode_layout_line_break_class(_code_point: u32, _allow_conditional_japanese_starters: bool) -> u8 {+ extern "C" fn unicode_layout_line_break_class(_code_point: u32) -> u8 {unreachable!("no unit test segments text");}@@ -846,7 +848,6 @@ struct LineBreaker<'text> {text: &'text [u16],line_segmenter: LineSegmenter<'text>,word_break: u8,- allow_conditional_japanese_starters: bool,}impl<'text> LineBreaker<'text> {@@ -855,8 +856,6 @@ impl<'text> LineBreaker<'text> {text,line_segmenter: LineSegmenter::new(text, line_break, line_break_language),word_break,- // NB: Apply CJ tailoring to word-break classification as well as to ICU's line segmenter.- allow_conditional_japanese_starters: matches!(line_break, line_break::NORMAL | line_break::LOOSE),}}@@ -867,10 +866,7 @@ impl<'text> LineBreaker<'text> {}let mut index = index;let mut previous_code_point = previous_code_point_at(self.text, &mut index);- while line_break_class(previous_code_point, self.allow_conditional_japanese_starters)- == line_break_class::COMBINING_MARK- && index > 0- {+ while line_break_class(previous_code_point) == line_break_class::COMBINING_MARK && index > 0 {previous_code_point = previous_code_point_at(self.text, &mut index);}Some(previous_code_point)@@ -894,8 +890,13 @@ impl<'text> LineBreaker<'text> {use line_break_class::*;let breaks_anywhere = |code_point| {matches!(- line_break_class(code_point, self.allow_conditional_japanese_starters),- ALPHABETIC | NUMERIC | COMPLEX_CONTEXT | IDEOGRAPHIC+ line_break_class(code_point),+ ALPHABETIC+ | NUMERIC+ | COMPLEX_CONTEXT+ | IDEOGRAPHIC+ | CONDITIONAL_JAPANESE_STARTER+ | HANGUL_JAMO)};if let Some(previous_code_point) = get_previous_code_point()@@ -911,10 +912,14 @@ impl<'text> LineBreaker<'text> {return false;}use line_break_class::*;+ // https://drafts.csswg.org/css-text-3/#valdef-word-break-keep-all+ // Breaking is forbidden within “words”: implicit soft wrap opportunities between typographic letter+ // units (or other typographic character units belonging to the NU, AL, AI, or ID Unicode line breaking+ // classes [UAX14]) are suppressed, [...]let keeps_together = |code_point| {matches!(- line_break_class(code_point, self.allow_conditional_japanese_starters),- ALPHABETIC | NUMERIC | AMBIGUOUS | IDEOGRAPHIC+ line_break_class(code_point),+ ALPHABETIC | NUMERIC | AMBIGUOUS | IDEOGRAPHIC | CONDITIONAL_JAPANESE_STARTER | HANGUL_JAMO)};if let Some(previous_code_point) = get_previous_code_point()diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/word-break/reference/word-break-break-all-ref-031.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/word-break/reference/word-break-break-all-ref-031.htmlnew file mode 100644index 00000000000..1e28e2d3588--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/word-break/reference/word-break-break-all-ref-031.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<html lang="en" >+<head>+<meta charset="utf-8">+<title>word-break: break-all, ID and CJ</title>+<link rel='author' title='Makoto Kato' href='mailto:[email protected]'>+<style type='text/css'>+.test { word-break: break-all; }+/* the CSS below is not part of the test */+.test, .ref { border: 1px solid orange; margin: 20px; padding: 10px; width: 390px; font: 36px/1 sans-serif; }+</style>+</head>+<body>+<div id='instructions'>Test passes if the two orange boxes are the same.</div>+<div class="ref" lang="ja"><span>フォ フ<br/>ォ</span></div>+<div class="ref" lang="ja"><span>フォ フ<br/>ォ</span></div>+</body>+</html>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/word-break/reference/word-break-keep-all-ref-010.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/word-break/reference/word-break-keep-all-ref-010.htmlnew file mode 100644index 00000000000..cbfd3476089--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/word-break/reference/word-break-keep-all-ref-010.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<html lang="en" >+<head>+<meta charset="utf-8">+<title>word-break: keep-all, korean (Hangul Jamos)</title>+<link rel='author' title='Makoto Kato' href='mailto:[email protected]'>+<style type='text/css'>+.test { word-break: keep-all; }+/* the CSS below is not part of the test */+.test, .ref { border: 1px solid orange; margin: 20px; padding: 10px; width: 390px; font: 36px/1 sans-serif; }+</style>+</head>+<body>+<div id='instructions'>Test passes if the two orange boxes are the same.</div>+<div class="ref" lang="ko"><span>애기판다<br/>애기판다</span></div>+<div class="ref" lang="ko"><span>애기판다<br/>애기판다</span></div>+</body>+</html>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-break-all-031.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-break-all-031.htmlnew file mode 100644index 00000000000..82d85d98d85--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-break-all-031.html@@ -0,0 +1,25 @@+<!DOCTYPE html>+<html lang="en" >+<head>+<meta charset="utf-8">+<title>word-break: break-all, ID and CJ</title>+<meta name="assert" content="word-break: break-all means lines may break between ID and CJ.">+<link rel='help' href='https://drafts.csswg.org/css-text-3/#word-break-property'>+<link rel='match' href='../../../../../expected/wpt-import/css/css-text/word-break/reference/word-break-break-all-ref-031.html'>+<link rel='author' title='Makoto Kato' href='mailto:[email protected]'>+<style type='text/css'>+.test { word-break: break-all; }+/* the CSS below is not part of the test */+.test, .ref { border: 1px solid orange; margin: 20px; padding: 10px; width: 390px; font: 36px/1 sans-serif; }+</style>+</head>+<body>+<div id='instructions'>Test passes if the two orange boxes are the same.</div>+<div class="test" lang="ja"><div id="testdiv"><span id="testspan">フォ フォ</span></div></div>+<div class="ref" lang="ja"><span>フォ フ<br/>ォ</span></div>+<script>+var sentenceWidth = document.getElementById('testspan').offsetWidth;+document.getElementById('testdiv').style.width = String(sentenceWidth - 5)+'px';+</script>+</body>+</html>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-keep-all-010.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-keep-all-010.htmlnew file mode 100644index 00000000000..ca03da5060d--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/word-break/word-break-keep-all-010.html@@ -0,0 +1,25 @@+<!DOCTYPE html>+<html lang="en" >+<head>+<meta charset="utf-8">+<title>word-break: keep-all, korean (Hangul Jamos)</title>+<meta name="assert" content="word-break: keep-all means breaking is forbidden within 'words'. In this style, sequences of CJK characters do not break.">+<link rel='help' href='https://drafts.csswg.org/css-text-3/#word-break-property'>+<link rel='match' href='../../../../../expected/wpt-import/css/css-text/word-break/reference/word-break-keep-all-ref-010.html'>+<link rel='author' title='Makoto Kato' href='mailto:[email protected]'>+<style type='text/css'>+.test { word-break: keep-all; }+/* the CSS below is not part of the test */+.test, .ref { border: 1px solid orange; margin: 20px; padding: 10px; width: 390px; font: 36px/1 sans-serif; }+</style>+</head>+<body>+<div id='instructions'>Test passes if the two orange boxes are the same.</div>+<div class="test" lang="ko"><div id="testdiv"><span id="testspan">애기판다 애기판다</span></div></div>+<div class="ref" lang="ko"><span>애기판다<br/>애기판다</span></div>+<script>+var sentenceWidth = document.getElementById('testspan').offsetWidth;+document.getElementById('testdiv').style.width = String(sentenceWidth - 5)+'px';+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/expected/css/word-break-soft-wrap-opportunities.txt b/Tests/LibWeb/Text/expected/css/word-break-soft-wrap-opportunities.txtindex 8b7c83d4bf5..d29cadb29c0 100644--- a/Tests/LibWeb/Text/expected/css/word-break-soft-wrap-opportunities.txt+++ b/Tests/LibWeb/Text/expected/css/word-break-soft-wrap-opportunities.txt@@ -1,2 +1,3 @@break-all "မာစာ": "မာ|စာ"break-all "क्" + "ष": "क्ष"+keep-all "フォフ": "フォフ"diff --git a/Tests/LibWeb/Text/input/css/word-break-soft-wrap-opportunities.html b/Tests/LibWeb/Text/input/css/word-break-soft-wrap-opportunities.htmlindex 98b3de3daca..1a8e297b83e 100644--- a/Tests/LibWeb/Text/input/css/word-break-soft-wrap-opportunities.html+++ b/Tests/LibWeb/Text/input/css/word-break-soft-wrap-opportunities.html@@ -40,6 +40,7 @@["break-all", "\u1019\u102c\u1005\u102c"],// A grapheme cluster split between two text nodes.["break-all", "\u0915\u094d\u0937", 2],+ ["keep-all", "\u30d5\u30a9\u30d5"],]) {text.style.wordBreak = wordBreak;if (splitAt === undefined) {