Compare commits

..
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 0eda97fe8c #8811: the status bar's muted-ink override returns nothing
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FypgCXNomWeGUu3duixKdm
2026-12-05 08:48:41 +00:00
Martin BallandClaude Sonnet 5.5 f9ff36d67c #8811: status bar page, word count and language read in the muted ink again
Cause: the craft-ui port drew the readouts in full ink; v0.19.1 used text_dim.
Fix: set AfterInk::Muted around the readouts; craft-libs now honours it on ghost buttons
(depends on the craft-libs PR, builds after the repin).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FypgCXNomWeGUu3duixKdm
2026-12-05 04:26:00 +00:00
24 changed files with 90 additions and 482 deletions
-46
View File
@@ -3,7 +3,6 @@
use serde_json::Value;
use wordcraft_doc::math_edit::MathPos;
use wordcraft_doc::para::{NBSP, OBJ};
use wordcraft_doc::props::TextDirection;
use wordcraft_doc::{InlineObject, Paragraph, Path, Pos, StoryRef};
use wordcraft_layout::ViewMode;
@@ -114,47 +113,6 @@ fn bidi_para(s: &Session) -> bool {
/// Left/Right: with a selection and no Shift, collapse to its edge.
fn lr(s: &mut Session, v: &Value, is_left: bool) -> CmdResult {
if let Some(t) = turn(s) {
// Vertical text (#8986): Left/Right change line; top-to-bottom lines stack leftwards.
return line_step(s, v, (t == TextDirection::Down) == is_left, is_left);
}
lr_along(s, v, is_left)
}
/// The text direction at the caret when it is in turned (vertical) text.
fn turn(s: &mut Session) -> Option<TextDirection> {
let l = s.layout();
l.turn_at(&s.sel.focus, s.page_hint)
}
/// Vertical text: to the next (`next`) or previous line, at the same distance along it. With no
/// such line in the caret's flow (a table cell's only line, the last column), Left/Right step along
/// the text as they did before (`is_left`: backwards).
fn line_step(s: &mut Session, v: &Value, next: bool, is_left: bool) -> CmdResult {
let ext = extend(v);
if !ext && !s.sel.is_collapsed() {
let (a, b) = s.sel.ordered();
s.sel = Selection::caret(if next { b } else { a });
s.goal_x = None;
return sel_result(s);
}
let l = s.layout();
let from = s.sel.focus.clone();
let to = match l.turned_line(&from, s.goal_x, next, s.page_hint) {
Some((p, g)) => {
s.goal_x = Some(g);
p
}
None => return lr_along(s, v, is_left),
};
let gx = s.goal_x;
apply(s, to, ext);
s.goal_x = gx;
sel_result(s)
}
/// Left/Right as a step along the text (`is_left`: backwards).
fn lr_along(s: &mut Session, v: &Value, is_left: bool) -> CmdResult {
let ext = extend(v);
if !ext && !s.sel.is_collapsed() {
let (a, b) = s.sel.ordered();
@@ -416,10 +374,6 @@ fn para_down(s: &mut Session, p: &Pos) -> Pos {
}
fn vert(s: &mut Session, v: &Value, dir: i32) -> CmdResult {
if let Some(t) = turn(s) {
// Vertical text (#8986): Up/Down step along the line (top-to-bottom text runs down).
return lr_along(s, v, (dir < 0) == (t == TextDirection::Down));
}
let ext = extend(v);
let l = s.layout();
let from = s.sel.focus.clone();
+2 -2
View File
@@ -97,8 +97,8 @@ mod tests {
use super::*;
use crate::packs::{Backend, FixedBackend};
/// Tests that set the process-wide backend or packs directory share the dictionary test lock.
use crate::custom_dict::DICT_TEST_LOCK as LOCK;
/// Tests that set the process-wide backend take turns.
static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
/// Puts the process back to no backend and no background thread when dropped, even when
/// the test panicked.
+1 -6
View File
@@ -273,7 +273,7 @@ pub fn save_custom_dictionary(path: &Path, removed: &[String]) -> Result<(), Str
}
#[cfg(test)]
pub(crate) use tests::{DICT_TEST_LOCK, TestDir, dict_test_lock};
pub(crate) use tests::{DICT_TEST_LOCK, TestDir};
#[cfg(test)]
mod tests {
@@ -282,11 +282,6 @@ mod tests {
/// Test lock serializing tests that access the global proofing dictionary.
pub(crate) static DICT_TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
/// Acquire [`DICT_TEST_LOCK`], recovering cleanly if an earlier test panicked while holding it.
pub(crate) fn dict_test_lock() -> std::sync::MutexGuard<'static, ()> {
DICT_TEST_LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner)
}
/// RAII guard for temporary directories in dictionary tests.
pub(crate) struct TestDir(pub(crate) std::path::PathBuf);
-1
View File
@@ -300,7 +300,6 @@ mod tests {
#[test]
fn layout_drops_stale_revision_slot_but_keeps_same_revision_mode() {
let _dict_guard = crate::custom_dict::dict_test_lock();
let mut session = Session::new(Document::new());
let first = session.layout();
let first_weak = Arc::downgrade(&first);
+27 -31
View File
@@ -11890,17 +11890,19 @@ fn next_footnote_skips_endnotes() {
assert_eq!(s.sel.focus.off, 9);
}
/// Tests that read or mutate process-wide proofing dictionaries take turns through `DICT_TEST_LOCK`.
/// Tests that install a test dictionary wait for the dictionaries-folder test, which changes the
/// folder and then reads what each language reports: an install in between reports no file.
static DICTIONARIES: std::sync::Mutex<()> = std::sync::Mutex::new(());
fn dictionaries_turn() -> std::sync::MutexGuard<'static, ()> {
crate::custom_dict::dict_test_lock()
DICTIONARIES.lock().unwrap_or_else(std::sync::PoisonError::into_inner)
}
/// A tiny synthetic Polish Hunspell dictionary (written for these tests). Real dictionaries are
/// installed on the system, never bundled; every Polish test installs this same one.
fn polish_test_dictionary() -> std::sync::MutexGuard<'static, ()> {
let turn = dictionaries_turn();
fn polish_test_dictionary() {
let _turn = dictionaries_turn();
wordcraft_proof::pl::install_dictionary(POLISH_TEST_AFF, POLISH_TEST_DIC).unwrap();
turn
}
const POLISH_TEST_AFF: &str = "SET UTF-8\nTRY aioeznrwcyszżtkpdmłjlubąęgh\nMAP 2\nMAP oó\nMAP zż\nREP 2\nREP ż rz\nREP rz ż\n";
@@ -11908,10 +11910,9 @@ const POLISH_TEST_DIC: &str = "12\npłynie\nrzeka\na\nto\nwiem\nże\ntak\nw\nog
/// A tiny synthetic Portuguese Hunspell dictionary (written for these tests). Real dictionaries
/// are installed on the system, never bundled; every Portuguese test installs this same one.
fn portuguese_test_dictionary() -> std::sync::MutexGuard<'static, ()> {
let turn = dictionaries_turn();
fn portuguese_test_dictionary() {
let _turn = dictionaries_turn();
wordcraft_proof::pt::install_dictionary(PORTUGUESE_TEST_AFF, PORTUGUESE_TEST_DIC).unwrap();
turn
}
const PORTUGUESE_TEST_AFF: &str =
@@ -11986,7 +11987,7 @@ fn dictionaries_folder_option_is_saved_searched_and_reported() {
/// grammar, suggestions come from it, and a suggestion fixes the text.
#[test]
fn portuguese_proofing_through_the_review_commands() {
let _turn = portuguese_test_dictionary();
portuguese_test_dictionary();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Saudade coraçao, e ele ele disse."}));
// English by default: the Portuguese words are English misspellings.
@@ -12017,10 +12018,9 @@ fn portuguese_proofing_through_the_review_commands() {
assert_eq!(left.as_array().unwrap().len(), 1, "{left}");
}
fn indonesian_test_dictionary() -> std::sync::MutexGuard<'static, ()> {
let turn = dictionaries_turn();
fn indonesian_test_dictionary() {
let _turn = dictionaries_turn();
wordcraft_proof::id::install_dictionary(INDONESIAN_TEST_AFF, INDONESIAN_TEST_DIC).unwrap();
turn
}
// Hand-written synthetic fixture (no system dictionary data).
@@ -12031,7 +12031,7 @@ const INDONESIAN_TEST_DIC: &str = "8\nrumah\nsekolah\nanak\nbermain\ndi\nmakan/A
/// Dictionary.
#[test]
fn indonesian_proofing_through_the_review_commands() {
let _turn = indonesian_test_dictionary();
indonesian_test_dictionary();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Saya di sekolha, anak anak bermain."}));
run(&mut s, "select.all", json!({}));
@@ -12086,7 +12086,6 @@ fn english_dialects_through_the_review_commands() {
if no_language_data("english_dialects_through_the_review_commands") {
return;
}
let _turn = dictionaries_turn();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "The colour of the center."}));
// US English by default: the British spelling is flagged, the American one isn't.
@@ -12194,20 +12193,19 @@ const SPANISH_TEST_AFF: &str =
const SPANISH_TEST_DIC: &str = "10\nesto\nes\nuna\nprueba/S\ndel\ncorrector\ntambién\nhabéis\nvenido\ndecir\n";
const URUGUAYAN_TEST_DIC: &str = "10\nesto\nes\nuna\nprueba/S\ndel\ncorrector\ntambién\ntener\nvenir\ndecir\n";
fn spanish_test_dictionaries() -> std::sync::MutexGuard<'static, ()> {
fn spanish_test_dictionaries() {
use wordcraft_proof::ProofLang;
let turn = dictionaries_turn();
let _turn = dictionaries_turn();
for (lang, dic) in [(ProofLang::Es, SPANISH_TEST_DIC), (ProofLang::EsUy, URUGUAYAN_TEST_DIC)] {
wordcraft_proof::es::install_dictionary(lang, SPANISH_TEST_AFF, dic).unwrap();
}
turn
}
/// #3553: Spanish proofing through the same commands as Review, F7, Change and Add to
/// Dictionary: `prueva` and `corector` are flagged with `prueba` and `corrector` offered.
#[test]
fn spanish_proofing_through_the_review_commands() {
let _turn = spanish_test_dictionaries();
spanish_test_dictionaries();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "esto es una prueva del corector. Habéis venido?"}));
run(&mut s, "select.all", json!({}));
@@ -12238,7 +12236,7 @@ fn spanish_proofing_through_the_review_commands() {
/// bytes.
#[test]
fn add_and_ignore_all_accept_both_normalization_forms() {
let _turn = spanish_test_dictionaries();
spanish_test_dictionaries();
let mut s = s();
let text = "esto zqanade\u{301}do y zqignora\u{301}do";
run(&mut s, "document.setText", json!({"text": text}));
@@ -12267,7 +12265,7 @@ fn add_and_ignore_all_accept_both_normalization_forms() {
/// Uruguayan Spanish accepts the `vos` forms, imperatives included, that Spain's flags.
#[test]
fn uruguayan_spanish_accepts_vos_forms() {
let _turn = spanish_test_dictionaries();
spanish_test_dictionaries();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Vení, decime qué tenés."}));
run(&mut s, "select.all", json!({}));
@@ -12286,7 +12284,7 @@ fn uruguayan_spanish_accepts_vos_forms() {
/// Czech proofing through the same commands as Review, F7, Change and Add to Dictionary.
#[test]
fn czech_proofing_through_the_review_commands() {
let _turn = czech_test_dict::install();
czech_test_dict::install();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Město pocitac, škola škola."}));
assert!(run(&mut s, "review.issues", json!({})).as_array().unwrap().len() >= 3);
@@ -12325,10 +12323,9 @@ fn czech_proofing_through_the_review_commands() {
const ITALIAN_TEST_AFF: &str = "SET UTF-8\nTRY aeiortnsclcaffèéè\nMAP 2\nMAP aà\nMAP eéè\nREP 1\nREP caffe caffè\n";
const ITALIAN_TEST_DIC: &str = "6\ncasa\ncaffè\nroma\ndisse\ne\nper\n";
fn italian_test_dictionary() -> std::sync::MutexGuard<'static, ()> {
let turn = dictionaries_turn();
fn italian_test_dictionary() {
let _turn = dictionaries_turn();
wordcraft_proof::it::install_dictionary(ITALIAN_TEST_AFF, ITALIAN_TEST_DIC).unwrap();
turn
}
/// Review › Language and the proofing commands work in Italian end to end: the language makes
@@ -12336,7 +12333,7 @@ fn italian_test_dictionary() -> std::sync::MutexGuard<'static, ()> {
/// suggestions come from it, and a suggestion fixes the text.
#[test]
fn italian_proofing_through_the_review_commands() {
let _turn = italian_test_dictionary();
italian_test_dictionary();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Casa caffe, e roma roma disse."}));
// English by default: the Italian words are English misspellings.
@@ -12369,7 +12366,7 @@ fn italian_proofing_through_the_review_commands() {
#[test]
fn polish_proofing_through_the_review_commands() {
let _turn = polish_test_dictionary();
polish_test_dictionary();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Płynie żeka, a wogóle to wiem że tak."}));
// English by default: the Polish words are English misspellings.
@@ -12409,7 +12406,6 @@ fn turkish_proofing_through_the_review_commands() {
if !crate::proof::tr::has_dictionary() {
return;
}
let _turn = dictionaries_turn();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Bana bazen gelenler oldu ise de. Sana olacaklardan sonra sorna"}));
run(&mut s, "select.all", json!({}));
@@ -12437,7 +12433,7 @@ fn turkish_proofing_through_the_review_commands() {
/// no parameters keep the old meaning (US English), and `default` needs a language.
#[test]
fn review_language_validates_tags_and_marks_text_unchecked() {
let _turn = polish_test_dictionary();
polish_test_dictionary();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Hello wrold"}));
run(&mut s, "select.all", json!({}));
@@ -12465,7 +12461,7 @@ fn review_language_validates_tags_and_marks_text_unchecked() {
/// the caret, not the document's default, so what is typed in them is proofed in that language.
#[test]
fn a_new_table_is_in_the_language_at_the_caret() {
let _turn = polish_test_dictionary();
polish_test_dictionary();
let cell_langs = |s: &Session| -> Vec<Option<String>> {
let t = s.doc.body.iter().find_map(|b| b.as_table()).unwrap();
t.rows.iter().flat_map(|r| &r.cells).flat_map(|c| &c.blocks).filter_map(|b| b.as_para()).map(|p| p.mark.lang.clone()).collect()
@@ -12509,7 +12505,7 @@ fn a_new_table_is_in_the_language_at_the_caret() {
/// a document with changes never does, and templates stay English.
#[test]
fn new_documents_follow_the_editing_language() {
let _turn = polish_test_dictionary();
polish_test_dictionary();
let mut s = s();
s.set_editing_language(Some("pl-PL"));
assert_eq!(s.doc.styles.default_chr.lang.as_deref(), Some("pl-PL"), "the untouched blank document switches");
@@ -12615,7 +12611,7 @@ fn rejected_default_proofing_language_does_not_survive_a_restart() {
/// English run (`w:lang`) come back, and so does the proofing.
#[test]
fn proofing_languages_survive_a_docx_round_trip() {
let _turn = polish_test_dictionary();
polish_test_dictionary();
let mut s = s();
run(&mut s, "document.setText", json!({"text": "Płynie żeka. Hello wrold."}));
run(&mut s, "select.all", json!({}));
+1 -3
View File
@@ -54,8 +54,6 @@ to
zqzakázané/F
";
pub fn install() -> std::sync::MutexGuard<'static, ()> {
let turn = super::dictionaries_turn();
pub fn install() {
super::install_dictionary(AFF, DIC).unwrap();
turn
}
+5 -6
View File
@@ -1,7 +1,6 @@
use super::ctx::{Ctx, Joining, page_anchored};
use super::floats::{
AnchoredFloat, AreaKind, ObjFrame, ObjectPlacement, WrapArea, align_in, float_rect, floating, left_out_objects, place_objects, rel_exclusions,
wrap_area,
AnchoredFloat, ObjFrame, ObjectPlacement, WrapArea, align_in, float_rect, floating, left_out_objects, place_objects, rel_exclusions, wrap_area,
};
use super::flow::again;
use super::page::PageFrame;
@@ -163,11 +162,11 @@ fn layout_table_block(input: TableBlockContext<'_, '_, '_>) -> bool {
Some(float) => {
let place = FloatPlace { shift: table::float_offset_shift(ctx, t), modern: ctx.doc.settings.compat_mode >= 15 };
let (rect, area) = box_float_table_rect(frame, width, *y, &layout, &float, place, float_tables);
exclusions.push((area, false, None, WrapText::BothSides, AreaKind::Table));
exclusions.push((area, false, None, WrapText::BothSides, true));
float_tables.push(area);
table_areas.push(area);
if float.v_rel == Anchor::Page {
page_table_wraps.push((area, false, None, WrapText::BothSides, AreaKind::Table));
page_table_wraps.push((area, false, None, WrapText::BothSides, true));
}
(rect.x, rect.y)
}
@@ -813,7 +812,7 @@ impl Joint {
let probe = again(ctx, eq, |ctx| ctx.para_labelled(q, width, table, &[], 0.0, None));
let (gap, height) = probe.lines.first().map_or((0.0, self.height), |l| ((self.baseline - (l.baseline - l.top)).max(0.0), l.height));
let rect = Rect::new(self.left, self.top, (self.end - self.left).max(0.0), (gap + height - 0.01).max(0.01));
let mut areas = vec![(rect, false, None, WrapText::Right, AreaKind::Object)];
let mut areas = vec![(rect, false, None, WrapText::Right, false)];
// Just below the first row as the line breaker tests it: the breaker tests every row at
// its estimate (`row_est`), not at the line's height, so the first row never meets this
// area and every later row, starting lower, does and moves below it. The probe's own first
@@ -821,7 +820,7 @@ impl Joint {
// line), so its height can't be used here.
let below = self.top + gap + probe.row_est + 0.01;
if self.bottom() > below {
areas.push((Rect::new(self.left, below, width.max(0.01), self.bottom() - below), true, None, WrapText::BothSides, AreaKind::Object));
areas.push((Rect::new(self.left, below, width.max(0.01), self.bottom() - below), true, None, WrapText::BothSides, false));
}
(gap, areas)
}
+6 -20
View File
@@ -117,20 +117,8 @@ pub(crate) fn align_in((start, extent): (f32, f32), offset: f32, size: f32, alig
/// An area text keeps clear of: its bounds, whether text may only go above and below it, and
/// (Tight and Through wrapping) the outline text follows inside it, the sides text may go on,
/// and what it comes from (a floating table: inclusive line-bottom contact, #3977; Tight and
/// Through wrapping: a narrower gap beside it before Word 2013 layout, #6316).
pub(crate) type WrapArea = (Rect, bool, Option<Arc<contour::Contour>>, WrapText, AreaKind);
/// What a [`WrapArea`] keeps text clear of.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum AreaKind {
/// A floating picture, shape, text box or chart wrapped Square or Top and Bottom.
Object,
/// A floating object wrapped Tight or Through, with or without an outline.
Tight,
/// A floating table.
Table,
}
/// and whether it comes from a floating table (inclusive line-bottom contact, #3977).
pub(crate) type WrapArea = (Rect, bool, Option<Arc<contour::Contour>>, WrapText, bool);
/// Wrap areas a page starts with (#2048): by page index, the floating objects (block, object
/// index) placed above the top of their anchor paragraph, with text before it on the page, and
@@ -222,14 +210,13 @@ pub(crate) fn wrap_area(r: Rect, float: &Float, outline: Option<&[(f32, f32)]>)
if matches!(float.wrap, Wrap::Tight | Wrap::Through)
&& let Some((area, c)) = outline.and_then(|o| contour::contour_area(r, float, o))
{
return Some((area, false, Some(Arc::new(c)), float.wrap_text, AreaKind::Tight));
return Some((area, false, Some(Arc::new(c)), float.wrap_text, false));
}
let d = |v: f32| if v.is_finite() { v.clamp(0.0, 1584.0) } else { 0.0 };
let (side, top, bottom) = (d(float.dist), d(float.dist_top), d(float.dist_bottom));
// A rotated object keeps text clear of its rotated bounds.
let r = float.spin().bounds(r);
let kind = if matches!(float.wrap, Wrap::Tight | Wrap::Through) { AreaKind::Tight } else { AreaKind::Object };
Some((Rect::new(r.x - side, r.y - top, r.w + side * 2.0, r.h + top + bottom), float.wrap == Wrap::TopAndBottom, None, float.wrap_text, kind))
Some((Rect::new(r.x - side, r.y - top, r.w + side * 2.0, r.h + top + bottom), float.wrap == Wrap::TopAndBottom, None, float.wrap_text, false))
}
/// Wrap areas relative to a paragraph whose column starts at `x0` and whose top is `y0`, with
@@ -237,7 +224,7 @@ pub(crate) fn wrap_area(r: Rect, float: &Float, outline: Option<&[(f32, f32)]>)
pub(crate) fn rel_exclusions(excl: &[WrapArea], x0: f32, y0: f32, space_before: f32) -> Vec<para::Exclusion> {
let before = if space_before > 0.0 { space_before } else { 0.0 };
excl.iter()
.map(|(r, tb, c, side, kind)| para::Exclusion {
.map(|(r, tb, c, side, table)| para::Exclusion {
top: r.y - y0,
bottom: r.bottom() - y0,
left: r.x - x0,
@@ -245,8 +232,7 @@ pub(crate) fn rel_exclusions(excl: &[WrapArea], x0: f32, y0: f32, space_before:
top_bottom: *tb,
contour: c.clone(),
side: *side,
table: *kind == AreaKind::Table,
tight: *kind == AreaKind::Tight,
table: *table,
})
// Top-and-Bottom areas ending within the paragraph's applied space before can still take
// room, with that space laid out again below them (#7143). Any ending at or above it
+1 -1
View File
@@ -1332,7 +1332,7 @@ mod tests {
pb.cap_columns();
// A preceding floating object leaves a narrow strip of the first column, but does
// not occupy the second column. The same kept paragraph fits there in one line.
pb.excl.push((Rect::new(pb.col_x(), top, pb.col_w() - 26.0, 100.0), false, None, WrapText::BothSides, crate::floats::AreaKind::Object));
pb.excl.push((Rect::new(pb.col_x(), top, pb.col_w() - 26.0, 100.0), false, None, WrapText::BothSides, false));
place_para_in_flow(ctx, pb, p, 0, top);
assert_eq!(pb.pages.len(), 1, "a fitting candidate kept the balance attempt on its page");
-36
View File
@@ -786,42 +786,6 @@ impl DocLayout {
None
}
/// The text direction of the lines holding `pos`; `None` for upright (horizontal) text.
pub fn turn_at(&self, pos: &Pos, page_hint: usize) -> Option<TextDirection> {
self.pieces(pos.story, &pos.path, page_hint).into_iter().find_map(|(_, it)| match it {
Placed::Lines { para, l0, l1, turn, .. } if turn.is_turned() && (*l0..*l1).contains(&para.line_of(pos.off)) => Some(*turn),
_ => None,
})
}
/// In turned text, the position on the next (`next`) or previous line in reading order, at
/// `goal` along the line (its own frame; `None` keeps the caret's). Returns it with that
/// along-line coordinate. Only lines of the same flow count (the paragraphs of one story
/// level or of one table cell, not another cell's), so `None` at the first/last line of the
/// caret's flow on the page.
pub fn turned_line(&self, pos: &Pos, goal: Option<f32>, next: bool, page_hint: usize) -> Option<(Pos, f32)> {
let c = self.caret_on(pos, page_hint)?;
let lines: Vec<(&Path, &std::sync::Arc<ParaLayout>, usize)> = items_of(self.pages.get(c.page)?, pos.story)
.filter_map(|it| match it {
Placed::Lines { story, path, para, l0, l1, turn, .. }
if *story == pos.story && turn.is_turned() && path.parent() == pos.path.parent() =>
{
Some((path, para, *l0, *l1))
}
_ => None,
})
.flat_map(|(path, para, l0, l1)| (l0..l1).map(move |li| (path, para, li)))
.collect();
let here = lines.iter().position(|(path, para, li)| *path == &pos.path && *li == para.line_of(pos.off))?;
let (path, para, li) = lines.get(if next { here + 1 } else { here.checked_sub(1)? })?;
let gx = match goal {
Some(g) => g,
None => lines[here].1.x_of(lines[here].2, pos.off)?,
};
let off = para.off_at_x(*li, gx);
Some((Pos { story: pos.story, path: (*path).clone(), off }, gx))
}
/// The position one line up (`dir < 0`) or down from `pos`, keeping `goal_x` (page x).
pub fn vertical(&self, pos: &Pos, goal_x: Option<f32>, dir: i32, page_hint: usize) -> Option<(Pos, f32)> {
let c = self.caret_on(pos, page_hint)?;
-3
View File
@@ -173,9 +173,6 @@ pub struct Exclusion {
pub side: WrapText,
/// A floating table counts a line touching its top as overlapping; shapes do not (#3977).
pub table: bool,
/// Tight and Through wrapping: before Word 2013 layout text goes in a narrower gap beside
/// it (#6316).
pub tight: bool,
}
impl Exclusion {
+18 -118
View File
@@ -30,9 +30,6 @@ struct Breaker<'e> {
/// Word 2013+ (compatibility mode 15) fits more text on a justified line by shrinking its
/// spaces (`space_room`); on a line with tabs, only the spaces after a final left/default tab.
shrink_spaces: bool,
/// Word 2013+ layout (compatibility mode 15): the narrowest span beside a Tight or Through
/// object is the same as beside any other ([`min_span`]).
layout_2013: bool,
/// Word 2003's indent rules (`w:doNotSuppressIndentation`) before Word 2013's layout, for an
/// unnumbered paragraph: a row starts right after a floating object before the indent.
tight_indent: bool,
@@ -211,7 +208,6 @@ impl<'e> Breaker<'e> {
hanging_at: if rp.indent_first < 0.0 { Some(rp.indent_left) } else { None },
tab_origin: if settings.odf.is_some_and(|o| o.tabs_from_indent) { rp.indent_left } else { 0.0 },
shrink_spaces: rp.align == Align::Justify && settings.compat_mode >= wordcraft_doc::COMPAT_MODE_CURRENT,
layout_2013: settings.compat_mode >= wordcraft_doc::COMPAT_MODE_CURRENT,
tight_indent: settings.do_not_suppress_indentation
&& settings.compat_mode < wordcraft_doc::COMPAT_MODE_CURRENT
&& level.is_none()
@@ -299,9 +295,7 @@ impl<'e> Breaker<'e> {
}
}
let row = (self.top, self.est_h, self.table_h);
match row_spans(self.exclusions, row, (lo, self.base_right), self.tight_indent, self.layout_2013)
.map(|mut spans| (spans.pop_front(), spans))
{
match row_spans(self.exclusions, row, (lo, self.base_right), self.tight_indent).map(|mut spans| (spans.pop_front(), spans)) {
Ok((Some((a, b)), rest)) => {
// Under Word 2003's indent rules a row can start left of the indent too.
let moved = if self.tight_indent { (a - lo).abs() > 0.01 } else { a > lo };
@@ -1196,28 +1190,10 @@ fn line_end_kern(pl: &ParaLayout, j: usize) -> f32 {
}
}
/// Narrowest span text flows into beside a floating table, points. Word puts an empty
/// Narrowest span text flows into beside a floating object, points. Word puts an empty
/// paragraph beside a floating table in a 21.3pt gap but not in an 18.6pt one.
const MIN_SPAN: f32 = 20.0;
/// Narrowest span text flows into beside a floating picture or shape, points: Word puts a line
/// in an 18pt gap to its wrap area but not in a 17.95pt one, for square, tight and through
/// wrapping alike, whatever the text (#6316).
const MIN_SPAN_OBJECT: f32 = 18.0;
/// Tight and Through wrapping before Word 2013 layout (compatibility mode 14 and below) need
/// only half that: 9pt fits, 8.95pt doesn't.
const MIN_SPAN_CONTOUR_OLD: f32 = 9.0;
/// The narrowest span text goes into beside `e`, with Word 2013 layout or later (`current`).
fn min_span(e: &Exclusion, current: bool) -> f32 {
match (e.table, e.tight) {
(true, _) => MIN_SPAN,
(false, true) if !current => MIN_SPAN_CONTOUR_OLD,
_ => MIN_SPAN_OBJECT,
}
}
/// Where a row starts under Word 2003's indent rules: right after the floating objects that end
/// at or before the indent `lo` on this row and let text past their right side (their outline's
/// right edge for Tight and Through wrapping), never left of the paragraph's own left edge (0) or
@@ -1248,18 +1224,16 @@ fn baseline_offset(spacing: LineSpacing, asc: f32, height: f32, desc: f32) -> f3
}
/// The spans of a row at `top` (about `h` tall) between `lo` and `hi` that text can use around
/// the exclusions, left to right (Square wrapping uses both sides of an object); a span must be
/// as wide as the minimum of each object it borders (`current`: Word 2013 layout or later).
/// `Err(y)`: none here, try again at `y` (below what's in the way). With `tight_indent` (Word
/// 2003's indent rules, `w:doNotSuppressIndentation`) a row starts right after a floating object
/// that ends before `lo`, the indent ignored (ECMA-376 Part 4 §14.8.3.12: a paragraph indented
/// 1" tightly wraps an object at 0.25").
/// the exclusions, left to right (Square wrapping uses both sides of an object). `Err(y)`: none
/// here, try again at `y` (below what's in the way). With `tight_indent` (Word 2003's indent
/// rules, `w:doNotSuppressIndentation`) a row starts right after a floating object that ends
/// before `lo`, the indent ignored (ECMA-376 Part 4 §14.8.3.12: a paragraph indented 1" tightly
/// wraps an object at 0.25").
fn row_spans(
exclusions: &[Exclusion],
(top, h, table_h): (f32, f32, f32),
(lo, hi): (f32, f32),
tight_indent: bool,
current: bool,
) -> Result<VecDeque<(f32, f32)>, f32> {
let lo = if tight_indent { tight_row_start(exclusions, (top, h, table_h), lo) } else { lo };
let here: Vec<&Exclusion> = exclusions.iter().filter(|e| e.intersects_row(top, h, table_h, lo, hi)).collect();
@@ -1267,14 +1241,13 @@ fn row_spans(
return Err(below);
}
// What each object takes of the row: its whole area, or (Tight, Through) the stretches its
// outline takes, as (left, right, bottom of the object's area, the narrowest span beside it).
let mut taken: Vec<(f32, f32, f32, f32)> = Vec::new();
// outline takes, as (left, right, bottom of the object's area).
let mut taken: Vec<(f32, f32, f32)> = Vec::new();
for e in &here {
let first = taken.len();
let min = min_span(e, current);
match &e.contour {
None => taken.push((e.left, e.right, e.bottom, min)),
Some(c) => taken.extend(c.occupied(top - e.top, top + h - e.top).into_iter().map(|(a, b)| (a + e.left, b + e.left, e.bottom, min))),
None => taken.push((e.left, e.right, e.bottom)),
Some(c) => taken.extend(c.occupied(top - e.top, top + h - e.top).into_iter().map(|(a, b)| (a + e.left, b + e.left, e.bottom))),
}
// Text on one side only: the object's other side of the row is taken too.
let Some(mine) = taken.get(first..).filter(|t| !t.is_empty() && !e.side.is_both()) else { continue };
@@ -1287,96 +1260,23 @@ fn row_spans(
_ => left - lo >= hi - right,
};
taken.truncate(first);
taken.push(if text_left { (left, hi.max(right), e.bottom, min) } else { (lo.min(left), right, e.bottom, min) });
taken.push(if text_left { (left, hi.max(right), e.bottom) } else { (lo.min(left), right, e.bottom) });
}
taken.retain(|(l, r, _, _)| *r > lo && *l < hi);
taken.retain(|(l, r, _)| *r > lo && *l < hi);
if taken.is_empty() {
return Ok(VecDeque::from([(lo, hi)]));
}
// Each span with the minimum of what borders it on the left and on the right (nothing at the
// row's ends): an object cutting a span becomes the new edge of both pieces, and an object
// ending right at a span's edge borders it too, the larger minimum winning (a picture and a
// table both ending at 70: the span after them needs the table's).
let mut spans = vec![(lo, hi, 0.0_f32, 0.0_f32)];
for &(left, right, _, min) in &taken {
let mut spans = vec![(lo, hi)];
for &(left, right, _) in &taken {
spans = spans
.into_iter()
.flat_map(|(a, b, ml, mr)| {
if right <= a || left >= b {
let ml = if (right - a).abs() < 0.01 { ml.max(min) } else { ml };
let mr = if (left - b).abs() < 0.01 { mr.max(min) } else { mr };
vec![(a, b, ml, mr)]
} else {
vec![(a, left.min(b), ml, min), (right.max(a), b, min, mr)]
}
})
.flat_map(|(a, b)| if right <= a || left >= b { vec![(a, b)] } else { vec![(a, left.min(b)), (right.max(a), b)] })
.collect();
}
let spans: VecDeque<(f32, f32)> = spans.into_iter().filter(|(a, b, ml, mr)| b - a >= ml.max(*mr)).map(|(a, b, ..)| (a, b)).collect();
spans.retain(|(a, b)| b - a >= MIN_SPAN);
if spans.is_empty() {
// Nothing wide enough: the line goes below the first object that ends.
return Err(taken.iter().map(|t| t.2).reduce(f32::min).unwrap_or(top));
}
Ok(spans)
}
#[cfg(test)]
mod tests {
use super::*;
/// An exclusion from the row's left edge to `right`, 100pt tall.
fn area(right: f32, table: bool, tight: bool) -> Exclusion {
Exclusion { top: 0.0, bottom: 100.0, left: 0.0, right, top_bottom: false, contour: None, side: WrapText::BothSides, table, tight }
}
/// Whether a line at the top of a 100pt row finds a span `gap` points wide beside `e`.
fn fits(e: Exclusion, gap: f32, current: bool) -> bool {
let hi = e.right + gap;
row_spans(&[e], (0.0, 12.0, 12.0), (0.0, hi), false, current).is_ok()
}
/// #6316: 18pt beside pictures and shapes; Tight and Through 9pt before Word 2013 layout;
/// floating tables keep 20.
#[test]
fn the_narrowest_span_depends_on_the_object() {
for current in [true, false] {
assert!(fits(area(50.0, false, false), 18.0, current) && !fits(area(50.0, false, false), 17.9, current));
assert!(fits(area(50.0, true, false), 20.0, current) && !fits(area(50.0, true, false), 19.9, current));
}
assert!(fits(area(50.0, false, true), 18.0, true) && !fits(area(50.0, false, true), 17.9, true));
assert!(fits(area(50.0, false, true), 9.0, false) && !fits(area(50.0, false, true), 8.9, false));
// A span between a picture and a table needs the table's 20.
let both = |gap: f32| {
let table = Exclusion { left: 50.0 + gap, right: 300.0, ..area(0.0, true, false) };
row_spans(&[area(50.0, false, false), table], (0.0, 12.0, 12.0), (0.0, 300.0), false, true).is_ok()
};
assert!(both(20.0) && !both(19.9));
// A span bordered only by a picture needs 18, whichever order the objects come in, also
// when a table cut the span first (a table at 0..70, a picture at 80..100, a 19pt span
// right of the picture).
let table = area(70.0, true, false);
let picture = Exclusion { left: 80.0, right: 100.0, ..area(0.0, false, false) };
for order in [[table.clone(), picture.clone()], [picture.clone(), table.clone()]] {
let spans = row_spans(&order, (0.0, 12.0, 12.0), (0.0, 119.0), false, true);
assert_eq!(spans, Ok(VecDeque::from([(100.0, 119.0)])), "{order:?}");
}
}
/// A picture and a table ending at the same edge: the span after them needs the table's 20,
/// whichever comes first, and on the other side too.
#[test]
fn objects_sharing_an_edge_need_the_larger_minimum() {
let row = (0.0, 12.0, 12.0);
let (picture, table) = (area(70.0, false, false), area(70.0, true, false));
for order in [[picture.clone(), table.clone()], [table.clone(), picture.clone()]] {
assert!(row_spans(&order, row, (0.0, 89.0), false, true).is_err(), "19pt: {order:?}");
assert_eq!(row_spans(&order, row, (0.0, 90.0), false, true), Ok(VecDeque::from([(70.0, 90.0)])), "20pt: {order:?}");
}
let picture = Exclusion { left: 30.0, right: 100.0, ..picture };
let table = Exclusion { left: 30.0, right: 100.0, ..table };
for order in [[picture.clone(), table.clone()], [table.clone(), picture.clone()]] {
assert!(row_spans(&order, row, (11.0, 100.0), false, true).is_err(), "19pt: {order:?}");
assert_eq!(row_spans(&order, row, (10.0, 100.0), false, true), Ok(VecDeque::from([(10.0, 30.0)])), "20pt: {order:?}");
}
}
Ok(spans.into())
}
-17
View File
@@ -2055,23 +2055,6 @@ mod width_tests {
assert_eq!(grid, [150.0, 150.0, 150.0]);
}
#[test]
fn grid_after_row_keeps_grid() {
let mut table = Table::new(2, 3, 300.0);
for row in &mut table.rows {
for cell in &mut row.cells {
cell.props.width = Some(100.0);
}
}
table.rows[1].props.grid_after = 1;
table.grid = vec![150.0, 150.0, 150.0];
table.props.width = Some(300.0);
let mut grid = table.grid.clone();
apply_cell_widths(&table, &mut grid);
assert_eq!(grid, [150.0, 150.0, 150.0]);
}
#[test]
fn disagreeing_row_edges_keep_grid() {
let mut table = Table::new(2, 3, 300.0);
+2 -2
View File
@@ -1,6 +1,6 @@
use super::boxes::{BoxInput, clear_of_float_tables, layout_box};
use super::ctx::{Ctx, with_pct_base};
use super::floats::{AreaKind, WrapArea, align_in, body_wraps};
use super::floats::{WrapArea, align_in, body_wraps};
use super::flow::again;
use super::headers::{begins_section, header_items_cap, header_table_areas, placed_cost};
use super::notes::table_notes;
@@ -435,7 +435,7 @@ fn place_floating_table(ctx: &mut Ctx, pb: &mut PageBuilder, tl: &table::TableLa
pg.float_tables.push(Path::top(block));
}
let area = r.inset(-dl, -dt, -dr, -db);
pb.excl.push((area, false, None, WrapText::BothSides, AreaKind::Table));
pb.excl.push((area, false, None, WrapText::BothSides, true));
pb.float_tables.push(area);
return;
}
-62
View File
@@ -12574,68 +12574,6 @@ fn tight_wrap_follows_an_ellipse() {
assert_eq!(through, tight);
}
/// #6316: how many of seven empty paragraphs (the first anchoring a 200pt-tall rectangle at the
/// column's left with `wrap`) go in the `free` points it leaves on its right (column edge to its
/// wrap area, 9pt from text included), in compatibility mode `mode`.
fn empty_lines_beside(wrap: wordcraft_doc::para::Wrap, free: f32, mode: u32) -> usize {
use wordcraft_doc::para::{Anchor, Float, ShapeKind};
let w = 468.0 - 9.0 - free;
let mut d = Document::from_text("");
d.settings.compat_mode = mode;
let float = Float { wrap, h_rel: Anchor::Column, v_rel: Anchor::Paragraph, dist: 9.0, ..Default::default() };
let shape = InlineObject::Shape {
kind: ShapeKind::Rectangle,
w,
h: 200.0,
fill: None,
stroke: None,
stroke_width: 1.0,
float,
story: None,
effects: Default::default(),
freeform: None,
extra: Default::default(),
};
d.insert_object(&Pos::body(0, 0), shape, &Default::default()).unwrap();
for i in 1..7 {
d.insert_block(StoryRef::Body, &Path::top(i), wordcraft_doc::Block::Para(Default::default())).unwrap();
}
let l = lay(&d);
let lines: Vec<(f32, f32)> =
l.pages[0].items.iter().filter_map(|i| if let Placed::Lines { y, para, .. } = i { Some((para.lines[0].left, *y)) } else { None }).collect();
let Some(top) = lines.iter().map(|l| l.1).reduce(f32::min) else { return 0 };
lines.iter().filter(|(left, y)| *left >= w + 9.0 - 0.01 && *y < top + 200.0).count()
}
/// #6316: Word puts a line beside a floating picture or shape when the gap between the column
/// edge and the object's wrap area is at least 18pt, for square, tight and through wrapping; a
/// tight-wrapped cover with 17.55 and 19.15pt gaps was pushed onto three pages by a 20pt minimum.
#[test]
fn text_goes_beside_a_float_in_an_18pt_gap() {
crate::test_fonts();
use wordcraft_doc::para::Wrap;
let current = wordcraft_doc::COMPAT_MODE_CURRENT;
for wrap in [Wrap::Square, Wrap::Tight, Wrap::Through] {
assert_eq!(empty_lines_beside(wrap, 18.1, current), 7, "{wrap:?} 18.1");
assert_eq!(empty_lines_beside(wrap, 17.9, current), 0, "{wrap:?} 17.9");
}
}
/// Before Word 2013 layout (mode 14 and below) a line goes beside a tight or through object in
/// a 9pt gap; square wrapping still needs 18.
#[test]
fn tight_wrap_needs_only_9pt_beside_it_before_word_2013_layout() {
crate::test_fonts();
use wordcraft_doc::para::Wrap;
for wrap in [Wrap::Tight, Wrap::Through] {
assert_eq!(empty_lines_beside(wrap, 9.1, 14), 7, "{wrap:?} 9.1");
assert_eq!(empty_lines_beside(wrap, 8.9, 14), 0, "{wrap:?} 8.9");
assert_eq!(empty_lines_beside(wrap, 9.1, wordcraft_doc::COMPAT_MODE_CURRENT), 0, "{wrap:?} 9.1 in mode 15");
}
assert_eq!(empty_lines_beside(Wrap::Square, 17.9, 14), 0);
assert_eq!(empty_lines_beside(Wrap::Square, 18.1, 14), 7);
}
#[test]
fn contour_wrap_turns_with_the_object() {
crate::test_fonts();
-43
View File
@@ -171,46 +171,3 @@ fn a_click_outside_a_floating_table_in_a_vertical_section_skips_its_cells() {
// Inside the table a click still lands in a cell.
assert!(l.hit(0, cx, cy, StoryRef::Body).unwrap().path.0.len() > 1);
}
/// #8986: in vertical text the next line is the next paragraph's, left of this one, at the same
/// distance along it; the first and last lines have no previous/next.
#[test]
fn turned_line_steps_to_the_adjacent_column() {
crate::test_fonts();
let mut d = Document::from_text("abc\ndef\nghi");
d.last_section.text_direction = TextDirection::Down;
let l = lay(&d);
let p = Pos::body(1, 1);
assert_eq!(l.turn_at(&p, 0), Some(TextDirection::Down));
let (next, g) = l.turned_line(&p, None, true, 0).unwrap();
assert_eq!((next.path, next.off), (Path::top(2), 1));
let (prev, _) = l.turned_line(&p, Some(g), false, 0).unwrap();
assert_eq!((prev.path, prev.off), (Path::top(0), 1));
assert!(l.turned_line(&Pos::body(2, 0), None, true, 0).is_none());
assert_eq!(lay(&Document::from_text("abc")).turn_at(&Pos::body(0, 0), 0), None);
}
/// #8986: in a table whose cells run vertical text, the next line is one of the same cell, never
/// another cell's (a cell's only line has no previous/next).
#[test]
fn turned_line_stays_in_its_table_cell() {
crate::test_fonts();
let mut d = Document::from_text("before");
let mut t = wordcraft_doc::Table::new(1, 3, 468.0);
for (i, c) in t.rows[0].cells.iter_mut().enumerate() {
c.props.text_direction = TextDirection::Down;
let paras = if i == 1 { ["abc", "def"].as_slice() } else { ["xyz"].as_slice() };
c.blocks = paras.iter().map(|s| wordcraft_doc::para_block(wordcraft_doc::Paragraph::with_text(s, Default::default()))).collect();
}
d.insert_block(StoryRef::Body, &Path::top(1), Block::Table(t)).unwrap();
let l = lay(&d);
let at = |cell: u32, para: u32, off: usize| Pos { story: StoryRef::Body, path: Path(vec![1, 0, cell, para]), off };
let (next, _) = l.turned_line(&at(1, 0, 1), None, true, 0).unwrap();
assert_eq!((next.path, next.off), (Path(vec![1, 0, 1, 1]), 1));
assert!(l.turned_line(&at(1, 1, 1), None, true, 0).is_none());
assert!(l.turned_line(&at(1, 0, 1), None, false, 0).is_none());
for cell in [0, 2] {
assert!(l.turned_line(&at(cell, 0, 1), None, true, 0).is_none());
assert!(l.turned_line(&at(cell, 0, 1), None, false, 0).is_none());
}
}
+2 -6
View File
@@ -265,12 +265,8 @@ impl WordApp {
if let Some(ctx) = self.ctx.clone() {
self.run_fired(&ctx, &out);
self.canvas.take_focus_after_pass(&ctx);
// The zoom is context-wide but the display scale is per window: read it from the active
// document window. The windowless root has no window, so it reports none (#8853).
let active = self.active_viewport();
let native_now = ctx.input_for(active, |i| i.viewport().native_pixels_per_point).or_else(|| ctx.native_pixels_per_point());
self.native_scale = theme::usable_scale(native_now.unwrap_or(1.0));
if let Some(native) = native_now
self.native_scale = theme::usable_scale(ctx.native_pixels_per_point().unwrap_or(1.0));
if let Some(native) = ctx.native_pixels_per_point()
&& let Some(old) = self.legacy_interface_size.take()
{
self.ui.interface_size = theme::migrate_legacy_interface_size(old, native);
+1 -4
View File
@@ -66,8 +66,6 @@ pub(crate) struct EquationFrameStyle {
line: StyleColor,
accent: StyleColor,
soft: StyleColor,
/// Behind the equation's text, so translucent: the argument the caret is in.
shade: StyleColor,
handle_fill: StyleColor,
handle_stroke: StyleColor,
}
@@ -123,7 +121,6 @@ impl Component for EquationFrameControl<'_> {
line: cx.color(t.color.overlay.line),
accent: cx.color(t.color.accent.solid),
soft: cx.color(t.color.accent.soft),
shade: cx.color(t.color.accent.solid.with_alpha(40)),
handle_fill: cx.color(t.color.overlay.handle_fill),
handle_stroke: cx.color(t.color.overlay.handle_stroke),
}
@@ -163,7 +160,7 @@ impl Component for EquationFrameControl<'_> {
let EquationFrame { outline, grip, strip } = equation_frame(self.page, self.bx, &style.sizes);
let corner = CornerRadius::from(style.radius);
if let Some(arg) = self.argument {
draw.fill(&PaintShape::Rect(arg, CornerRadius::ZERO), style.shade);
draw.fill(&PaintShape::Rect(arg, CornerRadius::ZERO), style.soft);
}
draw.fill(&PaintShape::Rect(strip, CornerRadius::ZERO), style.soft);
let (c, w) = (strip.center(), style.chevron / 2.0);
+12 -2
View File
@@ -9,10 +9,11 @@ use craft::theme::ControlSize;
use craft::theme::variant::Variant;
use craft::ui::bars::{Bar, BarKind};
use craft::ui::buttons::{Button, ButtonOutput, IconButton, ToggleButton};
use craft::ui::contract::{Bind, BodyCx, Gap, Props as _, Show as _, ShowContainer as _, TooltipSpec, Trigger};
use craft::ui::contract::{AfterInk, Bind, BodyCx, Gap, Props as _, Show as _, ShowContainer as _, TooltipSpec, Trigger};
use craft::ui::display::{Divider, Text};
use craft::ui::layout_components::Row;
use craft::ui::menu::{Menu, MenuItem};
use craft::ui::runtime::env::with_env;
use craft::ui::value_drag::{Slider, SliderScale};
use egui::Ui;
use serde_json::json;
@@ -45,7 +46,16 @@ pub(crate) fn show(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut WordApp) {
})
.show(ui, |ui, _| {
if let Ok(mut a) = app.try_borrow_mut() {
page.set(Some(readouts(&mut a, ui)));
// The readouts are secondary text, as v0.19.1 drew them (#8811): craft's ghost button takes the muted ink
// where it passes text contrast.
let rect = with_env(
ui,
|o| {
o.values.set(AfterInk::Muted);
},
|ui| readouts(&mut a, ui),
);
page.set(Some(rect));
}
});
if let (Some(page), Some(group), Ok(mut a)) = (page.get(), group.get(), app.try_borrow_mut()) {
-10
View File
@@ -413,11 +413,6 @@ fn smart_art_design_layouts_are_one_strip_and_size_is_labelled() {
/// control lies inside its group's access node.
#[test]
fn ribbon_groups_fit_above_their_labels() {
if crate::i18n::Lang::all().any(|l| l.code() == "ar")
&& crate::test_harness::skip_without_embedded_script("ribbon::tests::ribbon_groups_fit_above_their_labels", "Arab")
{
return;
}
fn rects(node: &egui_kittest::Node<'_>, out: &mut Vec<egui::Rect>) {
for child in node.children() {
// The framework's parts (a split button's arrow, a field's adornments) can be nodes with no
@@ -476,11 +471,6 @@ fn ribbon_groups_fit_above_their_labels() {
/// Language Preferences… opens Options › Language, and French text shows by name, checked.
#[test]
fn language_menu_reaches_every_language() {
if crate::i18n::Lang::all().any(|l| l.code() == "ar")
&& crate::test_harness::skip_without_embedded_script("ribbon::tests::language_menu_reaches_every_language", "Arab")
{
return;
}
let app = WordApp::new(Session::new(wordcraft_doc::Document::from_text("Bonjour")), crate::Services::default());
let mut h = tab_harness(app, "Review");
click_button(&mut h, "Language");
-43
View File
@@ -183,46 +183,3 @@ pub(crate) fn fixed_catalog() -> std::sync::Arc<craft::font_manager::Catalog> {
assert!(catalog.families().iter().any(|f| f == "Inter"), "fixed catalog loaded assets/fonts");
catalog
}
/// Evaluate whether a test missing an embedded `script` face should skip under
/// `CRAFT_FONTS_REQUIRED` (`None` / `""` skips, `"1"` fails, any other value fails naming the
/// variable and accepted values).
fn should_skip_missing_script(test: &str, script: &str, required: Option<&str>) -> bool {
match required {
None | Some("") => {
eprintln!("SKIPPED ({test}): no embedded {script} face in CRAFT_FONTS (set CRAFT_FONTS_DIR)");
true
}
Some("1") => panic!("{test}: missing embedded {script} face in CRAFT_FONTS (CRAFT_FONTS_REQUIRED=1)"),
Some(other) => panic!("{test}: invalid CRAFT_FONTS_REQUIRED={other:?}; accepted values are empty/unset (skip) or \"1\" (require)"),
}
}
/// Skip `test` when no embedded `craft-fonts` face covers `script`, unless `CRAFT_FONTS_REQUIRED`
/// requires or rejects the value.
pub(crate) fn skip_without_embedded_script(test: &str, script: &str) -> bool {
if crate::app::fonts::CRAFT_FONTS.iter().any(|f| f.has_script(script)) {
return false;
}
let required = std::env::var("CRAFT_FONTS_REQUIRED").ok();
should_skip_missing_script(test, script, required.as_deref())
}
#[cfg(test)]
mod tests {
use super::should_skip_missing_script;
#[test]
fn craft_fonts_required_controls_skip_and_rejects_unknown_values() {
assert!(should_skip_missing_script("t", "Arab", None));
assert!(should_skip_missing_script("t", "Arab", Some("")));
let required_err = std::panic::catch_unwind(|| should_skip_missing_script("t", "Arab", Some("1"))).unwrap_err();
let required_msg = required_err.downcast_ref::<String>().map(String::as_str).unwrap_or("");
assert!(required_msg.contains("CRAFT_FONTS_REQUIRED=1"), "{required_msg}");
let invalid_err = std::panic::catch_unwind(|| should_skip_missing_script("t", "Arab", Some("yes"))).unwrap_err();
let invalid_msg = invalid_err.downcast_ref::<String>().map(String::as_str).unwrap_or("");
assert!(invalid_msg.contains("CRAFT_FONTS_REQUIRED") && invalid_msg.contains("\"1\""), "{invalid_msg}");
}
}
+9 -15
View File
@@ -1089,19 +1089,13 @@ fn new_document_cascade_skips_ineligible_recent_window_to_earlier_predecessor()
let root_client = egui::vec2(800.0, 600.0);
let root_outer = egui::Rect::from_min_size(root_origin, root_client + egui::vec2(16.0, 38.0));
let root_inner = egui::Rect::from_min_size(root_origin + egui::vec2(8.0, 30.0), root_client);
let child_origin = egui::pos2(200.0, 220.0);
let child_client = egui::vec2(700.0, 520.0);
let child_outer = egui::Rect::from_min_size(child_origin, child_client + egui::vec2(12.0, 34.0));
let child_inner = egui::Rect::from_min_size(child_origin + egui::vec2(6.0, 28.0), child_client);
let zero = egui::Rect::from_min_size(child_origin, egui::Vec2::ZERO);
let infinite_size = egui::Rect::from_min_size(child_origin, egui::vec2(f32::INFINITY, 400.0));
let valid = egui::Rect::from_min_size(egui::pos2(200.0, 220.0), egui::vec2(500.0, 400.0));
let zero = egui::Rect::from_min_size(egui::pos2(200.0, 220.0), egui::Vec2::ZERO);
let infinite_size = egui::Rect::from_min_size(egui::pos2(200.0, 220.0), egui::vec2(f32::INFINITY, 400.0));
for (label, inner, outer, expected_client, expected_origin) in [
("valid child", Some(child_inner), Some(child_outer), child_client, child_origin),
("zero outer", Some(child_inner), Some(zero), root_client, root_origin),
("zero inner", Some(zero), Some(child_outer), root_client, root_origin),
("infinite outer size", Some(child_inner), Some(infinite_size), root_client, root_origin),
] {
for (label, child_inner, child_outer) in
[("zero outer", Some(valid), Some(zero)), ("zero inner", Some(zero), Some(valid)), ("infinite outer size", Some(valid), Some(infinite_size))]
{
let mut rig = Rig::new();
let mut a = app("First draft");
rig.kit.root_info(ViewportInfo { inner_rect: Some(root_inner), outer_rect: Some(root_outer), focused: Some(true), ..Default::default() });
@@ -1114,7 +1108,7 @@ fn new_document_cascade_skips_ineligible_recent_window_to_earlier_predecessor()
a.run("file.new", json!({})).unwrap();
assert_eq!(a.window_count(), 2);
rig.kit.root_info(ViewportInfo { inner_rect: Some(root_inner), outer_rect: Some(root_outer), focused: Some(false), ..Default::default() });
rig.kit.child_info(ViewportInfo { inner_rect: inner, outer_rect: outer, focused: Some(true), ..Default::default() });
rig.kit.child_info(ViewportInfo { inner_rect: child_inner, outer_rect: child_outer, focused: Some(true), ..Default::default() });
for _ in 0..3 {
rig.frame_with_reported_info(&mut a, Vec::new(), Vec::new());
}
@@ -1124,8 +1118,8 @@ fn new_document_cascade_skips_ineligible_recent_window_to_earlier_predecessor()
let third_title = a.window_title();
rig.frame_with_reported_info(&mut a, Vec::new(), Vec::new());
let builder = rig.builders.into_iter().find(|b| b.title.as_ref() == Some(&third_title)).expect("the third document opened a native window");
assert_eq!(builder.inner_size, Some(expected_client), "{label}: third window client size");
assert_eq!(builder.position, Some(expected_origin + egui::Vec2::splat(step)), "{label}: third window origin");
assert_eq!(builder.inner_size, Some(root_client), "{label}: skipped ineligible child to earlier root client size");
assert_eq!(builder.position, Some(root_origin + egui::Vec2::splat(step)), "{label}: skipped ineligible child to earlier root origin");
}
}
File diff suppressed because one or more lines are too long
-1
View File
@@ -169,7 +169,6 @@ including in headers and notes when the body uses balloons. Shift extends across
| Backspace, then type | the typed text takes the formatting of the character Backspace deleted, not of the one now left of the caret: in `Abc abc` with `Abc` bold, Backspace after the space then `X` gives a plain X; Backspace after a bold letter that follows a plain space gives a bold X. The Bold button shows it before typing, also with the caret inside a word (where it otherwise shows the word). Several Backspaces: the last deleted character's formatting. A Backspace that changes nothing (at the start of the document) keeps it, and keeps formatting set at the caret too. Typing goes on with it (in `ab Cd` with `C` bold, Backspace after the C then `YX` gives a bold YX), and undoing that typing brings it back. Moving the caret any way drops it, not only with the caret keys: a click elsewhere (also one that comes back to the same place), Go To, Find (typing over the found word takes that word's formatting; a Find with no match keeps it) and a paste, whose text never takes it (formatted or plain; a paste with nothing on the clipboard keeps it); typing then takes the formatting where the caret is. A command that is refused (a Backspace into a content control locked against editing) keeps it, and formatting set at the caret too. Forward Delete, a deleted selection, a paragraph join, an object or a break carry nothing. With Track Changes on Backspace carries it too: the character stays, marked deleted (or goes, when it is the author's own tracked insertion), and the typed text is a tracked insertion with that formatting, never marked deleted; moving the caret away and back drops it. Ctrl+Backspace that deletes a word or joins paragraphs drops formatting carried by an earlier Backspace (one that deletes nothing, at the start of the document, keeps it, like Backspace). Undo takes the carried formatting back with the Backspace. Observed in Word for Windows (#6518) | `typing_after_backspace_takes_the_deleted_characters_formatting`, `backspace_formatting_is_dropped_by_a_caret_move_and_delete_does_not_carry`, `backspace_at_the_document_start_keeps_waiting_formatting`, `ctrl_backspace_at_the_document_start_keeps_waiting_formatting`, `backspace_formatting_is_not_kept_past_a_paste`, `backspace_formatting_is_not_kept_past_find_or_go_to`, `backspace_formatting_survives_a_paste_of_an_empty_clipboard`, `backspace_formatting_is_not_kept_past_a_direct_caret_move_and_back`, `a_refused_backspace_keeps_the_formatting_waiting_at_the_caret`, `backspace_formatting_follows_typing_and_comes_back_with_undo`, `tracked_backspace_carries_the_deleted_characters_formatting` |
| select text right to left (from its end), type | the new text takes the first selected character's formatting (font, size…), as with a selection made left to right; not the text's before it (#2879) | `typing_over_backward_selection_keeps_its_font` |
| Down / Up (↓ / ↑) from a line beside a table | into the table's nearest row: the cell under the caret, or the nearest one when the caret is left or right of the cells' text (the start of the line above a table is left of the first cell's text); never past the table to the paragraph beyond it | `down_and_up_from_a_line_start_beside_a_table_go_into_it` |
| Arrows in vertical text (top-to-bottom, lines stacking leftwards, #8986) | Up / Down step to the previous / next character along the line; Left / Right go to the next / previous line (the column to the left / right), keeping the distance along the line. In bottom-to-top text Up steps forward and Left goes to the previous line. Left / Right stay within the text flow of the caret (a vertical section's paragraphs, or one table cell's): at its first or last line (a table cell's only line, say) they step along the text, as in horizontal text | `turned_line_steps_to_the_adjacent_column`, `turned_line_stays_in_its_table_cell` (layout) |
| Alt+Shift+Up / Down (⌃⇧↑ / ⌃⇧↓) | the paragraphs the selection touches swap with the paragraph above / below, keeping style and list membership; the selection moves with them; one undo step. A selection ending at the start of a paragraph doesn't take it along. Refused at the top or bottom of the story or cell, next to a table and across a section break | `alt_shift_down_then_up_moves_a_paragraph_and_back_and_undoes` |
| Alt+Shift+Left / Right (⌃⇧← / ⌃⇧→) | Promote / Demote: a heading goes up or down one level (Heading 1 and Heading 9 are the ends); promoted body text becomes a heading at the level of the heading before it; a list item changes level like Shift+Tab / Tab | `alt_shift_left_and_right_promote_and_demote_headings_and_list_items` |
| Outline view: Alt+Shift+Up / Down, Left / Right | as above, but a collapsed heading takes what is hidden under it along: moving passes whole shown paragraphs with their hidden content; promote/demote shifts the hidden subheadings too | `outline_collapse_hides_descendants_and_expand_restores` |