mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 22:37:12 +00:00
ppt-binary: an empty footer gives its look from its end mark; cap point spacing at DrawingML's
The footer row's look came from its first run, so an empty footer, date or slide number placeholder (no runs once normalized) gave none. It now falls back to the paragraph's end mark. This is the shared helper, so both paths take it. PowerPoint 95 point spacing was capped at 4000 pt, but DrawingML holds at most 1584 and the writer clamps to that, so a larger value changed on export. It is now capped at 1584.
This commit is contained in:
@@ -180,7 +180,8 @@ pub fn convert<'a>(d: &Doc<'a>, pictures: &'a [u8], app: &'a dyn Defaults) -> Pr
|
||||
/// A main master's placeholder of `kind` at `x`: the box of the default master's placeholder of
|
||||
/// the same family. The footer row (date, footer, slide number) sits in the same place on every
|
||||
/// layout, with the master's look: `look` gives its first paragraph, whose alignment and first
|
||||
/// run's size and colour the master's and layouts' footer placeholders take. `look` is called only
|
||||
/// run's size and colour (its end mark's, when it is empty) the master's and layouts' footer
|
||||
/// placeholders take. `look` is called only
|
||||
/// for the footer row, and only when the default master has such a placeholder.
|
||||
pub(crate) fn place_placeholder(master: &mut Master, kind: PhType, x: Xfrm, look: impl FnOnce() -> Option<Paragraph>) {
|
||||
let Some(s) = master.shapes.iter_mut().find(|s| s.ph_type().is_some_and(|t| same_family(t, kind))) else { return };
|
||||
@@ -191,10 +192,9 @@ pub(crate) fn place_placeholder(master: &mut Master, kind: PhType, x: Xfrm, look
|
||||
if let Some(p) = &look {
|
||||
let mut level = t.list_style.level(0).cloned().unwrap_or_default();
|
||||
level.para.align = p.props.align.or(level.para.align);
|
||||
if let Some(run) = p.runs.first() {
|
||||
level.run.size = run.props.size.or(level.run.size);
|
||||
level.run.fill = run.props.fill.clone().or(level.run.fill.take());
|
||||
}
|
||||
let first = p.runs.first().map_or(&p.end_props, |r| &r.props);
|
||||
level.run.size = first.size.or(level.run.size);
|
||||
level.run.fill = first.fill.clone().or(level.run.fill.take());
|
||||
t.list_style.set(0, level);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -763,7 +763,7 @@ fn paragraphs_keep_their_spacing() {
|
||||
[
|
||||
(Some(Spacing::Pct(1.5)), Some(Spacing::Pct(0.5)), Some(Spacing::Pct(0.0))),
|
||||
(Some(Spacing::Pts(36.0)), Some(Spacing::Pts(12.0)), Some(Spacing::Pts(6.0))),
|
||||
(Some(Spacing::Pct(100.0)), Some(Spacing::Pts(4000.0)), Some(Spacing::Pts(1.0))),
|
||||
(Some(Spacing::Pct(100.0)), Some(Spacing::Pts(1584.0)), Some(Spacing::Pts(1.0))),
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -931,6 +931,20 @@ fn master_placeholders_move_the_layout_boxes() {
|
||||
assert_eq!(own, ["Logo"]);
|
||||
}
|
||||
|
||||
/// An empty footer on the master still gives every layout's footer its size and colour: those of
|
||||
/// its end mark.
|
||||
#[test]
|
||||
fn an_empty_footer_keeps_its_look() {
|
||||
let empty = text(b"", &[char_run(1, 0, 10, 0, [0xFF, 0, 0, 0xFE])], &[para_run(1, false, 0, 2, 0)], 1, [0; 4], MASTER_BODY);
|
||||
let p = deck_of(vec![], &[placeholder_95(8, 1, 2, [-816, 1776, 816, 2064], Some(empty))]);
|
||||
for l in &p.masters[0].layouts {
|
||||
let footer = l.shapes.iter().find(|s| s.ph_type() == Some(PhType::Footer)).unwrap();
|
||||
let level = body_of(footer).list_style.level(0).unwrap();
|
||||
assert_eq!((level.para.align, level.run.size), (Some(Align::Right), Some(10.0)), "{}", l.name);
|
||||
assert_eq!(level.run.fill, Some(Fill::solid(ColorRef::rgb(Rgba::rgb(0xFF, 0, 0)))), "{}", l.name);
|
||||
}
|
||||
}
|
||||
|
||||
/// The characters, a font's face and a bullet character are Windows-1252, 0x80–0x9F included.
|
||||
#[test]
|
||||
fn text_is_windows_1252() {
|
||||
|
||||
@@ -411,10 +411,14 @@ fn run_props(r: &CharRun, env: &Env, scheme: &Scheme) -> RunProps {
|
||||
}
|
||||
}
|
||||
|
||||
/// The most points of spacing DrawingML holds (its `spcPts` reaches 158400 hundredths), as the
|
||||
/// writer clamps it, so an imported value survives export.
|
||||
const MAX_SPACING_PTS: f64 = 1584.0;
|
||||
|
||||
/// A paragraph run's spacing: a percentage of a line when positive, else minus a size in points.
|
||||
/// Bounded, so a hostile value can't push text off any page.
|
||||
fn spacing(v: i32) -> Spacing {
|
||||
if v >= 0 { Spacing::Pct((f64::from(v) / 100.0).min(100.0)) } else { Spacing::Pts((-f64::from(v)).min(4000.0)) }
|
||||
if v >= 0 { Spacing::Pct((f64::from(v) / 100.0).min(100.0)) } else { Spacing::Pts((-f64::from(v)).min(MAX_SPACING_PTS)) }
|
||||
}
|
||||
|
||||
/// A paragraph run's alignment, spacing and bullet, and the margins its level has in the text's
|
||||
|
||||
Reference in New Issue
Block a user