mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-25 03:45:46 +01:00
feat: read the export options and language quotes, and write values of the exporting edition
Decoded chunks: - EPUB (0x21A1A), HTML (0x21A19), fixed layout EPUB (0x21A25) and Publish Online (0x21A20) export options; the EPUB chunk is read in the layout of its two variable blocks that ends at the chunk's end. Files without a chunk get the values every such file has. - Adjust layout (0x7020): EnableAdjustLayout, AllowFontSizeAndLeadingAdjustment, EnableAutoAdjustMargins. - Language quotes (0x2D26), and $ID/ for an empty vendor of a language whose vendor is never stored; Romanian quotes without the chunk. Values without a field follow the InDesign that exported the IDML, taken from the save history or the edition that made the document (the language of its assignment name); preferences.md lists the rules and their exceptions: DOMVersion by the last session's release, Publish Online resolution and PublishPdf, EnableAdjustLayout after 14.0.0 and 14.0.1, the index title and separator, SnapZone, BaselineFrameGridColor and ColumnGuideColor by the last session's language code, and style shortcut key codes by its platform (also on character styles of DOM 7 to 12, which got none). compare.py --exclude own/, trustworthy pairs: 98.74 % -> 98.96 % together with the three commits before (+62,457 values, 0 lost on any key); e.g. EPubExportPreference 0 -> 1,242 per attribute, DOMVersion 668 -> 1,164 of 1,251, IndexOptions Title 284 -> 1,162, SnapZone 68 -> 1,240, Language HyphenationVendor 1,945 -> 2,818 of 2,829, BaselineFrameGridColor 934 -> 1,154 (object styles 4,163 -> 5,136), ColumnGuideColor 406 -> 1,228, CharacterStyle KeyboardShortcut 2,547 -> 3,154 of 3,154. Extra values 93,502 -> 92,838: +346 on Language elements the reference IDML leaves out (their new vendors and quotes), one PublishPdf of an IDML exported by another release.
This commit is contained in:
1 parent
8f8a3bff96
commit
e0e1f99b7a
11 files changed
+995
-92
No files matched your search
@@ -364,18 +364,64 @@ all of them have; the converter writes it in the order of the IDML files.
|
||||
| `HTMLFXLExportPreference` | 11 | both | |
|
||||
| `PublishExportPreference` | 11 | 7 | `ImageExportResolution`, `PublishPdf`, `CoverPage`, `PublishDescription`, `PublishFileName`, `PublishPageRange` |
|
||||
|
||||
The values left out here are read from the INDD or follow the rules of
|
||||
`preferences.md` (adjust layout; EPUB, HTML and Publish Online export;
|
||||
values of the exporting edition). The converter writes
|
||||
`TaggedPDFPreference` from version 7.5, which the per-major blocks
|
||||
cannot express.
|
||||
|
||||
### DOM version
|
||||
|
||||
Every package part has the `DOMVersion` of the application that
|
||||
exported the IDML. Several releases keep the DOM version of an earlier
|
||||
one. Over the 1,460 pairs of the corpus of 2026-10, by the version of
|
||||
the last session of the save history (`objects.md`, save history):
|
||||
|
||||
| Last session | `DOMVersion` |
|
||||
|---|---|
|
||||
| 9.1, 9.2 | 9.0 |
|
||||
| 11.1 | 11.0 |
|
||||
| 14.3 | 14.0 |
|
||||
| 16.3, 16.4 | 16.2 |
|
||||
| 17.1 to 17.4 | 17.0 |
|
||||
| 18.1 to 18.4 | 18.0 |
|
||||
| 19.1, 19.2 | 19.0 |
|
||||
| 20.1 | 20.0 |
|
||||
| 20.5 | 20.4 |
|
||||
| every other version seen (7.0 to 21.5) | its major and minor version |
|
||||
|
||||
The converter writes this value, from the header's version where the
|
||||
save history has none or names another major version. It matches 1,164
|
||||
of 1,251 trustworthy pairs (the header's major version with `.0`
|
||||
matched 668). The others are files that a later release exported
|
||||
without saving them: 68 sessions of 10.1 whose IDML has 10.2, 16 of
|
||||
13.0 with 13.1, and 3 more; their IDML `product` names that release.
|
||||
This is a rule of the exporting edition (`preferences.md`, values of
|
||||
the exporting edition).
|
||||
|
||||
`Assignment` (1,495 elements, one per file): `UserName="$ID/"`,
|
||||
`ExportOptions="AssignedSpreads"`, `IncludeLinksWhenPackage="true"`,
|
||||
`FilePath="$ID/"` and `FrameColor` `Nothing`, from DOM 7.
|
||||
|
||||
### 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):
|
||||
64 languages. Languages whose IDML quotes differ between files are left
|
||||
out (among them Romanian, Japanese and Korean).
|
||||
A language object stores its quotes only in chunk 0x2D26, which 34
|
||||
language objects of the corpus have (`objects.md`, languages); the
|
||||
converter writes those. For the others, 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): 64 languages.
|
||||
|
||||
The tool reads IDML only, so it counts the languages with chunk 0x2D26
|
||||
too. Over the 3,139 IDML languages of the corpus pairs matched with an
|
||||
INDD language, only Romanian differs because of them: every Romanian
|
||||
language without the chunk has `‚’` and `„”` (21 of 21 files), and the
|
||||
one with the chunk `‘’` and `»«`. The converter writes these quotes for
|
||||
Romanian without the chunk. Three names differ without the chunk too,
|
||||
and are left out: Japanese (`''` and `""` in 162 files, `‘’` and `“”`
|
||||
in 2), Korean (457 and 7) and Hebrew (74 and 1, `‘’` and `“”`). No
|
||||
stored value tells the exceptions apart; they follow the dictionary
|
||||
preferences of the exporting computer.
|
||||
|
||||
Pasted smooth shades are keyed the same way by `ContentsType`: every
|
||||
`ConstantShade` (and every `AxialShade`) has `ContentsVersion="0"`,
|
||||
|
||||
+51
-14
@@ -111,7 +111,7 @@ session that saved the document, oldest first:
|
||||
| Field | Contents |
|
||||
|---|---|
|
||||
| u16 | kind (not used) |
|
||||
| u16 | platform (not used) |
|
||||
| u16 | platform: 0 or 3 (style shortcuts, below) |
|
||||
| u16, u16 | not identified |
|
||||
| u16 | language code (below) |
|
||||
| flag byte, in-object string | application version, such as `16.1.0.20` |
|
||||
@@ -551,8 +551,9 @@ defaults.
|
||||
Every document has one object of class 0x1BE01, listed in chunk 0x1BE13
|
||||
of the document; IDML writes it as an `Assignment` with `Self` its UID
|
||||
(495 of 495 trustworthy pairs). Chunk 0x1BE1B starts with a flag byte
|
||||
and the name in the language the document was made in (`Unassigned
|
||||
InCopy Content`, `Contenu InCopy non affecté`, …), then two empty
|
||||
and the name in the language of the edition the document was made with
|
||||
(`Unassigned InCopy Content`, `Contenu InCopy non affecté`, …; the
|
||||
converter uses it for values of that edition, `preferences.md`), then two empty
|
||||
strings and fields that are the same in every pair. IDML names it
|
||||
`$ID/UnassignedInCopy` in 476 pairs and gives the stored name in 19, in
|
||||
files of several languages and versions, so the name follows the
|
||||
@@ -663,9 +664,42 @@ found. For the 1,249 IDML languages the names and `Id` are equal in
|
||||
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`).
|
||||
depends on the computer that exported it.
|
||||
|
||||
**Vendors without a stored name.** Over the 3,139 language objects of
|
||||
the corpus of 2026-10 matched with an IDML `Language` by name, an empty
|
||||
vendor (flag 0, u32 0x01000000, empty string) is written `$ID/` for every
|
||||
language whose vendor of that kind is never stored with flag 1 anywhere
|
||||
in the corpus: hyphenation 914 of 914 (847 trustworthy), spelling 894
|
||||
of 895 (the other, in a stale pair, has `Hunspell`). For the languages
|
||||
that have a stored vendor in some document, an empty vendor is written
|
||||
as the exporting computer's dictionary (`Hunspell` 14 and 19, `Duden` 1
|
||||
and 1, `$ID/` 1 and 1), which no stored value shows; the converter
|
||||
leaves those out. The two lists of languages without a stored vendor:
|
||||
|
||||
- Hyphenation (33): `Albanian`, `Arabic`, `Byelorussian`, `Chinese: Hong
|
||||
Kong`, `Chinese: Simplified`, `Chinese: Taiwan`, `Chinese:
|
||||
Traditional`, `Icelandic`, `Japanese`, `Korean`, `Neutral`,
|
||||
`Vietnamese`, `cy_GB`, `en_US+Medical`, `eu_ES`, `fo_FO`, `fy_NL`,
|
||||
`ga_IE`, `gl_ES`, `gv_GB`, `ko_KR`, `la_VA`, `lb_LU`, `mk_MK`, `mn_MN`,
|
||||
`ms_MY`, `ne_NE`, `oc_FR`, `sr_RS`, `sr_RS-Cyr`, `sr_RS-Lat`, `tk_TM`,
|
||||
`uz_UZ`.
|
||||
- Spelling (29): the same without `Arabic`, `Vietnamese`,
|
||||
`en_US+Medical` and `ko_KR`.
|
||||
|
||||
Two other hyphenation vendor flags occur: flag 3 with the text
|
||||
`DefaultLinguistic` is written `$ID/` (24 of 24, Korean and Chinese:
|
||||
Traditional), flag 10 with `InDihyph` is written `$ID/InDihyph` (2 of
|
||||
2). Two spelling vendors with flag 1 and the text `InDitect` are
|
||||
`Hunspell` in IDML; the converter writes the stored text for flag 1.
|
||||
|
||||
**Quotes (chunk 0x2D26).** 34 language objects of the corpus have a
|
||||
second chunk 0x2D26: a flag byte, the language name as an in-object
|
||||
string, then four UTF-16 units, the two single quotes and the two double
|
||||
quotes. IDML writes them as `SingleQuotes` and `DoubleQuotes`: 34 of 34
|
||||
(Japanese `‘’` `“”`, Romanian `‘’` `»«`, Hebrew `’’` `””`, Korean). Without
|
||||
the chunk, the quotes come from observation (`idml-values.md`, language
|
||||
quotes).
|
||||
|
||||
## Interface colours (0x1F11)
|
||||
|
||||
@@ -2023,18 +2057,21 @@ whose IDML style has the same name.
|
||||
| Key | `KeyboardShortcut` | `ExtendedKeyboardShortcut` |
|
||||
|---|---|---|
|
||||
| 0 (5,272 styles) | `0 0` | `0 0 0` |
|
||||
| 0xC000*xx*, *xx* a digit `0`–`9`, *m1* = 0 | *m0* and the code below | `0 0 0` |
|
||||
| the same, *m1* = 1, paragraph style | *m0* + 256 and 96 + the digit | `0 0 0` |
|
||||
| 0xC000*xx*, *xx* a digit `0`–`9` | *m0* + 256 × *m1* and the code below | `0 0 0` |
|
||||
| 0x8000*xx* (4 styles, one file) | `0 0` | not written (`256 49 1` and similar in IDML) |
|
||||
|
||||
The 103 styles with a key other than 0 are in 38 files.
|
||||
|
||||
Codes with *m1* = 0: digits 0 to 7 give 82 to 89, 8 gives 91 and 9 gives
|
||||
92 (every digit occurs). The converter writes the attribute only for
|
||||
these rows; character styles with *m1* = 1 (11 styles: `257 83`, `257 84`,
|
||||
`257 105`) are left out. Over all pairs, `KeyboardShortcut` is
|
||||
reproduced for 5,273 of 5,273 paragraph styles and 2,191 of 2,202
|
||||
character styles. IDML has `ExtendedKeyboardShortcut` from DOM 15 on;
|
||||
The key code follows the platform of the last session of the save
|
||||
history (the second u16 of its record), not the style: with platform 0
|
||||
digits 0 to 7 give 82 to 89, 8 gives 91 and 9 gives 92 (every digit
|
||||
occurs); with platform 3 the code is 96 + the digit. This is a rule of
|
||||
the exporting edition (`preferences.md`): over the trustworthy pairs of
|
||||
the corpus of 2026-10 it reproduces `KeyboardShortcut` for 3,154 of
|
||||
3,154 character styles and 6,927 of 6,928 paragraph styles (a rule by
|
||||
*m1* failed for 26 character and 33 paragraph styles with *m1* 0 and
|
||||
platform 3). The converter writes the attribute on every style other
|
||||
than the root styles. IDML has `ExtendedKeyboardShortcut` from DOM 15 on;
|
||||
the converter writes it from version 15.
|
||||
|
||||
**Preview colour.** Fourteen bytes before the name's flag byte is a
|
||||
|
||||
+135
-23
@@ -234,8 +234,11 @@ stored data, not a decoded field. Over the 803 pairs of the corpus of
|
||||
| No chunk 0x2834 (offset 168 is 0 in all) | 125 | `LightBlue` |
|
||||
|
||||
No stored field was found that holds the colour when the u32 is 0. Both
|
||||
the colour and offset 168 appear to be defaults of the edition that
|
||||
created the document. Every object style's `BaselineFrameGridColor`
|
||||
the colour and offset 168 appear to be defaults of an edition. In the
|
||||
corpus of 2026-10 offset 168 is 1 exactly when the first session of the
|
||||
save history is of a Japanese or Chinese edition, while the IDML colour
|
||||
follows the last one; the converter uses the rule of the exporting
|
||||
edition (below) where the u32 is 0. Every object style's `BaselineFrameGridColor`
|
||||
equals the preference's in 803 of 803 pairs (3,515 object styles), so
|
||||
the converter writes this colour in the preference and in every object
|
||||
style. A UID that is not an interface colour, or another byte at 168,
|
||||
@@ -632,11 +635,8 @@ 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` 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,
|
||||
and `; ` (no title) for other codes, whose titles vary.
|
||||
`BetweenEntriesSeparator` is `; ` or `、`. Both follow the edition
|
||||
(values of the exporting edition, below).
|
||||
|
||||
## Chapter numbering (`ChapterNumberPreference`)
|
||||
|
||||
@@ -663,23 +663,136 @@ pairs). With it, `Composition` is `UseDocument` in 16 of 21; the other 5
|
||||
(DOM 14 and 15) have `Both` with the same bytes. The converter writes
|
||||
`UseDocument` when the chunk is there.
|
||||
|
||||
## EPUB export (`EPubExportPreference`)
|
||||
## EPUB, HTML and Publish Online export
|
||||
|
||||
From DOM 8. Chunk 0x21A1A of the preferences object, in 13 of the 482
|
||||
trustworthy pairs with DOM 8 or later:
|
||||
From DOM 8 for EPUB and HTML, DOM 10 for fixed layout EPUB, DOM 11 for
|
||||
Publish Online (designmap.xml). Each has a chunk of the preferences
|
||||
object that only some documents have; values are from the corpus of
|
||||
2026-10 (1,460 pairs, 1,251 trustworthy). A "string" here is a flag
|
||||
byte and an in-object string; for `TocStyleName`, `ParagraphStyleName`
|
||||
and `CoverPage`, flag 1 means `$ID/` before the text.
|
||||
|
||||
- u32 at 0: `Version`, 0 `Epub2`, 1 `Epub3` (13 of 13).
|
||||
- `Id` is the in-object string in the chunk that starts with
|
||||
`urn:uuid:` (13 of 13). The rest of the chunk is not decoded; its
|
||||
length varies.
|
||||
**`EPubExportPreference`, chunk 0x21A1A** (39 files, 37 trustworthy),
|
||||
read in order:
|
||||
|
||||
Without the chunk (469 of 469):
|
||||
| Field | IDML |
|
||||
|---|---|
|
||||
| u32 | `Version`: 0 `Epub2`, 1 `Epub3` |
|
||||
| u32 | `ExportOrder`: 1 `LayoutOrder`, 2 `ArticlePanelOrder` |
|
||||
| u32 | `EpubCover`: 0 `None`, 1 `FirstPage`, 2 `ExternalImage` |
|
||||
| string | `CoverImageFile` |
|
||||
| u16 | 1 in all (not mapped) |
|
||||
| string | `TocStyleName`; `UseTocStyle` is `true` exactly when its text is not empty (11 `true`, 28 `false`) |
|
||||
| u16 | `BreakDocument` |
|
||||
| string | `ParagraphStyleName` |
|
||||
| 46 bytes | not mapped |
|
||||
| string | `EpubPublisher` |
|
||||
| string | `Id` |
|
||||
| 50 bytes (52 in the DOM 8 file, which has 2 more first) | u16 at 0: G (below); u16 at 2: `ImageExportResolution` in ppi (72 `Ppi72`, 150 `Ppi150`); u16 at 6: `CustomImageSizeOption` (0 `SizeFixed`, 1 `SizeRelativeToTextFlow`) |
|
||||
| string | empty in all |
|
||||
| 20 bytes (INDD 8 to 10, 18 files), 22 (13.x, 4) or 26 (17 on, 17) | u16 at 10 (at 14 in the 26-byte block): `EmbedFont` |
|
||||
| 6 strings, not in the DOM 8 file | `EpubTitle`, `EpubCreator`, `EpubDate`, `EpubDescription`, `EpubRights`, `EpubSubject` |
|
||||
|
||||
- `Id` is `urn:uuid:29d919dd-24f5-4384-be78-b447c9dc299b` and
|
||||
`TocStyleName` is `$ID/`.
|
||||
- `Version` is `Epub2` for INDD files up to version 18.0 and `Epub3`
|
||||
from 18.1 (the 5 DOM 18.0 pairs whose INDD is 18.0 have `Epub2`, the
|
||||
13 whose INDD is 18.1 to 18.4 have `Epub3`).
|
||||
G = 1 gives `PreserveLayoutAppearence="true"`,
|
||||
`FootnotePlacement="FootnoteAfterStory"` and `UseExistingImageOnExport`
|
||||
and `UseOriginalImageOnExport` `false`; G = 0 gives `false`,
|
||||
`FootnoteInsidePopup`, `true` and `true`. The four change together in
|
||||
all 39 files (one collection of 10 has 0), so they are written as a
|
||||
group, for these codes only. Which length the two blocks have is not
|
||||
stored; the converter reads the layout that ends exactly at the chunk's
|
||||
end (one of the six combinations does in all 39 files). Every attribute
|
||||
matches in 39 of 39 files. A chunk that no combination reads to its end
|
||||
gives only `Version` and `Id` (the string that starts with `urn:uuid:`).
|
||||
The u16 at 0 of the 20- to 26-byte block is 5 in all files, as is IDML
|
||||
`Level`; it is not mapped.
|
||||
|
||||
**`HTMLExportPreference`, chunk 0x21A19** (7 files, all trustworthy):
|
||||
u32 at 4 `ExportOrder` (as above), u16 at 48
|
||||
`ViewDocumentAfterExport`, u16 at 54 `PreserveLayoutAppearence`; after
|
||||
byte 98: a string, 6 bytes (10 in the file of InDesign 17), two
|
||||
strings, a u16 and the u16 `PreserveLocalOverride`. 7 of 7 each. The
|
||||
second of the two strings is `.jpg` in all 7, as is IDML
|
||||
`ImageExtension`; it is not mapped.
|
||||
|
||||
**`EPubFixedLayoutExportPreference`, chunk 0x21A25** (18 files, all
|
||||
trustworthy), in order: u32 `EpubCover`; string `CoverImageFile`; u16;
|
||||
string `TocStyleName`; u16; string `EpubPublisher`; string `Id`; 16
|
||||
bytes; a string (empty in all); 12 bytes; the six metadata strings
|
||||
above, then a string empty in all (IDML `EpubPageRange` is empty in
|
||||
all, so it is not mapped); 12 bytes with u32 at 8
|
||||
`EpubNavigationStyles` (0 `NoNavigation`, 2 `TocStyleNavigation`, 3
|
||||
`BookmarksNavigation`). 18 of 18 for each attribute; the parse ends at
|
||||
the chunk's end in all 18.
|
||||
|
||||
**`PublishExportPreference`, chunk 0x21A20** (9 files, all
|
||||
trustworthy), in order: u32 0, u32 1; strings `PublishFileName`,
|
||||
`PublishDescription`, `PublishPageRange`; 16 bytes; a string (empty in
|
||||
all); 7 bytes; a string (empty in all); 5 bytes; string `CoverPage`
|
||||
(flag 1 and empty text: `$ID/`). 9 of 9; the parse ends at the chunk's
|
||||
end. `ImageExportResolution` follows the exporting edition (below).
|
||||
|
||||
**Without the chunk** every file of the corpus of 2026-10 has these
|
||||
values (all pairs; trustworthy in brackets):
|
||||
|
||||
| Element | Values | Files |
|
||||
|---|---|---|
|
||||
| `EPubExportPreference` | `Id` `urn:uuid:29d919dd-24f5-4384-be78-b447c9dc299b`, `TocStyleName` `$ID/`, `UseTocStyle` and `BreakDocument` `false`, `ExportOrder` `LayoutOrder`, `EpubCover` `FirstPage`, `CoverImageFile` and `EpubPublisher` empty, `ParagraphStyleName` `$ID/NormalParagraphStyle`, `PreserveLayoutAppearence` and `EmbedFont` `true`, `ImageExportResolution` `Ppi150` | 1,411 (1,205) |
|
||||
| | `Version` `Epub2` before INDD 18.1, `Epub3` from 18.1 | 1,411 (1,205) |
|
||||
| | `CustomImageSizeOption` `SizeFixed` before INDD 21.1, `SizeRelativeToTextFlow` from 21.1 | 1,410 of 1,411 (1,205 of 1,205); the other is a stale pair |
|
||||
| | `FootnotePlacement` `FootnoteAfterStory`, `UseOriginalImageOnExport` `false`: IDML has them from INDD 9.2 | 1,306 (1,112) |
|
||||
| | the six metadata strings empty, `UseExistingImageOnExport` `false`: IDML has them from INDD 10.0 | 1,302 (1,108) |
|
||||
| `HTMLExportPreference` | `ExportOrder` `LayoutOrder`, `ViewDocumentAfterExport` `true`, `PreserveLayoutAppearence` `false`, `PreserveLocalOverride` `true` | 1,443 (1,235) |
|
||||
| `EPubFixedLayoutExportPreference` | `EpubCover` `FirstPage`, `CoverImageFile`, `EpubPublisher` and the six metadata strings empty, `TocStyleName` `$ID/`, `Id` as for EPUB, `EpubNavigationStyles` `NoNavigation` | 1,322 (1,127) |
|
||||
| `PublishExportPreference` | `PublishFileName`, `PublishDescription`, `PublishPageRange` empty, `CoverPage` `$ID/` | 1,211 (1,023) |
|
||||
|
||||
The version boundaries are those of the INDD header: no IDML of an
|
||||
earlier version has these attributes, every IDML from that version on
|
||||
has them.
|
||||
|
||||
## Adjust layout (`AdjustLayoutPreference` in designmap.xml)
|
||||
|
||||
From DOM 14. Chunk 0x7020 of the preferences object (26 bytes, 83
|
||||
files): u16 at 0 `EnableAdjustLayout`, at 4
|
||||
`AllowFontSizeAndLeadingAdjustment`, at 24 `EnableAutoAdjustMargins`;
|
||||
83 of 83 each (36, 2 and 1 `true`). The u16 at 2 and 6 and the f64 at 8
|
||||
and 16 have one value in every file (1, 0, 6, 324), as have the IDML
|
||||
attributes next to them; they are not mapped. Without the chunk (634
|
||||
files, 547 trustworthy) the last two are `false` in every file, and
|
||||
`EnableAdjustLayout` follows the save history (below).
|
||||
|
||||
## Values of the exporting edition
|
||||
|
||||
Some values have no field in the INDD: IDML writes the defaults of the
|
||||
InDesign that exported it. The converter takes that application from
|
||||
the save history (`objects.md`, save history) or from the name of the
|
||||
document's assignment, which is in the language of the edition that
|
||||
made the document (`objects.md`, assignments). These rules have
|
||||
exceptions where a document was exported by another installation than
|
||||
the one that saved it last; the counts give them. Over the corpus of
|
||||
2026-10, trustworthy pairs (all pairs in brackets):
|
||||
|
||||
| Value | Rule | Matches |
|
||||
|---|---|---|
|
||||
| `BaselineFrameGridColor` (preference and object styles) where chunk 0x2834 names no colour | `Charcoal` when the last session's language code is 0x0101, else `LightBlue` | 1,112 of 1,209 (1,318 of 1,416); the byte-168 rule matched 892. 96 exceptions are two collections of one Korean publisher (code 0x0101, IDML `LightBlue`) |
|
||||
| `DocumentPreference` `ColumnGuideColor` without chunk 0x555 | `Lavender` for code 0x0101, else `Violet` | 822 of 845 (965 of 989); 22 exceptions in the same collections |
|
||||
| `PublishExportPreference` `ImageExportResolution`, `PublishPdf` | by the last session's version: 11.0 `Ppi72` and no `PublishPdf`; 11.1 `Ppi96` and no `PublishPdf`; 11.2 and later `Ppi96` and `PublishPdf="false"` | 1,021 of 1,023 trustworthy pairs from 11.0 (the two exceptions have an IDML of another release than the last session); by the header version 5 more fail, among them 3 files of header 11.4 last saved by 11.0 |
|
||||
| `AdjustLayoutPreference` `EnableAdjustLayout` without chunk 0x7020 | `true` when the last session's version string starts with 14.0.0 or 14.0.1, else `false` | 634 of 634 files from version 14 without the chunk (547 trustworthy) |
|
||||
| `IndexOptions` `Title` and `BetweenEntriesSeparator` without chunk 0x13010 | by the assignment name: Japanese `索引` and `、`; Chinese `索引` and `; `; Korean `색인` and `; `; English, French, German, Dutch `Index` and `; `; Italian `Indice` and `; `; other languages `; ` and no title; English with a last session of code 0x0101 `; ` and no title | title 1,096 of 1,155 written (59 English documents exported by a Korean or Italian edition), 30 left out; separator 1,183 of 1,185 |
|
||||
| `LayoutAdjustmentPreference` `SnapZone` without chunk 0x7006 | `0.70866141732283` (0.25 mm) when the horizontal ruler unit is millimetres or centimetres or the assignment name is not English, else `2` | 1,172 of 1,183 (1,358 of 1,377); the exceptions are English documents in picas, points, inches or pixels |
|
||||
| `DOMVersion` of every part | by the last session's version (`idml-values.md`, DOM version) | 1,164 of 1,251 |
|
||||
| `KeyboardShortcut` of a style with a digit key | by the platform of the last session (`objects.md`, styles) | 3,154 of 3,154 character and 6,927 of 6,928 paragraph styles |
|
||||
|
||||
The assignment names are `Unassigned InCopy Content` (English, 648
|
||||
files), `할당되지 않은 InCopy 내용` (Korean, 433), `アサインされていない
|
||||
InCopy の内容` (Japanese, 155), `未指定的 InCopy 內容` and `未指定的
|
||||
InCopy 内容` (Chinese, 93), `Contenu InCopy non affecté` (French, 67),
|
||||
`Nicht zugewiesener InCopy-Inhalt` (German, 44), `Niet toegewezen
|
||||
InCopy-inhoud` (Dutch, 10), `Contenuto InCopy non assegnato` (Italian,
|
||||
3) and four others in one to four files (Russian, Spanish, Czech,
|
||||
Portuguese), whose titles are not written. Korean editions write the
|
||||
code 0x0101 as Japanese and Chinese ones do, so the code alone does not
|
||||
give the title: 369 of 369 documents with the Korean name have `색인`,
|
||||
with either code.
|
||||
|
||||
## Default styles, grids and other settings
|
||||
|
||||
@@ -730,6 +843,5 @@ in another form, `fonts.md`).
|
||||
| 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
|
||||
4 of the 417 pairs without the chunk contradict. Without chunk 0x7006,
|
||||
`SnapZone` varies and is not written.
|
||||
Without chunk 0x555, `ColumnGuideColor` and without chunk 0x7006
|
||||
`SnapZone` follow the edition (values of the exporting edition, below).
|
||||
+135
-5
@@ -30,7 +30,115 @@ pub(super) fn index_header_type(group: &str, variant: u16) -> Option<&'static st
|
||||
})
|
||||
}
|
||||
|
||||
/// Languages whose hyphenation vendor is never stored in the corpus: IDML
|
||||
/// writes `$ID/` for their empty vendor (objects.md, languages).
|
||||
const NO_HYPHENATION_VENDOR: &[&str] = &[
|
||||
"Albanian",
|
||||
"Arabic",
|
||||
"Byelorussian",
|
||||
"Chinese: Hong Kong",
|
||||
"Chinese: Simplified",
|
||||
"Chinese: Taiwan",
|
||||
"Chinese: Traditional",
|
||||
"Icelandic",
|
||||
"Japanese",
|
||||
"Korean",
|
||||
"Neutral",
|
||||
"Vietnamese",
|
||||
"cy_GB",
|
||||
"en_US+Medical",
|
||||
"eu_ES",
|
||||
"fo_FO",
|
||||
"fy_NL",
|
||||
"ga_IE",
|
||||
"gl_ES",
|
||||
"gv_GB",
|
||||
"ko_KR",
|
||||
"la_VA",
|
||||
"lb_LU",
|
||||
"mk_MK",
|
||||
"mn_MN",
|
||||
"ms_MY",
|
||||
"ne_NE",
|
||||
"oc_FR",
|
||||
"sr_RS",
|
||||
"sr_RS-Cyr",
|
||||
"sr_RS-Lat",
|
||||
"tk_TM",
|
||||
"uz_UZ",
|
||||
];
|
||||
|
||||
/// Languages whose spelling vendor is never stored in the corpus.
|
||||
const NO_SPELLING_VENDOR: &[&str] = &[
|
||||
"Albanian",
|
||||
"Byelorussian",
|
||||
"Chinese: Hong Kong",
|
||||
"Chinese: Simplified",
|
||||
"Chinese: Taiwan",
|
||||
"Chinese: Traditional",
|
||||
"Icelandic",
|
||||
"Japanese",
|
||||
"Korean",
|
||||
"Neutral",
|
||||
"cy_GB",
|
||||
"eu_ES",
|
||||
"fo_FO",
|
||||
"fy_NL",
|
||||
"ga_IE",
|
||||
"gl_ES",
|
||||
"gv_GB",
|
||||
"la_VA",
|
||||
"lb_LU",
|
||||
"mk_MK",
|
||||
"mn_MN",
|
||||
"ms_MY",
|
||||
"ne_NE",
|
||||
"oc_FR",
|
||||
"sr_RS",
|
||||
"sr_RS-Cyr",
|
||||
"sr_RS-Lat",
|
||||
"tk_TM",
|
||||
"uz_UZ",
|
||||
];
|
||||
|
||||
/// Quotes that every IDML has for a language without chunk 0x2D26, where
|
||||
/// the value files lack them because languages with the chunk differ
|
||||
/// (idml-values.md, language quotes).
|
||||
const QUOTES_WITHOUT_CHUNK: &[(&str, &str, &str)] = &[("Romanian", "\u{201A}\u{2019}", "\u{201E}\u{201D}")];
|
||||
|
||||
impl Writer<'_> {
|
||||
/// Values of designmap settings that follow the InDesign that saved the
|
||||
/// document last, as the save history gives it (`preferences.md`,
|
||||
/// values of the exporting edition). They apply where the INDD gives
|
||||
/// none.
|
||||
fn exporter_values(&self, tag: &str) -> Vec<(&'static str, &'static str)> {
|
||||
let header = (self.doc.version.major, self.doc.version.minor);
|
||||
let last = self.doc.last_session_version.unwrap_or(header);
|
||||
match tag {
|
||||
"PublishExportPreference" => {
|
||||
let mut out = Vec::new();
|
||||
if last == (11, 0) {
|
||||
out.push(("ImageExportResolution", "Ppi72"));
|
||||
} else if last >= (11, 1) {
|
||||
out.push(("ImageExportResolution", "Ppi96"));
|
||||
}
|
||||
if last >= (11, 2) {
|
||||
out.push(("PublishPdf", "false"));
|
||||
}
|
||||
out
|
||||
}
|
||||
"AdjustLayoutPreference" => {
|
||||
let early_14 = last == (14, 0) && matches!(self.doc.last_session_patch, Some(0 | 1));
|
||||
vec![
|
||||
("EnableAdjustLayout", if early_14 { "true" } else { "false" }),
|
||||
("AllowFontSizeAndLeadingAdjustment", "false"),
|
||||
("EnableAutoAdjustMargins", "false"),
|
||||
]
|
||||
}
|
||||
_ => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn designmap(&self, name: &str) -> String {
|
||||
let doc = self.doc;
|
||||
let mut x = Xml::new();
|
||||
@@ -155,6 +263,11 @@ impl Writer<'_> {
|
||||
for v in doc.prefs.values.iter().filter(|v| v.element == tag) {
|
||||
ours.attrs.push((v.name.to_string(), v.value.clone()));
|
||||
}
|
||||
for (k, v) in self.exporter_values(tag) {
|
||||
if !ours.attrs.iter().any(|(a, _)| a == k) {
|
||||
ours.attrs.push((k.to_string(), v.to_string()));
|
||||
}
|
||||
}
|
||||
let colors: Vec<Node> = doc
|
||||
.prefs
|
||||
.colors
|
||||
@@ -473,22 +586,39 @@ impl Writer<'_> {
|
||||
x.start("Language")
|
||||
.attr("Self", format!("Language/{}", self_name(&full)))
|
||||
.attr("Name", &full);
|
||||
if let Some(q) = values::keyed("Language", &full) {
|
||||
// The quotes stored with the language, else those every IDML
|
||||
// has for its name (objects.md, languages).
|
||||
if let Some((single, double)) = &l.quotes {
|
||||
x.attr("SingleQuotes", single).attr("DoubleQuotes", double);
|
||||
} else if let Some(q) = values::keyed("Language", &full) {
|
||||
for k in ["SingleQuotes", "DoubleQuotes"] {
|
||||
if let Some(v) = q.attr(k) {
|
||||
x.attr(k, v);
|
||||
}
|
||||
}
|
||||
} else if let Some((_, single, double)) =
|
||||
QUOTES_WITHOUT_CHUNK.iter().find(|(n, ..)| *n == l.name)
|
||||
{
|
||||
x.attr("SingleQuotes", *single).attr("DoubleQuotes", *double);
|
||||
}
|
||||
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);
|
||||
let vendor = |flag: u8, text: &str, without: &[&str]| match flag {
|
||||
1 => Some(text.to_string()),
|
||||
0 if text.is_empty() && without.contains(&l.name.as_str()) => {
|
||||
Some("$ID/".to_string())
|
||||
}
|
||||
3 => Some("$ID/".to_string()),
|
||||
10 => Some(builtin_key(text)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(v) = vendor(*hf, hyphenation, NO_HYPHENATION_VENDOR) {
|
||||
x.attr("HyphenationVendor", v);
|
||||
}
|
||||
if *sf == 1 {
|
||||
x.attr("SpellingVendor", spelling);
|
||||
if let Some(v) = vendor(*sf, spelling, NO_SPELLING_VENDOR) {
|
||||
x.attr("SpellingVendor", v);
|
||||
}
|
||||
}
|
||||
x.end();
|
||||
|
||||
+49
-1
@@ -94,6 +94,22 @@ impl Writer<'_> {
|
||||
(d.major, d.minor) >= v || self.doc.last_session_version.is_some_and(|s| s >= v)
|
||||
}
|
||||
|
||||
/// The edition that made the document, by the language of the name of
|
||||
/// its first assignment (`docs/format/objects.md`, assignments).
|
||||
pub(super) fn edition(&self) -> Option<Edition> {
|
||||
Some(match self.doc.assignment_name.as_deref()? {
|
||||
"Unassigned InCopy Content" => Edition::English,
|
||||
"Contenu InCopy non affecté" => Edition::French,
|
||||
"Nicht zugewiesener InCopy-Inhalt" => Edition::German,
|
||||
"Niet toegewezen InCopy-inhoud" => Edition::Dutch,
|
||||
"Contenuto InCopy non assegnato" => Edition::Italian,
|
||||
"할당되지 않은 InCopy 내용" => Edition::Korean,
|
||||
"アサインされていない InCopy の内容" => Edition::Japanese,
|
||||
"未指定的 InCopy 內容" | "未指定的 InCopy 内容" => Edition::Chinese,
|
||||
_ => Edition::Other,
|
||||
})
|
||||
}
|
||||
|
||||
/// language depend on it (`docs/format/objects.md`, save history).
|
||||
pub(super) fn japanese_session(&self) -> Option<bool> {
|
||||
self.doc.last_session_code.map(|c| c == 0x0101)
|
||||
@@ -171,13 +187,45 @@ impl Writer<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The language of the InDesign edition that made a document.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(super) enum Edition {
|
||||
English,
|
||||
French,
|
||||
German,
|
||||
Dutch,
|
||||
Italian,
|
||||
Korean,
|
||||
Japanese,
|
||||
Chinese,
|
||||
Other,
|
||||
}
|
||||
|
||||
/// The `DOMVersion` of the application that saved the document last, by
|
||||
/// the save history, else by the header (`idml-values.md`, DOM version).
|
||||
/// Several releases keep the DOM version of an earlier one.
|
||||
fn dom_version(doc: &Document) -> String {
|
||||
let header = (doc.version.major, doc.version.minor);
|
||||
let (major, minor) = doc
|
||||
.last_session_version
|
||||
.filter(|v| v.0 == header.0)
|
||||
.unwrap_or(header);
|
||||
let minor = match (major, minor) {
|
||||
(9, 1 | 2) | (11, 1) | (14, 3) | (17, 1..=4) | (18, 1..=4) | (19, 1 | 2) | (20, 1) => 0,
|
||||
(16, 3 | 4) => 2,
|
||||
(20, 5) => 4,
|
||||
_ => minor,
|
||||
};
|
||||
format!("{major}.{minor}")
|
||||
}
|
||||
|
||||
/// Write `doc` as an IDML package. `name` is the document name (file
|
||||
/// name). Returns warnings about values left out because the IDML schema
|
||||
/// does not allow them.
|
||||
pub fn write(doc: &Document, name: &str, out: impl std::io::Write) -> std::io::Result<Vec<String>> {
|
||||
let w = Writer {
|
||||
doc,
|
||||
dom: format!("{}.0", doc.version.major),
|
||||
dom: dom_version(doc),
|
||||
name: name.to_string(),
|
||||
group_path: group_paths(doc),
|
||||
warnings: Default::default(),
|
||||
|
||||
+45
-4
@@ -33,6 +33,8 @@ pub(super) const PREFERENCE_TAGS: &[&str] = &[
|
||||
"CjkGridPreference",
|
||||
"MojikumiUiPreference",
|
||||
"XMLImportPreference",
|
||||
"HTMLExportPreference",
|
||||
"EPubFixedLayoutExportPreference",
|
||||
];
|
||||
|
||||
/// A tree of preference values as a `Node`.
|
||||
@@ -753,6 +755,24 @@ impl Writer<'_> {
|
||||
out
|
||||
}
|
||||
|
||||
/// The index title, where one is known, and the separator between
|
||||
/// entries of a document without index options. Both follow the
|
||||
/// edition that made the document (preferences.md, index options).
|
||||
fn index_title(&self) -> Option<(Option<&'static str>, &'static str)> {
|
||||
let japanese_session = self.japanese_session() == Some(true);
|
||||
Some(match self.edition()? {
|
||||
Edition::Japanese => (Some("索引"), "、"),
|
||||
Edition::Chinese => (Some("索引"), "; "),
|
||||
Edition::Korean => (Some("색인"), "; "),
|
||||
Edition::English if japanese_session => (None, "; "),
|
||||
Edition::English | Edition::French | Edition::German | Edition::Dutch => {
|
||||
(Some("Index"), "; ")
|
||||
}
|
||||
Edition::Italian => (Some("Indice"), "; "),
|
||||
Edition::Other => (None, "; "),
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn preferences(&self) -> String {
|
||||
let mut x = Xml::new();
|
||||
self.package_root(&mut x, "Preferences");
|
||||
@@ -1106,16 +1126,37 @@ impl Writer<'_> {
|
||||
] {
|
||||
ours[i].attrs.push((k.into(), v.into()));
|
||||
}
|
||||
if let Some(japanese) = self.japanese_session() {
|
||||
if japanese {
|
||||
ours[i].attrs.push(("Title".into(), "索引".into()));
|
||||
if let Some((title, separator)) = self.index_title() {
|
||||
if let Some(t) = title {
|
||||
ours[i].attrs.push(("Title".into(), t.into()));
|
||||
}
|
||||
let separator = if japanese { "、" } else { "; " };
|
||||
ours[i]
|
||||
.attrs
|
||||
.push(("BetweenEntriesSeparator".into(), separator.into()));
|
||||
}
|
||||
}
|
||||
// Without chunk 0x7006 the snap zone follows the ruler units and
|
||||
// the edition that made the document (preferences.md, layout
|
||||
// adjustment).
|
||||
if !prefs
|
||||
.values
|
||||
.iter()
|
||||
.any(|v| v.element == "LayoutAdjustmentPreference" && v.name == "SnapZone")
|
||||
&& let Some(edition) = self.edition()
|
||||
{
|
||||
let metric = prefs.values.iter().any(|v| {
|
||||
v.element == "ViewPreference"
|
||||
&& v.name == "HorizontalMeasurementUnits"
|
||||
&& matches!(v.value.as_str(), "Millimeters" | "Centimeters")
|
||||
});
|
||||
let zone = if metric || edition != Edition::English {
|
||||
"0.70866141732283"
|
||||
} else {
|
||||
"2"
|
||||
};
|
||||
let i = ours_of(&mut ours, "LayoutAdjustmentPreference");
|
||||
ours[i].attrs.push(("SnapZone".into(), zone.into()));
|
||||
}
|
||||
ours.push(self.footnote_option());
|
||||
if let Some(c) = prefs.baseline_frame_grid_color.and_then(frame_grid_color) {
|
||||
let i = ours_of(&mut ours, "BaselineFrameGridOption");
|
||||
|
||||
+13
-6
@@ -10,7 +10,10 @@ use super::*;
|
||||
/// `KeyboardShortcut` and `ExtendedKeyboardShortcut` of a style, from its
|
||||
/// stored key (`docs/format/objects.md`, style shortcuts). `None` where the
|
||||
/// samples do not show the value.
|
||||
pub(super) fn style_shortcut(s: &crate::model::Style) -> (Option<String>, Option<String>) {
|
||||
pub(super) fn style_shortcut(
|
||||
s: &crate::model::Style,
|
||||
platform: Option<u16>,
|
||||
) -> (Option<String>, Option<String>) {
|
||||
let Some((key, low, high)) = s.shortcut else {
|
||||
return (None, None);
|
||||
};
|
||||
@@ -21,9 +24,11 @@ pub(super) fn style_shortcut(s: &crate::model::Style) -> (Option<String>, Option
|
||||
match key >> 16 {
|
||||
0xC000 if (0x30..=0x39).contains(&ch) => {
|
||||
let d = ch - 0x30;
|
||||
let code = match (high, s.paragraph) {
|
||||
(0, _) => Some(82 + d + u32::from(d >= 8)),
|
||||
(1, true) => Some(96 + d),
|
||||
// The key code follows the platform of the last session (an
|
||||
// edition rule, objects.md, style shortcuts).
|
||||
let code = match platform {
|
||||
Some(3) => Some(96 + d),
|
||||
Some(0) => Some(82 + d + u32::from(d >= 8)),
|
||||
_ => None,
|
||||
};
|
||||
let mods = u32::from(low) + 256 * u32::from(high);
|
||||
@@ -904,8 +909,8 @@ impl Writer<'_> {
|
||||
}
|
||||
}
|
||||
extra = more;
|
||||
} else if let Some(n) = values::element(tag, doc.version.major) {
|
||||
let (short, extended) = style_shortcut(s);
|
||||
} else {
|
||||
let (short, extended) = style_shortcut(s, doc.last_session_platform);
|
||||
if let Some(k) = short {
|
||||
x.attr("KeyboardShortcut", k);
|
||||
}
|
||||
@@ -914,6 +919,8 @@ impl Writer<'_> {
|
||||
{
|
||||
x.attr("ExtendedKeyboardShortcut", e);
|
||||
}
|
||||
}
|
||||
if !is_root && let Some(n) = values::element(tag, doc.version.major) {
|
||||
// Other styles get the values every IDML has on them.
|
||||
x.attrs_missing(n.attrs.iter());
|
||||
x.attrs_missing(values::when_written(tag, doc.version.major).iter());
|
||||
|
||||
+28
-4
@@ -28,6 +28,10 @@ pub struct Document {
|
||||
/// Major and minor version of the application of the last session in
|
||||
/// the save history (`16.1.0.20` gives 16, 1).
|
||||
pub last_session_version: Option<(u32, u32)>,
|
||||
/// The third number of that version (`16.1.0.20` gives 0).
|
||||
pub last_session_patch: Option<u32>,
|
||||
/// The platform of the last session: 0 or 3.
|
||||
pub last_session_platform: Option<u16>,
|
||||
/// The document's label (chunk 0x1630B): key and value, as IDML
|
||||
/// writes them.
|
||||
pub label: Vec<(String, String)>,
|
||||
@@ -47,6 +51,9 @@ pub struct Document {
|
||||
pub axial_shades: Vec<AxialShade>,
|
||||
/// Assignment objects (class 0x1BE01), in UID order.
|
||||
pub assignments: Vec<u32>,
|
||||
/// The name of the first assignment, in the language of the edition
|
||||
/// that made the document.
|
||||
pub assignment_name: Option<String>,
|
||||
/// Named grids (class 0xCD12, chunk 0xCD28: u32, a flag byte, 1 for
|
||||
/// a built-in key, and the name), in UID order.
|
||||
pub named_grids: Vec<NamedGrid>,
|
||||
@@ -205,13 +212,27 @@ impl<'a> Reader<'a> {
|
||||
.insert(a.uid, format!("PastedSmoothShade/u{:x}", a.uid));
|
||||
}
|
||||
let assignments = self.assignments();
|
||||
// The name of the first assignment: a flag byte and a string at the
|
||||
// start of chunk 0x1BE1B (objects.md, assignments).
|
||||
let assignment_name = match assignments.first() {
|
||||
Some(&u) => self.chunk(u, chunk::ASSIGNMENT_NAME).ok().flatten().and_then(|d| {
|
||||
let mut c = self.cursor(&d);
|
||||
c.flag().ok()?;
|
||||
c.string().ok()
|
||||
}),
|
||||
None => None,
|
||||
};
|
||||
let users_script = self.users_script(DOC);
|
||||
let last_session = self.last_session(DOC);
|
||||
let last_session_platform = self.last_session_platform(DOC);
|
||||
let last_session_code = last_session.as_ref().map(|(c, _)| *c);
|
||||
let last_session_version = last_session.and_then(|(_, v)| {
|
||||
let mut it = v.split('.').map(|n| n.parse::<u32>().ok());
|
||||
Some((it.next()??, it.next()??))
|
||||
});
|
||||
let session_number = |i: usize| {
|
||||
last_session
|
||||
.as_ref()
|
||||
.and_then(|(_, v)| v.split('.').nth(i)?.parse::<u32>().ok())
|
||||
};
|
||||
let last_session_version = session_number(0).zip(session_number(1));
|
||||
let last_session_patch = session_number(2);
|
||||
let numbering_lists = self.numbering_lists().unwrap_or_else(|e| {
|
||||
self.warn(format!("numbering lists left out: {e}"));
|
||||
Vec::new()
|
||||
@@ -274,6 +295,7 @@ impl<'a> Reader<'a> {
|
||||
constant_shade,
|
||||
axial_shades,
|
||||
assignments,
|
||||
assignment_name,
|
||||
style_groups: objects.style_groups,
|
||||
object_styles: objects.object_styles,
|
||||
cell_styles: objects.cell_styles,
|
||||
@@ -282,6 +304,8 @@ impl<'a> Reader<'a> {
|
||||
users_script,
|
||||
last_session_code,
|
||||
last_session_version,
|
||||
last_session_patch,
|
||||
last_session_platform,
|
||||
label,
|
||||
numbering_lists,
|
||||
sections,
|
||||
|
||||
@@ -206,6 +206,10 @@ pub mod chunk {
|
||||
/// Style export settings: tag maps, then u16 flags.
|
||||
pub const STYLE_EXPORT: u32 = 0x28F0;
|
||||
pub const LANGUAGE_NAME: u32 = 0x2D0F;
|
||||
/// The quotes of a language.
|
||||
pub const LANGUAGE_QUOTES: u32 = 0x2D26;
|
||||
/// The name of an assignment, then two strings.
|
||||
pub const ASSIGNMENT_NAME: u32 = 0x1BE1B;
|
||||
pub const ANCHOR_CHILDREN: u32 = 0x2C8;
|
||||
/// Anchored object settings, of an anchor or an object style.
|
||||
pub const ANCHOR_SETTINGS: u32 = 0x2800;
|
||||
|
||||
+445
-25
@@ -794,6 +794,14 @@ mod id {
|
||||
pub const DICTIONARY: u32 = 0x2806;
|
||||
/// EPUB export options.
|
||||
pub const EPUB: u32 = 0x21A1A;
|
||||
/// HTML export options.
|
||||
pub const HTML: u32 = 0x21A19;
|
||||
/// Fixed layout EPUB export options.
|
||||
pub const EPUB_FIXED_LAYOUT: u32 = 0x21A25;
|
||||
/// Publish Online export options.
|
||||
pub const PUBLISH: u32 = 0x21A20;
|
||||
/// Adjust layout options.
|
||||
pub const ADJUST_LAYOUT: u32 = 0x7020;
|
||||
pub const DEFAULT_PARAGRAPH_STYLE: u32 = 0x28D4;
|
||||
pub const DEFAULT_CHARACTER_STYLE: u32 = 0x28D5;
|
||||
pub const DEFAULT_OBJECT_STYLES: u32 = 0x1B959;
|
||||
@@ -838,6 +846,8 @@ mod ui {
|
||||
pub const MAGENTA: [f64; 3] = [1.0, 0.31, 1.0];
|
||||
pub const FIESTA: [f64; 3] = [0.97, 0.35, 0.42];
|
||||
pub const GRID_BLUE: [f64; 3] = [0.48, 0.73, 0.85];
|
||||
pub const LAVENDER: [f64; 3] = [0.6, 0.6, 1.0];
|
||||
pub const VIOLET: [f64; 3] = [0.6, 0.2, 1.0];
|
||||
}
|
||||
|
||||
/// `CreateLinkToXML` from the XML import options (chunk 0x1BC0B): a u32
|
||||
@@ -860,6 +870,228 @@ fn xml_import_link(enc: Encoding, d: &[u8]) -> Option<bool> {
|
||||
(n == 0).then_some(false)
|
||||
}
|
||||
|
||||
/// The EPUB metadata strings, in the order of chunks 0x21A1A and 0x21A25.
|
||||
const EPUB_METADATA: [&str; 6] = [
|
||||
"EpubTitle",
|
||||
"EpubCreator",
|
||||
"EpubDate",
|
||||
"EpubDescription",
|
||||
"EpubRights",
|
||||
"EpubSubject",
|
||||
];
|
||||
|
||||
/// A flagged string as IDML writes a style name: `$ID/` before the text of
|
||||
/// a built-in name (flag 1).
|
||||
fn style_name((flag, text): (u8, String)) -> String {
|
||||
if flag == 1 {
|
||||
format!("$ID/{text}")
|
||||
} else {
|
||||
text
|
||||
}
|
||||
}
|
||||
|
||||
/// `ImageExportResolution` of a stored resolution in ppi.
|
||||
fn resolution(ppi: u32) -> Option<&'static str> {
|
||||
match ppi {
|
||||
72 => Some("Ppi72"),
|
||||
150 => Some("Ppi150"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Values of the EPUB export options (chunk 0x21A1A), or `None` for a
|
||||
/// layout the samples do not show. Two blocks have lengths that differ
|
||||
/// between versions; the layout read is the one that ends exactly at the
|
||||
/// chunk's end (preferences.md, EPUB export).
|
||||
fn epub_export(enc: Encoding, d: &[u8]) -> Option<Vec<(&'static str, String)>> {
|
||||
let read = |b2: usize, b3: usize| -> Result<Vec<(&'static str, String)>, Error> {
|
||||
let mut c = enc.cursor(d);
|
||||
let mut out = Vec::new();
|
||||
let mut code = |name, v: u32, codes: &[(u32, &'static str)]| {
|
||||
if let Some((_, s)) = codes.iter().find(|(k, _)| *k == v) {
|
||||
out.push((name, s.to_string()));
|
||||
}
|
||||
};
|
||||
code("Version", c.u32()?, &[(0, "Epub2"), (1, "Epub3")]);
|
||||
code(
|
||||
"ExportOrder",
|
||||
c.u32()?,
|
||||
&[(1, "LayoutOrder"), (2, "ArticlePanelOrder")],
|
||||
);
|
||||
code(
|
||||
"EpubCover",
|
||||
c.u32()?,
|
||||
&[(0, "None"), (1, "FirstPage"), (2, "ExternalImage")],
|
||||
);
|
||||
out.push(("CoverImageFile", flagged(&mut c)?.1));
|
||||
c.u16()?;
|
||||
let toc = flagged(&mut c)?;
|
||||
out.push(("UseTocStyle", (!toc.1.is_empty()).to_string()));
|
||||
out.push(("TocStyleName", style_name(toc)));
|
||||
match c.u16()? {
|
||||
0 => out.push(("BreakDocument", "false".into())),
|
||||
1 => out.push(("BreakDocument", "true".into())),
|
||||
_ => {}
|
||||
}
|
||||
out.push(("ParagraphStyleName", style_name(flagged(&mut c)?)));
|
||||
c.skip(46)?;
|
||||
out.push(("EpubPublisher", flagged(&mut c)?.1));
|
||||
out.push(("Id", flagged(&mut c)?.1));
|
||||
c.skip(b2 - 50)?;
|
||||
let mut b = enc.cursor(c.bytes(50)?);
|
||||
// Four settings change together in every sample.
|
||||
match b.u16()? {
|
||||
0 => out.extend([
|
||||
("PreserveLayoutAppearence", "false".to_string()),
|
||||
("FootnotePlacement", "FootnoteInsidePopup".into()),
|
||||
("UseExistingImageOnExport", "true".into()),
|
||||
("UseOriginalImageOnExport", "true".into()),
|
||||
]),
|
||||
1 => out.extend([
|
||||
("PreserveLayoutAppearence", "true".to_string()),
|
||||
("FootnotePlacement", "FootnoteAfterStory".into()),
|
||||
("UseExistingImageOnExport", "false".into()),
|
||||
("UseOriginalImageOnExport", "false".into()),
|
||||
]),
|
||||
_ => {}
|
||||
}
|
||||
if let Some(r) = resolution(u32::from(b.u16()?)) {
|
||||
out.push(("ImageExportResolution", r.into()));
|
||||
}
|
||||
b.u16()?;
|
||||
match b.u16()? {
|
||||
0 => out.push(("CustomImageSizeOption", "SizeFixed".into())),
|
||||
1 => out.push(("CustomImageSizeOption", "SizeRelativeToTextFlow".into())),
|
||||
_ => {}
|
||||
}
|
||||
if !flagged(&mut c)?.1.is_empty() {
|
||||
return Err(Error::Corrupt("EPUB export: string not empty".into()));
|
||||
}
|
||||
let block = c.bytes(b3)?;
|
||||
let font = enc.u16_at(block, if b3 == 26 { 14 } else { 10 });
|
||||
match font {
|
||||
Some(0) => out.push(("EmbedFont", "false".into())),
|
||||
Some(1) => out.push(("EmbedFont", "true".into())),
|
||||
_ => {}
|
||||
}
|
||||
if c.remaining() > 0 {
|
||||
for name in EPUB_METADATA {
|
||||
out.push((name, flagged(&mut c)?.1));
|
||||
}
|
||||
}
|
||||
if c.remaining() > 0 {
|
||||
return Err(Error::Corrupt("EPUB export: bytes left".into()));
|
||||
}
|
||||
Ok(out)
|
||||
};
|
||||
[(50, 20), (50, 22), (50, 26), (52, 20), (52, 22), (52, 26)]
|
||||
.into_iter()
|
||||
.find_map(|(b2, b3)| read(b2, b3).ok())
|
||||
}
|
||||
|
||||
/// Values of the HTML export options (chunk 0x21A19): u32 at 4, u16 at
|
||||
/// 48 and 54, and after byte 98 a string, 6 bytes (10 from InDesign 17),
|
||||
/// two strings, a u16 and the u16 `PreserveLocalOverride`.
|
||||
fn html_export(enc: Encoding, d: &[u8]) -> Vec<(&'static str, String)> {
|
||||
let mut out = Vec::new();
|
||||
match enc.u32_at(d, 4) {
|
||||
Some(1) => out.push(("ExportOrder", "LayoutOrder".to_string())),
|
||||
Some(2) => out.push(("ExportOrder", "ArticlePanelOrder".to_string())),
|
||||
_ => {}
|
||||
}
|
||||
for (o, name) in [
|
||||
(48, "ViewDocumentAfterExport"),
|
||||
(54, "PreserveLayoutAppearence"),
|
||||
] {
|
||||
match enc.u16_at(d, o) {
|
||||
Some(0) => out.push((name, "false".into())),
|
||||
Some(1) => out.push((name, "true".into())),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let local = |gap: usize| -> Result<u16, Error> {
|
||||
let mut c = enc.cursor(d);
|
||||
c.skip(98)?;
|
||||
flagged(&mut c)?;
|
||||
c.skip(gap)?;
|
||||
flagged(&mut c)?;
|
||||
flagged(&mut c)?;
|
||||
c.u16()?;
|
||||
c.u16()
|
||||
};
|
||||
match local(6).or_else(|_| local(10)) {
|
||||
Ok(0) => out.push(("PreserveLocalOverride", "false".into())),
|
||||
Ok(1) => out.push(("PreserveLocalOverride", "true".into())),
|
||||
_ => {}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Values of the fixed layout EPUB export options (chunk 0x21A25), read
|
||||
/// to the chunk's end; `None` if the layout does not end there.
|
||||
fn fixed_layout_export(enc: Encoding, d: &[u8]) -> Option<Vec<(&'static str, String)>> {
|
||||
let read = || -> Result<Vec<(&'static str, String)>, Error> {
|
||||
let mut c = enc.cursor(d);
|
||||
let mut out = Vec::new();
|
||||
match c.u32()? {
|
||||
0 => out.push(("EpubCover", "None".to_string())),
|
||||
1 => out.push(("EpubCover", "FirstPage".to_string())),
|
||||
2 => out.push(("EpubCover", "ExternalImage".to_string())),
|
||||
_ => {}
|
||||
}
|
||||
out.push(("CoverImageFile", flagged(&mut c)?.1));
|
||||
c.u16()?;
|
||||
out.push(("TocStyleName", style_name(flagged(&mut c)?)));
|
||||
c.u16()?;
|
||||
out.push(("EpubPublisher", flagged(&mut c)?.1));
|
||||
out.push(("Id", flagged(&mut c)?.1));
|
||||
c.skip(16)?;
|
||||
flagged(&mut c)?;
|
||||
c.skip(12)?;
|
||||
for name in EPUB_METADATA {
|
||||
out.push((name, flagged(&mut c)?.1));
|
||||
}
|
||||
// The page range: empty in every sample.
|
||||
flagged(&mut c)?;
|
||||
let tail = c.bytes(12)?;
|
||||
match enc.u32_at(tail, 8) {
|
||||
Some(0) => out.push(("EpubNavigationStyles", "NoNavigation".into())),
|
||||
Some(2) => out.push(("EpubNavigationStyles", "TocStyleNavigation".into())),
|
||||
Some(3) => out.push(("EpubNavigationStyles", "BookmarksNavigation".into())),
|
||||
_ => {}
|
||||
}
|
||||
if c.remaining() > 0 {
|
||||
return Err(Error::Corrupt("fixed layout export: bytes left".into()));
|
||||
}
|
||||
Ok(out)
|
||||
};
|
||||
read().ok()
|
||||
}
|
||||
|
||||
/// Values of the Publish Online export options (chunk 0x21A20), read to
|
||||
/// the chunk's end; `None` if the layout does not end there.
|
||||
fn publish_export(enc: Encoding, d: &[u8]) -> Option<Vec<(&'static str, String)>> {
|
||||
let read = || -> Result<Vec<(&'static str, String)>, Error> {
|
||||
let mut c = enc.cursor(d);
|
||||
c.skip(8)?;
|
||||
let mut out = Vec::new();
|
||||
for name in ["PublishFileName", "PublishDescription", "PublishPageRange"] {
|
||||
out.push((name, flagged(&mut c)?.1));
|
||||
}
|
||||
c.skip(16)?;
|
||||
flagged(&mut c)?;
|
||||
c.skip(7)?;
|
||||
flagged(&mut c)?;
|
||||
c.skip(5)?;
|
||||
out.push(("CoverPage", style_name(flagged(&mut c)?)));
|
||||
if c.remaining() > 0 {
|
||||
return Err(Error::Corrupt("publish export: bytes left".into()));
|
||||
}
|
||||
Ok(out)
|
||||
};
|
||||
read().ok()
|
||||
}
|
||||
|
||||
/// The EPUB identifier of documents without EPUB export options.
|
||||
const EPUB_ID: &str = "urn:uuid:29d919dd-24f5-4384-be78-b447c9dc299b";
|
||||
|
||||
@@ -1291,23 +1523,26 @@ impl Reader<'_> {
|
||||
);
|
||||
}
|
||||
|
||||
// Values without a field follow the edition of the last session of
|
||||
// the save history (preferences.md, values of the exporting
|
||||
// edition).
|
||||
let japanese_session = self.last_session(1).map(|(code, _)| code == 0x0101);
|
||||
// Text preferences and the default text frame columns.
|
||||
let mut baseline_frame_grid_color = None;
|
||||
if let Some(d) = get(id::TEXT)?.filter(|d| d.len() >= 174) {
|
||||
// Bytes 168 and 170 are `UseCidMojikumi` and
|
||||
// `UseNewVerticalScaling` in an order not known; they are
|
||||
// equal in every sample. Byte 168 also gives the default
|
||||
// colour of baseline frame grids (preferences.md).
|
||||
// equal in every sample.
|
||||
if d[168] == d[170] && d[168] <= 1 {
|
||||
let on = (d[168] == 1).to_string();
|
||||
set("TextPreference", "UseCidMojikumi", on.clone());
|
||||
set("TextPreference", "UseNewVerticalScaling", on);
|
||||
}
|
||||
let ui = get(id::BASELINE_FRAME_GRID)?.and_then(|g| self.enc().u32_at(&g, 20));
|
||||
baseline_frame_grid_color = match (ui, d[168]) {
|
||||
baseline_frame_grid_color = match (ui, japanese_session) {
|
||||
(Some(u), _) if u != 0 => self.ui_color(u)?.map(FrameGridColor::Rgb),
|
||||
(_, 1) => Some(FrameGridColor::Charcoal),
|
||||
(_, 0) => Some(FrameGridColor::LightBlue),
|
||||
(_, Some(true)) => Some(FrameGridColor::Charcoal),
|
||||
(_, Some(false)) => Some(FrameGridColor::LightBlue),
|
||||
_ => None,
|
||||
};
|
||||
let f = |o: usize| self.cursor(&d[o..]).f64();
|
||||
@@ -1743,7 +1978,7 @@ impl Reader<'_> {
|
||||
18,
|
||||
"DocumentPreference",
|
||||
"ColumnGuideColor",
|
||||
None,
|
||||
japanese_session.map(|j| if j { ui::LAVENDER } else { ui::VIOLET }),
|
||||
),
|
||||
] {
|
||||
match get(id)? {
|
||||
@@ -1876,31 +2111,173 @@ impl Reader<'_> {
|
||||
None => "Both",
|
||||
};
|
||||
set("DictionaryPreference", "Composition", composition.into());
|
||||
// EPUB export, from DOM 8: u32 version at 0 and the identifier.
|
||||
// EPUB and HTML export, from DOM 8 (preferences.md, EPUB, HTML
|
||||
// and Publish Online export).
|
||||
if major >= 8 {
|
||||
let v = (major, version.minor);
|
||||
match get(id::EPUB)? {
|
||||
Some(d) => {
|
||||
match self.cursor(&d).u32()? {
|
||||
0 => set("EPubExportPreference", "Version", "Epub2".into()),
|
||||
1 => set("EPubExportPreference", "Version", "Epub3".into()),
|
||||
_ => {}
|
||||
Some(d) => match epub_export(self.enc(), &d) {
|
||||
Some(e) => {
|
||||
for (name, value) in e {
|
||||
let since = match name {
|
||||
"FootnotePlacement" | "UseOriginalImageOnExport" => (9, 2),
|
||||
n if EPUB_METADATA.contains(&n)
|
||||
|| n == "UseExistingImageOnExport" =>
|
||||
{
|
||||
(10, 0)
|
||||
}
|
||||
_ => (8, 0),
|
||||
};
|
||||
if v >= since {
|
||||
set("EPubExportPreference", name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
// The layout after the version is not decoded; the
|
||||
// identifier is the string that starts `urn:uuid:`.
|
||||
if let Some((_, _, id)) =
|
||||
super::strings::find_flagged_string(self.enc(), &d, 4, |s| {
|
||||
s.starts_with("urn:uuid:")
|
||||
})
|
||||
{
|
||||
set("EPubExportPreference", "Id", id);
|
||||
None => {
|
||||
// A layout the samples do not show: the version and
|
||||
// the identifier, the string that starts `urn:uuid:`.
|
||||
match self.cursor(&d).u32()? {
|
||||
0 => set("EPubExportPreference", "Version", "Epub2".into()),
|
||||
1 => set("EPubExportPreference", "Version", "Epub3".into()),
|
||||
_ => {}
|
||||
}
|
||||
if let Some((_, _, id)) =
|
||||
super::strings::find_flagged_string(self.enc(), &d, 4, |s| {
|
||||
s.starts_with("urn:uuid:")
|
||||
})
|
||||
{
|
||||
set("EPubExportPreference", "Id", id);
|
||||
}
|
||||
}
|
||||
},
|
||||
None => {
|
||||
let epub3 = v >= (18, 1);
|
||||
let version = if epub3 { "Epub3" } else { "Epub2" };
|
||||
let size = if v >= (21, 1) {
|
||||
"SizeRelativeToTextFlow"
|
||||
} else {
|
||||
"SizeFixed"
|
||||
};
|
||||
for (name, value) in [
|
||||
("Version", version),
|
||||
("Id", EPUB_ID),
|
||||
("TocStyleName", "$ID/"),
|
||||
("UseTocStyle", "false"),
|
||||
("ExportOrder", "LayoutOrder"),
|
||||
("EpubCover", "FirstPage"),
|
||||
("CoverImageFile", ""),
|
||||
("BreakDocument", "false"),
|
||||
("ParagraphStyleName", "$ID/NormalParagraphStyle"),
|
||||
("EpubPublisher", ""),
|
||||
("PreserveLayoutAppearence", "true"),
|
||||
("ImageExportResolution", "Ppi150"),
|
||||
("CustomImageSizeOption", size),
|
||||
("EmbedFont", "true"),
|
||||
] {
|
||||
set("EPubExportPreference", name, value.into());
|
||||
}
|
||||
if v >= (9, 2) {
|
||||
set(
|
||||
"EPubExportPreference",
|
||||
"FootnotePlacement",
|
||||
"FootnoteAfterStory".into(),
|
||||
);
|
||||
set(
|
||||
"EPubExportPreference",
|
||||
"UseOriginalImageOnExport",
|
||||
"false".into(),
|
||||
);
|
||||
}
|
||||
if v >= (10, 0) {
|
||||
for name in EPUB_METADATA {
|
||||
set("EPubExportPreference", name, String::new());
|
||||
}
|
||||
set(
|
||||
"EPubExportPreference",
|
||||
"UseExistingImageOnExport",
|
||||
"false".into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
match get(id::HTML)? {
|
||||
Some(d) => {
|
||||
for (name, value) in html_export(self.enc(), &d) {
|
||||
set("HTMLExportPreference", name, value);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let epub3 = (major, version.minor) >= (18, 1);
|
||||
let v = if epub3 { "Epub3" } else { "Epub2" };
|
||||
set("EPubExportPreference", "Version", v.into());
|
||||
set("EPubExportPreference", "Id", EPUB_ID.into());
|
||||
set("EPubExportPreference", "TocStyleName", "$ID/".into());
|
||||
for (name, value) in [
|
||||
("ExportOrder", "LayoutOrder"),
|
||||
("ViewDocumentAfterExport", "true"),
|
||||
("PreserveLayoutAppearence", "false"),
|
||||
("PreserveLocalOverride", "true"),
|
||||
] {
|
||||
set("HTMLExportPreference", name, value.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fixed layout EPUB export, from DOM 10.
|
||||
if major >= 10 {
|
||||
match get(id::EPUB_FIXED_LAYOUT)? {
|
||||
Some(d) => {
|
||||
for (name, value) in fixed_layout_export(self.enc(), &d).unwrap_or_default() {
|
||||
set("EPubFixedLayoutExportPreference", name, value);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
for (name, value) in [
|
||||
("EpubCover", "FirstPage"),
|
||||
("CoverImageFile", ""),
|
||||
("TocStyleName", "$ID/"),
|
||||
("EpubPublisher", ""),
|
||||
("Id", EPUB_ID),
|
||||
("EpubNavigationStyles", "NoNavigation"),
|
||||
] {
|
||||
set("EPubFixedLayoutExportPreference", name, value.into());
|
||||
}
|
||||
for name in EPUB_METADATA {
|
||||
set("EPubFixedLayoutExportPreference", name, String::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Adjust layout (designmap), from DOM 14: u16 flags at 0, 4 and 24
|
||||
// of the 26-byte chunk. Without it the writer decides
|
||||
// `EnableAdjustLayout` by the save history.
|
||||
if major >= 14
|
||||
&& let Some(d) = get(id::ADJUST_LAYOUT)?.filter(|d| d.len() == 26)
|
||||
{
|
||||
for (o, name) in [
|
||||
(0, "EnableAdjustLayout"),
|
||||
(4, "AllowFontSizeAndLeadingAdjustment"),
|
||||
(24, "EnableAutoAdjustMargins"),
|
||||
] {
|
||||
match self.enc().u16_at(&d, o) {
|
||||
Some(0) => set("AdjustLayoutPreference", name, "false".into()),
|
||||
Some(1) => set("AdjustLayoutPreference", name, "true".into()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Publish Online export (designmap), from DOM 11.
|
||||
if major >= 11 {
|
||||
match get(id::PUBLISH)? {
|
||||
Some(d) => {
|
||||
for (name, value) in publish_export(self.enc(), &d).unwrap_or_default() {
|
||||
set("PublishExportPreference", name, value);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
for (name, value) in [
|
||||
("PublishFileName", ""),
|
||||
("PublishDescription", ""),
|
||||
("PublishPageRange", ""),
|
||||
("CoverPage", "$ID/"),
|
||||
] {
|
||||
set("PublishExportPreference", name, value.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2330,4 +2707,47 @@ mod tests {
|
||||
// A pair cut short.
|
||||
assert_eq!(xml_import_link(enc, &d[..d.len() - 3]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_the_epub_export_layout_that_ends_the_chunk() {
|
||||
let enc = Encoding::default();
|
||||
let mut d = Vec::new();
|
||||
for v in [1u32, 2, 0] {
|
||||
d.extend(v.to_le_bytes());
|
||||
}
|
||||
fstr(&mut d, 0, "");
|
||||
d.extend([1, 0]);
|
||||
fstr(&mut d, 0, "TOC");
|
||||
d.extend([1, 0]);
|
||||
fstr(&mut d, 1, "NormalParagraphStyle");
|
||||
d.extend([0; 46]);
|
||||
fstr(&mut d, 0, "Pub");
|
||||
fstr(&mut d, 0, "urn:uuid:x");
|
||||
let mut block = [0u8; 50];
|
||||
block[2] = 72;
|
||||
block[6] = 1;
|
||||
d.extend(block);
|
||||
fstr(&mut d, 0, "");
|
||||
let mut tail = [0u8; 26];
|
||||
tail[14] = 1;
|
||||
d.extend(tail);
|
||||
for s in ["T", "C", "D", "Desc", "R", "S"] {
|
||||
fstr(&mut d, 0, s);
|
||||
}
|
||||
let e = epub_export(enc, &d).unwrap();
|
||||
let get = |k: &str| e.iter().find(|(n, _)| *n == k).map(|(_, v)| v.as_str());
|
||||
assert_eq!(get("Version"), Some("Epub3"));
|
||||
assert_eq!(get("ExportOrder"), Some("ArticlePanelOrder"));
|
||||
assert_eq!(get("EpubCover"), Some("None"));
|
||||
assert_eq!(get("UseTocStyle"), Some("true"));
|
||||
assert_eq!(get("BreakDocument"), Some("true"));
|
||||
assert_eq!(get("ParagraphStyleName"), Some("$ID/NormalParagraphStyle"));
|
||||
assert_eq!(get("FootnotePlacement"), Some("FootnoteInsidePopup"));
|
||||
assert_eq!(get("ImageExportResolution"), Some("Ppi72"));
|
||||
assert_eq!(get("CustomImageSizeOption"), Some("SizeRelativeToTextFlow"));
|
||||
assert_eq!(get("EmbedFont"), Some("true"));
|
||||
assert_eq!(get("EpubSubject"), Some("S"));
|
||||
// A chunk that no layout reads to its end.
|
||||
assert!(epub_export(enc, &d[..d.len() - 1]).is_none());
|
||||
}
|
||||
}
|
||||
+38
-4
@@ -104,6 +104,9 @@ pub struct Language {
|
||||
pub id: u16,
|
||||
/// The spelling and hyphenation vendors, each with its flag byte.
|
||||
pub vendors: Option<[(u8, String); 2]>,
|
||||
/// Single and double quotes (chunk 0x2D26), where the language has
|
||||
/// them.
|
||||
pub quotes: Option<(String, String)>,
|
||||
}
|
||||
|
||||
/// A bullet character of the document's list (IDML `ABullet`): u32
|
||||
@@ -312,6 +315,17 @@ impl<'a> Reader<'a> {
|
||||
/// u32). `None` when the chunk is missing or empty or does not parse.
|
||||
/// See `docs/format/objects.md`, save history.
|
||||
pub(super) fn last_session(&self, doc: u32) -> Option<(u16, String)> {
|
||||
self.last_record(doc).map(|(_, code, version)| (code, version))
|
||||
}
|
||||
|
||||
/// The platform (the second u16) of the last record of the save
|
||||
/// history: 0 or 3 (`objects.md`, save history).
|
||||
pub(super) fn last_session_platform(&self, doc: u32) -> Option<u16> {
|
||||
self.last_record(doc).map(|(platform, ..)| platform)
|
||||
}
|
||||
|
||||
/// Platform, code and version string of the last save history record.
|
||||
fn last_record(&self, doc: u32) -> Option<(u16, u16, String)> {
|
||||
let d = self.chunk(doc, chunk::DOC_HISTORY).ok()??;
|
||||
let mut c = self.cursor(&d);
|
||||
let n = c.u32().ok()? as usize;
|
||||
@@ -321,16 +335,17 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
let mut last = None;
|
||||
for _ in 0..n {
|
||||
for _ in 0..4 {
|
||||
c.u16().ok()?;
|
||||
}
|
||||
c.u16().ok()?;
|
||||
let platform = c.u16().ok()?;
|
||||
c.u16().ok()?;
|
||||
c.u16().ok()?;
|
||||
let code = c.u16().ok()?;
|
||||
c.flag().ok()?;
|
||||
let version = c.string().ok()?;
|
||||
c.u16().ok()?;
|
||||
c.u32().ok()?;
|
||||
c.u32().ok()?;
|
||||
last = Some((code, version));
|
||||
last = Some((platform, code, version));
|
||||
}
|
||||
last
|
||||
}
|
||||
@@ -554,6 +569,24 @@ impl<'a> Reader<'a> {
|
||||
let hyphenation = vendor()?;
|
||||
Ok((primary, sub, id, [spelling, hyphenation]))
|
||||
})();
|
||||
// Quotes (chunk 0x2D26): flag byte, the language name, then the
|
||||
// two single and the two double quotes as UTF-16 units.
|
||||
let quotes = match self.chunk(uid, chunk::LANGUAGE_QUOTES)? {
|
||||
Some(q) => (|| -> Result<(String, String), Error> {
|
||||
let mut c = self.cursor(&q);
|
||||
c.flag()?;
|
||||
c.string()?;
|
||||
let mut unit = || -> Result<char, Error> {
|
||||
char::from_u32(u32::from(c.u16()?))
|
||||
.ok_or_else(|| Error::Corrupt("quote is not a character".into()))
|
||||
};
|
||||
let single: String = [unit()?, unit()?].into_iter().collect();
|
||||
let double: String = [unit()?, unit()?].into_iter().collect();
|
||||
Ok((single, double))
|
||||
})()
|
||||
.ok(),
|
||||
None => None,
|
||||
};
|
||||
let language = rest.ok().map(|(primary, sub, id, vendors)| Language {
|
||||
uid,
|
||||
name: name.clone(),
|
||||
@@ -561,6 +594,7 @@ impl<'a> Reader<'a> {
|
||||
sub,
|
||||
id,
|
||||
vendors: Some(vendors),
|
||||
quotes,
|
||||
});
|
||||
Ok(Some((name, language)))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user