Truly independent web browser
LibWeb: Keep iteration marks inside a word under keep-all
sideshowbarkera190a6f11016
diff --git a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs b/Libraries/LibWeb/Rust/src/layout/text_chunker.rsindex 4a3b0d5da0a..7a6b288d095 100644--- a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs+++ b/Libraries/LibWeb/Rust/src/layout/text_chunker.rs@@ -187,6 +187,7 @@ mod line_break_class {pub(super) const GLUE: u8 = 15;pub(super) const WORD_JOINER: u8 = 16;pub(super) const ZERO_WIDTH_JOINER: u8 = 17;+ pub(super) const OTHER: u8 = 18;}fn line_break_class(code_point: u32) -> u8 {@@ -1060,11 +1061,12 @@ impl<'text> LineBreaker<'text> {// 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),- ALPHABETIC | NUMERIC | AMBIGUOUS | IDEOGRAPHIC | CONDITIONAL_JAPANESE_STARTER | HANGUL_JAMO- )+ // NB: A letter in a class of its own, such as the iteration mark U+3005 (class NS), is a typographic+ // letter unit too.+ let keeps_together = |code_point| match line_break_class(code_point) {+ ALPHABETIC | NUMERIC | AMBIGUOUS | IDEOGRAPHIC | CONDITIONAL_JAPANESE_STARTER | HANGUL_JAMO => true,+ OTHER => super::tree_builder::ladybird_layout_code_point_category_facts(code_point).is_letter,+ _ => false,};if let Some(previous_code_point) = get_previous_code_point()&& keeps_together(previous_code_point)diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 88a4d40b538..83c577c52a8 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -1091,7 +1091,7 @@ pub struct FfiCodePointCategoryFacts {}unsafe extern "C" {- safe fn ladybird_layout_code_point_category_facts(code_point: u32) -> FfiCodePointCategoryFacts;+ pub(crate) safe fn ladybird_layout_code_point_category_facts(code_point: u32) -> FfiCodePointCategoryFacts;}#[derive(Clone, Copy, Debug, PartialEq, Eq)]diff --git a/Tests/LibWeb/Text/expected/word-break-keep-all-iteration-marks.txt b/Tests/LibWeb/Text/expected/word-break-keep-all-iteration-marks.txtnew file mode 100644index 00000000000..5dc30c03de6--- /dev/null+++ b/Tests/LibWeb/Text/expected/word-break-keep-all-iteration-marks.txt@@ -0,0 +1,9 @@+ideographs: kept on one line+U+3005 ideographic iteration mark: kept on one line+U+309D hiragana iteration mark: kept on one line+U+309E hiragana voiced iteration mark: kept on one line+U+30FD katakana iteration mark: kept on one line+U+30FE katakana voiced iteration mark: kept on one line+U+303B vertical ideographic iteration mark: kept on one line+U+30FB katakana middle dot: broken+U+3002 ideographic full stop: brokendiff --git a/Tests/LibWeb/Text/input/word-break-keep-all-iteration-marks.html b/Tests/LibWeb/Text/input/word-break-keep-all-iteration-marks.htmlnew file mode 100644index 00000000000..6e71fbe3348--- /dev/null+++ b/Tests/LibWeb/Text/input/word-break-keep-all-iteration-marks.html@@ -0,0 +1,30 @@+<!DOCTYPE html>+<meta charset="utf-8">+<style>+ div {+ font: 20px sans-serif;+ width: 0;+ word-break: keep-all;+ }+</style>+<!-- Under keep-all, a run of letters breaks nowhere, the iteration marks included; punctuation still breaks. -->+<div data-name="ideographs">方方方方</div>+<div data-name="U+3005 ideographic iteration mark">方々方々</div>+<div data-name="U+309D hiragana iteration mark">こゝろゝ</div>+<div data-name="U+309E hiragana voiced iteration mark">みゞかゞ</div>+<div data-name="U+30FD katakana iteration mark">コヽロヽ</div>+<div data-name="U+30FE katakana voiced iteration mark">ミヾカヾ</div>+<div data-name="U+303B vertical ideographic iteration mark">方〻方〻</div>+<div data-name="U+30FB katakana middle dot">方・方・</div>+<div data-name="U+3002 ideographic full stop">方。方。</div>+<script src="include.js"></script>+<script>+ test(() => {+ const range = document.createRange();+ for (const div of document.querySelectorAll("div")) {+ range.selectNodeContents(div);+ const lines = new Set([...range.getClientRects()].map(rect => Math.round(rect.top))).size;+ println(`${div.dataset.name}: ${lines === 1 ? "kept on one line" : "broken"}`);+ }+ });+</script>