mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-28 00:59:15 +01:00
feat: read more preference chunks and write the values of files without them
Chunks of the preferences object: the story settings of new frames
(0x2EE) and the story orientation (byte 116 of 0x280), the text wrap of
new page items (0x3720), DocumentGridShown (0x566),
EnableStylePreviewMode (0xCAF3), three highlight flags (0xCA62, 0xCAD3,
0xCAD4), four layout grid flags (0xCD14, 0xCD1C to 0xCD1E),
MojikumiUiSettings (0x42DB), the tagged PDF structure order and
dictionary recomposition (0x11C69), CreateLinkToXML (0x1BC0B), the
pasteboard theme colour flag (byte 32 of 0x5D2), and the footnote
EosPlacement and minimum first baseline offset (0x2820).
Where every file without a chunk has one value, the converter writes it:
anchored object, story and text wrap settings, footnote options,
index options, chapter numbering, booklet margins, layout adjustment,
smart text reflow flags. TaggedPDFPreference is written from 7.5.
Evidence in preferences.md and footnotes.md.
compare.py --exclude own/, trustworthy pairs, with the two commits
before: 98.51 % -> 98.74 % (+67,661 values, 0 lost on any key), e.g.
MojikumiUiPreference and TaggedPDFPreference elements 0 -> 1,251 and
1,242, ChapterNumberPreference 73 -> 1,251, IndexOptions 66 -> 1,251
per attribute. Extra values unchanged (93,502). The text range count
in d7bc060 is 1,605, not 1,562.
This commit is contained in:
1 parent
d7bc060fd4
commit
d34092793e
5 files changed
+552
-49
No files matched your search
@@ -75,7 +75,7 @@ all 643 files there are 4 mismatches, all in stale pairs
|
||||
| 20 | u16 | 0 in all |
|
||||
| 24 | f64 | `SpaceBetween` |
|
||||
| 32 | f64 | `Spacer` |
|
||||
| 40 | u16 | 0 in all |
|
||||
| 40 | u16 | `EosPlacement` (1 `true`): 21 files `true`, 1,364 `false`, all matching (corpus of 2026-10) |
|
||||
| 42 | u16 | `ShowPrefixSuffix`: 0 `NoPrefixSuffix` (640), 1 `PrefixSuffixReference` (1), 3 `PrefixSuffixBoth` (2) |
|
||||
| 44 | string | `Prefix` |
|
||||
| | string | `Suffix` |
|
||||
@@ -90,6 +90,7 @@ The tail follows the separator: 172 bytes in files from InDesign 7 to 11,
|
||||
| Offset | Type | IDML |
|
||||
|---|---|---|
|
||||
| 0 | u16 | `NoSplitting` |
|
||||
| 4 | f64 | `FootnoteMinimumFirstBaselineOffset`: 19.84 in one file, 0 in the 1,384 others with a known tail, all matching (corpus of 2026-10) |
|
||||
| 12 | u16, 174-byte tail only | `EnableStraddling` (317 of 317 trustworthy pairs) |
|
||||
| R | rule block, 78 bytes | `Rule…` |
|
||||
| R + 78 | the same block | `ContinuingRule…` |
|
||||
@@ -114,14 +115,26 @@ R is 18 for a 174-byte tail and 16 for a 172-byte tail. Each block:
|
||||
|
||||
A tail of another length is not read: the converter keeps the observed
|
||||
values for the rules and warns. Codes not listed are left out.
|
||||
`FootnoteFirstBaselineOffset`, `FootnoteMinimumFirstBaselineOffset`,
|
||||
`EosPlacement` and the overprint flags have one value in every sample and
|
||||
come from the generated value file (`idml-values.md`).
|
||||
`FootnoteFirstBaselineOffset` and the overprint flags have one value in
|
||||
every sample and come from the generated value file (`idml-values.md`).
|
||||
|
||||
**Without the chunk** (90 files) the IDML has the defaults of the value
|
||||
file, `FootnoteTextStyle="ParagraphStyle/$ID/NormalParagraphStyle"`,
|
||||
`SeparatorText` tab, and `EnableStraddling="true"` from DOM 12 (67 of 67).
|
||||
The converter writes those.
|
||||
In the corpus of 2026-10 the 75 files without the chunk (51 trustworthy)
|
||||
also have, each in 75 of 75: `StartAt="1"`, `Prefix=""`, `Suffix=""`,
|
||||
`FootnoteMarkerStyle="CharacterStyle/$ID/[No character style]"`,
|
||||
`SpaceBetween="0"`, `Spacer="0"`,
|
||||
`FootnoteMinimumFirstBaselineOffset="0"`, `EosPlacement="false"`,
|
||||
`NoSplitting="false"`; for the rule and the continuing rule `…On`
|
||||
`true`, `…LineWeight` 1, `…Tint` and `…GapTint` 100, `…LeftIndent` 0,
|
||||
`…Width` 72 (rule) and 288 (continuing rule), `…Offset` 0, `…Type`
|
||||
`StrokeStyle/$ID/Solid`, `…Color` `Color/Black`, `…GapColor`
|
||||
`Swatch/None`; and the properties `FootnoteNumberingStyle` `Arabic`,
|
||||
`RestartNumbering` `DontRestart`, `ShowPrefixSuffix` `NoPrefixSuffix`
|
||||
and `MarkerPositioning` `SuperscriptMarker`. The value files lost most of
|
||||
these when the corpus grew, because files with the chunk vary; the
|
||||
converter writes them for files without the chunk.
|
||||
|
||||
`SeparatorText` in the value file is the reference `	`; the value file
|
||||
reader now decodes numeric character references, so the tab is written
|
||||
|
||||
+105
-9
@@ -83,6 +83,29 @@ whose IDML has the other value (5 and 12 files), so these two settings
|
||||
are stored somewhere else as well in some documents; that place is not
|
||||
known.
|
||||
|
||||
More u16 flags, over the corpus of 2026-10 (1,460 pairs, 1,251 of them
|
||||
trustworthy). Every file with the chunk matches; "absent" gives the
|
||||
value of every file without it.
|
||||
|
||||
| Chunk | Attribute | With the chunk | Absent |
|
||||
|---|---|---|---|
|
||||
| 0x566 | `GridPreference` `DocumentGridShown` | 122 of 122 (7 `true`) | `false`, 1,338 of 1,338 |
|
||||
| 0xCAF3 | `TextPreference` `EnableStylePreviewMode` | 115 of 115 (11 `true`) | `false`, 1,345 of 1,345 |
|
||||
| 0xCD1D | `CjkGridPreference` `ShowAllFrameGrids` | 90 of 90 (45 `true`) | `true`, 1,370 of 1,370 |
|
||||
| 0xCD1E | `CjkGridPreference` `ShowCharacterCount` | 103 of 103 (60 `true`) | `true`, 1,357 of 1,357 |
|
||||
| 0xCD14 | `CjkGridPreference` `SnapToLayoutGrid` | 1,460 of 1,460 (every file has it) | |
|
||||
| 0xCD1C | `CjkGridPreference` `ShowAllLayoutGrids` | 1,460 of 1,460 (every file has it) | |
|
||||
| 0xCA62 | `TextPreference` `HighlightHjViolations` | 63 of 63 (4 `true`) | varies |
|
||||
| 0xCAD3 | `TextPreference` `HighlightCustomSpacing` | 57 of 57 (1 `true`) | varies |
|
||||
| 0xCAD4 | `TextPreference` `HighlightSubstitutedGlyphs` | 57 of 57 (4 `true`) | varies |
|
||||
|
||||
Without one of the three highlight chunks, IDML has `false` in all but 4
|
||||
or 5 files, which have no highlight chunk at all and every highlight on
|
||||
in IDML (or are one collection with other values); no stored value
|
||||
separates them, so the converter writes these three only from the chunk.
|
||||
`HighlightKeeps` and `HighlightSubstitutedFonts` have no chunk; they are
|
||||
left to the value files, which do not have them because they vary.
|
||||
|
||||
## Document setup (`DocumentPreference`)
|
||||
|
||||
Chunk 0x533 (146 bytes) also holds the page size, facing pages, intent
|
||||
@@ -222,7 +245,14 @@ Chunk 0x28BE (14 bytes, 16 from InDesign 18), u8 flags: 4
|
||||
`SmartTextReflow`, 6 `LimitToMasterTextFrames`, 8 `DeleteEmptyPages`, 10
|
||||
`PreserveFacingPageSpreads`, 12 `SmartTextReflowSync` (16 bytes). 620 of
|
||||
620 files with the chunk (283 of 283 for the last). The 34 files without
|
||||
it have `SmartTextReflow="false"` and `LimitToMasterTextFrames="true"`.
|
||||
it have `SmartTextReflow="false"` and `LimitToMasterTextFrames="true"`;
|
||||
in the corpus of 2026-10 the 60 files without it also have
|
||||
`DeleteEmptyPages` and `PreserveFacingPageSpreads` `false` (60 of 60).
|
||||
|
||||
**Story orientation.** Byte 116 of chunk 0x280, after
|
||||
`TextColumnCount`, is `StoryPreference` `StoryOrientation`: 0
|
||||
`Horizontal` (1,349 files), 1 `Vertical` (111); 1,460 of 1,460 pairs of
|
||||
the corpus of 2026-10, every chunk length.
|
||||
|
||||
Chunk 0x3768 (4 or 6 bytes): u8 at 0 `AbutTextToTextWrap`, u8 at 2
|
||||
`ZOrderTextWrap`, and in 6-byte chunks u8 at 4
|
||||
@@ -260,6 +290,60 @@ without it have `-1 72` and 72, except one stale pair. Four u32 UIDs of
|
||||
interface colours follow; the IDML colours (`LightGray`, `GridBlue`) are
|
||||
not in the table of `objects.md`, so they are not written.
|
||||
|
||||
From DOM 9 the chunk has 34 bytes, and byte 32 is
|
||||
`MatchPreviewBackgroundToThemeColor` (4 `true`): 199 of 199 files with
|
||||
a 34-byte chunk. Without the chunk, IDML from DOM 9 has `false` (1,156
|
||||
of 1,156 files of the corpus of 2026-10). The 32-byte chunk of DOM 7 and
|
||||
8 has no such byte, and their IDML no attribute.
|
||||
|
||||
## Story settings of new frames (`StoryPreference`)
|
||||
|
||||
Chunk 0x2EE of the preferences object (16 bytes) has the layout of the
|
||||
story chunk 0x2EE (`objects.md`, story settings): u16 at 12
|
||||
`OpticalMarginAlignment`, u16 at 14 `FrameType` (0 `TextFrameType`, 1
|
||||
`FrameGridType`), f64 at 2 `OpticalMarginSize`. 197 of 197 files with
|
||||
the chunk, for each attribute. The u16 at 0 is 0 in all 197, also in
|
||||
documents with vertical stories; the orientation is in chunk 0x280
|
||||
(above). Without the chunk, IDML has `OpticalMarginAlignment="false"`
|
||||
and `FrameType="TextFrameType"` (1,263 of 1,263), but
|
||||
`OpticalMarginSize` is 12 in 1,207 files and 9.2126 (13 Q) in 56. No
|
||||
stored value was found that separates the 56 (all have a session of a
|
||||
Japanese edition in the save history, but so do 326 files with 12), so
|
||||
the converter leaves the size out without the chunk.
|
||||
|
||||
## Text wrap of new page items (`TextWrapPreference`)
|
||||
|
||||
Chunk 0x3720 of the preferences object (40 bytes) is the page item text
|
||||
wrap chunk 0x3703 (`objects.md`, text wrap) without the path UID: u32 at
|
||||
0 the wrap mode (0 `None`, 1 `JumpObjectTextWrap`, 3
|
||||
`BoundingBoxTextWrap`, 6 `Contour`), f64 at 4, 12, 20 and 28 the left,
|
||||
top, right and bottom `TextWrapOffset`, and u32 at 36: 1 is
|
||||
`ApplyToMasterPageOnly="false"`, 0 is `true`. Every attribute matches in
|
||||
the 42 files with the chunk (20 with mode 0 and `true`, 13 with mode 0
|
||||
and `false`, 4 bounding box, 4 jump object, 1 contour). The 1,418 files
|
||||
without it have `None`, offsets 0 and `false`.
|
||||
|
||||
## Other settings in their own chunks
|
||||
|
||||
| Chunk | Attribute | Evidence (corpus of 2026-10) |
|
||||
|---|---|---|
|
||||
| 0x42DB (i16) | `MojikumiUiPreference` `MojikumiUiSettings`, signed decimal (0x8000 is −32768) | 92 of 92 (16384, 16383, 9729, −32768, 32767, 1); without the chunk 16383, 1,368 of 1,368 |
|
||||
| 0x11C69 (u32 1) | `TaggedPDFPreference` (designmap) `StructureOrder="UseArticles"` and `DictionaryPreference` `RecomposeWhenChanged="false"` | 2 of 2; without the chunk `UseXMLStructure` (1,448 of 1,448 IDML files that have the element) and `true` (1,458 of 1,458) |
|
||||
| 0x1BC0B | `XMLImportPreference` `CreateLinkToXML` | u32 count of key and value pairs, each a u32 length in UTF-16 units and text segments; key `XMediaUI_CreateLink` with value `1` is `true` (1 file, 10 pairs); count 0 is `false` (1,459 of 1,459) |
|
||||
|
||||
`StructureOrder` and `RecomposeWhenChanged` differ from the common values
|
||||
only in the same two documents (one collection, version 20.5), which are
|
||||
also the only files with chunk 0x11C69. Which of the two the chunk
|
||||
stores is not known; the converter writes both from it. The other keys
|
||||
of chunk 0x1BC0B (`XMediaUI_RunXSLTScriptEnabled`,
|
||||
`XMediaUI_PreserveStoryTextStyling` and more) occur only in that one
|
||||
file, whose other `XMLImportPreference` values are the common ones, so
|
||||
they are not mapped.
|
||||
|
||||
**Tagged PDF.** Every IDML from version 7.5 has a `TaggedPDFPreference`
|
||||
in designmap.xml (1,450 of 1,450 files), none of version 7.0 (0 of 10);
|
||||
the converter writes it from 7.5.
|
||||
|
||||
## Default XML tags (`XMLPreference`)
|
||||
|
||||
Chunk 0xBF4F: five entries, each a name (u32 length, text segments) and
|
||||
@@ -456,8 +540,9 @@ paper name, not mapped), 4 bytes, then f64 `TopMargin`, `BottomMargin`,
|
||||
`LeftMargin`, `RightMargin`, then 34 bytes (`AutoAdjustMargins` and the
|
||||
other attributes have one value in every file). The chunk is in 11
|
||||
trustworthy pairs (12 of all pairs); the margins match in all of them.
|
||||
Without the chunk, IDML has the margins 36 (478 of 478). Left and right
|
||||
are equal in every sample, so their order is assumed.
|
||||
Without the chunk, IDML has the margins 36 (478 of 478; 1,447 of 1,447
|
||||
in the corpus of 2026-10). Left and right are equal in every sample, so
|
||||
their order is assumed.
|
||||
|
||||
## Index header setting (`IndexHeaderSetting`)
|
||||
|
||||
@@ -535,9 +620,19 @@ Evidence: every attribute in 10 of 10 trustworthy pairs (titles in
|
||||
several languages, `ReplaceExistingIndex` `false` once,
|
||||
`IncludeSectionHeadings` `false` once, user style references).
|
||||
|
||||
Without the chunk, IDML has `Title="Index"` in most documents and a
|
||||
Without the chunk every IDML of the corpus of 2026-10 (1,392 of 1,392)
|
||||
has `TitleStyle`, `Level1Style` to `Level4Style` and
|
||||
`SectionHeadingStyle` `ParagraphStyle/$ID/[No paragraph style]`,
|
||||
`PageNumberStyle`, `CrossReferenceStyle` and `CrossReferenceTopicStyle`
|
||||
`CharacterStyle/$ID/[No character style]`, `ReplaceExistingIndex="true"`,
|
||||
`IncludeBookDocuments="false"`, `IncludeHiddenEntries="false"`,
|
||||
`IndexFormat="NestedFormat"`, `IncludeSectionHeadings="true"`,
|
||||
`IncludeEmptyIndexSections="false"`, and the separators ` ` (two
|
||||
spaces, following topic), `^=` (page range), `, ` (between page
|
||||
numbers), `. ` (before a cross reference) and the empty end separator.
|
||||
The converter writes these. The title is `Index` in most documents and a
|
||||
translation in the others (`索引`, `Indice`, `Указатель`, …), and
|
||||
`BetweenEntriesSeparator` `; ` or `、`. Both follow the language of the
|
||||
`BetweenEntriesSeparator` is `; ` or `、`. Both follow the language of the
|
||||
exporting application. The language code of the document's last
|
||||
session (`objects.md`, save history) shows a Japanese or Chinese
|
||||
edition: the converter writes `Title="索引"` and `、` for code 0x0101,
|
||||
@@ -555,9 +650,10 @@ trustworthy pairs:
|
||||
| 8 | u32 | `ChapterNumber` |
|
||||
| 12 | u16 | not identified |
|
||||
|
||||
Evidence: 37 of 37. Without the chunk, IDML has the observed values
|
||||
(`ChapterNumber="1"`, `ContinueFromPreviousDocument`, `1, 2, 3, 4...`)
|
||||
in 452 of 452.
|
||||
Evidence: 37 of 37. Without the chunk, IDML has `ChapterNumber="1"`,
|
||||
`ContinueFromPreviousDocument` and `1, 2, 3, 4...` in 452 of 452 (1,345
|
||||
of 1,345 in the corpus of 2026-10); the converter writes the element
|
||||
with these values.
|
||||
|
||||
## Dictionary (`DictionaryPreference`)
|
||||
|
||||
@@ -631,7 +727,7 @@ in another form, `fonts.md`).
|
||||
| 0x555 | colour at 18 | `DocumentPreference` `ColumnGuideColor` | (observed value) | 72 of 72 |
|
||||
| 0x5D2 | colours at 20, 24, 28 | `PasteboardPreference` `BleedGuideColor`, `SlugGuideColor`, `PreviewBackgroundColor` | `Fiesta`, `GridBlue`, `LightGray` | 80 of 80; 409 of 409 |
|
||||
| 0x54A (18 bytes) | f64 at 0, f64 at 8 | `Document` `ZeroPoint` | `0 0` | 46 of 46; 443 of 443 |
|
||||
| 0x7006 (20 bytes) | u8 at 0; f64 at 12 | `LayoutAdjustmentPreference` `EnableLayoutAdjustment`, `SnapZone` | `false` (observed), `SnapZone` not written | 24 of 24 |
|
||||
| 0x7006 (20 bytes) | u8 at 0; f64 at 12 | `LayoutAdjustmentPreference` `EnableLayoutAdjustment`, `SnapZone` | `false` (1,377 of 1,377 in the corpus of 2026-10), `SnapZone` below | 24 of 24 |
|
||||
| 0xCA0B | u16 1 | `ViewPreference` `ShowTextThreads` `true`, INDD version 21.1 on | `false` | IDML has the attribute only from version 21.1: 26 of 26 (28 of 28 in all pairs) |
|
||||
|
||||
Without chunk 0x555, `ColumnGuideColor` keeps its observed value, which
|
||||
|
||||
+11
-1
@@ -132,7 +132,17 @@ impl Writer<'_> {
|
||||
// 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) {
|
||||
// Every IDML from 7.5 has the tagged PDF settings, none of 7.0
|
||||
// (preferences.md, tagged PDF).
|
||||
let present = values::present(&format!("Document/{tag}"), major).or_else(|| {
|
||||
(tag == "TaggedPDFPreference" && (major, doc.version.minor) >= (7, 5)).then(|| {
|
||||
Node {
|
||||
tag: tag.to_string(),
|
||||
..Node::default()
|
||||
}
|
||||
})
|
||||
});
|
||||
if let Some(n) = present {
|
||||
// Values read from the INDD (`model::prefs`) first.
|
||||
let mut ours = match tag {
|
||||
"EndnoteOption" => self.endnote_option(),
|
||||
|
||||
+119
-11
@@ -28,6 +28,11 @@ pub(super) const PREFERENCE_TAGS: &[&str] = &[
|
||||
"EPubExportPreference",
|
||||
"TransparencyPreference",
|
||||
"LayoutAdjustmentPreference",
|
||||
"StoryPreference",
|
||||
"TextWrapPreference",
|
||||
"CjkGridPreference",
|
||||
"MojikumiUiPreference",
|
||||
"XMLImportPreference",
|
||||
];
|
||||
|
||||
/// A tree of preference values as a `Node`.
|
||||
@@ -423,11 +428,73 @@ impl Writer<'_> {
|
||||
};
|
||||
let attr = |n: &mut Node, k: &str, v: String| n.attrs.push((k.to_string(), v));
|
||||
let Some(f) = &self.doc.prefs.footnotes else {
|
||||
// Without the chunk every IDML has these values.
|
||||
// Without the chunk every IDML has these values (footnotes.md,
|
||||
// footnote options).
|
||||
if major >= 12 {
|
||||
attr(&mut n, "EnableStraddling", "true".into());
|
||||
}
|
||||
attr(&mut n, "FootnoteTextStyle", self.style_ref(None, true));
|
||||
for (k, v) in [
|
||||
("StartAt", "1"),
|
||||
("Prefix", ""),
|
||||
("Suffix", ""),
|
||||
(
|
||||
"FootnoteMarkerStyle",
|
||||
"CharacterStyle/$ID/[No character style]",
|
||||
),
|
||||
("SpaceBetween", "0"),
|
||||
("Spacer", "0"),
|
||||
("FootnoteMinimumFirstBaselineOffset", "0"),
|
||||
("EosPlacement", "false"),
|
||||
("NoSplitting", "false"),
|
||||
] {
|
||||
attr(&mut n, k, v.into());
|
||||
}
|
||||
for prefix in ["Rule", "ContinuingRule"] {
|
||||
for (k, v) in [
|
||||
("On", "true"),
|
||||
("LineWeight", "1"),
|
||||
("Tint", "100"),
|
||||
("GapTint", "100"),
|
||||
("LeftIndent", "0"),
|
||||
(
|
||||
"Width",
|
||||
if prefix == "Rule" { "72" } else { "288" },
|
||||
),
|
||||
("Offset", "0"),
|
||||
] {
|
||||
attr(&mut n, &format!("{prefix}{k}"), v.into());
|
||||
}
|
||||
}
|
||||
let text_prop = |name: String, ty: &str, text: &str| Node {
|
||||
tag: name,
|
||||
attrs: vec![("type".into(), ty.into())],
|
||||
text: Some(text.into()),
|
||||
..Node::default()
|
||||
};
|
||||
let mut props: Vec<Node> = [
|
||||
("FootnoteNumberingStyle", "Arabic"),
|
||||
("RestartNumbering", "DontRestart"),
|
||||
("ShowPrefixSuffix", "NoPrefixSuffix"),
|
||||
("MarkerPositioning", "SuperscriptMarker"),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(k, v)| text_prop(k.into(), "enumeration", v))
|
||||
.collect();
|
||||
for prefix in ["Rule", "ContinuingRule"] {
|
||||
for (k, v) in [
|
||||
("Type", "StrokeStyle/$ID/Solid"),
|
||||
("Color", "Color/Black"),
|
||||
("GapColor", "Swatch/None"),
|
||||
] {
|
||||
props.push(text_prop(format!("{prefix}{k}"), "object", v));
|
||||
}
|
||||
}
|
||||
n.children.push(Node {
|
||||
tag: "Properties".into(),
|
||||
children: props,
|
||||
..Node::default()
|
||||
});
|
||||
return n;
|
||||
};
|
||||
let bool_text = |b: bool| b.to_string();
|
||||
@@ -452,6 +519,18 @@ impl Writer<'_> {
|
||||
attr(&mut n, "SeparatorText", f.separator.clone());
|
||||
attr(&mut n, "SpaceBetween", num(f.space_between));
|
||||
attr(&mut n, "Spacer", num(f.spacer));
|
||||
if let Some(t) = &f.tail {
|
||||
attr(
|
||||
&mut n,
|
||||
"FootnoteMinimumFirstBaselineOffset",
|
||||
num(t.minimum_first_baseline),
|
||||
);
|
||||
}
|
||||
match f.eos_placement {
|
||||
0 => attr(&mut n, "EosPlacement", "false".into()),
|
||||
1 => attr(&mut n, "EosPlacement", "true".into()),
|
||||
_ => {}
|
||||
}
|
||||
let mut props: Vec<Node> = Vec::new();
|
||||
let mut prop = |name: &str, ty: &str, text: String| {
|
||||
props.push(Node {
|
||||
@@ -913,18 +992,47 @@ impl Writer<'_> {
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k.to_string(), v)),
|
||||
);
|
||||
} else if let Some(japanese) = self.japanese_session() {
|
||||
// Without the chunk, the title and the separator follow the
|
||||
// language of the last session (`preferences.md`, index
|
||||
// options). Other languages have different titles.
|
||||
} else {
|
||||
// Without the chunk every IDML has these values; the title and
|
||||
// the separator follow the language of the last session
|
||||
// (`preferences.md`, index options). Other languages have
|
||||
// different titles.
|
||||
let i = ours_of(&mut ours, "IndexOptions");
|
||||
if japanese {
|
||||
ours[i].attrs.push(("Title".into(), "索引".into()));
|
||||
let paragraph = "ParagraphStyle/$ID/[No paragraph style]";
|
||||
let character = "CharacterStyle/$ID/[No character style]";
|
||||
for (k, v) in [
|
||||
("TitleStyle", paragraph),
|
||||
("ReplaceExistingIndex", "true"),
|
||||
("IncludeBookDocuments", "false"),
|
||||
("IncludeHiddenEntries", "false"),
|
||||
("IndexFormat", "NestedFormat"),
|
||||
("IncludeSectionHeadings", "true"),
|
||||
("IncludeEmptyIndexSections", "false"),
|
||||
("Level1Style", paragraph),
|
||||
("Level2Style", paragraph),
|
||||
("Level3Style", paragraph),
|
||||
("Level4Style", paragraph),
|
||||
("SectionHeadingStyle", paragraph),
|
||||
("PageNumberStyle", character),
|
||||
("CrossReferenceStyle", character),
|
||||
("CrossReferenceTopicStyle", character),
|
||||
("FollowingTopicSeparator", " "),
|
||||
("PageRangeSeparator", "^="),
|
||||
("BetweenPageNumbersSeparator", ", "),
|
||||
("BeforeCrossReferenceSeparator", ". "),
|
||||
("EntryEndSeparator", ""),
|
||||
] {
|
||||
ours[i].attrs.push((k.into(), v.into()));
|
||||
}
|
||||
if let Some(japanese) = self.japanese_session() {
|
||||
if japanese {
|
||||
ours[i].attrs.push(("Title".into(), "索引".into()));
|
||||
}
|
||||
let separator = if japanese { "、" } else { "; " };
|
||||
ours[i]
|
||||
.attrs
|
||||
.push(("BetweenEntriesSeparator".into(), separator.into()));
|
||||
}
|
||||
let separator = if japanese { "、" } else { "; " };
|
||||
ours[i]
|
||||
.attrs
|
||||
.push(("BetweenEntriesSeparator".into(), separator.into()));
|
||||
}
|
||||
ours.push(self.footnote_option());
|
||||
if let Some(c) = prefs.baseline_frame_grid_color.and_then(frame_grid_color) {
|
||||
|
||||
+299
-23
@@ -151,6 +151,8 @@ pub struct FootnoteOptions {
|
||||
pub marker: (u16, u16),
|
||||
pub space_between: f64,
|
||||
pub spacer: f64,
|
||||
/// u16 at 40: `EosPlacement`.
|
||||
pub eos_placement: u16,
|
||||
/// Prefix and suffix display code.
|
||||
pub prefix_suffix: u16,
|
||||
pub prefix: String,
|
||||
@@ -163,6 +165,8 @@ pub struct FootnoteOptions {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct FootnoteTail {
|
||||
pub no_splitting: bool,
|
||||
/// f64 at 4: `FootnoteMinimumFirstBaselineOffset`.
|
||||
pub minimum_first_baseline: f64,
|
||||
/// `EnableStraddling`; only in the 174-byte tail.
|
||||
pub straddling: Option<bool>,
|
||||
/// The rule and the continuing rule.
|
||||
@@ -200,7 +204,7 @@ impl FootnoteOptions {
|
||||
let ruby = c.u16()?;
|
||||
let space_between = c.f64()?;
|
||||
let spacer = c.f64()?;
|
||||
c.skip(2)?;
|
||||
let eos_placement = c.u16()?;
|
||||
let prefix_suffix = c.u16()?;
|
||||
let prefix = counted_string(&mut c)?;
|
||||
let suffix = counted_string(&mut c)?;
|
||||
@@ -236,6 +240,7 @@ impl FootnoteOptions {
|
||||
};
|
||||
Some(FootnoteTail {
|
||||
no_splitting: enc.u16_at(tail, 0) != Some(0),
|
||||
minimum_first_baseline: enc.f64_at(tail, 4).unwrap_or_default(),
|
||||
straddling: (t == 174).then(|| enc.u16_at(tail, 12) != Some(0)),
|
||||
rules: [rule(rule_at)?, rule(rule_at + 78)?],
|
||||
})
|
||||
@@ -251,6 +256,7 @@ impl FootnoteOptions {
|
||||
marker: (superscript, ruby),
|
||||
space_between,
|
||||
spacer,
|
||||
eos_placement,
|
||||
prefix_suffix,
|
||||
prefix,
|
||||
suffix,
|
||||
@@ -803,6 +809,26 @@ mod id {
|
||||
pub const ZERO_POINT: u32 = 0x54A;
|
||||
pub const LAYOUT_ADJUSTMENT: u32 = 0x7006;
|
||||
pub const SHOW_TEXT_THREADS: u32 = 0xCA0B;
|
||||
pub const DOCUMENT_GRID_SHOWN: u32 = 0x566;
|
||||
pub const STYLE_PREVIEW: u32 = 0xCAF3;
|
||||
pub const HIGHLIGHT_HJ_VIOLATIONS: u32 = 0xCA62;
|
||||
pub const HIGHLIGHT_CUSTOM_SPACING: u32 = 0xCAD3;
|
||||
pub const HIGHLIGHT_SUBSTITUTED_GLYPHS: u32 = 0xCAD4;
|
||||
pub const SNAP_TO_LAYOUT_GRID: u32 = 0xCD14;
|
||||
pub const SHOW_ALL_LAYOUT_GRIDS: u32 = 0xCD1C;
|
||||
pub const SHOW_ALL_FRAME_GRIDS: u32 = 0xCD1D;
|
||||
pub const SHOW_CHARACTER_COUNT: u32 = 0xCD1E;
|
||||
/// i16 `MojikumiUiSettings`.
|
||||
pub const MOJIKUMI_UI: u32 = 0x42DB;
|
||||
/// u32 1 where the tagged PDF structure follows the articles.
|
||||
pub const ARTICLE_ORDER: u32 = 0x11C69;
|
||||
/// XML import options: u32 count of key and value pairs.
|
||||
pub const XML_IMPORT: u32 = 0x1BC0B;
|
||||
/// Story settings, as the story chunk 0x2EE.
|
||||
pub const STORY: u32 = 0x2EE;
|
||||
/// Text wrap of new page items: the page item chunk 0x3703 without
|
||||
/// the path UID.
|
||||
pub const ITEM_TEXT_WRAP: u32 = 0x3720;
|
||||
}
|
||||
|
||||
/// Interface colours that preferences without their chunk have
|
||||
@@ -814,6 +840,26 @@ mod ui {
|
||||
pub const GRID_BLUE: [f64; 3] = [0.48, 0.73, 0.85];
|
||||
}
|
||||
|
||||
/// `CreateLinkToXML` from the XML import options (chunk 0x1BC0B): a u32
|
||||
/// count of key and value pairs, each a u32 length in UTF-16 units and
|
||||
/// text segments. No pairs is `false`; key `XMediaUI_CreateLink` with
|
||||
/// value `1` is `true`. `None` where the pairs cannot be read or lack the
|
||||
/// key.
|
||||
fn xml_import_link(enc: Encoding, d: &[u8]) -> Option<bool> {
|
||||
let mut c = enc.cursor(d);
|
||||
let n = c.u32().ok()?;
|
||||
for _ in 0..n {
|
||||
let len = c.u32().ok()? as usize;
|
||||
let key = c.segments(len).ok()?;
|
||||
let len = c.u32().ok()? as usize;
|
||||
let value = c.segments(len).ok()?;
|
||||
if key == "XMediaUI_CreateLink" {
|
||||
return Some(value == "1");
|
||||
}
|
||||
}
|
||||
(n == 0).then_some(false)
|
||||
}
|
||||
|
||||
/// The EPUB identifier of documents without EPUB export options.
|
||||
const EPUB_ID: &str = "urn:uuid:29d919dd-24f5-4384-be78-b447c9dc299b";
|
||||
|
||||
@@ -1044,11 +1090,179 @@ impl Reader<'_> {
|
||||
"ShowInvisibles",
|
||||
),
|
||||
(id::GRIDS_IN_BACK, true, "GridPreference", "GridsInBack"),
|
||||
(
|
||||
id::DOCUMENT_GRID_SHOWN,
|
||||
false,
|
||||
"GridPreference",
|
||||
"DocumentGridShown",
|
||||
),
|
||||
(
|
||||
id::STYLE_PREVIEW,
|
||||
false,
|
||||
"TextPreference",
|
||||
"EnableStylePreviewMode",
|
||||
),
|
||||
(
|
||||
id::SHOW_ALL_FRAME_GRIDS,
|
||||
true,
|
||||
"CjkGridPreference",
|
||||
"ShowAllFrameGrids",
|
||||
),
|
||||
(
|
||||
id::SHOW_CHARACTER_COUNT,
|
||||
true,
|
||||
"CjkGridPreference",
|
||||
"ShowCharacterCount",
|
||||
),
|
||||
] {
|
||||
if let Some(v) = flag(id, absent)? {
|
||||
set(element, name, v);
|
||||
}
|
||||
}
|
||||
// Flags whose documents without the chunk do not have one value.
|
||||
for (id, element, name) in [
|
||||
(
|
||||
id::HIGHLIGHT_HJ_VIOLATIONS,
|
||||
"TextPreference",
|
||||
"HighlightHjViolations",
|
||||
),
|
||||
(
|
||||
id::HIGHLIGHT_CUSTOM_SPACING,
|
||||
"TextPreference",
|
||||
"HighlightCustomSpacing",
|
||||
),
|
||||
(
|
||||
id::HIGHLIGHT_SUBSTITUTED_GLYPHS,
|
||||
"TextPreference",
|
||||
"HighlightSubstitutedGlyphs",
|
||||
),
|
||||
(
|
||||
id::SNAP_TO_LAYOUT_GRID,
|
||||
"CjkGridPreference",
|
||||
"SnapToLayoutGrid",
|
||||
),
|
||||
(
|
||||
id::SHOW_ALL_LAYOUT_GRIDS,
|
||||
"CjkGridPreference",
|
||||
"ShowAllLayoutGrids",
|
||||
),
|
||||
] {
|
||||
if get(id)?.is_some()
|
||||
&& let Some(v) = flag(id, false)?
|
||||
{
|
||||
set(element, name, v);
|
||||
}
|
||||
}
|
||||
match get(id::MOJIKUMI_UI)? {
|
||||
Some(d) => {
|
||||
if let Some(v) = self.enc().u16_at(&d, 0) {
|
||||
set(
|
||||
"MojikumiUiPreference",
|
||||
"MojikumiUiSettings",
|
||||
(v as i16).to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
None => set(
|
||||
"MojikumiUiPreference",
|
||||
"MojikumiUiSettings",
|
||||
"16383".into(),
|
||||
),
|
||||
}
|
||||
// Chunk 0x11C69 changes both values; which one it stores is not
|
||||
// known (preferences.md, single-chunk preferences).
|
||||
let articles = match get(id::ARTICLE_ORDER)? {
|
||||
None => Some(false),
|
||||
Some(d) => (self.enc().u32_at(&d, 0) == Some(1)).then_some(true),
|
||||
};
|
||||
if let Some(a) = articles {
|
||||
let order = if a { "UseArticles" } else { "UseXMLStructure" };
|
||||
set("TaggedPDFPreference", "StructureOrder", order.into());
|
||||
set(
|
||||
"DictionaryPreference",
|
||||
"RecomposeWhenChanged",
|
||||
(!a).to_string(),
|
||||
);
|
||||
}
|
||||
if let Some(d) = get(id::XML_IMPORT)?
|
||||
&& let Some(link) = xml_import_link(self.enc(), &d)
|
||||
{
|
||||
set("XMLImportPreference", "CreateLinkToXML", link.to_string());
|
||||
}
|
||||
// Story settings of new text frames: u16 at 12 optical margin
|
||||
// alignment, u16 at 14 frame type, f64 at 2 optical margin size.
|
||||
match get(id::STORY)? {
|
||||
Some(d) if d.len() == 16 => {
|
||||
let u = |o: usize| self.enc().u16_at(&d, o);
|
||||
match u(12) {
|
||||
Some(0) => set("StoryPreference", "OpticalMarginAlignment", "false".into()),
|
||||
Some(1) => set("StoryPreference", "OpticalMarginAlignment", "true".into()),
|
||||
_ => {}
|
||||
}
|
||||
match u(14) {
|
||||
Some(0) => set("StoryPreference", "FrameType", "TextFrameType".into()),
|
||||
Some(1) => set("StoryPreference", "FrameType", "FrameGridType".into()),
|
||||
_ => {}
|
||||
}
|
||||
if let Some(size) = self.enc().f64_at(&d, 2) {
|
||||
set("StoryPreference", "OpticalMarginSize", num(size));
|
||||
}
|
||||
}
|
||||
Some(_) => {}
|
||||
None => {
|
||||
set("StoryPreference", "OpticalMarginAlignment", "false".into());
|
||||
set("StoryPreference", "FrameType", "TextFrameType".into());
|
||||
}
|
||||
}
|
||||
// Text wrap of new page items: u32 mode, four f64 offsets (left,
|
||||
// top, right, bottom), u32 1 where the wrap applies everywhere.
|
||||
let wrap = match get(id::ITEM_TEXT_WRAP)? {
|
||||
Some(d) if d.len() == 40 => {
|
||||
let mut c = self.cursor(&d);
|
||||
let mode = c.u32()?;
|
||||
let offsets = [c.f64()?, c.f64()?, c.f64()?, c.f64()?];
|
||||
let everywhere = c.u32()?;
|
||||
Some((Some(mode), offsets, Some(everywhere)))
|
||||
}
|
||||
Some(_) => None,
|
||||
None => Some((Some(0), [0.0; 4], Some(1))),
|
||||
};
|
||||
if let Some((mode, [left, top, right, bottom], everywhere)) = wrap {
|
||||
let mode = match mode {
|
||||
Some(0) => Some("None"),
|
||||
Some(1) => Some("JumpObjectTextWrap"),
|
||||
Some(3) => Some("BoundingBoxTextWrap"),
|
||||
Some(6) => Some("Contour"),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(m) = mode {
|
||||
set("TextWrapPreference", "TextWrapMode", m.into());
|
||||
}
|
||||
match everywhere {
|
||||
Some(0) => set("TextWrapPreference", "ApplyToMasterPageOnly", "true".into()),
|
||||
Some(1) => set("TextWrapPreference", "ApplyToMasterPageOnly", "false".into()),
|
||||
_ => {}
|
||||
}
|
||||
props.push((
|
||||
"TextWrapPreference",
|
||||
"TextWrapOffset",
|
||||
PrefProp::Attrs(vec![
|
||||
("Top", num(top)),
|
||||
("Left", num(left)),
|
||||
("Bottom", num(bottom)),
|
||||
("Right", num(right)),
|
||||
]),
|
||||
));
|
||||
}
|
||||
// The story orientation of new text frames: byte 116 of the text
|
||||
// preferences.
|
||||
if let Some(d) = get(id::TEXT)? {
|
||||
match d.get(116) {
|
||||
Some(0) => set("StoryPreference", "StoryOrientation", "Horizontal".into()),
|
||||
Some(1) => set("StoryPreference", "StoryOrientation", "Vertical".into()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Document setup beyond `DocumentPreferences`.
|
||||
if let Some(d) = get(chunk::DOCUMENT_PREFERENCES)?
|
||||
@@ -1155,6 +1369,8 @@ impl Reader<'_> {
|
||||
None => {
|
||||
set("TextPreference", "SmartTextReflow", "false".into());
|
||||
set("TextPreference", "LimitToMasterTextFrames", "true".into());
|
||||
set("TextPreference", "DeleteEmptyPages", "false".into());
|
||||
set("TextPreference", "PreserveFacingPageSpreads", "false".into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1201,6 +1417,28 @@ impl Reader<'_> {
|
||||
);
|
||||
set("PasteboardPreference", "MinimumSpaceAboveAndBelow", num(v));
|
||||
}
|
||||
// From DOM 9 the chunk has 34 bytes, byte 32 the theme colour flag.
|
||||
match get(id::PASTEBOARD)? {
|
||||
Some(d) if d.len() == 34 => match d[32] {
|
||||
0 => set(
|
||||
"PasteboardPreference",
|
||||
"MatchPreviewBackgroundToThemeColor",
|
||||
"false".into(),
|
||||
),
|
||||
1 => set(
|
||||
"PasteboardPreference",
|
||||
"MatchPreviewBackgroundToThemeColor",
|
||||
"true".into(),
|
||||
),
|
||||
_ => {}
|
||||
},
|
||||
None if major >= 9 => set(
|
||||
"PasteboardPreference",
|
||||
"MatchPreviewBackgroundToThemeColor",
|
||||
"false".into(),
|
||||
),
|
||||
_ => {}
|
||||
}
|
||||
// Text wrap: u8 at 0, 2 and, in 6-byte chunks, 4.
|
||||
if let Some(d) = get(id::TEXT_WRAP)?.filter(|d| d.len() >= 3) {
|
||||
set(
|
||||
@@ -1341,21 +1579,24 @@ impl Reader<'_> {
|
||||
|
||||
// Booklet options: u32, a flagged string (not mapped), 4 bytes,
|
||||
// then the four margins.
|
||||
if let Some(d) = get(id::BOOKLET_OPTIONS)? {
|
||||
let mut c = self.cursor(&d);
|
||||
let margins = (|| -> Result<[f64; 4], Error> {
|
||||
c.u32()?;
|
||||
flagged(&mut c)?;
|
||||
c.skip(4)?;
|
||||
Ok([c.f64()?, c.f64()?, c.f64()?, c.f64()?])
|
||||
})();
|
||||
if let Ok(m) = margins {
|
||||
for (name, v) in ["TopMargin", "BottomMargin", "LeftMargin", "RightMargin"]
|
||||
.into_iter()
|
||||
.zip(m)
|
||||
{
|
||||
set("PrintBookletOption", name, num(v));
|
||||
}
|
||||
let booklet = match get(id::BOOKLET_OPTIONS)? {
|
||||
Some(d) => {
|
||||
let mut c = self.cursor(&d);
|
||||
(|| -> Result<[f64; 4], Error> {
|
||||
c.u32()?;
|
||||
flagged(&mut c)?;
|
||||
c.skip(4)?;
|
||||
Ok([c.f64()?, c.f64()?, c.f64()?, c.f64()?])
|
||||
})()
|
||||
}
|
||||
None => Ok([36.0; 4]),
|
||||
};
|
||||
if let Ok(m) = booklet {
|
||||
for (name, v) in ["TopMargin", "BottomMargin", "LeftMargin", "RightMargin"]
|
||||
.into_iter()
|
||||
.zip(m)
|
||||
{
|
||||
set("PrintBookletOption", name, num(v));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1547,13 +1788,20 @@ impl Reader<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(d) = get(id::LAYOUT_ADJUSTMENT)? {
|
||||
if let Some(v) = bool_at(&d, 0) {
|
||||
set("LayoutAdjustmentPreference", "EnableLayoutAdjustment", v);
|
||||
}
|
||||
if let Some(z) = self.enc().f64_at(&d, 12) {
|
||||
set("LayoutAdjustmentPreference", "SnapZone", num(z));
|
||||
match get(id::LAYOUT_ADJUSTMENT)? {
|
||||
Some(d) => {
|
||||
if let Some(v) = bool_at(&d, 0) {
|
||||
set("LayoutAdjustmentPreference", "EnableLayoutAdjustment", v);
|
||||
}
|
||||
if let Some(z) = self.enc().f64_at(&d, 12) {
|
||||
set("LayoutAdjustmentPreference", "SnapZone", num(z));
|
||||
}
|
||||
}
|
||||
None => set(
|
||||
"LayoutAdjustmentPreference",
|
||||
"EnableLayoutAdjustment",
|
||||
"false".into(),
|
||||
),
|
||||
}
|
||||
if (major, version.minor) >= (21, 1) {
|
||||
let shown =
|
||||
@@ -1578,7 +1826,21 @@ impl Reader<'_> {
|
||||
}
|
||||
}
|
||||
// Chapter numbering: u32 format code, u32 source, u32 number, u16.
|
||||
if let Some(d) = get(id::CHAPTER_NUMBER)?.filter(|d| d.len() >= 12) {
|
||||
let chapter = get(id::CHAPTER_NUMBER)?;
|
||||
if chapter.is_none() {
|
||||
props.push((
|
||||
"ChapterNumberPreference",
|
||||
"ChapterNumberFormat",
|
||||
PrefProp::Text("string", "1, 2, 3, 4...".into()),
|
||||
));
|
||||
set(
|
||||
"ChapterNumberPreference",
|
||||
"ChapterNumberSource",
|
||||
"ContinueFromPreviousDocument".into(),
|
||||
);
|
||||
set("ChapterNumberPreference", "ChapterNumber", "1".into());
|
||||
}
|
||||
if let Some(d) = chapter.filter(|d| d.len() >= 12) {
|
||||
let mut c = self.cursor(&d);
|
||||
let (format, source, number) = (c.u32()?, c.u32()?, c.u32()?);
|
||||
if let Some(f) = chapter_format(format) {
|
||||
@@ -2054,4 +2316,18 @@ mod tests {
|
||||
assert_eq!(num_half_even(0.0625), "0.0625");
|
||||
assert_eq!(num_half_even(f64::from(16.6_f32)), "16.600000381469727");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_the_xml_import_link() {
|
||||
let enc = Encoding::default();
|
||||
let mut d = 2u32.to_le_bytes().to_vec();
|
||||
for (k, v) in [("XMediaUI_SparseImport", "0"), ("XMediaUI_CreateLink", "1")] {
|
||||
cstr(&mut d, k);
|
||||
cstr(&mut d, v);
|
||||
}
|
||||
assert_eq!(xml_import_link(enc, &d), Some(true));
|
||||
assert_eq!(xml_import_link(enc, &[0; 4]), Some(false));
|
||||
// A pair cut short.
|
||||
assert_eq!(xml_import_link(enc, &d[..d.len() - 3]), None);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user