ppt-binary: a paragraph's end mark keeps the formatting at its CR, on both paths

Both paths gave a paragraph's end mark the formatting of its first
character. PowerPoint reads it from the character run at the CR (or at
the text's end for the last paragraph): a .ppt PowerPoint 16 saved, with
'AB\rCD' at 24 pt and only the first CR at 40, opens with that paragraph's
endParaRPr at 40. PowerPoint 95 gives the CR a run of its own when it
differs, so its path reads the same position.
This commit is contained in:
kiwi4boy
2026-11-20 01:49:15 -05:00
parent bf729d6d02
commit c9eba77824
4 changed files with 59 additions and 2 deletions
+3 -1
View File
@@ -939,7 +939,9 @@ impl<'a> Ctx<'a> {
para.runs.push(Run::with(String::from_utf16_lossy(&units), props));
i = j;
}
para.end_props = first;
// The paragraph mark's own formatting, as PowerPoint reads it: the character run at the
// CR, or at the text's end for the last paragraph.
para.end_props = self.run_props(&cf_at(end), &scope.scheme);
para.normalize();
out.push(para);
if end >= total {
+23
View File
@@ -686,6 +686,23 @@ fn the_font_table_is_the_first_list_with_a_face() {
assert_eq!(body_of(&p.slides[0].shapes[0]).paragraphs[0].runs[0].props.font.as_deref(), Some("Arial"));
}
/// A paragraph's end mark keeps the formatting of the character run at its CR, which PowerPoint 95
/// gives a run of its own when it differs (`endmark`, `endmark2`): not that of the paragraph's
/// first character.
#[test]
fn a_paragraphs_end_mark_keeps_the_formatting_at_its_cr() {
let end_sizes = |runs: &[(u32, u16)]| {
let runs: Vec<_> = runs.iter().map(|&(n, size)| char_run(n, 0, size, 0, [0, 0, 0, 1])).collect();
let body = text(b"AB\rCD", &runs, &[para_run(5, false, 0, 0, 0)], 1, [0; 4], BODY);
let p = deck_of(vec![shape_95([-2362, -1613, -518, -1325], Some(body))], &[]);
body_of(&p.slides[0].shapes[0]).paragraphs.iter().map(|para| para.end_props.size).collect::<Vec<_>>()
};
// What PowerPoint 95 wrote for "AB\rCD" at 40 pt with A and C at 24, and at 24 with the first
// CR at 40.
assert_eq!(end_sizes(&[(1, 24), (2, 40), (1, 24), (1, 40)]), [Some(40.0), Some(40.0)]);
assert_eq!(end_sizes(&[(2, 24), (1, 40), (2, 24)]), [Some(40.0), Some(24.0)]);
}
#[test]
fn character_runs_keep_their_formatting() {
let runs = [
@@ -1025,6 +1042,12 @@ fn check_sample(name: &str, p: &Presentation) {
let paras = |i: usize, j: usize| &body_of(&shapes(i)[j]).paragraphs;
let first_run = |i: usize, j: usize| &paras(i, j)[0].runs[0];
match name {
// "AB\rCD" at 40 pt with A and C at 24; at 24 with the first CR at 40 (Font.Points).
"endmark" | "endmark2" => {
let ends: Vec<_> = body_of(&p.slides[0].shapes[0]).paragraphs.iter().map(|q| q.end_props.size).collect();
let want = if name == "endmark" { [Some(40.0), Some(40.0)] } else { [Some(40.0), Some(24.0)] };
assert_eq!(ends, want, "{name}");
}
"twoslides" => assert_eq!(p.slides.len(), 2),
"title" => {
assert_eq!(layout_kind(p, 1), LayoutType::Title);
+3 -1
View File
@@ -382,7 +382,9 @@ fn paragraphs(chars: &[char], char_runs: &[CharRun], para_runs: &[ParaRun], rule
para.runs.push(Run::with(text, props));
i = j;
}
para.end_props = props_at(start);
// The paragraph mark's own formatting: the character run at the CR (PowerPoint 95 gives
// it one of its own when it differs), or the last run for the last paragraph.
para.end_props = props_at(end);
para.normalize();
out.push(para);
if end >= total {
+30
View File
@@ -723,6 +723,36 @@ fn a_shadowed_run_keeps_its_shadow() {
assert!(runs[1].props.shadow.is_none());
}
/// A paragraph's end mark keeps the formatting of the character run at its CR, not of the
/// paragraph's first character, as PowerPoint reads a .ppt PowerPoint saved: "AB\rCD" at 40 pt
/// with A and C at 24 ends each paragraph at 40; at 24 with only the first CR at 40, its first
/// paragraph ends at 40 and its second at 24.
#[test]
fn a_paragraphs_end_mark_keeps_the_formatting_at_its_cr() {
let end_sizes = |runs: &[(u32, u16)]| {
let mut style = vec![];
style.extend_from_slice(&6u32.to_le_bytes());
style.extend_from_slice(&0u16.to_le_bytes());
style.extend_from_slice(&pf_bytes(0, false));
for (n, size) in runs {
style.extend_from_slice(&n.to_le_bytes());
style.extend_from_slice(&0x2_0000u32.to_le_bytes()); // mask: size
style.extend_from_slice(&size.to_le_bytes());
}
let tb = container(
rt::SP_CONTAINER,
0,
&[fsp(202, 2049, 0xA00), anchor(0, 0, 1000, 1000), text_box(4, "AB\rCD", &[atom(rt::STYLE_TEXT_PROP, 0, &style)])],
);
let slide = container(rt::SLIDE, 0, &[slide_atom(1, MASTER_ID, 0x7), drawing(None, &[tb])]);
let (cu, doc, pics) = streams_of(0xE391_C05F, 1, slide, None);
let p = import(&build(&[("Current User", &cu), ("PowerPoint Document", &doc), ("Pictures", &pics)])).unwrap();
p.slides[0].shapes[0].text.as_ref().unwrap().paragraphs.iter().map(|para| para.end_props.size).collect::<Vec<_>>()
};
assert_eq!(end_sizes(&[(1, 24), (2, 40), (1, 24), (2, 40)]), [Some(40.0), Some(40.0)]);
assert_eq!(end_sizes(&[(2, 24), (1, 40), (3, 24)]), [Some(40.0), Some(24.0)]);
}
/// `tests/fixtures/old-talk.pps`: a one-slide `.pps` built here from records, for applications'
/// tests that need real 97–2003 bytes (DeckCraft's show-on-open test). Run this test with
/// `CRAFT_WRITE_PPT_FIXTURE=1` to rebuild the file after changing the builders.