mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-29 09:34:02 +01:00
feat: write the index sort options of every document
The index groups of the preferences object become IndexingSortOption elements in their stored order, with their include flag and a header type by group and header variant. Value coverage on trustworthy pairs: 86.86 % to 87.08 %.
This commit is contained in:
1 parent
3f1f10799d
commit
44f2d9c1a7
3 files changed
+123
No files matched your search
@@ -225,6 +225,38 @@ true in every layer; the two fields that are 1 in every sample may hold
|
||||
them. The converter reads the fields only when the name starts at offset
|
||||
19 (in all little-endian corpus pairs, 1,465 layers).
|
||||
|
||||
## Index sort options
|
||||
|
||||
Chunk 0x1307E of the preferences object (class 0x2202) holds the index
|
||||
groups: u32 count, then for each group its name (a flag byte and an
|
||||
in-object string such as `kIndexGroup_Symbol` or
|
||||
`kWRIndexGroup_GreekAlphabet`), u8 include, u8, u16 header variant, and
|
||||
further fields with the group's sections, whose letters and names repeat
|
||||
strings. The section records are not decoded: the converter finds each
|
||||
group at the first occurrence of its name (a flagged string starting
|
||||
with `kIndexGroup_` or `kWRIndexGroup_`) and uses the result only when it
|
||||
finds as many groups as the count says.
|
||||
|
||||
IDML writes an `IndexingSortOption` per group, in the stored order:
|
||||
`Self` `dIndexingSortOptionn` and the name, `Name` `$ID/` and the name,
|
||||
`Include`, `Priority` (the position, from 0) and `HeaderType`:
|
||||
|
||||
| Group | Variant | `HeaderType` |
|
||||
|---|---|---|
|
||||
| `kIndexGroup_Alphabet` | 0, 3, 5 | `BasicLatin`, `Spanish`, `Czech` |
|
||||
| `kWRIndexGroup_CyrillicAlphabet` | 2 | `Russian` |
|
||||
| `kIndexGroup_Kana` | 0 | `HiraganaAll` |
|
||||
| `kIndexGroup_Chinese` | 0 | `ChinesePinyin` |
|
||||
| `kIndexGroup_Korean` | 0 | `KoreanConsonant` |
|
||||
| Symbol, numeric, Greek, Arabic and Hebrew groups | 0 | `Nothing` |
|
||||
|
||||
The converter leaves `HeaderType` out for other combinations. Evidence:
|
||||
the 495 trustworthy pairs have 11 different lists (8 or 10 groups, in
|
||||
different orders, with different groups included); the converted groups
|
||||
match the IDML in all 4,934 groups on every attribute. Over all 654
|
||||
pairs the Alphabet variant is 0 in 652 files, 3 and 5 in one each, and
|
||||
the Cyrillic variant is 2 in all.
|
||||
|
||||
## Assignments (0x1BE01)
|
||||
|
||||
Every document has one object of class 0x1BE01, listed in chunk 0x1BE13
|
||||
|
||||
@@ -553,6 +553,29 @@ fn layout_constraints(flags: u8) -> Option<(String, String)> {
|
||||
Some((side(flags >> 4), side(flags & 7)))
|
||||
}
|
||||
|
||||
/// IDML `HeaderType` of an index group by its name and header variant.
|
||||
/// See `docs/format/objects.md`, index sort options.
|
||||
fn index_header_type(group: &str, variant: u16) -> Option<&'static str> {
|
||||
Some(match (group, variant) {
|
||||
("kIndexGroup_Alphabet", 0) => "BasicLatin",
|
||||
("kIndexGroup_Alphabet", 3) => "Spanish",
|
||||
("kIndexGroup_Alphabet", 5) => "Czech",
|
||||
("kWRIndexGroup_CyrillicAlphabet", 2) => "Russian",
|
||||
("kIndexGroup_Kana", 0) => "HiraganaAll",
|
||||
("kIndexGroup_Chinese", 0) => "ChinesePinyin",
|
||||
("kIndexGroup_Korean", 0) => "KoreanConsonant",
|
||||
(
|
||||
"kIndexGroup_Symbol"
|
||||
| "kIndexGroup_Numeric"
|
||||
| "kWRIndexGroup_GreekAlphabet"
|
||||
| "kWRIndexGroup_ArabicAlphabet"
|
||||
| "kWRIndexGroup_HebrewAlphabet",
|
||||
0,
|
||||
) => "Nothing",
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Numbers separated by spaces.
|
||||
fn join_numbers(v: &[u32]) -> String {
|
||||
v.iter().map(u32::to_string).collect::<Vec<_>>().join(" ")
|
||||
@@ -1364,6 +1387,19 @@ impl Writer<'_> {
|
||||
);
|
||||
x.end();
|
||||
}
|
||||
// Index sort options: the groups in their order, with the header
|
||||
// type each group and header variant has in IDML (objects.md).
|
||||
for (i, (name, include, variant)) in doc.index_groups.iter().enumerate() {
|
||||
x.start("IndexingSortOption")
|
||||
.attr("Self", format!("dIndexingSortOptionn{name}"))
|
||||
.attr("Name", format!("$ID/{name}"))
|
||||
.attr("Include", include.to_string())
|
||||
.attr("Priority", i.to_string());
|
||||
if let Some(h) = index_header_type(name, *variant) {
|
||||
x.attr("HeaderType", h);
|
||||
}
|
||||
x.end();
|
||||
}
|
||||
// InCopy assignments: the values every IDML has on them; the name
|
||||
// depends on the computer that exported the IDML (objects.md).
|
||||
if let Some(n) = values::element("Assignment", doc.version.major) {
|
||||
|
||||
@@ -163,6 +163,8 @@ pub mod chunk {
|
||||
pub const ROOT_GROUP_KIND: u32 = 0x28C2;
|
||||
pub const SECTION_INFO: u32 = 0x4C02;
|
||||
pub const DOCUMENT_PREFERENCES: u32 = 0x533;
|
||||
/// Index sort groups, in the preferences object.
|
||||
pub const INDEX_GROUPS: u32 = 0x1307E;
|
||||
pub const XML_TAG_NAME: u32 = 0xBF2F;
|
||||
pub const XML_TAG_COLOR: u32 = 0x117;
|
||||
/// Bullet characters, in the preferences object.
|
||||
@@ -662,6 +664,9 @@ pub struct Document {
|
||||
pub active_layer: Option<u32>,
|
||||
/// Document users (chunk 0xA443): flag byte and name.
|
||||
pub users: Vec<(u8, String)>,
|
||||
/// Index sort groups (preferences chunk 0x1307E), in order: name,
|
||||
/// include flag and header variant.
|
||||
pub index_groups: Vec<(String, bool, u16)>,
|
||||
/// Assignment objects (class 0x1BE01), in UID order.
|
||||
pub assignments: Vec<u32>,
|
||||
/// Named grids (class 0xCD12, chunk 0xCD28: u32, a flag byte, 1 for
|
||||
@@ -1370,6 +1375,7 @@ impl<'a> Reader<'a> {
|
||||
language_list,
|
||||
toc_styles: self.toc_styles(),
|
||||
named_grids: self.named_grids(),
|
||||
index_groups: self.index_groups(),
|
||||
assignments: {
|
||||
let mut a: Vec<u32> = self
|
||||
.db
|
||||
@@ -2718,6 +2724,55 @@ impl<'a> Reader<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The index sort groups of the preferences object, chunk 0x1307E: u32
|
||||
/// group count, then the groups with their sections. Each group is
|
||||
/// found by its name, a flag byte and an in-object string starting with
|
||||
/// `kIndexGroup_` or `kWRIndexGroup_`, at its first occurrence; after
|
||||
/// the name come u8 include, u8, u16 header variant. Empty unless the
|
||||
/// names found are as many as the count. See `docs/format/objects.md`.
|
||||
fn index_groups(&self) -> Vec<(String, bool, u16)> {
|
||||
let Some(&(uid, _)) = self
|
||||
.db
|
||||
.classes()
|
||||
.iter()
|
||||
.find(|(_, c)| *c == class::PREFERENCES)
|
||||
else {
|
||||
return Vec::new();
|
||||
};
|
||||
let Ok(Some(d)) = self.chunk(uid, chunk::INDEX_GROUPS) else {
|
||||
return Vec::new();
|
||||
};
|
||||
if crate::object::big_endian() {
|
||||
return Vec::new();
|
||||
}
|
||||
let Some(count) = u32_at(&d, 0) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut out: Vec<(String, bool, u16)> = Vec::new();
|
||||
for i in 4..d.len().saturating_sub(6) {
|
||||
if d[i] != 1 || d[i + 1] != 2 {
|
||||
continue;
|
||||
}
|
||||
let mut c = Cursor::new(&d[i + 1..]);
|
||||
let Ok(name) = c.string() else { continue };
|
||||
if !(name.starts_with("kIndexGroup_") || name.starts_with("kWRIndexGroup_"))
|
||||
|| out.iter().any(|(n, _, _)| *n == name)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let at = i + 1 + c.pos();
|
||||
let (Some(&include), Some(header)) = (d.get(at), u16_at(&d, at + 2)) else {
|
||||
continue;
|
||||
};
|
||||
out.push((name, include != 0, header));
|
||||
}
|
||||
if out.len() == count as usize {
|
||||
out
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// The named grids, in UID order.
|
||||
fn named_grids(&self) -> Vec<(bool, String)> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
Reference in new issue
Block a user