mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-27 04:06:52 -06:00
M12.AR15: never write a font family over 14 (review)
This commit is contained in:
@@ -438,7 +438,7 @@ fn font_xml(f: &Font, dxf: bool, minor: bool) -> String {
|
||||
s.push_str("<color theme=\"1\"/>");
|
||||
}
|
||||
if !dxf {
|
||||
let family = f.family.unwrap_or(DEFAULT_FONT_FAMILY);
|
||||
let family = f.family.filter(|v| *v <= MAX_FONT_FAMILY).unwrap_or(DEFAULT_FONT_FAMILY);
|
||||
let _ = write!(s, "<name val=\"{}\"/><family val=\"{family}\"/>", esc_attr(&f.name));
|
||||
if let Some(charset) = f.charset {
|
||||
let _ = write!(s, "<charset val=\"{charset}\"/>");
|
||||
|
||||
@@ -1175,6 +1175,15 @@ fn out_of_range_family_is_ignored() {
|
||||
let mut pkg = Package::open(&saved).unwrap();
|
||||
let xml = String::from_utf8(pkg.read("xl/styles.xml").unwrap().unwrap()).unwrap();
|
||||
assert!(xml.contains("<name val=\"Arial\"/><family val=\"2\"/>"), "{xml}");
|
||||
|
||||
let mut set_directly = wb.clone();
|
||||
let wide = set_directly.styles.derive(StyleId::DEFAULT, |st| st.font.family = Some(200));
|
||||
set_directly.sheet_mut(0).unwrap().set_value(CellRef::new(0, 0), Value::text("x"));
|
||||
set_directly.sheet_mut(0).unwrap().set_style(CellRef::new(0, 0), wide);
|
||||
let saved = write_xlsx(&set_directly).unwrap();
|
||||
let mut pkg = Package::open(&saved).unwrap();
|
||||
let xml = String::from_utf8(pkg.read("xl/styles.xml").unwrap().unwrap()).unwrap();
|
||||
assert!(!xml.contains("<family val=\"200\"/>"), "{xml}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user