summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/typst-layout/src/inline/linebreak.rs25
-rw-r--r--tests/ref/issue-5489-matrix-stray-linebreak.pngbin0 -> 644 bytes
-rw-r--r--tests/suite/layout/inline/linebreak.typ8
3 files changed, 31 insertions, 2 deletions
diff --git a/crates/typst-layout/src/inline/linebreak.rs b/crates/typst-layout/src/inline/linebreak.rs
index 31512604..ada048c7 100644
--- a/crates/typst-layout/src/inline/linebreak.rs
+++ b/crates/typst-layout/src/inline/linebreak.rs
@@ -690,13 +690,34 @@ fn breakpoints(p: &Preparation, mut f: impl FnMut(usize, Breakpoint)) {
let breakpoint = if point == text.len() {
Breakpoint::Mandatory
} else {
+ const OBJ_REPLACE: char = '\u{FFFC}';
match lb.get(c) {
- // Fix for: https://github.com/unicode-org/icu4x/issues/4146
- LineBreak::Glue | LineBreak::WordJoiner | LineBreak::ZWJ => continue,
LineBreak::MandatoryBreak
| LineBreak::CarriageReturn
| LineBreak::LineFeed
| LineBreak::NextLine => Breakpoint::Mandatory,
+
+ // https://github.com/typst/typst/issues/5489
+ //
+ // OBJECT-REPLACEMENT-CHARACTERs provide Contingent Break
+ // opportunities before and after by default. This behaviour
+ // is however tailorable, see:
+ // https://www.unicode.org/reports/tr14/#CB
+ // https://www.unicode.org/reports/tr14/#TailorableBreakingRules
+ // https://www.unicode.org/reports/tr14/#LB20
+ //
+ // Don't provide a line breaking opportunity between a LTR-
+ // ISOLATE (or any other Combining Mark) and an OBJECT-
+ // REPLACEMENT-CHARACTER representing an inline item, if the
+ // LTR-ISOLATE could end up as the only character on the
+ // previous line.
+ LineBreak::CombiningMark
+ if text[point..].starts_with(OBJ_REPLACE)
+ && last + c.len_utf8() == point =>
+ {
+ continue;
+ }
+
_ => Breakpoint::Normal,
}
};
diff --git a/tests/ref/issue-5489-matrix-stray-linebreak.png b/tests/ref/issue-5489-matrix-stray-linebreak.png
new file mode 100644
index 00000000..2d278bd5
--- /dev/null
+++ b/tests/ref/issue-5489-matrix-stray-linebreak.png
Binary files differ
diff --git a/tests/suite/layout/inline/linebreak.typ b/tests/suite/layout/inline/linebreak.typ
index e4b04b24..86a90025 100644
--- a/tests/suite/layout/inline/linebreak.typ
+++ b/tests/suite/layout/inline/linebreak.typ
@@ -139,3 +139,11 @@ Some texts feature many longer
words. Those are often exceedingly
challenging to break in a visually
pleasing way.
+
+--- issue-5489-matrix-stray-linebreak ---
+#table(
+ columns: (70pt,) * 1,
+ align: horizon + center,
+ stroke: 0.6pt,
+ [$mat(2241/2210,-71/1105;-71/1105,147/1105)$],
+)