Apply review fixes

- crates/pptx/src/read.rs
- crates/pptx/src/read/shapes.rs
This commit is contained in:
aiongg
2026-11-08 13:36:49 +00:00
committed by Neil Cawse
parent 348014c7ff
commit 3e8da178f2
2 changed files with 11 additions and 4 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ pub struct Imp<'a> {
pub custom_show_names: HashMap<String, String>,
/// GUIDs (upper case) of the table styles the file defines.
pub table_style_ids: Vec<String>,
/// Per legacy VML drawing part: shape id → preview picture part (see `shapes::vml_preview`).
/// Per legacy VML drawing part: shape id or o:spid → preview picture part (see `shapes::vml_preview`).
pub vml_previews: HashMap<String, HashMap<String, String>>,
/// Aggregate byte count of retained chart sidecars across the presentation.
pub kept_sidecar_bytes: usize,
+10 -3
View File
@@ -510,8 +510,7 @@ fn vml_preview(imp: &mut Imp, part: &Part, spid: &str) -> Option<deckcraft_model
None
}
/// Every shape id in a VML drawing with a picture, mapped to that picture's part: parsed once per
/// drawing however many objects look it up.
/// The VML part with Office conditional-comment markers (`<!--[if …]>`, `<![if …]>`, `<![endif]-->`) removed, so shapes wrapped in them are parsed.
fn strip_vml_conditionals(bytes: &[u8]) -> std::borrow::Cow<'_, [u8]> {
let mut out = Vec::with_capacity(bytes.len());
let mut at = 0;
@@ -541,12 +540,20 @@ fn strip_vml_conditionals(bytes: &[u8]) -> std::borrow::Cow<'_, [u8]> {
if changed { std::borrow::Cow::Owned(out) } else { std::borrow::Cow::Borrowed(bytes) }
}
/// Every shape id and o:spid in a VML drawing with a picture, mapped to that picture's part: parsed once per
/// drawing however many objects look it up.
fn vml_index(pkg: &crate::opc::Package, vml: &str) -> std::collections::HashMap<String, String> {
let mut out = std::collections::HashMap::new();
let Some(bytes) = pkg.xml_bytes(vml) else { return out };
let decoded = crate::xml::decode_xml_bytes(bytes);
let bytes = strip_vml_conditionals(&decoded);
let Ok(doc) = crate::xml::parse(&bytes) else { return out };
let doc = match crate::xml::parse(&bytes) {
Ok(d) => d,
Err(e) => {
log::warn!("pptx: {vml}: {e}");
return out;
}
};
let rels = pkg.rels(vml);
let mut shapes = vec![];
doc.root.find_all("shape", &mut shapes);