diff --git a/crates/drawingml/src/part.rs b/crates/drawingml/src/part.rs
index c3e530dd8..37d99481d 100644
--- a/crates/drawingml/src/part.rs
+++ b/crates/drawingml/src/part.rs
@@ -286,6 +286,38 @@ mod tests {
assert!(back.sys_colors.is_empty() && back.fonts.minor.latin_attrs.is_empty());
}
+ #[test]
+ fn font_panose_is_dropped_when_the_typeface_changes() {
+ let mut t = crate::theme::read_theme(&mut Part::new(), &parse(THEME_FILE.as_bytes()).unwrap());
+ t.fonts.minor.latin = "Arial".into();
+ let (xml, _) = theme_round_trip(&t);
+ assert!(xml.contains(r#""#), "{xml}");
+ assert!(!xml.contains("020F0502020204030204"), "{xml}");
+ assert!(xml.contains(r#""#, r#""#)
+ .replace(r#""#, r#""#);
+ let t = crate::theme::read_theme(&mut Part::new(), &parse(file.as_bytes()).unwrap());
+ let (xml, _) = theme_round_trip(&t);
+ assert!(xml.contains(r#""#), "{xml}");
+ assert!(xml.contains(r#""#), "{xml}");
+ }
+
+ #[test]
+ fn custom_colours_and_family_id_without_object_defaults_follow_an_empty_one() {
+ let file = THEME_FILE.replace("", "");
+ let t = crate::theme::read_theme(&mut Part::new(), &parse(file.as_bytes()).unwrap());
+ let (xml, back) = theme_round_trip(&t);
+ let at = |n: &str| xml.find(n).unwrap_or_else(|| panic!("{n} in {xml}"));
+ assert!(at("") < at(""), "{xml}");
+ assert!(at("") < at(",
pub pitch_family: Option,
diff --git a/crates/drawingml/src/theme/read.rs b/crates/drawingml/src/theme/read.rs
index 24b882b3a..0f4e4b2f0 100644
--- a/crates/drawingml/src/theme/read.rs
+++ b/crates/drawingml/src/theme/read.rs
@@ -24,7 +24,7 @@ fn font_set(e: Option<&El>) -> FontSet {
let attrs = |n: &str| {
let c = e.and_then(|e| e.child(Local(n)));
let at = |a: &str| c.and_then(|c| c.attr_local(a)).map(String::from);
- TypefaceAttrs { panose: at("panose"), pitch_family: at("pitchFamily"), charset: at("charset") }
+ TypefaceAttrs { typeface: at("typeface").unwrap_or_default(), panose: at("panose"), pitch_family: at("pitchFamily"), charset: at("charset") }
};
FontSet { latin: tf("latin"), ea: tf("ea"), cs: tf("cs"), latin_attrs: attrs("latin"), ea_attrs: attrs("ea"), cs_attrs: attrs("cs"), scripts }
}
diff --git a/crates/drawingml/src/theme/write.rs b/crates/drawingml/src/theme/write.rs
index 98a87f3a2..bc46d59e3 100644
--- a/crates/drawingml/src/theme/write.rs
+++ b/crates/drawingml/src/theme/write.rs
@@ -13,6 +13,9 @@ use crate::write as dml;
fn font_set(w: &mut Writer, tag: &str, f: &FontSet) {
w.open(tag, &[]);
let face = |w: &mut Writer, tag: &str, name: &str, a: &TypefaceAttrs| {
+ // Panose and the like describe one font: a changed typeface does not keep them.
+ let none = TypefaceAttrs::default();
+ let a = if a.typeface == name { a } else { &none };
w.tag(tag)
.attr("typeface", name)
.attr_opt("panose", a.panose.as_deref())