fix(pptx): preserve font subset preference (#3410)

This commit is contained in:
Ap3pp3rs94 authored and GitHub committed 2026-11-30 07:57:16 -05:00
1 parent 1e321ca65c
commit ddb7340bac
4 files changed
+28 -1

No files matched your search

+3
View File
@@ -1083,6 +1083,8 @@ pub struct Presentation {
pub next_id: u32,
/// Embedded fonts. The face bytes live in [`Self::media`].
pub embedded_fonts: Vec<EmbeddedFont>,
/// Whether the next save should keep only the characters used by embedded fonts.
pub save_subset_fonts: bool,
/// Table styles defined in the file (`ppt/tableStyles.xml`).
#[serde(skip_serializing_if = "Vec::is_empty")]
pub table_styles: Vec<table::TableStyleDef>,
@@ -1131,6 +1133,7 @@ impl Default for Presentation {
first_slide_number: 1,
next_id: 0,
embedded_fonts: vec![],
save_subset_fonts: false,
table_styles: vec![],
tags: vec![],
kept_parts: vec![],
+1
View File
@@ -575,6 +575,7 @@ fn read_presentation_settings(imp: &mut Imp, p: &mut Presentation, pres_part: &P
p.notes_size = Size::new(sane_len(w, 540.0), sane_len(h, 720.0));
}
p.first_slide_number = pres_el.attr_local("firstSlideNum").and_then(value::to_u32_lossy).unwrap_or(1).min(9999);
p.save_subset_fonts = pres_el.attr_local("saveSubsetFonts").and_then(value::to_bool).unwrap_or(false);
if let Some(dts) = pres_el.child(Local("defaultTextStyle")) {
p.default_text_style = dml::list_style(&mut Src(imp, pres_part), dts);
}
+5 -1
View File
@@ -1153,7 +1153,11 @@ fn presentation_xml(x: &mut Exp, o: &mut Out, masters: &[(u64, String)], notes:
let p = x.p;
let mut w = Writer::document();
let first = (p.first_slide_number != 1).then_some(p.first_slide_number.min(9999));
root_open(&mut w, "p:presentation", A::new().a("saveSubsetFonts", 1).t("embedTrueTypeFonts", !fonts.is_empty()).o("firstSlideNum", first));
root_open(
&mut w,
"p:presentation",
A::new().t("saveSubsetFonts", p.save_subset_fonts).t("embedTrueTypeFonts", !fonts.is_empty()).o("firstSlideNum", first),
);
w.open("p:sldMasterIdLst", &[]);
for (id, rid) in masters {
w.tag("p:sldMasterId").attr("id", id).attr("r:id", rid).empty();
+19
View File
@@ -100,6 +100,25 @@ fn a_deck_without_masters_gets_the_callers() {
assert_eq!(q.slides[0].layout, q.masters[0].layouts[0].id);
}
#[test]
fn subset_font_setting_is_not_invented_and_survives_when_present() {
let bytes = craft_pptx::export(&deck(), &Plain).unwrap();
assert!(!part(&bytes, "ppt/presentation.xml").contains("saveSubsetFonts"), "a new deck must not opt into font subsetting");
let with_subset = common::rewrite(
&bytes,
|name, data| {
if name != "ppt/presentation.xml" {
return Some(data.to_vec());
}
let xml = String::from_utf8(data.to_vec()).unwrap();
Some(xml.replace("<p:presentation ", "<p:presentation saveSubsetFonts=\"1\" ").into_bytes())
},
&[],
);
let round_trip = craft_pptx::export(&craft_pptx::import(&with_subset, &Plain).unwrap(), &Plain).unwrap();
assert!(part(&round_trip, "ppt/presentation.xml").contains("saveSubsetFonts=\"1\""), "an explicit subset-font setting must survive");
}
#[test]
fn a_missing_picture_is_written_as_a_transparent_stand_in() {
let mut p = deck();