Skip to content

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.rs
index 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.rs
index 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.txt
new file mode 100644
index 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: broken
diff --git a/Tests/LibWeb/Text/input/word-break-keep-all-iteration-marks.html b/Tests/LibWeb/Text/input/word-break-keep-all-iteration-marks.html
new file mode 100644
index 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">&#x65B9;&#x65B9;&#x65B9;&#x65B9;</div>
+<div data-name="U+3005 ideographic iteration mark">&#x65B9;&#x3005;&#x65B9;&#x3005;</div>
+<div data-name="U+309D hiragana iteration mark">&#x3053;&#x309D;&#x308D;&#x309D;</div>
+<div data-name="U+309E hiragana voiced iteration mark">&#x307F;&#x309E;&#x304B;&#x309E;</div>
+<div data-name="U+30FD katakana iteration mark">&#x30B3;&#x30FD;&#x30ED;&#x30FD;</div>
+<div data-name="U+30FE katakana voiced iteration mark">&#x30DF;&#x30FE;&#x30AB;&#x30FE;</div>
+<div data-name="U+303B vertical ideographic iteration mark">&#x65B9;&#x303B;&#x65B9;&#x303B;</div>
+<div data-name="U+30FB katakana middle dot">&#x65B9;&#x30FB;&#x65B9;&#x30FB;</div>
+<div data-name="U+3002 ideographic full stop">&#x65B9;&#x3002;&#x65B9;&#x3002;</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>