From 0e86f3597a7443b15c93ec3ab2091202f8802c95 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Tue, 3 Nov 2026 00:13:48 -0500 Subject: [PATCH] M4: wrap style on a text layer: Auto, Balance and Pretty decide where its lines break (#1827) (#1871) * M4: wrap style on a text layer: Auto, Balance and Pretty decide where its lines break (#1827) Co-Authored-By: Claude Fable 5.1 * Docs: no table pipe inside the wrap-style row's code span Co-Authored-By: Claude Fable 5.1 * Wrap styles: no new emergency breaks, hanging punctuation in Pretty's width, wrap style as an override Balance and Pretty reject a re-break with more mid-word breaks than the greedy lines; Pretty narrows a line by its text less its hanging marks; wrapStyle joins the textStyle override group; docs wording. Tests. Co-Authored-By: Claude Fable 5.1 --------- Co-authored-by: Claude Fable 5.1 Co-authored-by: Brandon Thomas --- crates/doc/src/text.rs | 20 ++ crates/engine/src/assets/components/diff.rs | 1 + .../engine/src/assets/components/instances.rs | 1 + crates/engine/src/automation/inspect.rs | 4 + crates/engine/src/cmd/props.rs | 5 +- crates/engine/src/cmd/text.rs | 11 + .../engine/src/components_behaviour_tests.rs | 9 + crates/engine/src/dev/codegen/css.rs | 5 + crates/engine/src/dev/tailwind.rs | 2 + crates/engine/src/text_behaviour_tests.rs | 66 +++++ crates/text/src/layout.rs | 236 +++++++++++++++++- crates/ui-egui/locales/en.toml | 6 + .../ui-egui/src/panels/typography/fields.rs | 12 + docs/ui-parity.md | 4 +- 14 files changed, 372 insertions(+), 10 deletions(-) diff --git a/crates/doc/src/text.rs b/crates/doc/src/text.rs index 0c41d3c9a..ba196edb3 100644 --- a/crates/doc/src/text.rs +++ b/crates/doc/src/text.rs @@ -234,6 +234,22 @@ pub enum LeadingTrim { CapHeight, } +/// Where lines break when text wraps to more than one line ("Wrap style controls where lines +/// break when text wraps to more than one line", Explore text properties). +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub enum WrapStyle { + /// "Figma fits as many words as possible on each line before wrapping to the next." + #[default] + Auto, + /// "Figma distributes text as evenly as possible across every line, so each line is close to + /// the same length." + Balance, + /// "Figma keeps each line full, but adjusts the last four lines to avoid an orphan -- a single + /// word stranded alone on the last line." + Pretty, +} + #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub enum ListStyle { @@ -466,6 +482,10 @@ pub struct TextData { /// as fit). #[serde(skip_serializing_if = "crate::node::is_default")] pub max_lines: u32, + /// Where lines break when the text wraps: greedily (Auto), as evenly as the words allow + /// (Balance), or full with no one word alone on the last line (Pretty). + #[serde(skip_serializing_if = "crate::node::is_default")] + pub wrap_style: WrapStyle, /// OpenType feature toggles (e.g. "liga": false). #[serde(skip_serializing_if = "crate::node::is_default")] pub features: std::collections::BTreeMap, diff --git a/crates/engine/src/assets/components/diff.rs b/crates/engine/src/assets/components/diff.rs index 41c1a4246..5c6b7e4c5 100644 --- a/crates/engine/src/assets/components/diff.rs +++ b/crates/engine/src/assets/components/diff.rs @@ -132,6 +132,7 @@ fn text_style_differs(x: &TextData, y: &TextData) -> bool { || x.hanging_list != y.hanging_list || x.max_lines != y.max_lines || x.features != y.features + || x.wrap_style != y.wrap_style } /// Whether a geometry change of `id` comes from layout rather than the user: an ancestor was diff --git a/crates/engine/src/assets/components/instances.rs b/crates/engine/src/assets/components/instances.rs index e7b3114ad..9e596e8eb 100644 --- a/crates/engine/src/assets/components/instances.rs +++ b/crates/engine/src/assets/components/instances.rs @@ -160,6 +160,7 @@ pub(crate) fn copy_group(from: &Node, to: &mut Node, g: &str) { b.hanging_list = a.hanging_list; b.max_lines = a.max_lines; b.features = a.features.clone(); + b.wrap_style = a.wrap_style; } to.styles.text = from.styles.text.clone(); } diff --git a/crates/engine/src/automation/inspect.rs b/crates/engine/src/automation/inspect.rs index ca3afa1ce..871dbea6f 100644 --- a/crates/engine/src/automation/inspect.rs +++ b/crates/engine/src/automation/inspect.rs @@ -103,6 +103,7 @@ pub const NODE_KEYS: &[&str] = &[ "visible", "width", "widthProfile", + "wrapStyle", "x", "y", ]; @@ -442,6 +443,9 @@ fn text_props(t: &TextData, o: &mut serde_json::Map, options: &In if t.leading_trim != figcraft_doc::LeadingTrim::None { insert_prop(o, options, "leadingTrim", || json!(t.leading_trim)); } + if t.wrap_style != figcraft_doc::WrapStyle::Auto { + insert_prop(o, options, "wrapStyle", || json!(t.wrap_style)); + } if !t.runs.is_empty() { insert_prop(o, options, "styledRuns", || serde_json::to_value(&t.runs).unwrap_or(Value::Null)); } diff --git a/crates/engine/src/cmd/props.rs b/crates/engine/src/cmd/props.rs index 96c9fa922..36e33dd79 100644 --- a/crates/engine/src/cmd/props.rs +++ b/crates/engine/src/cmd/props.rs @@ -961,6 +961,9 @@ fn apply_text(cmd: &str, doc: &mut Document, id: NodeId, props: &Map text_mut(cmd, doc.get_mut(id)?)?.leading_trim = enum_of(v).ok_or_else(|| bad(cmd, "leadingTrim: none|capHeight"))?, + "wrapStyle" | "textWrap" => { + text_mut(cmd, doc.get_mut(id)?)?.wrap_style = enum_of(v).ok_or_else(|| bad(cmd, "wrapStyle: auto|balance|pretty"))? + } "maxLines" => { let lines = f64_of(v).unwrap_or(0.0).clamp(0.0, 10_000.0) as u32; let n = doc.get_mut(id)?; @@ -1205,7 +1208,7 @@ pub fn override_group(k: &str) -> &'static str { "name" => "name", "characters" | "text" => "characters", "features" | "fontFeatures" | "openTypeFeatures" | "listStyle" | "indentation" | "listSpacing" | "maxLines" | "variationSettings" - | "hangingPunctuation" | "hangingList" => "textStyle", + | "hangingPunctuation" | "hangingList" | "wrapStyle" | "textWrap" => "textStyle", "cornerRadius" | "cornerSmoothing" | "topLeftRadius" | "topRightRadius" | "bottomRightRadius" | "bottomLeftRadius" => "corners", "width" | "height" | "w" | "h" => "size", "sizingH" | "sizingV" | "layoutSizingHorizontal" | "layoutSizingVertical" | "minWidth" | "maxWidth" | "minHeight" | "maxHeight" => "resizing", diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs index f72f215ee..7914f259e 100644 --- a/crates/engine/src/cmd/text.rs +++ b/crates/engine/src/cmd/text.rs @@ -308,6 +308,17 @@ pub fn specs() -> Vec { set_list(s, p, l, false) } ), + spec!( + "text.wrapStyle", + "Wrap style", + "{style: auto|balance|pretty, ids?} where lines break when the text wraps: Auto fits as many words as fit on each line, Balance makes the lines close to the same length, Pretty keeps lines full but leaves no one word alone on the last", + true, + |s, p| { + let w: figcraft_doc::WrapStyle = + get(p, "style").and_then(super::props::enum_of).ok_or_else(|| bad("text.wrapStyle", "`style`: auto|balance|pretty"))?; + para(s, p, |t| t.wrap_style = w) + } + ), spec!("text.paragraphIndent", "Paragraph indent", "{indent (px), ids?}", true, |s, p| { let v = finite(req_num("text.paragraphIndent", p, "indent")?).clamp(0.0, 10_000.0); para(s, p, |t| t.paragraph_indent = v) diff --git a/crates/engine/src/components_behaviour_tests.rs b/crates/engine/src/components_behaviour_tests.rs index 6d5a7ebcb..3458b0b22 100644 --- a/crates/engine/src/components_behaviour_tests.rs +++ b/crates/engine/src/components_behaviour_tests.rs @@ -338,6 +338,15 @@ fn overridable_properties_stay_through_main_edits_and_reset() { |n| text(n).paragraph_spacing.to_string(), "a text property like the others", ), + ( + "wrap style", + Layer::Title, + "textStyle", + json!({"wrapStyle": "balance"}), + Some(json!({"wrapStyle": "pretty"})), + |n| format!("{:?}", text(n).wrap_style), + "a text property like the others (#1827)", + ), ( "padding", Layer::Row, diff --git a/crates/engine/src/dev/codegen/css.rs b/crates/engine/src/dev/codegen/css.rs index eb9406f2a..2395c7873 100644 --- a/crates/engine/src/dev/codegen/css.rs +++ b/crates/engine/src/dev/codegen/css.rs @@ -302,6 +302,11 @@ fn text_decls(doc: &Document, n: &Node, tx: &figcraft_doc::TextData, t: &mut Tok TextAlignH::Right => put("text-align", "right".into()), TextAlignH::Justified => put("text-align", "justify".into()), } + match tx.wrap_style { + figcraft_doc::WrapStyle::Auto => {} + figcraft_doc::WrapStyle::Balance => put("text-wrap", "balance".into()), + figcraft_doc::WrapStyle::Pretty => put("text-wrap", "pretty".into()), + } match s.case { TextCase::Original => {} TextCase::Upper => put("text-transform", "uppercase".into()), diff --git a/crates/engine/src/dev/tailwind.rs b/crates/engine/src/dev/tailwind.rs index 70a562a9c..8279ef9ce 100644 --- a/crates/engine/src/dev/tailwind.rs +++ b/crates/engine/src/dev/tailwind.rs @@ -310,6 +310,8 @@ fn decl(key: &str, value: &str) -> Vec<(String, String)> { ("text-transform", "uppercase") => kw("uppercase"), ("text-transform", "lowercase") => kw("lowercase"), ("text-transform", "capitalize") => kw("capitalize"), + ("text-wrap", "balance") => kw("text-balance"), + ("text-wrap", "pretty") => kw("text-pretty"), ("text-decoration", "underline") => kw("underline"), ("text-decoration", "line-through") => kw("line-through"), _ => one(format!("[{key}:{}]", arb(value).trim_matches(['[', ']']))), diff --git a/crates/engine/src/text_behaviour_tests.rs b/crates/engine/src/text_behaviour_tests.rs index bed6b3d6b..1e700c688 100644 --- a/crates/engine/src/text_behaviour_tests.rs +++ b/crates/engine/src/text_behaviour_tests.rs @@ -371,6 +371,72 @@ fn max_lines_on_auto_height_text_hugs_that_many_lines() { assert_eq!(resize_mode(&s, fixed), TextAutoResize::Truncate); } +#[test] +fn balance_and_pretty_wrap_styles_break_lines_as_documented() { + // Explore text properties: "Auto: Figma fits as many words as possible on each line before + // wrapping to the next." "Balance: Figma distributes text as evenly as possible across every + // line, so each line is close to the same length." "Pretty: Figma keeps each line full, but + // adjusts the last four lines to avoid an orphan -- a single word stranded alone on the last + // line." The synthetic font: 8 px per character at 16 px. + let font = test_mono_font(); + let mut s = Session::new(); + let t = text(&mut s, "aaa bbb ccc ddd eee", json!({"fontFamily": font, "fontSize": 16, "lineHeight": 24})); + s.execute("node.set", &json!({"id": t, "props": {"textAutoResize": "height", "width": 136}})).unwrap(); + let lines = |s: &Session| -> Vec<(usize, usize)> { + let (l, _) = figcraft_text::layout_node(s.doc().unwrap().node(t).unwrap()).unwrap(); + l.lines.iter().map(|l| (l.char_start, l.char_end)).collect() + }; + // 136 px holds 17 characters: Auto fills the first line with four words and strands the fifth. + assert_eq!(lines(&s), [(0, 16), (16, 19)]); + // Balance: as even as the words allow, three and two. + s.execute("node.set", &json!({"id": t, "props": {"wrapStyle": "balance"}})).unwrap(); + assert_eq!(lines(&s), [(0, 12), (12, 19)]); + assert_eq!(crate::inspect::node_json(s.doc().unwrap(), t, 0)["wrapStyle"], json!("balance")); + // Pretty: the stranded word gets company from the line before. + s.execute("text.wrapStyle", &json!({"ids": [t], "style": "pretty"})).unwrap(); + assert_eq!(lines(&s), [(0, 12), (12, 19)]); + // Three lines of two-letter words in a 72 px box (nine characters): Auto strands "gg"; Pretty + // narrows the line before it alone ("aa bb cc" / "dd ee" / "ff gg"); Balance's narrowest + // width that still gives three lines (64 px) fills the first two lines as Auto does. + s.execute("node.set", &json!({"id": t, "props": {"characters": "aa bb cc dd ee ff gg", "width": 72, "wrapStyle": "auto"}})).unwrap(); + assert_eq!(lines(&s), [(0, 9), (9, 18), (18, 20)]); + s.execute("node.set", &json!({"id": t, "props": {"wrapStyle": "pretty"}})).unwrap(); + assert_eq!(lines(&s), [(0, 9), (9, 15), (15, 20)]); + s.execute("node.set", &json!({"id": t, "props": {"wrapStyle": "balance"}})).unwrap(); + assert_eq!(lines(&s), [(0, 9), (9, 18), (18, 20)]); + // A last line of two words is no orphan: Pretty leaves Auto's lines; a text on one line is + // left alone whatever the style. + s.execute("node.set", &json!({"id": t, "props": {"characters": "aa bb cc dd ee ff gg hh", "wrapStyle": "pretty"}})).unwrap(); + assert_eq!(lines(&s), [(0, 9), (9, 18), (18, 23)]); + s.execute("node.set", &json!({"id": t, "props": {"width": 400, "wrapStyle": "balance"}})).unwrap(); + assert_eq!(lines(&s), [(0, 23)]); + // Dev Mode's CSS says `text-wrap` for Balance and Pretty and nothing for Auto; junk is refused. + let css = |s: &mut Session| s.execute("inspect.code", &json!({"id": t})).unwrap()["code"].as_str().unwrap().to_string(); + assert!(css(&mut s).contains("text-wrap: balance;"), "{}", css(&mut s)); + s.execute("node.set", &json!({"id": t, "props": {"wrapStyle": "pretty"}})).unwrap(); + assert!(css(&mut s).contains("text-wrap: pretty;")); + s.execute("node.set", &json!({"id": t, "props": {"wrapStyle": "auto"}})).unwrap(); + assert!(!css(&mut s).contains("text-wrap")); + assert!(s.execute("node.set", &json!({"id": t, "props": {"wrapStyle": "zigzag"}})).is_err()); + assert!(s.execute("text.wrapStyle", &json!({"ids": [t], "style": "even"})).is_err()); + // A word as wide as the box is never broken in two by Balance or Pretty: 80 px holds the ten + // letters, and every narrower width Balance could try would have to split them. + s.execute("node.set", &json!({"id": t, "props": {"characters": "abcdefghij klm", "width": 80, "wrapStyle": "balance"}})).unwrap(); + assert_eq!(lines(&s), [(0, 11), (11, 14)]); + s.execute("node.set", &json!({"id": t, "props": {"wrapStyle": "pretty"}})).unwrap(); + assert_eq!(lines(&s), [(0, 11), (11, 14)]); + // Hanging punctuation: a line starting with an opening mark has that much more room, and + // Pretty narrows it by as much, so the line before the orphan still gives a word away. + s.execute( + "node.set", + &json!({"id": t, "props": {"characters": "aa bb cc (dd ee ff gg", "width": 72, "hangingPunctuation": true, "wrapStyle": "auto"}}), + ) + .unwrap(); + assert_eq!(lines(&s), [(0, 9), (9, 19), (19, 21)]); + s.execute("node.set", &json!({"id": t, "props": {"wrapStyle": "pretty"}})).unwrap(); + assert_eq!(lines(&s), [(0, 9), (9, 16), (16, 21)]); +} + #[test] fn max_lines_on_auto_width_text_keeps_auto_width_and_hugs_that_many_lines() { // "Max lines is available only if truncate text is enabled, and: Text resizing is set to diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index 7305dac15..f2c587206 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use figcraft_doc::{ DecorationLength, DecorationStyle, LeadingTrim, LetterSpacing, LineHeight, ListStyle, ParaList, TextAlignH, TextAutoResize, TextCase, TextData, - TextDecoration, TextStyle, color::PaintKind, valid_feature_tag, + TextDecoration, TextStyle, WrapStyle, color::PaintKind, valid_feature_tag, }; use figcraft_geom::{Affine, BezPath, Rect}; use harfrust::{Direction, Feature, ShapeOptions, ShaperInstance, Tag, UnicodeBuffer, Variation}; @@ -630,7 +630,8 @@ impl SavedStarts<'_> { } } -/// The lines (item range, paragraph end, paragraph), wrapped by measure or at `saved` line starts; +/// The lines (item range, paragraph end, paragraph), wrapped to `wrap_of` (the width for each line +/// of each paragraph; None: no wrapping) or at `saved` line starts; /// None when a saved line would overflow its box by more than [`SAVED_LINE_SLACK`]. Lines break /// where [`crate::breaks::break_between`] allows, and between the words `word_breaks` marks. fn break_lines( @@ -638,7 +639,7 @@ fn break_lines( chars: &[char], cluster_start: &[bool], word_breaks: &[bool], - wrap: Option, + wrap_of: &WidthOf<'_>, line_indent_of: &impl Fn(usize, bool, usize) -> f64, rtl_para_at: &impl Fn(usize) -> bool, hang_start: bool, @@ -652,6 +653,7 @@ fn break_lines( let mut last_break: Option = None; let mut para_first_line = true; let mut para = 0; + let mut line_in_para = 0; while i < items.len() { let Some(it) = items.get(i) else { break }; if it.ch == '\n' { @@ -662,6 +664,7 @@ fn break_lines( last_break = None; para_first_line = true; para += 1; + line_in_para = 0; continue; } // A line separator (a soft break) breaks the line inside its paragraph: no @@ -673,6 +676,7 @@ fn break_lines( x = 0.0; last_break = None; para_first_line = false; + line_in_para += 1; continue; } let line_indent = line_indent_of(para, para_first_line, it.char_start); @@ -681,7 +685,7 @@ fn break_lines( let ltr = !rtl_para_at(it.char_start); let hung = items.get(line_start).filter(|f| hang_start && ltr && opens(f.ch)).map_or(0.0, |f| f.adv) + if hang_end && ltr && closes(it.ch) { w } else { 0.0 }; - if let Some(maxw) = wrap + if let Some(maxw) = wrap_of(para, line_in_para) && i > line_start && !it.is_space() { @@ -702,6 +706,7 @@ fn break_lines( x = 0.0; last_break = None; para_first_line = false; + line_in_para += 1; continue; } } @@ -721,6 +726,220 @@ fn break_lines( Some(lines) } +/// A line as [`break_lines`] gives it: item range, paragraph end, paragraph. +type LineRange = (usize, usize, bool, usize); + +/// The width a line wraps to (its paragraph, the line's index in it); None: no wrapping. +type WidthOf<'a> = dyn Fn(usize, usize) -> Option + 'a; + +/// [`break_lines`] with the widths and the saved starts to follow, the rest bound. +type Breaker<'a> = dyn Fn(&WidthOf<'_>, Option>) -> Option> + 'a; + +/// What a paragraph's lines wrap to under Balance or Pretty: the paragraph's width, and a +/// narrower one for a single line (the line Pretty has give a word away). +#[derive(Clone, Copy)] +struct ParaWidth { + width: f64, + line: Option<(usize, f64)>, +} + +/// Whether the line's text is one word: no break opportunity between its items, its trailing +/// spaces and the paragraph's line break aside. +fn single_word(items: &[Item], word_breaks: &[bool], (start, end, _, _): LineRange) -> bool { + let Some(last) = (start..end).rev().find(|&k| items.get(k).is_some_and(|it| !it.is_space() && !is_line_break(it.ch))) else { + return false; + }; + !(start..last).any(|k| { + let (Some(a), Some(b)) = (items.get(k), items.get(k + 1)) else { return false }; + crate::breaks::break_between(a.ch, b.ch) || (a.char_end <= b.char_start && word_breaks.get(b.char_start).copied().unwrap_or(false)) + }) +} + +/// How many of `lines` end inside a word: emergency breaks, made where no word boundary fitted +/// the width. Balance and Pretty never add one (a word that fits the box stays whole). +fn emergency_breaks(items: &[Item], word_breaks: &[bool], lines: &[LineRange]) -> usize { + lines + .iter() + .filter(|&&(_, end, para_end, _)| { + if para_end { + return false; + } + let (Some(a), Some(b)) = (end.checked_sub(1).and_then(|k| items.get(k)), items.get(end)) else { return false }; + !(a.is_space() + || is_line_break(a.ch) + || crate::breaks::break_between(a.ch, b.ch) + || (a.char_end <= b.char_start && word_breaks.get(b.char_start).copied().unwrap_or(false))) + }) + .count() +} + +/// What a line's hanging punctuation adds to the room [`break_lines`] gives it (its opening mark +/// at the start, its closing one at the end), so Pretty narrows a line by its text as the breaker +/// measures it. +fn hung_width(items: &[Item], (s, e, _, _): LineRange, hang_start: bool, hang_end: bool, rtl_para_at: &dyn Fn(usize) -> bool) -> f64 { + let ltr = items.get(s).is_none_or(|it| !rtl_para_at(it.char_start)); + let first = items.get(s).filter(|it| hang_start && ltr && opens(it.ch)).map_or(0.0, |it| it.adv); + let last = e.checked_sub(1).filter(|k| *k > s).and_then(|k| items.get(k)).filter(|it| hang_end && ltr && closes(it.ch)).map_or(0.0, |it| it.adv); + first + last +} + +/// The width of the line's text, its trailing spaces and line break aside, as the breaker +/// measures it. +fn line_width(items: &[Item], (start, end, _, _): LineRange) -> f64 { + let mut x = 0.0; + let mut width = 0.0; + for it in items.get(start..end).unwrap_or(&[]) { + if is_line_break(it.ch) { + break; + } + x += it.adv; + if !it.is_space() { + width = x - it.spacing; + } + } + width +} + +/// Balance and Pretty: the greedy `lines` of a box `w` wide, re-broken paragraph by paragraph. +/// Balance narrows a paragraph as far as it goes without another line, so its lines come out +/// close to the same length ("distributes text as evenly as possible across every line, so each +/// line is close to the same length"; what browsers do for `text-wrap: balance`). Pretty leaves +/// lines full but, when the last line is one word, narrows one of the last four lines just enough +/// to give a word to the lines after it ("keeps each line full, but adjusts the last four lines to +/// avoid an orphan"). `rebreak` lays the text out again with a width per paragraph and line. +fn restyle_breaks( + style: WrapStyle, + w: f64, + lines: Vec, + items: &[Item], + word_breaks: &[bool], + line_indent_of: &dyn Fn(usize, bool, usize) -> f64, + hung_of: &dyn Fn(LineRange) -> f64, + rebreak: &dyn Fn(&WidthOf<'_>) -> Vec, +) -> Vec { + let paragraphs = lines.last().map_or(0, |l| l.3 + 1); + // Every pass lays the whole text out again: a very long text keeps its greedy lines. + if items.len().saturating_mul(paragraphs) > 2_000_000 { + return lines; + } + let mut plan = vec![ParaWidth { width: w, line: None }; paragraphs]; + // The lines with paragraph `p` wrapped to `pw` and the others as planned. + let with = |plan: &[ParaWidth], p: usize, pw: ParaWidth| { + let width_of = move |q: usize, li: usize| { + let pw = if q == p { pw } else { plan.get(q).copied().unwrap_or(ParaWidth { width: w, line: None }) }; + Some(match pw.line { + Some((j, narrow)) if li == j => narrow, + _ => pw.width, + }) + }; + rebreak(&width_of) + }; + let of = |ls: &[LineRange], p: usize| -> Vec { ls.iter().copied().filter(|l| l.3 == p).collect() }; + let mut current = lines; + for p in 0..paragraphs { + let para = of(¤t, p); + let n = para.len(); + if n < 2 { + continue; + } + // Words wider than the box break where they must; the re-breaking adds no such break. + let base = emergency_breaks(items, word_breaks, ¶); + match style { + WrapStyle::Auto => {} + WrapStyle::Balance => { + // The narrowest width that still gives `n` lines, to half a pixel. + let (mut lo, mut hi) = (0.0, w); + while hi - lo > 0.5 { + let mid = (lo + hi) / 2.0; + let ls = of(&with(&plan, p, ParaWidth { width: mid, line: None }), p); + if ls.len() == n && emergency_breaks(items, word_breaks, &ls) <= base { + hi = mid; + } else { + lo = mid; + } + } + let pw = ParaWidth { width: hi, line: None }; + current = with(&plan, p, pw); + if let Some(slot) = plan.get_mut(p) { + *slot = pw; + } + } + WrapStyle::Pretty => { + if !para.last().is_some_and(|l| single_word(items, word_breaks, *l)) { + continue; + } + // The line before the last, back to the fourth from the end: narrowed to just under + // its text, its last word goes to the lines after it (which stay full); a word or + // two more if the last line is still alone. A line that would rather start another + // line can't give a word away. + 'lines: for j in (n.saturating_sub(4)..n - 1).rev() { + let Some(&line) = para.get(j) else { continue }; + let indent = line_indent_of(p, j == 0, items.get(line.0).map_or(0, |it| it.char_start)); + let mut narrow = line_width(items, line) - hung_of(line); + for _ in 0..3 { + narrow -= 0.5; + if narrow <= 0.0 { + break; + } + let pw = ParaWidth { width: w, line: Some((j, narrow + indent)) }; + let ls = with(&plan, p, pw); + let after = of(&ls, p); + if after.len() != n || emergency_breaks(items, word_breaks, &after) > base { + break; + } + if !after.last().is_some_and(|l| single_word(items, word_breaks, *l)) { + current = ls; + if let Some(slot) = plan.get_mut(p) { + *slot = pw; + } + break 'lines; + } + narrow = after.get(j).map_or(0.0, |l| line_width(items, *l) - hung_of(*l)); + } + } + } + } + } + current +} + +/// Pins a breaking closure to the signature [`wrapped_lines`] takes: a closure whose parameter +/// borrows a trait object is otherwise inferred for one lifetime, not any. +fn breaker(f: F) -> F +where + F: Fn(&WidthOf<'_>, Option>) -> Option>, +{ + f +} + +/// The lines of a text wrapped to `wrap`: the file's saved breaks while they hold, else greedy +/// ones, re-broken for Balance or Pretty. `breaks` runs [`break_lines`] with a width per line and +/// the saved starts to follow. +fn wrapped_lines( + text: &TextData, + wrap: Option, + items: &[Item], + word_breaks: &[bool], + line_indent_of: &dyn Fn(usize, bool, usize) -> f64, + hung_of: &dyn Fn(LineRange) -> f64, + breaks: &Breaker<'_>, +) -> Vec { + // Where the file saved its line breaks, they win while the text and box are as saved. + let saved = wrap.and_then(|w| text.saved_breaks_for(w)).map(|starts| SavedStarts { starts, next: 0 }); + let from_saved = saved.and_then(|s| breaks(&|_, _| wrap, Some(s))); + let followed = from_saved.is_some(); + let lines = from_saved.or_else(|| breaks(&|_, _| wrap, None)).unwrap_or_default(); + // Balance and Pretty re-break the paragraphs at narrower widths (never saved breaks). + match wrap { + Some(w) if !followed && text.wrap_style != WrapStyle::Auto => { + restyle_breaks(text.wrap_style, w, lines, items, word_breaks, line_indent_of, hung_of, &|wrap_of| { + breaks(wrap_of, None).unwrap_or_default() + }) + } + _ => lines, + } +} + #[derive(Clone, Copy)] struct LayoutFinish<'a> { text: &'a TextData, @@ -970,10 +1189,11 @@ pub fn layout(text: &TextData, box_width: Option, box_height: Option) TextAutoResize::WidthAndHeight => None, _ => box_width.filter(|w| w.is_finite() && *w > 0.0), }; - let breaks = |saved| break_lines(&items, &chars, &cluster_start, &word_breaks, wrap, &line_indent_of, &rtl_para_at, hang_start, hang_end, saved); - // Where the file saved its line breaks, they win while the text and box are as saved. - let saved = wrap.and_then(|w| text.saved_breaks_for(w)).map(|starts| SavedStarts { starts, next: 0 }); - let lines = saved.and_then(|s| breaks(Some(s))).or_else(|| breaks(None)).unwrap_or_default(); + let breaks = breaker(|wrap_of, saved| { + break_lines(&items, &chars, &cluster_start, &word_breaks, wrap_of, &line_indent_of, &rtl_para_at, hang_start, hang_end, saved) + }); + let hung_of = |l: LineRange| hung_width(&items, l, hang_start, hang_end, &rtl_para_at); + let lines = wrapped_lines(text, wrap, &items, &word_breaks, &line_indent_of, &hung_of, &breaks); // Line metrics and positions. let default_style = styles.first().cloned().unwrap_or_default(); let default_face = faces.first().cloned().flatten(); diff --git a/crates/ui-egui/locales/en.toml b/crates/ui-egui/locales/en.toml index a23c281ba..11f0bb4ac 100644 --- a/crates/ui-egui/locales/en.toml +++ b/crates/ui-egui/locales/en.toml @@ -406,6 +406,12 @@ name = "English" "Decoration style" = "Decoration style" "Decoration" = "Decoration" "Deep select" = "Deep select" +"Wrap style" = "Wrap style" +"Balance" = "Balance" +"Pretty" = "Pretty" +"Auto: as many words as fit on each line" = "Auto: as many words as fit on each line" +"Balance: every line close to the same length" = "Balance: every line close to the same length" +"Pretty: full lines, no one word alone on the last" = "Pretty: full lines, no one word alone on the last" "Set hug contents" = "Set hug contents" "Set fill container" = "Set fill container" "Double-click an edge of an auto layout frame" = "Double-click an edge of an auto layout frame" diff --git a/crates/ui-egui/src/panels/typography/fields.rs b/crates/ui-egui/src/panels/typography/fields.rs index cd3c485c3..20b9d8e90 100644 --- a/crates/ui-egui/src/panels/typography/fields.rs +++ b/crates/ui-egui/src/panels/typography/fields.rs @@ -385,6 +385,18 @@ fn type_settings( if let Some(i) = text_seg(ui, "trim", &items, trim, w) { app.set_props(ids, json!({"leadingTrim": if i == 1 { "capHeight" } else { "none" }})); } + // Where lines break when the text wraps (Explore text properties). + caption(ui, tr("Wrap style")); + let wrap = common(doc, ids, |n| n.kind.text().map(|t| t.wrap_style as usize)).flatten(); + let items = [ + (tr("Auto"), tr_noop("Auto: as many words as fit on each line")), + (tr("Balance"), tr_noop("Balance: every line close to the same length")), + (tr("Pretty"), tr_noop("Pretty: full lines, no one word alone on the last")), + ]; + if let Some(i) = text_seg(ui, "wrap", &items, wrap, w) { + let style = ["auto", "balance", "pretty"].get(i).copied().unwrap_or("auto"); + app.set_props(ids, json!({"wrapStyle": style})); + } let resize = common(doc, ids, |n| n.kind.text().map(|t| t.auto_resize)).flatten(); // Auto-height text with a line limit truncates too. let truncating = common(doc, ids, |n| n.kind.text().map(TextData::truncates)).flatten(); diff --git a/docs/ui-parity.md b/docs/ui-parity.md index f5966f334..cc0fc9db8 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI and interaction parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-02 · **Change:** patch (a click with the Bend tool on a sharp point curves it, its handles along the line between its neighbours, as Edit vector layers says (#1875); Backspace or Delete at the start of a list item keeps the item's indentation level, as the lists article says; max lines on auto-width text keep it auto width, hugging that many lines, as the text properties article says; superscript and subscript are synthesised where the font has no glyphs for them, from the standard glyphs shrunk and shifted by the font's OS/2 metrics, and a run mixing available and unavailable glyphs is synthesised whole, as Explore text properties says (#1828); Alt+Enter while editing text opens the link at the caret, as the accessibility page documents; Minimize, by its shortcut or the button by the file name, collapses the navigation bar and both sidebars as the help center says, with the right sidebar back while something is selected (#1835); the interface size keys of the help center's accessibility page: Cmd/Ctrl+Shift+Alt with =, - and 0 step the interface through the Preferences sizes and back to the system's size; Cmd/Ctrl+Alt+arrows rotate the selection a degree at a time, 15 with Shift, as the help center's accessibility page says; they resized before; the Layers panel answers Ctrl+1 as well as Alt+1 on Windows and Linux, the two keys the help center gives it; the colour picker's Image tab shows a placeholder and Upload from computer, an asset preview, and a file dropped on it replaces the image, keeping the fill mode, crop and position (#1682); the keyboard's Menu key opens the context menu, as Shift+F10 does; the eyedropper with Cmd/Ctrl+Shift makes a colour style or variable of what it picks; sidebar number and text fields keep their text vertically centered when focused, including typography spacing; with the pen out, Enter or a double-click ends the path and edits the vector with the Move tool instead of drawing on (#1430); the Actions palette offers only commands that run from it, and no second row reading like a menu item: Place image opens the file dialog (#1574); Preferences ▸ Scroll wheel zoom: a mouse wheel zooms the canvas about the pointer and Cmd/Ctrl+wheel scrolls (#1390); boolean operations refuse input past their caps, and a boolean group past them draws without its result (#1104); the selection and hover outlines of rounded rectangles and frames follow their corners (#1506); colour picker review fixes for text undo, fitted sidebars, moving controls and gradient variables; Corner smoothing: an original icon and the shared number-field drag gesture, preserving fractional baselines; guides snap to layers when dragged; Crop image: Object ▸ Crop image, the right-click menu and the image fill row enter crop mode (`image.crop`, #1464); the Design panel's sections on one grid — 16 / 8 margins, 88 + 8 + 88 + 8 + 24 columns, 24 pt rows, 4 pt between a row's buttons (#858); the toolbar on one 32 pt grid, without its Resources button (#1210); colour picker LCH and OKLCH models; an XML (Android Vector Drawable) export format; Context menus: the Menu key reaches egui 0.37 but is unbound (row done → partial); the Text on a path tool; board tool keys pinned; community fixes: the text box by dragging, the font picker keys, the pen path on leaving Design, a still canvas in vector edit mode, a scrolling pages list, colour emoji, readable new text in frames, system theme on first run; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths; fields select their text on focus; Typography spacing icons support scrubbing (#373); CSS colour names in hex fields; a rename selects the whole name, so typing replaces it; Escape or Enter after a pen path stays on the same vector (#760); IME composition kept on through idle frames of a text edit, candidates at the caret (#747); Selection colors for mixed selections and smart-selection spacing (#753); submenus with a hover delay and a safe triangle; the Actions palette's tabs, ranked search, highlight and recents; menu items that ask for a value; editor fixes from the community batches) · **Target:** Figma Design UI3 (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-02 · **Change:** minor (a click with the Bend tool on a sharp point curves it, its handles along the line between its neighbours, as Edit vector layers says (#1875); wrap style: Auto, Balance and Pretty on a text layer decide where its lines break, as Explore text properties says (#1827), with the Type settings control, `text.wrapStyle`, `node.set wrapStyle`, inspect and the CSS `text-wrap`; Backspace or Delete at the start of a list item keeps the item's indentation level, as the lists article says; max lines on auto-width text keep it auto width, hugging that many lines, as the text properties article says; superscript and subscript are synthesised where the font has no glyphs for them, from the standard glyphs shrunk and shifted by the font's OS/2 metrics, and a run mixing available and unavailable glyphs is synthesised whole, as Explore text properties says (#1828); Alt+Enter while editing text opens the link at the caret, as the accessibility page documents; Minimize, by its shortcut or the button by the file name, collapses the navigation bar and both sidebars as the help center says, with the right sidebar back while something is selected (#1835); the interface size keys of the help center's accessibility page: Cmd/Ctrl+Shift+Alt with =, - and 0 step the interface through the Preferences sizes and back to the system's size; Cmd/Ctrl+Alt+arrows rotate the selection a degree at a time, 15 with Shift, as the help center's accessibility page says; they resized before; the Layers panel answers Ctrl+1 as well as Alt+1 on Windows and Linux, the two keys the help center gives it; the colour picker's Image tab shows a placeholder and Upload from computer, an asset preview, and a file dropped on it replaces the image, keeping the fill mode, crop and position (#1682); the keyboard's Menu key opens the context menu, as Shift+F10 does; the eyedropper with Cmd/Ctrl+Shift makes a colour style or variable of what it picks; sidebar number and text fields keep their text vertically centered when focused, including typography spacing; with the pen out, Enter or a double-click ends the path and edits the vector with the Move tool instead of drawing on (#1430); the Actions palette offers only commands that run from it, and no second row reading like a menu item: Place image opens the file dialog (#1574); Preferences ▸ Scroll wheel zoom: a mouse wheel zooms the canvas about the pointer and Cmd/Ctrl+wheel scrolls (#1390); boolean operations refuse input past their caps, and a boolean group past them draws without its result (#1104); the selection and hover outlines of rounded rectangles and frames follow their corners (#1506); colour picker review fixes for text undo, fitted sidebars, moving controls and gradient variables; Corner smoothing: an original icon and the shared number-field drag gesture, preserving fractional baselines; guides snap to layers when dragged; Crop image: Object ▸ Crop image, the right-click menu and the image fill row enter crop mode (`image.crop`, #1464); the Design panel's sections on one grid — 16 / 8 margins, 88 + 8 + 88 + 8 + 24 columns, 24 pt rows, 4 pt between a row's buttons (#858); the toolbar on one 32 pt grid, without its Resources button (#1210); colour picker LCH and OKLCH models; an XML (Android Vector Drawable) export format; Context menus: the Menu key reaches egui 0.37 but is unbound (row done → partial); the Text on a path tool; board tool keys pinned; community fixes: the text box by dragging, the font picker keys, the pen path on leaving Design, a still canvas in vector edit mode, a scrolling pages list, colour emoji, readable new text in frames, system theme on first run; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths; fields select their text on focus; Typography spacing icons support scrubbing (#373); CSS colour names in hex fields; a rename selects the whole name, so typing replaces it; Escape or Enter after a pen path stays on the same vector (#760); IME composition kept on through idle frames of a text edit, candidates at the caret (#747); Selection colors for mixed selections and smart-selection spacing (#753); submenus with a hover delay and a safe triangle; the Actions palette's tabs, ranked search, highlight and recents; menu items that ask for a value; editor fixes from the community batches) · **Target:** Figma Design UI3 (desktop app 126.10.7) Fine canvas control is what Figma users feel first: handles, snapping, nudging, modifier keys, drag behaviour, numeric precision. This checklist covers the tools, gestures and panels. Status: @@ -90,6 +90,7 @@ interaction feel not yet compared. | Shape builder (Shift+M) on fills, strokes and open paths; variable width (Shift+W), one side with Alt | done | | | Boolean groups: clicked where the result is, double-click or Cmd/Ctrl-click into operands, live results while dragging or editing points, per-operand operations | done | a group past the path operations' caps (250 000 segments, 2 million possible crossings, 4 million segments swept over a fold) draws without its result, with a warning, and Flatten refuses it (#1104) | | Text: point, auto height, fixed; caret, words, lines, IME | done | Backspace or Delete at the start of a list item takes its marker and keeps its level, the paragraph starting where the item's text did ("delete the counter, but keep the same level of indentation", Create bulleted and numbered lists; `text_tail_tests::list_keys_at_list_items`, text crate `behaviour_tests`); max lines on auto-width text keep it auto width, hugging up to that many lines and growing with its longest line ("Text resizing is set to auto height or auto width", Explore text properties; `text_behaviour_tests::max_lines_on_auto_width_text_keeps_auto_width_and_hugs_that_many_lines`); Alt+Enter while editing opens the link at the caret, web and mail links only (`text.openLink`; "press ⌥Option Return/Alt Enter to activate a focused link", Accessibility at Figma; `text_link_tests`); the font picker previews a family on the canvas while hovered (no undo step; Escape restores, #653) and Up/Down step through it (#352); a selection highlight after a line break starts at that line's start and an empty last line shows its mark (#665); carets step over whole emoji and accented letters; colour emoji draw from their colour tables (#300); IME composition replayed in tests as macOS sends it, not yet checked on a Mac (#747); CJK words by script run (no dictionary); vertical trim in Type settings; no spell check | +| Text: wrap style (Auto, Balance, Pretty) | done | per text layer (`wrapStyle` on `node.set`, `text.wrapStyle`, the Type settings control under Vertical trim, inspect, CSS `text-wrap: balance` or `pretty`): Auto breaks greedily; Balance narrows each paragraph as far as it goes without another line, so its lines come out close to the same length (what browsers do for `text-wrap: balance`); Pretty keeps lines full and, when the last line is one word, narrows one of the last four lines just enough to give a word to the lines after it (Explore text properties: "Auto: Figma fits as many words as possible on each line before wrapping to the next", "Balance: Figma distributes text as evenly as possible across every line, so each line is close to the same length", "Pretty: Figma keeps each line full, but adjusts the last four lines to avoid an orphan"). Saved line breaks from a file still win. Not yet included: per-paragraph settings, text-style support and the `.fig` import/export mapping (#1827). Test: `text_behaviour_tests::balance_and_pretty_wrap_styles_break_lines_as_documented` | | Text: superscript and subscript | done | `sups` / `subs` use the font's own glyphs where it has the feature and every letter or digit of the run gets one; otherwise the standard glyphs are drawn shrunk and raised or lowered by the font's OS/2 superscript and subscript metrics (0.65 em at 0.35 em up or 0.14 em down without them), and a run mixing available and unavailable glyphs is synthesised whole, as Explore text properties says ("Figma draws a synthesized version by using the font's standard version of the character, shrinking it, and positioning it accordingly"; mixed glyphs "all update to the synthesized form for consistency"), #1828; tests `text::tests::superscript_native_or_synthesised_and_never_mixed`, `text_behaviour_tests::superscript_and_subscript_are_synthesised_without_glyphs_for_them` | | Eyedropper (I) | done | picks the colour seen under the pointer (opaque) into the selection's fill and the recent colours, one undo step (`fx_behaviour_tests`); with Cmd/Ctrl+Shift held it makes a colour style or variable of it instead, as the reference app's eyedropper does: a Create from color window asks which, its name (the next free "Color n") and a variable's collection (the file's first, or a new one made with it in the same undo step), and leaves the selection's fills alone (`eyedropper_create_tests`, `sampled_color_tests`) | | Comment (C), Shift+C to show/hide | done | local only | @@ -178,6 +179,7 @@ in the table. `crates/ui-egui/src/shortcut_keys_tests.rs` drives the keys a look | Date | Change | Summary | |---|---|---| | 2026-11-02 | patch | M8, #1875: a click with the Bend tool on a sharp point between two segments gives it handles along the line between its neighbours, a third of the way to each ("Click on a point or path where you want to add a curve", Edit vector layers); a click on a curved point still makes it sharp, a drag still sets the handles by hand, an endpoint is left alone. Between a handle's end and a point both within reach of the pointer, the nearer one on the page is hit (the handle on a tie), so a short path's point (its handles a few pixels long) can be clicked again. Before, only a drag curved a point, and a short one left two tiny handles in its direction. Tests: `vectoredit::tests::short_handles_leave_their_point_clickable`, `vectoredit::tests::a_bend_click_curves_a_sharp_point_between_its_neighbours`, `bend_tool_smooths_and_sharpens_points`. Numbers unchanged. | +| 2026-11-02 | minor | M4, #1827: wrap style on a text layer (`WrapStyle`: Auto, Balance, Pretty): Balance re-breaks each paragraph at the narrowest width that keeps its line count (bisection over the greedy breaker, as browsers balance), Pretty narrows one of the last four lines just enough so the last line isn't one word; `text.wrapStyle`, `node.set wrapStyle` (`textWrap` too), inspect `wrapStyle`, Dev Mode CSS `text-wrap` (Tailwind `text-balance` / `text-pretty`), the Type settings control under Vertical trim. Per-paragraph settings, text-style support and the `.fig` import/export mapping stay open. Test: `text_behaviour_tests::balance_and_pretty_wrap_styles_break_lines_as_documented`. | | 2026-11-02 | patch | M4: Backspace or Delete at the start of a list item takes its marker and keeps its level ("Use Backspace or Delete at the beginning of a list item to delete the counter, but keep the same level of indentation", Create bulleted and numbered lists): a plain paragraph may now carry a list level, and the text layout starts it where that level's item text starts (the gutters stay even when no list is left). Backspace used to drop the level too, and Delete at an item's start deleted the next character. Tab on such a paragraph types a tab, as outside a list. Tests: `text_tail_tests::list_keys_at_list_items`, text crate `behaviour_tests::a_plain_paragraph_at_a_list_level_starts_where_the_items_text_does` | | 2026-11-02 | patch | M4: max lines on an auto-width text keep it auto width: the box hugs up to that many lines and still grows with its longest line ("Max lines is available only if truncate text is enabled, and: Text resizing is set to auto height or auto width", Explore text properties). `text.maxLines` turned such a text into a fixed truncating box with a stale height, so later typing no longer widened it; fixed-size text still becomes a truncating box, auto-height text hugs as before. Test: `text_behaviour_tests::max_lines_on_auto_width_text_keeps_auto_width_and_hugs_that_many_lines` | | 2026-11-02 | patch | M4, #1828: superscript and subscript synthesised where the font has no `sups` / `subs` glyphs (the standard glyph shrunk and shifted by the OS/2 metrics, the usual 0.65 em and 0.35 / 0.14 em offsets without them), and a run mixing available and unavailable glyphs synthesised whole, as Explore text properties says. Tests: `text::tests::superscript_native_or_synthesised_and_never_mixed`, `text_behaviour_tests::superscript_and_subscript_are_synthesised_without_glyphs_for_them`. |