A fast, helpful, and open-source document parser
wip
Logan Markewich0d6499f4a3ba
diff --git a/crates/liteparse-ooxml/src/pptx/cascade.rs b/crates/liteparse-ooxml/src/pptx/cascade.rsindex 30d9fc0..b5a05b1 100644--- a/crates/liteparse-ooxml/src/pptx/cascade.rs+++ b/crates/liteparse-ooxml/src/pptx/cascade.rs@@ -325,7 +325,8 @@ pub fn background_fill() -> ResolvedFill {let ctx = DrawingColorContext::new(theme).with_color_map(color_map);match bg {- Background::Properties(fill) => resolve_fill(fill, &ctx, media),+ // A background is not inside a shape tree, so it has no group.+ Background::Properties(fill) => resolve_fill(fill, &ctx, media, None),Background::Reference(r) => resolve_background_fill(r, theme, &ctx, media),}}diff --git a/crates/liteparse-ooxml/src/pptx/mod.rs b/crates/liteparse-ooxml/src/pptx/mod.rsindex 682f64e..3136e92 100644--- a/crates/liteparse-ooxml/src/pptx/mod.rs+++ b/crates/liteparse-ooxml/src/pptx/mod.rs@@ -28,7 +28,8 @@ pub use package::{EMU_PER_POINT, Part, PresentationInfo, PresentationPackage, Slpub use shapes::{AutoShape, Background, Connector, GraphicFrame, GraphicFramePayload, Group, Placeholder,PlaceholderKind, Shape, ShapeKind, ShapeStyle, SlidePart, Table, TableCell,- TableCellProperties, TableRow, parse_shape_tree, parse_slide_part, visit_all,+ TableCellProperties, TableRow, parse_shape_tree, parse_slide_part, shows_inherited_shapes,+ visit_all,};pub use text::{AutoNumberScheme, Bullet, ListStyle, Spacing, TextBody, TextParagraph, TextParagraphProperties,diff --git a/crates/liteparse-ooxml/src/pptx/shapes.rs b/crates/liteparse-ooxml/src/pptx/shapes.rsindex d5c1ac1..9f8aa83 100644--- a/crates/liteparse-ooxml/src/pptx/shapes.rs+++ b/crates/liteparse-ooxml/src/pptx/shapes.rs@@ -250,7 +250,19 @@ pub struct Connector {/// numbers it needs.#[derive(Clone, Debug, Default)]pub struct Group {- pub properties: Option<ShapeProperties>,+ /// §20.1.8.35 — the fill a descendant's `a:grpFill` inherits.+ ///+ /// A [`ShapeProperties`] would be the obvious type and is the wrong one:+ /// §19.3.1.23's `p:grpSpPr` is `a:xfrm` + `EG_FillProperties` ++ /// `EG_EffectProperties` + `a:scene3d`, so a group has **no geometry and+ /// no `a:ln`** — those two fields could never be populated — and its+ /// transform is already hoisted onto [`Shape::transform`], where the+ /// geometry pass reads it. Carrying the one member that has a consumer+ /// keeps the second copy of the transform from existing to drift.+ ///+ /// A group never paints this itself: it has no geometry to put it in.+ /// The fill exists only as the source of the children's inheritance.+ pub fill: Option<DrawingFill>,/// `a:chOff` — the origin of the child coordinate space.pub child_offset: Option<Offset<Emu>>,/// `a:chExt` — the extent of the child coordinate space.@@ -546,6 +558,51 @@ pub fn parse_shape_tree(data: &[u8]) -> Result<Vec<Shape>> {Ok(parse_slide_part(data)?.shapes)}+/// §19.2.1.32 `@showMasterSp` alone, read from the root element without+/// deserializing the part.+///+/// [`parse_slide_part`] already returns this as+/// [`SlidePart::show_inherited_shapes`], and that is what every *walk* should+/// use. This exists for the one caller that needs the attribute **without** the+/// shape tree: the deck-wide tally of inherited text has to know which slides+/// really draw a rung, and it visits every slide before either walk begins.+/// Deserializing 1,278 slide parts a second time to read one boolean measured+/// at +7.5% on the corpus's end-to-end markdown run; this measures at nothing.+///+/// The duplication is deliberate and is fenced by+/// `cheap_reader_agrees_with_the_full_parse`, which asserts the two answers+/// match on the same bytes — a second reader of an attribute is only safe while+/// something fails when they disagree.+///+/// Defaults to **true**, per the schema, and on anything it cannot read: a part+/// whose XML is malformed is the full parse's problem to report, and answering+/// "shows its rungs" here keeps the failure in one place.+pub fn shows_inherited_shapes(data: &[u8]) -> bool {+ let mut reader = quick_xml::Reader::from_reader(data);+ let mut buf = Vec::new();+ loop {+ // The root element is the first `Start` — `Empty` cannot be it, since a+ // `p:sld` with no `p:cSld` is still not self-closing in any producer,+ // and an empty root has no rungs to draw anyway.+ match reader.read_event_into(&mut buf) {+ Ok(quick_xml::events::Event::Start(e)) => {+ // The true-family is `AttrBool`'s, spelled the same way on+ // purpose: anything else present — `0`, `off`, a typo — is+ // false there, and a reader that only special-cased `"0"`+ // would answer differently on the odd ones.+ return e+ .try_get_attribute("showMasterSp")+ .ok()+ .flatten()+ .and_then(|a| a.unescape_value().ok())+ .is_none_or(|v| matches!(v.as_ref(), "1" | "true" | "on"));+ }+ Ok(quick_xml::events::Event::Eof) | Err(_) => return true,+ _ => buf.clear(),+ }+ }+}+/// A `p:cSld`'s two payloads: its shape tree and its background.////// One struct rather than two entry points because both come out of the same@@ -1056,12 +1113,29 @@ struct NvGrpSpPrXml {cnv_pr: CNvPrXml,}+/// §19.3.1.23 `p:grpSpPr` — `a:xfrm` + `EG_FillProperties` ++/// `EG_EffectProperties` + `a:scene3d`. There is deliberately no `ln` field:+/// the schema gives a group no outline, which is why a census of the corpus+/// finds an `a:ln` on 0 of 695 groups. The six fill members route through+/// [`pick_fill`], the same collapse `SpPrXml` and `p:bgPr` use.#[derive(Debug, Deserialize, Default)]struct GrpSpPrXml {#[serde(rename = "xfrm", default)]xfrm: Option<GroupXfrmXml>,#[serde(rename = "@bwMode", default)]_bw_mode: Option<String>,+ #[serde(rename = "noFill", default)]+ no_fill: Option<crate::docx::parse::drawing::schema::fill::Empty>,+ #[serde(rename = "solidFill", default)]+ solid_fill: Option<crate::docx::parse::drawing::schema::fill::SolidFillXml>,+ #[serde(rename = "gradFill", default)]+ grad_fill: Option<crate::docx::parse::drawing::schema::fill::GradFillXml>,+ #[serde(rename = "blipFill", default)]+ blip_fill: Option<crate::docx::parse::drawing::schema::fill::BlipFillXml>,+ #[serde(rename = "pattFill", default)]+ patt_fill: Option<crate::docx::parse::drawing::schema::fill::PattFillXml>,+ #[serde(rename = "grpFill", default)]+ grp_fill: Option<crate::docx::parse::drawing::schema::fill::Empty>,}/// A group's `<a:xfrm>`, which is `XfrmXml` **plus** `chOff`/`chExt`.@@ -1391,7 +1465,16 @@ fn lower_cxn(cxn: CxnSpXml) -> Shape {}fn lower_grp(grp: GrpSpXml) -> Shape {- let xfrm = grp.grp_sp_pr.and_then(|p| p.xfrm);+ let grp_sp_pr = grp.grp_sp_pr.unwrap_or_default();+ let fill = pick_fill(+ grp_sp_pr.no_fill,+ grp_sp_pr.grp_fill,+ grp_sp_pr.solid_fill,+ grp_sp_pr.grad_fill,+ grp_sp_pr.blip_fill,+ grp_sp_pr.patt_fill,+ );+ let xfrm = grp_sp_pr.xfrm;let transform = xfrm.as_ref().map(GroupXfrmXml::transform);Shape {non_visual: doc_properties(grp.nv_grp_sp_pr.map(|nv| nv.cnv_pr)),@@ -1402,7 +1485,7 @@ fn lower_grp(grp: GrpSpXml) -> Shape {// §19.3.1.22: `p:grpSp` has no `style` child in the schema.style: None,kind: ShapeKind::Group(Box::new(Group {- properties: None,+ fill,child_offset: xfrm.as_ref().and_then(|x| x.ch_off.as_ref())@@ -1863,6 +1946,53 @@ mod tests {assert_eq!(group.children.len(), 1);}+ /// §19.3.1.23 — the group's own fill, which is what a member's `a:grpFill`+ /// inherits. 82 corpus groups declare a `solidFill` here.+ #[test]+ fn group_fill_is_lowered() {+ let shapes = tree(&format!(+ r#"<p:grpSp>+ <p:nvGrpSpPr><p:cNvPr id="5" name="g"/></p:nvGrpSpPr>+ <p:grpSpPr><a:solidFill><a:srgbClr val="FF0000"/></a:solidFill></p:grpSpPr>+ {}+ </p:grpSp>"#,+ sp("<p:spPr><a:grpFill/></p:spPr>")+ ));+ let ShapeKind::Group(group) = &shapes[0].kind else {+ panic!("expected a group");+ };+ assert!(matches!(group.fill, Some(DrawingFill::Solid(_))));+ // The member defers rather than declaring nothing: the distinction is+ // the whole of `grpFill`, and a `None` here would be a shape that+ // silently falls through to its `p:style` instead.+ let ShapeKind::AutoShape(member) = &group.children[0].kind else {+ panic!("expected an autoshape");+ };+ assert!(matches!(+ member.properties.as_ref().and_then(|p| p.fill.as_ref()),+ Some(DrawingFill::Group)+ ));+ }++ /// A group with no fill element is the spec's "inherit nothing" — it must+ /// not be confused with one that names `noFill`, which says the same thing+ /// but says it, nor silently become a fill.+ #[test]+ fn group_without_a_fill_lowers_to_none() {+ let shapes = tree(+ r#"<p:grpSp>+ <p:nvGrpSpPr><p:cNvPr id="5" name="g"/></p:nvGrpSpPr>+ <p:grpSpPr><a:xfrm><a:off x="1" y="2"/><a:ext cx="3" cy="4"/></a:xfrm></p:grpSpPr>+ </p:grpSp>"#,+ );+ let ShapeKind::Group(group) = &shapes[0].kind else {+ panic!("expected a group");+ };+ assert!(group.fill.is_none());+ // The `xfrm` still has to survive alongside the new fill fields.+ assert_eq!(shapes[0].transform.unwrap().offset.unwrap().x.raw(), 1);+ }+#[test]fn groups_nest_and_visit_is_preorder() {let shapes = tree(&format!(@@ -2134,9 +2264,53 @@ mod tests {</p:spTree></p:cSld></p:sld>"#);- parse_slide_part(xml.as_bytes())+ let full = parse_slide_part(xml.as_bytes()).expect("parses")- .show_inherited_shapes+ .show_inherited_shapes;+ // Every case below fences the second reader, not just the one test+ // written for it: `shows_inherited_shapes` exists only while it cannot+ // drift from the parse it shortcuts.+ assert_eq!(+ full,+ shows_inherited_shapes(xml.as_bytes()),+ "cheap reader disagreed on {root_attrs:?}"+ );+ full+ }++ /// The two readers must agree on the whole `AttrBool` true-family and on+ /// the values outside it, which is where a hand-rolled attribute scan is+ /// most likely to go its own way.+ #[test]+ fn cheap_reader_agrees_with_the_full_parse() {+ for attrs in [+ "",+ r#"showMasterSp="0""#,+ r#"showMasterSp="1""#,+ r#"showMasterSp="true""#,+ r#"showMasterSp="false""#,+ r#"showMasterSp="on""#,+ r#"showMasterSp="off""#,+ // Not a value the schema allows. Both sides must still land on the+ // same answer, whatever it is.+ r#"showMasterSp="yes""#,+ // A sibling attribute, to catch a scan that matches by prefix.+ r#"preserve="1""#,+ ] {+ show_inherited(attrs);+ }+ }++ /// The attribute is on the **root**, and a `p:sp` deeper in the part may+ /// carry unrelated attributes. A reader that took the first match anywhere+ /// would read the wrong element.+ #[test]+ fn cheap_reader_reads_the_root_not_a_descendant() {+ let xml = r#"<p:sldLayout xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"+ showMasterSp="0">+ <p:cSld><p:spTree><p:sp showMasterSp="1"/></p:spTree></p:cSld>+ </p:sldLayout>"#;+ assert!(!shows_inherited_shapes(xml.as_bytes()));}/// The schema default is `true`, and it is the *absence* of the attributediff --git a/crates/liteparse-ooxml/src/render/layout/build/floating.rs b/crates/liteparse-ooxml/src/render/layout/build/floating.rsindex 737f2da..c68a327 100644--- a/crates/liteparse-ooxml/src/render/layout/build/floating.rs+++ b/crates/liteparse-ooxml/src/render/layout/build/floating.rs@@ -255,6 +255,9 @@ pub(super) fn extract_floating_shapes(// Word autoshape stays unpainted — as it was before this argument// existed. Wiring it is a DOCX-side step with its own corpus.None,+ // No enclosing group: this walk visits `wps:wsp` anchors, and a+ // Word group's members do not reach it.+ None,);// §20.1.7.6 transform attributes (rotation/flip) live on the shape'sdiff --git a/crates/liteparse-ooxml/src/render/resolve/shape_visuals.rs b/crates/liteparse-ooxml/src/render/resolve/shape_visuals.rsindex fb71ba5..bf602cc 100644--- a/crates/liteparse-ooxml/src/render/resolve/shape_visuals.rs+++ b/crates/liteparse-ooxml/src/render/resolve/shape_visuals.rs@@ -51,6 +51,14 @@ pub struct ResolvedVisuals {/// the theme is no longer the only thing a scheme colour resolves through:/// PresentationML states its `bg1`/`tx1` mapping in the master's §19.3.1.6/// `p:clrMap`, and a shape fill has to see the same map its text does.+///+/// `group_fill` is the **already-resolved** fill of the nearest enclosing+/// group, which is what a `a:grpFill` on this shape inherits (§20.1.8.35);+/// `None` for a shape at the top of a tree, and for every DOCX caller. It+/// arrives resolved rather than as a `DrawingFill` for two reasons: the+/// group's fill resolves in the group's own colour context, which is the one+/// place it is correct to resolve it, and a group with 776 children resolves+/// once instead of 776 times.pub fn resolve_shape_visuals(props: Option<&ShapeProperties>,style_line_ref: Option<&StyleMatrixRef>,@@ -58,6 +66,7 @@ pub fn resolve_shape_visuals(style_fill_ref: Option<&StyleMatrixRef>,ctx: &DrawingColorContext<'_>,media: Option<&PartMedia>,+ group_fill: Option<&ResolvedFill>,) -> ResolvedVisuals {let theme = ctx.theme;let props = match props {@@ -75,8 +84,12 @@ pub fn resolve_shape_visuals(// §20.1.4.1.13: a direct spPr fill wins; otherwise fall back to the theme// fill style referenced by `<a:fillRef>` (recolored by its phClr).+ // A `grpFill` is a *declared* fill, so it wins over a `fillRef` even when+ // the group hands back nothing: 269 corpus shapes declare both, and+ // falling through to the theme on an unanswered group would paint them a+ // colour the file never asks for.let fill = match props.fill.as_ref() {- Some(f) => resolve_fill(f, ctx, media),+ Some(f) => resolve_fill(f, ctx, media, group_fill),None => resolve_theme_fill(style_fill_ref, theme, ctx, media),};@@ -146,7 +159,9 @@ fn resolve_theme_fill(Some(c) => ctx.with_placeholder(resolve_drawing_color(c, ctx)),None => *ctx,};- resolve_fill(fill, &fill_ctx, media)+ // A theme fill style entry cannot itself defer to a group: there is no+ // shape, so there is no enclosing group.+ resolve_fill(fill, &fill_ctx, media, None)}/// §19.3.1.3: resolve a slide/layout/master `<p:bgRef>` against the theme.@@ -190,7 +205,7 @@ pub fn resolve_background_fill(Some(c) => ctx.with_placeholder(resolve_drawing_color(c, ctx)),None => *ctx,};- resolve_fill(fill, &fill_ctx, media)+ resolve_fill(fill, &fill_ctx, media, None)}/// Look up a theme line style by its 1-based `lnRef` index.@@ -245,10 +260,15 @@ pub fn default_path_fill_for_stroked_shape() -> PathFillMode {/// today). A blip fill without one resolves to [`ResolvedFill::None`]: the/// alternative — resolving against whatever table happened to be in scope —/// is how an inherited picture acquires the slide's `rId1` instead of its own.+///+/// `group_fill` is the resolved fill of the nearest enclosing group — see+/// [`resolve_shape_visuals`]. `None` means there is no group to inherit from,+/// which is a correct reading of the file and not a gap.pub fn resolve_fill(fill: &DrawingFill,ctx: &DrawingColorContext<'_>,media: Option<&PartMedia>,+ group_fill: Option<&ResolvedFill>,) -> ResolvedFill {match fill {DrawingFill::None => ResolvedFill::None,@@ -281,12 +301,19 @@ pub fn resolve_fill(log::warn!("shape_visuals: pattern fill not yet resolved (Tier 3)");ResolvedFill::None}- DrawingFill::Group => {- log::warn!(- "shape_visuals: group fill (grpFill) not resolved — no enclosing group context"- );- ResolvedFill::None- }+ // §20.1.8.35 — take the enclosing group's fill. The chain through+ // nested groups is collapsed by the caller before it gets here: a+ // group whose own fill is itself `grpFill` resolves against *its*+ // parent, so what arrives is always a fill, never another deferral.+ DrawingFill::Group => match group_fill {+ Some(f) => f.clone(),+ None => {+ log::debug!(+ "shape_visuals: grpFill with no enclosing group fill — nothing to inherit"+ );+ ResolvedFill::None+ }+ },}}@@ -594,6 +621,7 @@ mod tests {None,&DrawingColorContext::new(None),None,+ None,);assert!(matches!(v.fill, ResolvedFill::None));assert!(v.stroke.is_none());@@ -617,6 +645,7 @@ mod tests {None,&DrawingColorContext::new(None),None,+ None,);let ResolvedFill::Solid(c) = v.fill else {panic!()@@ -648,6 +677,7 @@ mod tests {None,&DrawingColorContext::new(None),None,+ None,);let s = v.stroke.unwrap();assert_eq!(s.width, Pt::new(0.75));@@ -681,6 +711,7 @@ mod tests {None,&DrawingColorContext::new(None),None,+ None,);let s = v.stroke.unwrap();assert_eq!(s.width, Pt::new(0.75));@@ -711,6 +742,7 @@ mod tests {None,&DrawingColorContext::new(None),None,+ None,);assert!(v.stroke.is_none());}@@ -768,6 +800,7 @@ mod tests {None,&DrawingColorContext::new(Some(&theme)),None,+ None,);let s = v.stroke.unwrap();assert_eq!(s.width, Pt::new(2.0));@@ -822,6 +855,7 @@ mod tests {None,&DrawingColorContext::new(Some(&theme)),None,+ None,);let s = v.stroke.expect("a colourless outline is still an outline");assert_eq!(s.color.to_rgb24(), 0x4472C4, "phClr := the lnRef's colour");@@ -851,6 +885,7 @@ mod tests {None,&DrawingColorContext::new(Some(&theme)),None,+ None,);let s = v.stroke.expect("the theme line style is the outline");assert_eq!(s.color.to_rgb24(), 0xED7D31);@@ -877,6 +912,7 @@ mod tests {None,&DrawingColorContext::new(None),None,+ None,);assert_eq!(v.stroke.unwrap().color.to_rgb24(), 0x000000);assert!(@@ -902,6 +938,7 @@ mod tests {None,&DrawingColorContext::new(Some(&theme)),None,+ None,);assert!(v.stroke.is_none());assert!(!v.stroke_color_defaulted);@@ -943,6 +980,7 @@ mod tests {None,&DrawingColorContext::new(Some(&theme)),None,+ None,);assert_eq!(v.effects.len(), 1);}@@ -997,6 +1035,7 @@ mod tests {None,&DrawingColorContext::new(Some(&theme)),None,+ None,);let ResolvedEffect::OuterShadow {blur_radius, color, ..@@ -1036,6 +1075,7 @@ mod tests {None,&DrawingColorContext::new(None),None,+ None,);assert_eq!(v.effects.len(), 1);let ResolvedEffect::OuterShadow {@@ -1080,6 +1120,7 @@ mod tests {Some(&fill_ref),&DrawingColorContext::new(Some(&theme)),None,+ None,);let ResolvedFill::Solid(c) = v.fill else {panic!("expected solid theme fill, got {:?}", v.fill);@@ -1087,6 +1128,57 @@ mod tests {assert_eq!(c.to_rgb24(), 0xFF0000, "phClr substituted by fillRef color");}+ /// §20.1.8.35 — the enclosing group supplies the fill.+ #[test]+ fn grp_fill_takes_the_enclosing_group_fill() {+ let props = shape_props(Some(DrawingFill::Group), None, None);+ let group = ResolvedFill::Solid(Rgba::from_rgb24(0x00FF00));+ let v = resolve_shape_visuals(+ Some(&props),+ None,+ None,+ None,+ &DrawingColorContext::new(None),+ None,+ Some(&group),+ );+ let ResolvedFill::Solid(c) = v.fill else {+ panic!("expected the group's fill, got {:?}", v.fill);+ };+ assert_eq!(c.to_rgb24(), 0x00FF00);+ }++ /// With no group to inherit from, a `grpFill` is still a *declared* fill:+ /// it resolves to nothing rather than falling through to the `fillRef`.+ /// 269 corpus shapes declare both, and the fall-through would paint every+ /// one of them a colour the file never asks for.+ #[test]+ fn unanswered_grp_fill_does_not_fall_through_to_fill_ref() {+ let theme = ph_theme();+ let fill_ref = StyleMatrixRef {+ idx: 1,+ color: Some(DrawingColor::Srgb {+ rgb: 0xFF0000,+ transforms: vec![],+ }),+ };+ let props = shape_props(Some(DrawingFill::Group), None, None);+ let v = resolve_shape_visuals(+ Some(&props),+ None,+ None,+ Some(&fill_ref),+ &DrawingColorContext::new(Some(&theme)),+ None,+ None,+ );+ assert!(+ matches!(v.fill, ResolvedFill::None),+ "grpFill with no group must not inherit the theme fill, got {:?}",+ v.fill+ );+ }+#[test]fn direct_fill_wins_over_fill_ref() {let theme = ph_theme();@@ -1112,6 +1204,7 @@ mod tests {Some(&fill_ref),&DrawingColorContext::new(Some(&theme)),None,+ None,);let ResolvedFill::Solid(c) = v.fill else {panic!("expected solid fill");@@ -1134,6 +1227,7 @@ mod tests {Some(&fill_ref),&DrawingColorContext::new(Some(&theme)),None,+ None,);assert!(matches!(v.fill, ResolvedFill::None));}diff --git a/crates/liteparse/src/office/pptx.rs b/crates/liteparse/src/office/pptx.rsindex 037d3f7..3a2d500 100644--- a/crates/liteparse/src/office/pptx.rs+++ b/crates/liteparse/src/office/pptx.rs@@ -139,6 +139,13 @@ pub struct Deck {/// that [`PreparedSlide`] can borrow it and every walk builds the *same*/// `TextCascade` — see [`Deck::prepare`].fallback_defaults: DeckTextDefaults,+ /// How many slides of this deck an inherited string lands on, keyed by the+ /// string itself. Built once in [`Deck::index_inherited_text`].+ ///+ /// Deck-wide by necessity: whether a layout's text is furniture or content+ /// is not a property of the slide showing it, and cannot be decided while+ /// standing on one. See [`PreparedSlide::inherited_text`].+ inherited_text_counts: HashMap<String, usize>,}/// One slide's shapes with their geometry composed and their text cascade@@ -180,10 +187,28 @@ pub struct PreparedSlide<'d> {/// Borrowed, not cloned: unlike `background` this is a whole shape tree per/// part, shared by every slide under it.///- /// Read by the geometry pass only. The markdown emitter deliberately- /// ignores it — see the module note on why layout text is a measured gap- /// rather than something this field quietly fixes.+ /// Read by the paint walk only: it is the whole rung, placeholders already+ /// dropped, and most of it is furniture with no text at all. The text these+ /// shapes carry reaches a reader through `inherited_text`, which is a much+ /// smaller list and a different rule.pub inherited: [&'d [Shape]; 2],+ /// The inherited shapes whose text a reader should actually get:+ /// `[master, layout]`, parallel to `inherited`, groups already flattened so+ /// each entry is a `p:sp` that carries its own composed rectangle.+ ///+ /// **This is a filtered list, and the filter is the point.** A layout shape+ /// is drawn on every slide that uses the layout, so emitting its text+ /// per-slide reprints the deck's furniture once per page: the census found+ /// 371 occurrences behind just 43 distinct strings, one of them a speaker+ /// banner landing on 47 slides and another the literal `‹#›` of a slide+ /// number. [`Deck::keeps_inherited_text`] admits only the strings that land+ /// on exactly one slide of the deck — 29 of the 371 — which is what makes+ /// this a content fix rather than a letterhead regression.+ ///+ /// Both walks read it, and neither re-derives it: the markdown a reader+ /// gets and the boxes the geometry pass reports are the same shapes by+ /// construction.+ pub inherited_text: [Vec<&'d Shape>; 2],/// Whether each arm of `inherited` is empty because it was **declined**/// rather than because the part had nothing to give: `[master, layout]`,/// parallel to `inherited`.@@ -233,7 +258,7 @@ impl Deck {// rather than failing the deck.let default_text_style =pptx::parse_default_text_style(&pkg.presentation.xml).unwrap_or_default();- Self {+ let mut deck = Self {master_geo: HashMap::new(),layout_geo: HashMap::new(),master_text: HashMap::new(),@@ -251,9 +276,101 @@ impl Deck {default_text_style: default_text_style.clone(),},default_text_style,+ inherited_text_counts: HashMap::new(),+ };+ deck.index_inherited_text(pkg);+ deck+ }++ /// Count, deck-wide, how many slides each inherited string lands on.+ ///+ /// Runs here rather than lazily because the answer is not knowable from one+ /// slide, and both walks need it on their first. It primes the rung caches+ /// as it goes, so the parts it reads are the ones the walks would have+ /// parsed anyway — the only work this adds is one attribute read per slide.+ ///+ /// That attribute is `@showMasterSp`, and it is read through+ /// [`pptx::shows_inherited_shapes`] rather than by deserializing the slide:+ /// a slide that declines a rung draws none of its text, so counting its+ /// occurrences would push a string off the "lands on one slide" rule and+ /// silently drop content. Getting it from a second `parse_slide_part` per+ /// slide measured at +7.5% on the corpus's markdown run, for one boolean.+ fn index_inherited_text(&mut self, pkg: &PresentationPackage) {+ for slide in &pkg.slides {+ self.prime(slide);+ let shows_layout = pptx::shows_inherited_shapes(&slide.slide.xml);+ let mut found = Vec::new();+ for shapes in self.inherited_rungs(slide, shows_layout).0 {+ collect_text_shapes(shapes, &mut found);+ }+ // The keys are owned before the counter is touched: `found` borrows+ // the rung caches, and the tally borrows `self` mutably.+ let keys: Vec<String> = found.into_iter().map(|(_, key)| key).collect();+ for key in keys {+ *self.inherited_text_counts.entry(key).or_default() += 1;+ }}}+ /// Whether an inherited string is content rather than furniture.+ ///+ /// **Lands on exactly one slide of the deck.** Measured against the+ /// alternative — "comes from a rung part that exactly one slide draws",+ /// which needs no string keying — on the 45-deck corpus: the two keep the+ /// same 29 occurrences, and the rung rule additionally emits 10 the text+ /// rule rejects. All 10 are furniture, and one of them is an authoring note+ /// to whoever edits the deck ("Glegoo is een niet-Windows-Font…"), which is+ /// as clear a statement as the corpus can make about which axis is right.+ fn keeps_inherited_text(&self, key: &str) -> bool {+ self.inherited_text_counts.get(key) == Some(&1)+ }++ /// The `[master, layout]` shape trees a slide draws, and whether each empty+ /// arm was **declined** rather than absent.+ ///+ /// Shared by [`Deck::prepare`] and [`Deck::index_inherited_text`] because+ /// the two must agree about what a slide shows: a tally that counted a rung+ /// the walk then declines would drop a string that is on one page only.+ ///+ /// §19.2.1.32: the slide's own `@showMasterSp` turns off *everything* the+ /// rungs above supply, so it gates the master arm as well as the layout's —+ /// a slide that declines its layout's design does not then take the+ /// master's, which the layout was itself drawing over. §19.3.1.39: the+ /// layout's gates only the master's.+ fn inherited_rungs(+ &self,+ slide: &pptx::SlideParts,+ shows_layout: bool,+ ) -> ([&[Shape]; 2], [bool; 2]) {+ let layout = slide.layout.as_ref();+ let shows_master = shows_layout+ && layout+ .and_then(|l| self.layout_shows_master.get(&l.path))+ .copied()+ .unwrap_or(true);+ (+ [+ if shows_master {+ slide+ .master+ .as_ref()+ .and_then(|m| self.master_shapes.get(&m.path))+ .map_or(&[][..], Vec::as_slice)+ } else {+ &[]+ },+ if shows_layout {+ layout+ .and_then(|l| self.layout_shapes.get(&l.path))+ .map_or(&[][..], Vec::as_slice)+ } else {+ &[]+ },+ ],+ [!shows_master, !shows_layout],+ )+ }+/// Prime the cascades for this slide's layout/master, parse its shape/// tree, and compose its geometry.///@@ -320,36 +437,20 @@ impl Deck {pptx::apply_inherited_geometry(&mut shapes, layout_geo, MatchRule::Idx);pptx::apply_slide_geometry(&mut shapes);- // §19.2.1.32: the slide's own `@showMasterSp` turns off *everything*- // the rungs above supply, so it gates the master arm as well as the- // layout's — a slide that declines its layout's design does not then- // take the master's, which the layout was itself drawing over.- // §19.3.1.39: the layout's gates only the master's.- let layout = slide.layout.as_ref();- let shows_layout = part.show_inherited_shapes;- let shows_master = shows_layout- && layout- .and_then(|l| self.layout_shows_master.get(&l.path))- .copied()- .unwrap_or(true);- let inherited = [- if shows_master {- slide- .master- .as_ref()- .and_then(|m| self.master_shapes.get(&m.path))- .map_or(&[][..], Vec::as_slice)- } else {- &[]- },- if shows_layout {- layout- .and_then(|l| self.layout_shapes.get(&l.path))- .map_or(&[][..], Vec::as_slice)- } else {- &[]- },- ];+ let (inherited, declined) = self.inherited_rungs(slide, part.show_inherited_shapes);+ // Filtered here rather than at either walk's door, for the same reason+ // `inherited_shapes` drops placeholders at cache-build time: what comes+ // out of `prepare` should be exactly what the walks may show, so the+ // markdown and the geometry cannot apply the rule differently.+ let inherited_text = inherited.map(|shapes| {+ let mut found = Vec::new();+ collect_text_shapes(shapes, &mut found);+ found+ .into_iter()+ .filter(|(_, key)| self.keeps_inherited_text(key))+ .map(|(shape, _)| shape)+ .collect()+ });let master = slide.master@@ -372,7 +473,8 @@ impl Deck {background,color_map,inherited,- declined: [!shows_master, !shows_layout],+ inherited_text,+ declined,media: self.media.get(Some(slide.slide.path.as_str())),inherited_media: [self.media.get(master_path), self.media.get(layout_path)],background_media,@@ -392,17 +494,28 @@ impl Deck {let Some(prepared) = self.prepare(pkg, slide) else {continue;};- let shapes = &prepared.shapes;-let mut ctx = SlideCtx {cascade: prepared.cascade(),part: &slide.slide,package: &pkg.package,opts,};- for shape in reading_order(shapes) {- emit_shape(shape, &mut ctx, &mut out, BlockSource::Slide(idx));+ for read in slide_reading_order(&prepared) {+ // The part an `r:id` resolves in — see [`Reading::rung`]. The+ // fallback cannot fire: a rung contributes shapes only when+ // `inherited_rungs` found its part, which is the same `Option`.+ ctx.part = match read.rung {+ Some(0) => slide.master.as_ref().unwrap_or(&slide.slide),+ Some(_) => slide.layout.as_ref().unwrap_or(&slide.slide),+ None => &slide.slide,+ };+ emit_shape(read.shape, &mut ctx, &mut out, BlockSource::Slide(idx));}+ // Put the slide's own part back before anything else reads `ctx`:+ // the notes walk below resolves its rels through this field, and+ // leaving it pointing at whichever rung happened to sort last would+ // be a bug that only shows on slides that inherit text.+ ctx.part = &slide.slide;if opts.notes&& let Some(notes) = &slide.notes@@ -546,23 +659,125 @@ pub fn reading_order(shapes: &[Shape]) -> Vec<&Shape> {.iter().filter(|s| !is_chrome(s.placeholder.as_ref())).collect();- v.sort_by_key(|s| {- let (band, x) = match s.slide_rect {- Some(r) => {- let b = r.bounding_box();- (b.origin.y.raw().div_euclid(ROW_BAND_EMU), b.origin.x.raw())- }- // A shape with no rectangle cannot be placed. Sorting it last- // keeps it in the output — dropping content to keep a sort total- // is never the right trade — while leaving positioned shapes in- // their proper order. The census measured 0 of these.- None => (i64::MAX, i64::MAX),- };- (!is_title(s.placeholder.as_ref()), band, x)- });+ v.sort_by_key(|s| reading_key(s));+ v+}++/// One shape's position in the reading order: title first, then top-to-bottom+/// in bands, then left-to-right.+///+/// Factored out of [`reading_order`] so that [`slide_reading_order`], which+/// sorts a list the former cannot build, is provably the same order rather than+/// a copy that agrees today.+fn reading_key(shape: &Shape) -> (bool, i64, i64) {+ let (band, x) = match shape.slide_rect {+ Some(r) => {+ let b = r.bounding_box();+ (b.origin.y.raw().div_euclid(ROW_BAND_EMU), b.origin.x.raw())+ }+ // A shape with no rectangle cannot be placed. Sorting it last+ // keeps it in the output — dropping content to keep a sort total+ // is never the right trade — while leaving positioned shapes in+ // their proper order. The census measured 0 of these.+ None => (i64::MAX, i64::MAX),+ };+ (!is_title(shape.placeholder.as_ref()), band, x)+}++/// A shape in a slide's reading order, and which tree it came out of.+#[doc(hidden)]+pub struct Reading<'a> {+ pub shape: &'a Shape,+ /// `None` for the slide's own `p:spTree`; `Some(0)` for the master's and+ /// `Some(1)` for the layout's — the same `[master, layout]` index as+ /// [`PreparedSlide::inherited`] and `inherited_media`.+ ///+ /// Carried rather than derived because an inherited shape's `r:id`s resolve+ /// in the part that wrote them: a layout's `rId3` and the slide's `rId3`+ /// are unrelated relationships, and a hyperlink read from the wrong table+ /// is a real URL pointing somewhere the author never wrote.+ pub rung: Option<usize>,+}++/// Everything a slide shows, in one reading order: its own shapes and the+/// inherited text that survived the furniture rule.+///+/// **One sort, not two passes.** An inherited shape is a backdrop in *paint*+/// order — that is why the paint walk draws the rungs before the slide — but it+/// is not a backdrop in *reading* order: `waterun`'s inherited subtitle sits+/// under the slide's title and reads there. Appending the rungs and sorting+/// once puts each string where it appears on the page, which is the only+/// ordering claim this module ever makes.+///+/// The slide's own shapes are inserted first, so on a tie — same band, same x —+/// the slide's text reads before the template's. `sort_by_key` is stable, so+/// that is a property of the order rather than an accident of it.+///+/// Public for the same reason [`reading_order`] is: a probe must measure this+/// traversal, not a re-implementation of it.+#[doc(hidden)]+pub fn slide_reading_order<'a>(prepared: &'a PreparedSlide<'_>) -> Vec<Reading<'a>> {+ let mut v: Vec<Reading<'a>> = prepared+ .shapes+ .iter()+ .filter(|s| !is_chrome(s.placeholder.as_ref()))+ .map(|shape| Reading { shape, rung: None })+ .collect();+ for (rung, shapes) in prepared.inherited_text.iter().enumerate() {+ // No chrome filter: `is_chrome` reads a `p:ph`, and an inherited shape+ // has none by construction — `inherited_shapes` dropped every+ // placeholder before these reached the cache.+ v.extend(shapes.iter().map(|&shape| Reading {+ shape,+ rung: Some(rung),+ }));+ }+ v.sort_by_key(|r| reading_key(r.shape));v}+/// Every text-bearing `p:sp` in a rung's tree, with the string the furniture+/// rule counts, groups flattened.+///+/// Flattened rather than walked as a tree because the rule is per *string*: a+/// group holding a logo and a strapline is two decisions, not one, and the+/// shapes come out of `inherited_shapes` with their group transforms already+/// composed — so a leaf carries its own rectangle and needs no parent.+///+/// The key joins the paragraphs a reader would see, and is what+/// `bench/pptx_corpus/inherited_text_census.py` counts, so the census's numbers+/// and this module's are about the same strings.+fn collect_text_shapes<'a>(shapes: &'a [Shape], out: &mut Vec<(&'a Shape, String)>) {+ for shape in shapes {+ match &shape.kind {+ ShapeKind::AutoShape(sp) => {+ if let Some(body) = &sp.text {+ let mut key = String::new();+ for para in &body.paragraphs {+ let line = para.text();+ if line.trim().is_empty() {+ continue;+ }+ if !key.is_empty() {+ key.push('\n');+ }+ key.push_str(&line);+ }+ let key = key.trim();+ if !key.is_empty() {+ out.push((shape, key.to_string()));+ }+ }+ }+ ShapeKind::Group(group) => collect_text_shapes(&group.children, out),+ // A `p:graphicFrame`'s table is a second gap of a different shape —+ // 2 of them in layout parts against 237 `p:sp`s — and folding the+ // two would make neither number act on.+ _ => {}+ }+ }+}+#[doc(hidden)]pub fn is_title(ph: Option<&Placeholder>) -> bool {matches!(@@ -1114,4 +1329,163 @@ mod tests {assert!(!is_title(ph(PlaceholderKind::SubTitle).as_ref()));assert!(!is_title(None));}++ // ── inherited text ──────────────────────────────────────────────────────++ /// A shape tree from a fragment, with geometry composed the way+ /// `inherited_shapes` composes a rung's before it caches it.+ fn tree(inner: &str) -> Vec<Shape> {+ let xml = format!(+ r#"<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"+ xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">+ <p:cSld><p:spTree>+ <p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>+ <p:grpSpPr/>+ {inner}+ </p:spTree></p:cSld>+ </p:sld>"#+ );+ let mut shapes = pptx::parse_shape_tree(xml.as_bytes()).expect("parses");+ pptx::apply_slide_geometry(&mut shapes);+ shapes+ }++ /// A `p:sp` at `(x, y)` EMU carrying one paragraph per line of `text`.+ fn text_shape(id: u32, x: i64, y: i64, text: &[&str]) -> String {+ let paras: String = text+ .iter()+ .map(|t| format!("<a:p><a:r><a:t>{t}</a:t></a:r></a:p>"))+ .collect();+ format!(+ r#"<p:sp>+ <p:nvSpPr><p:cNvPr id="{id}" name="s{id}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>+ <p:spPr><a:xfrm><a:off x="{x}" y="{y}"/><a:ext cx="914400" cy="914400"/></a:xfrm></p:spPr>+ <p:txBody><a:bodyPr/><a:lstStyle/>{paras}</p:txBody>+ </p:sp>"#+ )+ }++ /// The key is the string the census counts: paragraphs joined by newline,+ /// blank ones skipped. A key that drifted from the census's would make+ /// every number in the plan's write-up about a different population.+ #[test]+ fn the_key_joins_the_paragraphs_a_reader_would_see() {+ let shapes = tree(&text_shape(+ 2,+ 0,+ 0,+ &["Thank you", "", "for your", "attention"],+ ));+ let mut found = Vec::new();+ collect_text_shapes(&shapes, &mut found);+ assert_eq!(found.len(), 1);+ assert_eq!(found[0].1, "Thank you\nfor your\nattention");+ }++ /// A rung's logo-plus-strapline group is two strings, not one: the rule is+ /// per string, and a group that kept its children together would let a+ /// repeated logo drag a one-off strapline out of the output with it.+ #[test]+ fn groups_are_flattened_into_one_decision_per_string() {+ let shapes = tree(&format!(+ r#"<p:grpSp>+ <p:nvGrpSpPr><p:cNvPr id="9" name="g"/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>+ <p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="914400" cy="914400"/>+ <a:chOff x="0" y="0"/><a:chExt cx="914400" cy="914400"/></a:xfrm></p:grpSpPr>+ {}{}+ </p:grpSp>"#,+ text_shape(10, 0, 0, &["ACME"]),+ text_shape(11, 0, 100, &["a one-off strapline"]),+ ));+ let mut found = Vec::new();+ collect_text_shapes(&shapes, &mut found);+ let keys: Vec<&str> = found.iter().map(|(_, k)| k.as_str()).collect();+ assert_eq!(keys, ["ACME", "a one-off strapline"]);+ }++ /// A picture or a connector carries no `p:txBody`, and an empty one is not+ /// a string — neither may enter the tally, or the counts stop matching the+ /// census and a blank shape starts competing for a "lands on one slide".+ #[test]+ fn shapes_with_nothing_to_say_are_not_counted() {+ let shapes = tree(&format!(+ r#"{}<p:cxnSp><p:nvCxnSpPr><p:cNvPr id="4" name="c"/><p:cNvCxnSpPr/><p:nvPr/></p:nvCxnSpPr>+ <p:spPr/></p:cxnSp>"#,+ text_shape(3, 0, 0, &["", " "]),+ ));+ let mut found = Vec::new();+ collect_text_shapes(&shapes, &mut found);+ assert!(found.is_empty(), "{found:?} should be empty");+ }++ /// A `PreparedSlide` holding hand-built trees, so the merged order can be+ /// tested without a package on disk.+ fn prepared<'a>(+ shapes: Vec<Shape>,+ inherited: &'a [Shape],+ defaults: &'a DeckTextDefaults,+ media: &'a PartMedia,+ ) -> PreparedSlide<'a> {+ PreparedSlide {+ shapes,+ background: None,+ color_map: None,+ inherited: [&[], &[]],+ inherited_text: [Vec::new(), inherited.iter().collect()],+ declined: [false, false],+ media,+ inherited_media: [media, media],+ background_media: media,+ layout_text: None,+ master_text: None,+ deck_defaults: defaults,+ }+ }++ /// Inherited text is a backdrop in *paint* order and not in *reading*+ /// order: `waterun`'s inherited strapline sits above the slide's own first+ /// line and reads there, which one sort over both trees gives for free.+ #[test]+ fn inherited_text_reads_where_it_sits_on_the_page() {+ let defaults = DeckTextDefaults::default();+ let slide = tree(&text_shape(2, 0, 3_000_000, &["the slide's own line"]));+ let rung = tree(&text_shape(3, 0, 0, &["an inherited strapline"]));+ let media = PartMedia::default();+ let p = prepared(slide, &rung, &defaults, &media);+ let order: Vec<Option<usize>> = slide_reading_order(&p).iter().map(|r| r.rung).collect();+ assert_eq!(order, [Some(1), None]);+ }++ /// Same band, same x. The slide's own text is inserted first and the sort+ /// is stable, so it reads first — a template's caption should not cut in+ /// front of the line it was authored behind.+ #[test]+ fn the_slide_wins_a_tie_with_its_template() {+ let defaults = DeckTextDefaults::default();+ let slide = tree(&text_shape(2, 0, 0, &["the slide's own line"]));+ let rung = tree(&text_shape(3, 0, 0, &["an inherited line"]));+ let media = PartMedia::default();+ let p = prepared(slide, &rung, &defaults, &media);+ let order: Vec<Option<usize>> = slide_reading_order(&p).iter().map(|r| r.rung).collect();+ assert_eq!(order, [None, Some(1)]);+ }++ /// Title-first survives the merge. An inherited banner across the top of+ /// every slide sits above the title geometrically, and sorting on position+ /// alone would put it in front of the `#` on every page that keeps one.+ #[test]+ fn a_title_still_reads_first_under_an_inherited_banner() {+ let defaults = DeckTextDefaults::default();+ let mut slide = tree(&text_shape(2, 0, 3_000_000, &["the title"]));+ slide[0].placeholder = Some(Placeholder {+ kind: PlaceholderKind::Title,+ idx: 0,+ });+ let rung = tree(&text_shape(3, 0, 0, &["an inherited banner"]));+ let media = PartMedia::default();+ let p = prepared(slide, &rung, &defaults, &media);+ let order: Vec<Option<usize>> = slide_reading_order(&p).iter().map(|r| r.rung).collect();+ assert_eq!(order, [None, Some(1)]);+ }}diff --git a/crates/liteparse/src/office/pptx_layout.rs b/crates/liteparse/src/office/pptx_layout.rsindex 1577d28..c1d8016 100644--- a/crates/liteparse/src/office/pptx_layout.rs+++ b/crates/liteparse/src/office/pptx_layout.rs@@ -55,8 +55,8 @@ use liteparse_ooxml::model::{StyleMatrixRef, Theme,};use liteparse_ooxml::pptx::{- self, PresentationPackage, ResolvedTextStyle, Shape, ShapeKind, Spacing, TextBody, TextCascade,- TextParagraph,+ self, Group, PresentationPackage, ResolvedTextStyle, Shape, ShapeKind, Spacing, TextBody,+ TextCascade, TextParagraph,};use liteparse_ooxml::render::dimension::Pt;use liteparse_ooxml::render::fonts::FontRegistry;@@ -77,13 +77,15 @@ use liteparse_ooxml::render::resolve::drawing_color::{DrawingColorContext, resoluse liteparse_ooxml::render::resolve::fonts::resolve_font_set_themes;use liteparse_ooxml::render::resolve::images::PartMedia;use liteparse_ooxml::render::resolve::shape_geometry::build_geometry;-use liteparse_ooxml::render::resolve::shape_visuals::{resolve_blip_fill, resolve_shape_visuals};+use liteparse_ooxml::render::resolve::shape_visuals::{+ resolve_blip_fill, resolve_fill, resolve_shape_visuals,+};use std::collections::HashMap;use crate::error::LiteParseError;use crate::office::docx_layout;-use crate::office::pptx::{Deck, is_title, reading_order};+use crate::office::pptx::{self as pptx_emit, Deck, is_title, reading_order};use crate::types::{Page, TextItem};/// EMU per point (§20.1.2.1: 914400 EMU/inch ÷ 72 pt/inch).@@ -222,16 +224,28 @@ pub struct SlideGeometry {/// — the same class as `unpainted_shapes`, counted separately for the same/// reason as above.pub inherited_shapes_unpainted: usize,- /// Occurrences of an inherited shape that **carries text this pass does not- /// lay out**: 237 layout and 15 master shapes on the corpus, 13.7k- /// characters between them.+ /// Occurrences of an inherited shape that **carries text at all**: 371 on+ /// the corpus, of which 292 are a master's and 79 a layout's.///- /// A measured gap, deliberately left open. Emitting it would put text on a- /// page that the markdown emitter — which walks the slide's tree only —- /// does not emit, and the two must agree: a `TextItem` is a faithful box- /// only for markdown a reader actually gets. Closing it means teaching both- /// walks at once, which is its own step.+ /// Not a gap, and not a target. The census behind+ /// `bench/pptx_corpus/inherited_text_census.py` found only **43 distinct+ /// strings** under those 371 occurrences — a layout shape is drawn on every+ /// slide that uses the layout, so one speaker banner authored once lands on+ /// 47 pages, and 151 of the occurrences are the literal `‹#›` of a slide+ /// number. This counts the population; `inherited_text_laid_out` counts the+ /// part of it a reader gets.pub inherited_shapes_with_text: usize,+ /// Occurrences of inherited text this pass **did** lay out: the strings+ /// that land on exactly one slide of their deck, 29 of the 371 on the+ /// corpus. See [`PreparedSlide::inherited_text`] for the rule and what it+ /// was measured against.+ ///+ /// Counted in the text walk rather than the paint walk, so it is an+ /// occurrence of *emitted* text and not of a shape that happened to paint.+ /// The residue — 342 — is furniture, and dropping it is the feature.+ ///+ /// [`PreparedSlide::inherited_text`]: crate::office::pptx::PreparedSlide::inherited_text+ pub inherited_text_laid_out: usize,/// Slides that decline an inherited rung via `@showMasterSp="0"` — 4 slides/// declining their layout's shapes and, through 25 layouts, the slides that/// decline their master's. Counted because "painted nothing here" and@@ -258,6 +272,15 @@ pub struct SlideGeometry {/// Slides whose background is an image this pass now paints. Carved out of/// `unrenderable_backgrounds`, which was 63 before this step.pub blip_backgrounds_painted: usize,+ /// Shapes whose `spPr` fill is `a:grpFill` and which took a real fill from+ /// an enclosing group (§20.1.8.35).+ pub fills_from_group: usize,+ /// Shapes declaring `a:grpFill` where the chain of enclosing groups ends+ /// without one naming a fill. **Not a defect**: a group with `noFill`, or+ /// with no fill element at all, is the file saying "inherit nothing", and+ /// the shape is correctly left unpainted. Counted to keep that case+ /// visible and distinguishable from a lookup that missed.+ pub group_fills_unanswered: usize,/// Runs whose resolved colour is **exactly the colour of the slide's own/// background**, i.e. text that cannot be read.///@@ -355,6 +378,7 @@ fn layout_deck(pkg: &PresentationPackage, registry: &FontRegistry) -> SlideGeomeinherited_shapes_painted: 0,inherited_shapes_unpainted: 0,inherited_shapes_with_text: 0,+ inherited_text_laid_out: 0,slides_declining_layout: 0,slides_declining_master: 0,background_commands: Vec::with_capacity(pkg.slides.len()),@@ -370,6 +394,8 @@ fn layout_deck(pkg: &PresentationPackage, registry: &FontRegistry) -> SlideGeomepictures_implicit_rect: 0,blips_painted: 0,blip_backgrounds_painted: 0,+ fills_from_group: 0,+ group_fills_unanswered: 0,};for (idx, slide) in pkg.slides.iter().enumerate() {@@ -404,6 +430,7 @@ fn layout_deck(pkg: &PresentationPackage, registry: &FontRegistry) -> SlideGeomeinherited_shapes_painted: &mut out.inherited_shapes_painted,inherited_shapes_unpainted: &mut out.inherited_shapes_unpainted,inherited_shapes_with_text: &mut out.inherited_shapes_with_text,+ inherited_text_laid_out: &mut out.inherited_text_laid_out,painted_backgrounds: &mut out.painted_backgrounds,transparent_backgrounds: &mut out.transparent_backgrounds,unrenderable_backgrounds: &mut out.unrenderable_backgrounds,@@ -417,6 +444,8 @@ fn layout_deck(pkg: &PresentationPackage, registry: &FontRegistry) -> SlideGeomepictures_implicit_rect: &mut out.pictures_implicit_rect,blips_painted: &mut out.blips_painted,blip_backgrounds_painted: &mut out.blip_backgrounds_painted,+ fills_from_group: &mut out.fills_from_group,+ group_fills_unanswered: &mut out.group_fills_unanswered,};// Two walks over one `prepare`, in the order the raster wants// them. See [`paint_shape`] for why they cannot be one walk. The@@ -432,11 +461,24 @@ fn layout_deck(pkg: &PresentationPackage, registry: &FontRegistry) -> SlideGeome// from, which is why an inherited panel is a backdrop for the// slide's own shapes rather than a lid over them.for (rung, media) in prepared.inherited.into_iter().zip(prepared.inherited_media) {- paint_shapes(rung, Source::inherited(media), &mut ctx);+ paint_shapes(rung, Source::inherited(media), None, &mut ctx);}- paint_shapes(&prepared.shapes, Source::slide(prepared.media), &mut ctx);- for shape in reading_order(&prepared.shapes) {- layout_shape(shape, &mut ctx);+ paint_shapes(+ &prepared.shapes,+ Source::slide(prepared.media),+ None,+ &mut ctx,+ );+ // One order over the slide's own shapes *and* the inherited text+ // the furniture rule kept — the same list the markdown emitter+ // walks, from the same `prepare`. A `TextItem` is a faithful box+ // only for markdown a reader actually gets, so the two walks take+ // the same traversal or the claim is not true.+ for read in pptx_emit::slide_reading_order(&prepared) {+ if read.rung.is_some() {+ *ctx.inherited_text_laid_out += 1;+ }+ layout_shape(read.shape, &mut ctx);}out.slides_declining_master += usize::from(prepared.declined[0]);out.slides_declining_layout += usize::from(prepared.declined[1]);@@ -499,6 +541,7 @@ struct ShapeCtx<'a, 'r> {inherited_shapes_painted: &'a mut usize,inherited_shapes_unpainted: &'a mut usize,inherited_shapes_with_text: &'a mut usize,+ inherited_text_laid_out: &'a mut usize,painted_backgrounds: &'a mut usize,transparent_backgrounds: &'a mut usize,unrenderable_backgrounds: &'a mut usize,@@ -514,6 +557,8 @@ struct ShapeCtx<'a, 'r> {pictures_implicit_rect: &'a mut usize,blips_painted: &'a mut usize,blip_backgrounds_painted: &'a mut usize,+ fills_from_group: &'a mut usize,+ group_fills_unanswered: &'a mut usize,}/// Which part a painted shape came from.@@ -688,14 +733,53 @@ fn paint_background(/// chrome filter: this walk paints chrome, the text walk still drops it, and/// the 347 chrome shapes that carry text are a divergence this step leaves/// open rather than closes (see the module-level note in the plan).-fn paint_shapes(shapes: &[Shape], from: Source<'_>, ctx: &mut ShapeCtx<'_, '_>) {+/// `group_fill` is the fill the *enclosing* group offers its members, already+/// resolved and already chain-collapsed — see [`group_fill_for`].+fn paint_shapes(+ shapes: &[Shape],+ from: Source<'_>,+ group_fill: Option<&ResolvedFill>,+ ctx: &mut ShapeCtx<'_, '_>,+) {for shape in shapes {- paint_shape(shape, from, ctx);+ paint_shape(shape, from, group_fill, ctx);if let ShapeKind::Group(group) = &shape.kind {- // A group's own `grpSpPr` fill is not lowered to `ShapeProperties`- // at all, so a group paints nothing itself — its children carry- // every fill, in their own declaration order.- paint_shapes(&group.children, from, ctx);+ // A group puts no ink down itself: §19.3.1.23 gives it no+ // geometry, so its `grpSpPr` fill exists only as the thing its+ // members' `a:grpFill` names. Its children carry every fill, in+ // their own declaration order.+ let inherited = group_fill_for(group, group_fill, from, ctx);+ paint_shapes(&group.children, from, inherited.as_ref(), ctx);+ }+ }+}++/// What this group offers its members, given what its own parent offered it.+///+/// Collapses the chain here rather than at the point of use so that a+/// `DrawingFill::Group` reaching the resolver is always answerable in one+/// step. Three outcomes, and only the first paints:+///+/// * the group names a fill → that, resolved in this part's colour context+/// * the group's own fill is `a:grpFill` → whatever its parent offered,+/// passed straight through (6 corpus groups, carrying 414 shapes between+/// them, so the chain is load-bearing rather than theoretical)+/// * the group names `a:noFill`, or no fill at all → `None`. The spec's+/// "inherit nothing"; a member is then correctly unpainted.+fn group_fill_for(+ group: &Group,+ parent: Option<&ResolvedFill>,+ from: Source<'_>,+ ctx: &ShapeCtx<'_, '_>,+) -> Option<ResolvedFill> {+ match group.fill.as_ref()? {+ DrawingFill::Group => parent.cloned(),+ fill => {+ let color_ctx = DrawingColorContext::new(ctx.theme).with_color_map(ctx.color_map);+ match resolve_fill(fill, &color_ctx, Some(from.media), parent) {+ ResolvedFill::None => None,+ resolved => Some(resolved),+ }}}}@@ -708,7 +792,12 @@ fn paint_shapes(shapes: &[Shape], from: Source<'_>, ctx: &mut ShapeCtx<'_, '_>)/// self-placing. That also lets it carry the two flips, which a text bracket/// deliberately does not — §20.1.7.6 mirrors a shape's *geometry*, and/// PowerPoint does not mirror the text inside it.-fn paint_shape(shape: &Shape, from: Source<'_>, ctx: &mut ShapeCtx<'_, '_>) {+fn paint_shape(+ shape: &Shape,+ from: Source<'_>,+ group_fill: Option<&ResolvedFill>,+ ctx: &mut ShapeCtx<'_, '_>,+) {let Some(props) = shape_properties(shape) else {return;};@@ -732,7 +821,18 @@ fn paint_shape(shape: &Shape, from: Source<'_>, ctx: &mut ShapeCtx<'_, '_>) {style.and_then(|s| s.fill_ref.as_ref()),&DrawingColorContext::new(ctx.theme).with_color_map(ctx.color_map),Some(from.media),+ group_fill,);+ // §20.1.8.35 — tallied here, not after the paint gate: a `grpFill` that+ // resolved and then failed to build is a geometry gap, and folding it in+ // with the shapes that inherited nothing would blame the wrong step.+ if matches!(props.fill, Some(DrawingFill::Group)) {+ if matches!(visuals.fill, ResolvedFill::None) {+ *ctx.group_fills_unanswered += 1;+ } else {+ *ctx.fills_from_group += 1;+ }+ }// Where the ink came from, read *before* the picture override below// replaces the fill: a `p:pic` whose frame inherits a theme fill still// inherited it, and the photograph that lands on top is a different fact.