Merge storytold main into next (17 Nov sync)

storytold main 83cb1133dd (291 commits) into the integration head bab1a99b85; 47 conflicted files.

- Domain test files (metafile, prepress, pdf plates, settings store, heif, media-testkit, atomic): tests next cut stay cut; tests new on main are kept, as trials where the crate's test target runs trials.
- atomic: main's group-bits test and Faulty::set_group go to src/tests.rs. audio: main's GSM and SBC oracles join tests/main.rs. cms constructors, pdf knockout_backdrop and testing_pdf join their crates' one test binary; timeline's preflight tests become src/preflight_tests.rs trials.
- update: main's changes to detect, install (linux, macos) and the tests land in next's split modules. The app's own offer is inspected on a thread of its own, picked up by tick's polling; settle_for_tests settles offers too. Later on a ready update drops the close it asked for. updater_pin_tests.rs stays deleted; its new pin test is in tests/it/update.rs.
- craft-color: main added a different crate at crates/color (the colour tags of compositor and display frames); it is next's craft-color module `tags`, re-exported at the root.
- Old crates/ui (combo, docking, testing, README) and keymap's ui/view.rs stay deleted; main's new crates/ui/src/testing files are dropped with them.
- New crates in the craft facade: ai, control, dds, frame, ipc, media-source, palette, press-print, score, ssip. testkit and xtask are listed outside it.
- Cargo.lock: the union of both locks, resolved by cargo metadata. Workflow: main's nextest Windows leg, with next's --keep-going clippy.
This commit is contained in:
aiongg
2026-11-17 12:44:52 +00:00
581 changed files with 77998 additions and 3002 deletions
+18 -1
View File
@@ -131,7 +131,8 @@ pub fn parse_color(s: &str) -> Option<Rgb> {
if let Some(p) = x.strip_suffix('%') {
Some((p.trim().parse::<f64>().ok()? / 100.0).clamp(0.0, 1.0))
} else {
Some(x.parse::<f64>().ok()?.clamp(0.0, 1.0))
// CSS Color 4: numeric saturation and lightness use the same 0–100 scale as percentages.
Some((x.parse::<f64>().ok()? / 100.0).clamp(0.0, 1.0))
}
};
let s = parse_pct(parts[1])?;
@@ -193,4 +194,20 @@ mod tests {
assert_eq!(parse_color("rgba(0, 0, 0, inf)"), Some(Rgb(0, 0, 0)));
assert_eq!(parse_color("rgba(0, 0, 0, nan%)"), Some(Rgb(0, 0, 0)));
}
#[test]
fn numeric_hsl_channels_use_the_percentage_scale() {
for (numeric, percent, expected) in [
("hsl(0 0 50)", "hsl(0 0% 50%)", Rgb(128, 128, 128)),
("hsl(0 100 50)", "hsl(0 100% 50%)", Rgb(255, 0, 0)),
("hsl(120 50 50)", "hsl(120 50% 50%)", Rgb(64, 191, 64)),
("hsl(0 0 1)", "hsl(0 0% 1%)", Rgb(3, 3, 3)),
("hsl(0 -10 150)", "hsl(0 -10% 150%)", Rgb(255, 255, 255)),
("hsl(0 100 -10)", "hsl(0 100% -10%)", Rgb(0, 0, 0)),
("hsla(0.5turn 100 50 / 50%)", "hsla(0.5turn 100% 50% / 50%)", Rgb(128, 255, 255)),
] {
assert_eq!(parse_color(numeric), Some(expected), "{numeric}");
assert_eq!(parse_color(numeric), parse_color(percent), "{numeric} == {percent}");
}
}
}
+57 -13
View File
@@ -18,11 +18,7 @@ pub(super) fn uses_kind(blocks: &[FBlock], k: Kind, depth: usize) -> bool {
// ---------------------------------------------------------------------------------------------
// Document → Flow
/// Is this a monospace family name?
pub fn is_mono(font: &str) -> bool {
let f = font.to_ascii_lowercase();
f.contains("courier") || f.contains("mono") || f.contains("consolas") || f.contains("menlo") || f.contains("code") || f == "monaco"
}
pub use craft_wordmodel::font_kind::is_mono;
fn is_code_style(doc: &Document, id: &str) -> bool {
let names = |s: &str| {
@@ -201,7 +197,7 @@ fn para_extra(doc: &Document, p: &craft_wordmodel::props::ParaProps) -> Option<B
let outline_level = p.outline_level.or_else(|| style.as_ref().and_then(|_| doc.styles.resolve_para(p).outline_level));
let x = craft_wordmodel::props::ParaProps {
tabs,
shading: p.shading,
shading: doc.styles.resolve_para(p).shading,
style,
contextual_spacing: p.contextual_spacing,
bidi: p.bidi.filter(|b| *b),
@@ -342,6 +338,20 @@ fn rich_inlines(doc: &Document, o: &InlineObject, f: &Fmt, opts: FlowOpts) -> Op
})
}
/// The freeform a `w` × `h` frame shape with border `corner` (see
/// [`craft_wordmodel::connector::frame_width`]) draws: its outline clockwise and its hole the
/// other way, so the hole stays empty under either fill rule.
fn frame_freeform(corner: Option<u32>, w: f32, h: f32) -> craft_wordmodel::freeform::Freeform {
use craft_wordmodel::freeform::{FreePath, Freeform};
let (w, h) = (craft_wordmodel::geom::finite(w).max(0.0), craft_wordmodel::geom::finite(h).max(0.0));
let t = craft_wordmodel::connector::frame_width(corner, w, h);
let mut paths = vec![FreePath { pts: vec![[0.0, 0.0], [w, 0.0], [w, h], [0.0, h]], closed: true }];
if w - 2.0 * t > 0.0 && h - 2.0 * t > 0.0 {
paths.push(FreePath { pts: vec![[t, t], [t, h - t], [w - t, h - t], [w - t, t]], closed: true });
}
Freeform { w, h, paths, ..Default::default() }
}
/// Comment `c` (a reply to `parent`) of `doc` as a flow comment: its text holds no comments or
/// notes of its own.
/// The flow inline for picture, shape or group `o` of `doc` (a member of groups `depth` deep),
@@ -358,8 +368,12 @@ fn drawing_inline(doc: &Document, o: &InlineObject, opts: FlowOpts, depth: usize
{
// A connector stays one in formats that glue them (ODT, with boxes); elsewhere it is a
// straight line.
// A frame (a border with a hole), which the other formats have no shape for, is the
// freeform it draws: its outline and, wound the other way, its hole.
let frame = (*kind == ShapeKind::Frame).then(|| std::sync::Arc::new(frame_freeform(extra.corner, *w, *h)));
let kind = match kind {
ShapeKind::StraightConnector | ShapeKind::ElbowConnector | ShapeKind::CurvedConnector if !opts.boxes => ShapeKind::Line,
ShapeKind::Frame => ShapeKind::Freeform,
k => *k,
};
let inner = FlowOpts { notes: false, comments: false, boxes: false, ..opts };
@@ -383,7 +397,7 @@ fn drawing_inline(doc: &Document, o: &InlineObject, opts: FlowOpts, depth: usize
Box::new(crate::Chain { name: format!("Frame{id}"), next })
}),
};
let path = freeform.clone().filter(|_| kind == ShapeKind::Freeform);
let path = frame.or_else(|| freeform.clone()).filter(|_| kind == ShapeKind::Freeform);
Some(Inline::Shape { kind, w: w * sx, h: h * sy, float: kept_float(float), blocks, look, path })
}
InlineObject::Image { media, w, h, alt, float, ole, crop, .. } => {
@@ -418,10 +432,11 @@ fn drawing_inline(doc: &Document, o: &InlineObject, opts: FlowOpts, depth: usize
}
}
/// The placement a flow keeps for a drawing: when it floats, or turns or mirrors it in line.
/// Keep placement, transforms, and explicit stacking metadata even for inline drawings.
/// Presence alone does not imply anchoring: the retained Float keeps its original wrap.
fn kept_float(f: &craft_wordmodel::para::Float) -> Option<Box<craft_wordmodel::para::Float>> {
let turned = f.rot.is_finite() && f.rot.rem_euclid(360.0) > 0.001 && f.rot.rem_euclid(360.0) < 359.999;
(f.wrap != craft_wordmodel::para::Wrap::Inline || turned || f.flip_h || f.flip_v).then(|| Box::new(f.clone()))
(f.wrap != craft_wordmodel::para::Wrap::Inline || turned || f.flip_h || f.flip_v || f.z != 0).then(|| Box::new(f.clone()))
}
fn flow_comment(doc: &Document, c: &craft_wordmodel::Comment, parent: Option<u32>, opts: FlowOpts) -> FComment {
@@ -534,6 +549,12 @@ fn flow_paras_in(doc: &Document, p: &Paragraph, opts: FlowOpts) -> Vec<Para> {
if c == PAGE_BREAK {
if !hidden {
out.push_text(&std::mem::take(&mut buf), &f);
let extra = out.extra.as_ref().and_then(|x| {
let mut x = (**x).clone();
x.drop_cap = None;
x.drop_cap_distance = None;
(x != craft_wordmodel::props::ParaProps::default()).then(|| Box::new(x))
});
let next = Para {
kind,
list: None,
@@ -548,7 +569,7 @@ fn flow_paras_in(doc: &Document, p: &Paragraph, opts: FlowOpts) -> Vec<Para> {
mark_ins: None,
mark_del: None,
fmt_change: None,
extra: None,
extra,
mark: None,
kept: None,
wrap: None,
@@ -746,9 +767,14 @@ fn graphic_group(
.iter()
.take(10_000)
.filter_map(|item| match item {
GraphicItem::Shape { rect, kind, fill, stroke, stroke_width } if finite(rect) => {
GraphicItem::Shape { rect, kind, fill, stroke, stroke_width, alpha } if finite(rect) => {
let look = BoxLook {
fill: fill.map(craft_wordmodel::fill::Fill::solid).filter(|_| *kind != ShapeKind::Line),
fill: fill
.map(|color| craft_wordmodel::fill::Fill::Solid {
color,
transparency: (1.0 - if alpha.is_finite() { alpha.clamp(0.0, 1.0) } else { 1.0 }) * 100.0,
})
.filter(|_| *kind != ShapeKind::Line),
line: stroke.filter(|_| stroke_width.is_finite() && *stroke_width > 0.0).map(|c| (c, stroke_width.min(12.0))),
..plain.clone()
};
@@ -1083,7 +1109,10 @@ fn flow_table(doc: &Document, t: &Table, depth: usize, tracked: FlowOpts) -> FTa
let ncols =
t.rows.iter().map(|r| r.first_grid() + r.cells.iter().map(|c| c.span()).sum::<usize>() + r.grid_after()).max().unwrap_or(0).max(t.grid.len());
for (ri, r) in t.rows.iter().enumerate() {
let header = r.props.header || (ri == 0 && t.props.look.header_row && t.rows.len() > 1);
// The look's header row is an option of the table's style (`w:tblLook/@w:firstRow`): with
// no table style there is nothing to apply, so the first row stays an ordinary row, as in
// Word. Only Repeat as header row makes it one then.
let header = r.props.header || (ri == 0 && style.is_some() && t.props.look.header_row && t.rows.len() > 1);
let mut cells = Vec::new();
for (ci, c) in r.cells.iter().enumerate() {
let styled = if bake { styled_cell(t, style.as_ref(), (ri, ci), ncols) } else { None };
@@ -1254,3 +1283,18 @@ impl ListCounter {
}
}
}
#[cfg(test)]
mod stacking_tests {
#[test]
fn explicit_inline_stacking_preserves_wrap_without_creating_an_anchor() {
use craft_wordmodel::para::{Float, Wrap};
let f = Float { z: u32::MAX, ..Float::default() };
assert_eq!(f.wrap, Wrap::Inline);
let kept = super::kept_float(&f).unwrap();
assert_eq!(kept.wrap, Wrap::Inline);
assert_eq!(kept.z, u32::MAX);
assert_eq!(kept.rot, f.rot);
assert!(super::kept_float(&Float::default()).is_none());
}
}
+26
View File
@@ -80,6 +80,32 @@ mod tests {
assert!(kept);
}
/// The default look's header row is an option of the table style: a table with no style (or a
/// style the document doesn't have) has an ordinary first row, so RTF doesn't bold it or
/// repeat it on each page, and HTML doesn't make it `th`. Repeat as header row still does.
#[test]
fn look_header_row_needs_a_table_style() {
use craft_wordmodel::{Block, Document, table::Table};
let first_row_header = |style: Option<&str>, repeat: bool| {
let mut t = Table::new(2, 2, 200.0);
t.props.style = style.map(str::to_string);
assert!(t.props.look.header_row, "the default look has a header row");
if let Some(r) = t.rows.first_mut() {
r.props.header = repeat;
}
let mut doc = Document::new();
doc.body = vec![std::sync::Arc::new(Block::Table(t))];
let flow = from_doc(&doc);
let Some(FBlock::Table(ft)) = flow.blocks.iter().find(|b| matches!(b, FBlock::Table(_))) else { panic!("no table in {:?}", flow.blocks) };
assert!(ft.rows.get(1).is_some_and(|r| r.iter().all(|c| !c.header)), "the second row is never a header");
ft.rows.first().is_some_and(|r| r.iter().all(|c| c.header))
};
assert!(first_row_header(Some("TableGrid"), false), "a table style applies the look's header row");
assert!(!first_row_header(None, false), "no style, no header row");
assert!(!first_row_header(Some("NoSuchStyle"), false), "a missing style applies nothing");
assert!(first_row_header(None, true), "Repeat as header row");
}
#[test]
fn percent_decode_requires_hex_digits() {
assert_eq!(percent_decode("%+A"), b"%+A".to_vec());
+2 -1
View File
@@ -841,7 +841,8 @@ impl<'a> Builder<'a> {
tb.props.style = None;
}
if t.widths.len() == cols && t.widths.iter().all(|w| w.is_finite() && *w > 1.0) {
tb.grid = t.widths.iter().map(|w| w.clamp(6.0, 1584.0)).collect();
// Narrow columns stay as they are: raising them would widen the table past its source.
tb.grid = t.widths.iter().map(|w| w.min(1584.0)).collect();
}
tb.rows.clear();
if let Some(x) = &t.extra {
+3 -2
View File
@@ -170,8 +170,9 @@ pub struct Img {
pub w: f32,
pub h: f32,
pub alt: String,
/// How a floating picture is placed and wrapped, for formats that keep it (ODT); `None`: in
/// line with the text.
/// Placement and drawing metadata for formats that keep it (ODT). `None` is inline;
/// `Some` may also be inline, retaining rotation, mirroring or explicit stacking order.
/// The Float wrap, not the Option, determines anchoring.
pub float: Option<Box<craft_wordmodel::para::Float>>,
/// The embedded object this picture shows, kept whole (ODT only; see [`OdfObject`]).
pub object: Option<Arc<OdfObject>>,