DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #671: PARITY-IDML-INDEX: retain index reference source sort keys
aionggf9bc8a17a24f
diff --cc crates/idml/src/import.rsindex dcf0633b0,1b1cb7d8e..de22f99a9--- a/crates/idml/src/import.rs+++ b/crates/idml/src/import.rs@@@ -261,19 -206,32 +261,40 @@@ struct Importer<'r>/// Cross-reference format Self → name.xref_format_names: HashMap<String, String>,xref_formats: Vec<designcraft_doc::XrefFormat>,- /// Index topic Self → topic path; topic See / See also cross-references.- index_topics: HashMap<String, Vec<String>>,+ /// Index topic Self → topic path and per-level sort keys; topic cross-references.+ index_topics: HashMap<String, IndexTopic>,index_xrefs: Vec<designcraft_doc::IndexRef>,+ /// The file's text variables (`None`: it defines none) and their Self → index.+ text_vars: Option<Vec<designcraft_doc::vars::TextVariable>>,+ text_var_ids: HashMap<String, usize>,+ /// Creation and modification times (Unix seconds) from the package metadata.+ created: Option<i64>,+ modified: Option<i64>,+ /// Tab lists [`TabStop::sanitized_list`] had to repair (an import warning).+ repaired_tab_lists: usize,}+ /// IDML stores a sort key on each topic, rather than on its page references.+ #[derive(Clone, Default)]+ struct IndexTopic {+ path: Vec<String>,+ sort: Vec<String>,+ }++ impl IndexTopic {+ fn child(&self, topic: &El) -> Self {+ let mut path = self.path.clone();+ path.push(topic.get("Name").unwrap_or("").to_string());+ let mut sort = self.sort.clone();+ if let Some(key) = topic.get("SortOrder").filter(|key| !key.is_empty()) {+ // Keep empty positions before a child's key, but omit trailing defaults.+ sort.resize(self.path.len(), String::new());+ sort.push(key.to_string());+ }+ Self { path, sort }+ }+ }+fn lab_to_color(l: f32, a: f32, b: f32) -> Color {let rgb = lab::xyz_to_srgb(lab::lab_to_xyz(lab::Lab::new(l, a, b)));Color::rgb(rgb[0], rgb[1], rgb[2])@@@ -600,13 -474,9 +621,13 @@@ impl<'r> Importer<'r>self.xref_format(e);}if let Some(ix) = top.iter().find(|e| e.local() == "Index") {- self.index_topics_of(ix, &[]);+ self.index_topics_of(ix, &IndexTopic::default());}+ for e in top.iter().filter(|e| e.local() == "TextVariable") {+ self.text_variable(e);+ }// Stories (ids first so frames can reference them).+ let mut pending_stories = Vec::new();for e in top.iter().filter(|e| e.local() == "Story") {let id = StoryId(self.alloc());if let Some(s) = e.get("Self") {diff --cc crates/idml/src/tests.rsindex 0bc178e49,087a2b5d7..d3816cbc7--- a/crates/idml/src/tests.rs+++ b/crates/idml/src/tests.rs@@@ -8,13 -8,8 +8,14 @@@ use designcraft_geom::{Rect, shapes}use super::*;mod assets;+mod clipping;mod decorations;+ mod index_sort;+mod object_styles;+mod rtl_binding;+mod spread_rotation;+mod variables;+mod wrap;fn zip_files(files: &[(&str, &str)]) -> Vec<u8> {use zip::write::SimpleFileOptions;