feat: write languages, document users and document settings

designmap.xml gets the document's languages from their INDD objects,
with the quotes every IDML gives each language, the document users from
the document object, and the settings elements every IDML of the version
has (watermark, linked story and page item options, footnote and
endnote options and others) with their common values. User colours are
set by the exporting InDesign, not the INDD, and are left out of value
coverage.

Value coverage on trustworthy pairs: 81.65 % to 82.03 %.
This commit is contained in:
aiongg committed 2026-10-07 11:08:03 +00:00
1 parent fbe1e7f6ca
commit 722fddfe97
9 files changed
+419 -4

No files matched your search

+28
View File
@@ -237,6 +237,34 @@ Every spread has one `FlattenerPreference`, so the converter writes the
element on every spread. The other attributes of these elements come
from the INDD (`objects.md`).
### Document settings in designmap.xml
These elements are children of `Document` without `Self`. The tool keeps
an element when every IDML from some version on has it, with the values
all of them have; the converter writes it in the order of the IDML files.
| Element | From DOM | Values kept | Left out (vary) |
|---|---|---|---|
| `ConditionalTextPreference` | 7 | both | |
| `EndnoteOption` | 13 | 9 | `EndnoteTitle`, `EndnoteSeparatorText`, the marker and text styles, `EndnoteMarkerPositioning` |
| `TextFrameFootnoteOptionsObject` | 12 | all 4 | |
| `LinkedStoryOption` | 8 | all 4 | |
| `LinkedPageItemOption` | 8 | all 7 | |
| `WatermarkPreference` | 7 | 11 | the font family, style and colour |
| `TaggedPDFPreference` | 8 | `StructureOrder` | |
| `AdjustLayoutPreference` | 14 | 4 | `EnableAdjustLayout`, `EnableAutoAdjustMargins`, `AllowFontSizeAndLeadingAdjustment` |
| `HTMLFXLExportPreference` | 11 | both | |
| `PublishExportPreference` | 11 | 11 | `ImageExportResolution`, `PublishPdf` |
### Language quotes
The quotes of a language are not in its INDD object (`objects.md`,
languages). For each language name the tool keeps `SingleQuotes` and
`DoubleQuotes` when every IDML `Language` element with that name has the
same value, in at least 3 files (a `Keyed` block of the values file):
63 languages. Romanian and Japanese have two variants each and are left
out.
### Trap presets
All 683 IDML files list the same two `TrapPreset` elements at the end of
+41
View File
@@ -64,6 +64,22 @@ are in `big-endian.md`.
| 0x313 | u32: active layer (IDML `ActiveLayer`) |
| 0x222 | Two UID lists: the stories, then the XML backing story; IDML `StoryList` is both (`xml.md`) |
| 0x4C01 | UID list: sections |
| 0xA443 | Document users: u32 count, then per user a flag byte, the name as an in-object string, u32 colour |
**Document users.** IDML lists one `DocumentUser` per user in chunk
0xA443, `Self` being `dDocumentUser` and the index in hexadecimal (491 of
495 trustworthy pairs have as many users as the chunk; the other 4 are
DOM 7 and 16 files with one user more in the IDML). A user with flag 0
has its stored name as `UserName` (1,724 of 1,724). Flag 2 marks the
placeholder for an unknown user, stored with a name such as
`Unknown User Name` or the same words in the language of the computer
that saved it; IDML writes `$ID/Unknown User Name` for 495 of the 586
such users, and the stored name for the other 91. The schema requires
`UserName`, so the converter writes `$ID/Unknown User Name` for every
flag 2 user. The colour UID names an interface colour, but the IDML
`UserColor` does not follow from it (users stored with 0.6, 0.4, 0 are
`BrickRed` in 4 files and `Gold` in 1), so it is left out of the
conversion and of the measurement (`measurement.md`).
## Spreads (0x501) and master spreads (0x1401)
@@ -199,6 +215,31 @@ 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).
## Languages (0x2D07)
Chunk 0x2D0F: a flag byte and the name (`English: USA`), a flag byte and
the primary name (`English`), a flag byte and the secondary name (`USA`,
often empty), u16 `Id`, then two vendors, each a flag byte, a u32 and a
string: first the spelling vendor, then the hyphenation vendor
(`Hunspell`, `Proximity`, `Duden`, `WinSoft`); last the locale
(`en_US`).
IDML lists the language objects in UID order as `Language` elements at
the start of `designmap.xml`: `Name`, `PrimaryLanguageName` and
`SublanguageName` are `$ID/` and the stored names, except that the
language named `Neutral` is `$ID/[No Language]` in all three. Evidence
over the trustworthy pairs: in 488 of 495 the IDML list equals the INDD
objects in that order; in the other 7 the INDD has 4 to 61 language
objects and the IDML lists only some of them (1 or 2), for no reason
found. For the 1,249 IDML languages the names and `Id` are equal in
1,249. `HyphenationVendor` is the second vendor and `SpellingVendor` the
first when their flag is 1 (1,146 and 1,166 of 1,249); otherwise the
stored string is empty or names a vendor the IDML does not show, and
IDML gives `$ID/`, `$ID/InDihyph` or a vendor such as `Hunspell` that
depends on the computer that exported it, so the converter leaves the
attribute out. The quotes (`SingleQuotes`, `DoubleQuotes`) are not in the
chunk; they are written from observation (`idml-values.md`).
## Interface colours (0x1F11)
Layers, pages and XML tags name their colour by the UID of an object of
+1
View File
@@ -140,6 +140,7 @@ are left out of the counts (`EXCLUDED` in `compare.py`).
|---|---|---|
| `Font` | `Status` | It records whether the font is installed on the computer that exported the IDML. The same document gives a different value on another computer. |
| `idPkg:Story`, `idPkg:Spread` and the other part references in `designmap.xml` | `src` | The file names of the parts inside the IDML package. The IDML writer chooses them; they are not document content. |
| `DocumentUser` | `UserColor` | The colour of each user of the document as the exporting InDesign shows it. The INDD stores a colour for each user (`objects.md`, document users), but the IDML colour does not follow from it: users stored with the same colour get different IDML colours in different files. |
A value enters this list only with a reason of this kind. Values that are
hard to decode, or that the converter does not write yet, stay in the
+108
View File
@@ -33,6 +33,12 @@ tools/element_values.py; evidence in docs/format/idml-values.md.
<MasterSpread OverriddenPageItemProps="" ItemTransform="1 0 0 1 0 0" />
<Page AppliedTrapPreset="TrapPreset/$ID/kDefaultTrapStyleName" GridStartingPoint="TopOutside" />
<Layer ShowGuides="true" Expendable="true" />
<Document>
<ConditionalTextPreference Present="true" ShowConditionIndicators="ShowIndicators" ActiveConditionSet="n" />
<LinkedStoryOption UpdateWhileSaving="false" WarnOnUpdateOfEditedStory="true" RemoveForcedLineBreaks="false" />
<WatermarkPreference Present="true" WatermarkVisibility="false" WatermarkDoPrint="false" WatermarkDrawInBack="true" WatermarkText="" WatermarkFontPointSize="48" WatermarkOpacity="50" WatermarkRotation="0" WatermarkHorizontalPosition="WatermarkHCenter" WatermarkHorizontalOffset="0" WatermarkVerticalPosition="WatermarkVCenter" WatermarkVerticalOffset="0" />
<TaggedPDFPreference StructureOrder="UseXMLStructure" />
</Document>
</Values>
<Values MinimumVersion="8">
<Rectangle TargetInterfaceChangeCount="" LastUpdatedInterfaceChangeCount="">
@@ -79,6 +85,11 @@ tools/element_values.py; evidence in docs/format/idml-values.md.
</ObjectExportOption>
</TextFrame>
<Page SnapshotBlendingMode="IgnoreLayoutSnapshots" OptionalPage="false" />
<Document>
<LinkedStoryOption Present="true" ApplyStyleMappings="false" />
<LinkedPageItemOption Present="true" UpdateLinkWhileSaving="false" WarnOnUpdateOfEditedPageItem="true" PreserveSizeAndShape="false" PreserveAppearance="false" PreserveInteractivity="false" PreserveFrameContent="false" PreserveOthers="false" />
<TaggedPDFPreference Present="true" />
</Document>
</Values>
<Values MinimumVersion="10">
<TextFrame>
@@ -99,6 +110,38 @@ tools/element_values.py; evidence in docs/format/idml-values.md.
<Group>
<ObjectExportOption EpubType="$ID/" />
</Group>
<Document>
<HTMLFXLExportPreference EpubPageRange="" EpubPageRangeFormat="ExportAllPages" />
</Document>
</Values>
<Values MinimumVersion="11">
<Document>
<HTMLFXLExportPreference Present="true" />
<PublishExportPreference Present="true" PublishCover="FirstPage" CoverImageFile="" PublishPageRange="" PublishPageRangeFormat="ExportAllPages" ImageConversion="Automatic" PublishDescription="" PublishFileName="" PublishFormat="PublishByPages" CoverPage="$ID/" GIFOptionsPalette="AdaptivePalette" JPEGOptionsQuality="High" />
</Document>
</Values>
<Values MinimumVersion="12">
<Document>
<TextFrameFootnoteOptionsObject Present="true" EnableOverrides="false" SpanFootnotesAcross="false" MinimumSpacingOption="12" SpaceBetweenFootnotes="6" />
</Document>
</Values>
<Values MinimumVersion="13">
<Document>
<EndnoteOption Present="true" EndnoteTitleStyle="ParagraphStyle/$ID/NormalParagraphStyle" StartEndnoteNumberAt="1" EndnotePrefix="" EndnoteSuffix="">
<Properties>
<EndnoteNumberingStyle type="enumeration">Arabic</EndnoteNumberingStyle>
<RestartEndnoteNumbering type="enumeration">Continuous</RestartEndnoteNumbering>
<ScopeValue type="enumeration">EndnoteDocumentScope</ScopeValue>
<FrameCreateOption type="enumeration">NewPage</FrameCreateOption>
<ShowEndnotePrefixSuffix type="enumeration">NoPrefixSuffix</ShowEndnotePrefixSuffix>
</Properties>
</EndnoteOption>
</Document>
</Values>
<Values MinimumVersion="14">
<Document>
<AdjustLayoutPreference Present="true" AllowLockedObjectsToAdjust="true" ImposeFontSizeRestriction="false" MinimumFontSize="6" MaximumFontSize="324" />
</Document>
</Values>
<Values MinimumVersion="19">
<Spread SpreadHidden="false" />
@@ -127,4 +170,69 @@ tools/element_values.py; evidence in docs/format/idml-values.md.
<TrapPreset Self="TrapPreset/$ID/k[No Trap Preset]" Name="$ID/k[No Trap Preset]" DefaultTrapWidth="0.25" BlackWidth="0.5" TrapJoin="MiterEndJoin" TrapEnd="MiterTrapEnds" ObjectsToImages="true" ImagesToImages="true" InternalImages="false" OneBitImages="true" ImagePlacement="CenterEdges" StepThreshold="10" BlackColorThreshold="100" BlackDensity="1.6" SlidingTrapThreshold="70" ColorReduction="100" />
<TrapPreset Self="TrapPreset/$ID/kDefaultTrapStyleName" Name="$ID/kDefaultTrapStyleName" DefaultTrapWidth="0.25" BlackWidth="0.5" TrapJoin="MiterEndJoin" TrapEnd="MiterTrapEnds" ObjectsToImages="true" ImagesToImages="true" InternalImages="false" OneBitImages="true" ImagePlacement="CenterEdges" StepThreshold="10" BlackColorThreshold="100" BlackDensity="1.6" SlidingTrapThreshold="70" ColorReduction="100" />
</List>
<Keyed Tag="Language" Key="Name">
<Language Name="$ID/Arabic" SingleQuotes="‹›" DoubleQuotes="«»" />
<Language Name="$ID/Bulgarian" SingleQuotes="‚‘" DoubleQuotes="„“" />
<Language Name="$ID/Catalan" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Chinese: Simplified" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/Croatian" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Czech" SingleQuotes="‚‘" DoubleQuotes="„“" />
<Language Name="$ID/Danish" SingleQuotes="’’" DoubleQuotes="””" />
<Language Name="$ID/Dutch" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/English: Canadian" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/English: UK" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/English: USA" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/English: USA Legal" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/English: USA Medical" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Estonian" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Finnish" SingleQuotes="’’" DoubleQuotes="””" />
<Language Name="$ID/French" SingleQuotes="‘’" DoubleQuotes="«»" />
<Language Name="$ID/French: Canadian" SingleQuotes="‘’" DoubleQuotes="«»" />
<Language Name="$ID/German: Austrian" SingleQuotes="‚‘" DoubleQuotes="„“" />
<Language Name="$ID/German: Reformed" SingleQuotes="‚‘" DoubleQuotes="„“" />
<Language Name="$ID/German: Swiss" SingleQuotes="‹›" DoubleQuotes="«»" />
<Language Name="$ID/German: Traditional" SingleQuotes="‚‘" DoubleQuotes="„“" />
<Language Name="$ID/Greek" SingleQuotes="‘’" DoubleQuotes="«»" />
<Language Name="$ID/Hungarian" SingleQuotes="‚’" DoubleQuotes="„”" />
<Language Name="$ID/Italian" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Korean" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/Latvian" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Lithuanian" SingleQuotes="‚‘" DoubleQuotes="„“" />
<Language Name="$ID/Norwegian: Bokmal" SingleQuotes="’’" DoubleQuotes="””" />
<Language Name="$ID/Norwegian: Nynorsk" SingleQuotes="’’" DoubleQuotes="””" />
<Language Name="$ID/Polish" SingleQuotes="‚’" DoubleQuotes="„”" />
<Language Name="$ID/Portuguese" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Portuguese: Brazilian" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Portuguese: Orthographic Agreement" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Russian" SingleQuotes="‘’" DoubleQuotes="«»" />
<Language Name="$ID/Slovak" SingleQuotes="‚‘" DoubleQuotes="„“" />
<Language Name="$ID/Slovenian" SingleQuotes="''" DoubleQuotes="»«" />
<Language Name="$ID/Spanish: Castilian" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Swedish" SingleQuotes="’’" DoubleQuotes="””" />
<Language Name="$ID/Thai" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/Turkish" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/Ukrainian" SingleQuotes="‘’" DoubleQuotes="«»" />
<Language Name="$ID/Vietnamese" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/[No Language]" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/bn_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/de_CH_2006" SingleQuotes="‹›" DoubleQuotes="«»" />
<Language Name="$ID/de_DE_2006" SingleQuotes="‚‘" DoubleQuotes="„“" />
<Language Name="$ID/gu_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/hi_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/id_ID" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/km_KH" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/kn_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/lo_LA" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/ml_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/mr_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/my_MM" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/ne_NE" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/nl_NL_2005" SingleQuotes="‘’" DoubleQuotes="“”" />
<Language Name="$ID/or_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/pa_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/si_LK" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/sr_RS-Cyr" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/ta_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/te_IN" SingleQuotes="''" DoubleQuotes='""' />
</Keyed>
</ElementValues>
+81
View File
@@ -1155,6 +1155,7 @@ impl Writer<'_> {
if let Some(l) = doc.active_layer {
x.attr("ActiveLayer", uref(Some(l)));
}
self.languages(&mut x);
x.empty("idPkg:Graphic", &[("src", "Resources/Graphic.xml".into())]);
x.empty("idPkg:Fonts", &[("src", "Resources/Fonts.xml".into())]);
// Kinsoku tables, then mojikumi tables, as the schema orders them.
@@ -1189,10 +1190,32 @@ impl Writer<'_> {
("ContinueNumbersAcrossDocuments", "false".into()),
],
);
let major = doc.version.major;
// Elements every IDML of the version has, with the values they
// all have (idml-values.md), in the order of the IDML files.
let singleton = |x: &mut Xml, tag: &str| {
if let Some(n) = values::present(&format!("Document/{tag}"), major) {
n.write(x);
}
};
singleton(&mut x, "ConditionalTextPreference");
x.empty(
"idPkg:Preferences",
&[("src", "Resources/Preferences.xml".into())],
);
for tag in [
"EndnoteOption",
"TextFrameFootnoteOptionsObject",
"LinkedStoryOption",
"LinkedPageItemOption",
"WatermarkPreference",
"TaggedPDFPreference",
"AdjustLayoutPreference",
"HTMLFXLExportPreference",
"PublishExportPreference",
] {
singleton(&mut x, tag);
}
self.text_variables(&mut x);
x.empty("idPkg:Tags", &[("src", "XML/Tags.xml".into())]);
for l in doc.layers.iter().filter(|l| !l.internal) {
@@ -1263,6 +1286,23 @@ impl Writer<'_> {
}
x.end();
}
// Document users. A user with flag 2 is the placeholder for an
// unknown user, which IDML names `$ID/Unknown User Name`; the
// colours are left out (docs/format/objects.md, document users).
for (i, (flag, name)) in doc.users.iter().enumerate() {
let name = if *flag == 2 {
"$ID/Unknown User Name"
} else {
name.as_str()
};
x.empty(
"DocumentUser",
&[
("Self", format!("dDocumentUser{i:x}")),
("UserName", name.into()),
],
);
}
self.cross_reference_formats(&mut x);
x.empty(
"idPkg:BackingStory",
@@ -1305,6 +1345,47 @@ impl Writer<'_> {
x.finish()
}
/// The document's languages, in UID order. See
/// `docs/format/objects.md`, languages.
fn languages(&self, x: &mut Xml) {
let mut list: Vec<_> = self.doc.language_list.iter().collect();
list.sort_by_key(|l| l.uid);
for l in list {
// The language without one is `Neutral` in the INDD.
let neutral = l.name == "Neutral";
let name = |s: &str| {
if neutral {
"$ID/[No Language]".to_string()
} else {
format!("$ID/{s}")
}
};
let full = name(&l.name);
x.start("Language")
.attr("Self", format!("Language/{}", self_name(&full)))
.attr("Name", &full);
if let Some(q) = values::keyed("Language", &full) {
for k in ["SingleQuotes", "DoubleQuotes"] {
if let Some(v) = q.attr(k) {
x.attr(k, v);
}
}
}
x.attr("PrimaryLanguageName", name(&l.primary))
.attr("SublanguageName", name(&l.sub))
.attr("Id", l.id.to_string());
if let Some([(sf, spelling), (hf, hyphenation)]) = &l.vendors {
if *hf == 1 {
x.attr("HyphenationVendor", hyphenation);
}
if *sf == 1 {
x.attr("SpellingVendor", spelling);
}
}
x.end();
}
}
/// Colour groups and their swatches. See `docs/format/objects.md`.
fn color_groups(&self, x: &mut Xml) {
for (i, g) in self.doc.color_groups.iter().enumerate() {
+32
View File
@@ -242,6 +242,18 @@ pub fn element_attrs(path: &str, major: u32) -> Vec<(String, String)> {
.unwrap_or_default()
}
/// The element on `path` every IDML of InDesign version `major` in the
/// corpus has (`Present="true"` in `element_values.xml`), with its
/// observed values; `None` if not every IDML has it.
pub fn present(path: &str, major: u32) -> Option<Node> {
let mut n = element(path, major)?;
if n.attr("Present") != Some("true") {
return None;
}
n.attrs.retain(|(k, _)| k != "Present");
Some(n)
}
/// The list of `tag` elements every IDML of InDesign version `major` in
/// the corpus has, in order (`List` blocks of `element_values.xml`);
/// empty if there is none.
@@ -254,6 +266,21 @@ pub fn list(tag: &str, major: u32) -> Vec<Node> {
.collect()
}
/// The observed values of a `tag` element whose key attribute (such as
/// `Name`) has `value` (`Keyed` blocks of `element_values.xml`).
pub fn keyed(tag: &str, value: &str) -> Option<Node> {
let block = element_values()
.children
.iter()
.find(|b| b.tag == "Keyed" && b.attr("Tag") == Some(tag))?;
let key = block.attr("Key")?;
block
.children
.iter()
.find(|n| n.attr(key) == Some(value))
.cloned()
}
fn unescape(s: &str) -> String {
s.replace("&lt;", "<")
.replace("&gt;", ">")
@@ -390,6 +417,11 @@ mod tests {
// Export options differ between versions.
assert!(new.attr("EpubType").is_some());
assert_eq!(list("TrapPreset", 21).len(), 2);
let en = keyed("Language", "$ID/English: USA").unwrap();
assert_eq!(en.attr("DoubleQuotes"), Some("\u{201C}\u{201D}"));
let w = present("Document/WatermarkPreference", 21).unwrap();
assert!(w.attr("Present").is_none());
assert!(present("Document/EndnoteOption", 12).is_none());
assert!(
element("Polygon/ObjectExportOption", 8)
.unwrap()
+75 -1
View File
@@ -76,6 +76,9 @@ pub mod chunk {
pub const DOC_ACTIVE_LAYER: u32 = 0x313;
pub const DOC_STORIES: u32 = 0x222;
pub const DOC_SECTIONS: u32 = 0x4C01;
/// Document users: u32 count, then per user a flag byte, the name
/// and u32 colour.
pub const DOC_USERS: u32 = 0xA443;
pub const SPREAD_CHILDREN: u32 = 0x503;
pub const SPREAD_TRANSFORM: u32 = 0x56E;
pub const SPREAD_BINDING: u32 = 0x1B8;
@@ -608,6 +611,8 @@ pub struct Document {
pub version: Version,
pub layers: Vec<Layer>,
pub active_layer: Option<u32>,
/// Document users (chunk 0xA443): flag byte and name.
pub users: Vec<(u8, String)>,
pub spreads: Vec<Spread>,
pub master_spreads: Vec<Spread>,
pub stories: Vec<Story>,
@@ -620,6 +625,8 @@ pub struct Document {
pub swatches: BTreeMap<u32, String>,
/// Font families by UID.
pub fonts: BTreeMap<u32, FontFamily>,
/// The language objects (class 0x2D07) in UID order.
pub language_list: Vec<Language>,
/// Language name (IDML `AppliedLanguage` without `$ID/`) for each
/// language UID.
pub languages: BTreeMap<u32, String>,
@@ -731,6 +738,19 @@ pub mod numbering {
pub const KANJI: u32 = 0x4C12;
}
/// A language object (class 0x2D07), chunk 0x2D0F. See
/// `docs/format/objects.md`, languages.
#[derive(Debug, Clone, PartialEq)]
pub struct Language {
pub uid: u32,
pub name: String,
pub primary: String,
pub sub: String,
pub id: u16,
/// The spelling and hyphenation vendors, each with its flag byte.
pub vendors: Option<[(u8, String); 2]>,
}
/// A bullet character of the document's list (IDML `ABullet`): u32
/// character type, u32 character value, u32 font family (0 = none), the
/// font style as a flag byte and string, then a byte (0 in every sample).
@@ -872,6 +892,7 @@ impl<'a> Reader<'a> {
let mut swatches = BTreeMap::new();
let mut fonts = BTreeMap::new();
let mut languages = BTreeMap::new();
let mut language_list = Vec::new();
let mut style_groups = BTreeMap::new();
let mut object_styles = BTreeMap::new();
let mut cell_styles = BTreeMap::new();
@@ -1182,7 +1203,35 @@ impl<'a> Reader<'a> {
{
let mut c = Cursor::new(&d);
c.flag()?;
languages.insert(uid, c.string()?);
let name = c.string()?;
languages.insert(uid, name.clone());
// Then the primary and secondary names, u16
// ID, and two vendors (flag, u32, string).
let rest = (|| -> Result<_, Error> {
c.flag()?;
let primary = c.string()?;
c.flag()?;
let sub = c.string()?;
let id = c.u16()?;
let mut vendor = || -> Result<(u8, String), Error> {
let flag = c.u8()?;
c.u32()?;
Ok((flag, c.string()?))
};
let spelling = vendor()?;
let hyphenation = vendor()?;
Ok((primary, sub, id, [spelling, hyphenation]))
})();
if let Ok((primary, sub, id, vendors)) = rest {
language_list.push(Language {
uid,
name,
primary,
sub,
id,
vendors: Some(vendors),
});
}
}
}
_ => {}
@@ -1245,10 +1294,15 @@ impl<'a> Reader<'a> {
swatches,
fonts,
languages,
language_list,
style_groups,
object_styles,
cell_styles,
table_styles,
users: self.users(doc).unwrap_or_else(|e| {
self.warn(format!("document users left out: {e}"));
Vec::new()
}),
sections: self
.uid_list(doc, chunk::DOC_SECTIONS)?
.into_iter()
@@ -1803,6 +1857,26 @@ impl<'a> Reader<'a> {
})
}
/// The document's users, from chunk 0xA443 of the document.
fn users(&self, doc: u32) -> Result<Vec<(u8, String)>, Error> {
let Some(d) = self.chunk(doc, chunk::DOC_USERS)? else {
return Ok(Vec::new());
};
let mut c = Cursor::new(&d);
let n = c.u32()?;
if n as usize > d.len() / 9 {
return Err(Error::Corrupt(format!("{n} document users")));
}
(0..n)
.map(|_| {
let flag = c.flag()?;
let name = c.string()?;
c.u32()?;
Ok((flag, name))
})
.collect()
}
/// The settings every page item has (`ItemProps`).
fn item_props(&self, uid: u32) -> Result<ItemProps, Error> {
let name_chunk = if self.class(uid) == Some(class::GROUP) {
+2
View File
@@ -320,6 +320,8 @@ EXCLUDED = [
("Font", "Status", "whether the font is installed on the exporting computer"),
("Document/{http://ns.adobe.com/AdobeInDesign/idml/1.0/packaging}*", "src",
"file names of the package parts, chosen by the IDML writer"),
("DocumentUser", "P.UserColor",
"colour the exporting InDesign gives each user, not the colour in the INDD"),
]
+51 -3
View File
@@ -22,7 +22,8 @@ has one (`Document/WatermarkPreference`); for them the presence of the
element is kept the same way, and the converter writes the element.
LISTS are elements with `Self` whose whole list (every element, with all
attributes and children, in order) is the same in every file of a range;
the converter writes the list.
the converter writes the list. KEYED values depend only on another
attribute of the element, such as the quotes of a language on its name.
EXPLAINED lists values that are the same in nearly every element; the
others are values the converter reads from the INDD (the reason says
@@ -62,11 +63,22 @@ ELEMENTS = [
"Oval/ObjectExportOption", "Polygon/ObjectExportOption",
"GraphicLine/ObjectExportOption", "Group/ObjectExportOption",
"Spread", "MasterSpread", "Page", "Spread/FlattenerPreference", "Layer",
"Document/ConditionalTextPreference", "Document/EndnoteOption",
"Document/TextFrameFootnoteOptionsObject", "Document/LinkedStoryOption",
"Document/LinkedPageItemOption", "Document/WatermarkPreference",
"Document/TaggedPDFPreference", "Document/AdjustLayoutPreference",
"Document/HTMLFXLExportPreference", "Document/PublishExportPreference",
]
# Of those, the elements every IDML has one of (from some version on).
SINGLETONS = {p for p in ELEMENTS if p.startswith("Document/")}
# Elements with Self written as a whole list.
LISTS = ["TrapPreset"]
# Values that depend only on another attribute of the element: tag ->
# (key attribute, attributes). For each key value, an attribute is kept
# when every such element in every IDML has the same value, in at least
# MIN_KEYED_FILES files.
KEYED = {"Language": ("Name", ["SingleQuotes", "DoubleQuotes"])}
MIN_KEYED_FILES = 3
# Values that are nearly constant; the exceptions are read from the INDD.
# (path, key) -> reason, as recorded in docs/format/idml-values.md.
EXPLAINED = {}
@@ -134,6 +146,8 @@ def scan(arg):
for el in root.iter():
if el.tag in LISTS:
lists[el.tag].append(prop_text(el))
if el.tag in KEYED:
lists["keyed:" + el.tag].append(dict(el.attrib))
if el.get("Self") is None:
continue
if el.tag in wanted:
@@ -267,7 +281,30 @@ tools/element_values.py; evidence in docs/format/idml-values.md.
"""
def write(kept, presence, lists, order):
def analyse_keyed(scans):
"""{tag: [(key value, [(attr, value)], files)]} for KEYED."""
out = {}
for tag, (key, attrs) in KEYED.items():
seen = defaultdict(lambda: defaultdict(set)) # key value -> attr -> values
files = defaultdict(set)
for _dom, idml, _found, ls in scans:
for a in ls.get("keyed:" + tag, []):
k = a.get(key)
files[k].add(idml)
for name in attrs:
seen[k][name].add(a.get(name))
rows = []
for k in sorted(seen, key=lambda v: (v is None, v)):
if k is None or len(files[k]) < MIN_KEYED_FILES:
continue
kept = [(n, next(iter(v))) for n, v in seen[k].items() if len(v) == 1 and None not in v]
if kept:
rows.append((k, kept, len(files[k])))
out[tag] = rows
return out
def write(kept, presence, lists, order, keyed):
blocks = defaultdict(lambda: defaultdict(list)) # (first,last) -> path -> [(key,v)]
for path, items in kept.items():
for key, first, last, v, _n in items:
@@ -315,6 +352,13 @@ def write(kept, presence, lists, order):
s += f'\t<List Tag="{tag}"{gate}>\n'
s += "".join(f"\t\t{e}\n" for e in lst)
s += "\t</List>\n"
for tag, rows in keyed.items():
key = KEYED[tag][0]
s += f'\t<Keyed Tag="{tag}" Key="{key}">\n'
for k, attrs, _n in rows:
a = "".join(f" {n}={quoteattr(v)}" for n, v in [(key, k)] + attrs)
s += f"\t\t<{tag}{a} />\n"
s += "\t</Keyed>\n"
OUT.write_text(s + "</ElementValues>\n")
@@ -360,8 +404,12 @@ def main():
for tag, rs in lists.items():
print(f"list {tag}: " + ", ".join(
f"{len(v)} elements, {f}{'+' if l is None else f'-{l}'} ({n} files)" for f, l, v, n in rs))
keyed = analyse_keyed(scans)
for tag, rows in keyed.items():
n_attrs = Counter(n for _, attrs, _ in rows for n, _ in attrs)
print(f"keyed {tag} by {KEYED[tag][0]}: {len(rows)} values, kept {dict(n_attrs)}")
if "--write" in sys.argv:
write(kept, presence, lists, order)
write(kept, presence, lists, order, keyed)
print(f"wrote {OUT.relative_to(ROOT)}")