diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index c3cd626..fc8c271 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -163,10 +163,9 @@ only for attributes the element does not have. For value trees values. A few observed values are still written as literals in the writer, -where the generators cannot express them: the entries of the built-in -composite font, `AccurateLABSpots` of the document (one DOM 7 file lacks -it) and the default numbering list for a file whose lists cannot be -read. Each cites `idml-values.md`. +where the generators cannot express them: `AccurateLABSpots` of the +document (one DOM 7 file lacks it) and the default numbering list for a +file whose lists cannot be read. Each cites `idml-values.md`. ## Tests and tools diff --git a/README.md b/README.md index 78fb8ea..569bae1 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Each area below links to the document that holds the evidence. | Colours and swatches | Process, spot and registration colours, tints, gradients, inks, colour groups, the `None` swatch. [`objects.md`](docs/format/objects.md) | | Tables | Tables in stories and in cells: rows, columns, headers and footers, cells with spans, cell text, cell and table formatting, applied styles. [`tables.md`](docs/format/tables.md) | | Links and cross-references | Hyperlinks with text, paragraph and page item sources; text, page, URL and external page destinations; bookmarks; cross-reference sources and formats. [`hyperlinks.md`](docs/format/hyperlinks.md), [`cross-references.md`](docs/format/cross-references.md) | -| Fonts | Font families and fonts with their names (including built-in and native-script names), styles, types, PostScript names and Typekit IDs; missing fonts; composite font entries. [`fonts.md`](docs/format/fonts.md) | +| Fonts | Font families and fonts with their names (including built-in and native-script names), styles, types, PostScript names and Typekit IDs; missing fonts; composite fonts and their entries. [`fonts.md`](docs/format/fonts.md) | | CJK | Kinsoku and mojikumi tables (with the spacing of custom mojikumi tables), composite fonts, grid alignment of paragraphs, layout grids of pages, named grids, frame grids and their stories. [`objects.md`](docs/format/objects.md), [`fonts.md`](docs/format/fonts.md) | | XML | Tags, the XML structure with elements placed in story text, the backing story. [`xml.md`](docs/format/xml.md) | | Index | The index with its topics, page references in the text, index options and header groups, index sort groups. [`index.md`](docs/format/index.md), [`preferences.md`](docs/format/preferences.md) | diff --git a/docs/format/attributes.md b/docs/format/attributes.md index 4a34eda..33326eb 100644 --- a/docs/format/attributes.md +++ b/docs/format/attributes.md @@ -387,6 +387,7 @@ styles with INDD styles of the same name (486 styles), then checked with | 0x1BDB | `ParagraphShadingTopOffset` | f64 | 91/91 styles | | 0x1BDC | `ParagraphShadingBottomOffset` | f64 | 90/90 styles | | 0x1BF6 | `ParagraphBorderColor` (Properties) | swatch UID | 72/72 styles | +| 0x1BFA | `ParagraphBorderGapColor` (Properties) | swatch UID; 0 is `Swatch/None` | present exactly when the list has the ID (344 of 344 styles of the corpus of 2026-10); trustworthy pairs after 2026-10: 1,147 of 1,147 paragraph styles, 918 of 918 text defaults, 2,745 of 2,745 text ranges, 642 + 84 story and cell paragraph ranges | | 0x1BF9 | `ParagraphBorderOn` | 1 = true | 77/77 styles | | 0x1DF03 | `ParagraphBorderTopOffset` | f64 | 83/83 styles | | 0x1DF04 | `ParagraphBorderBottomOffset` | f64 | 83/83 styles | diff --git a/docs/format/fonts.md b/docs/format/fonts.md index 7f830aa..fdd9bb9 100644 --- a/docs/format/fonts.md +++ b/docs/format/fonts.md @@ -206,45 +206,63 @@ u32 count *n*, then *n* entries: u8 1 if the string is a built-in key ## Composite fonts -Every INDD file has one object of class 0xCB02, and every IDML one -`CompositeFont`, `[No composite font]` (240 of 240 IDML files). Its -entries are objects of class 0xCB03; IDML writes them as -`CompositeFontEntry` with `Self="u"`, six per file. Implemented in +Every INDD file has an object of class 0xCB02 for `[No composite font]`, +and every IDML that `CompositeFont` (240 of 240 IDML files of the early +corpus). User composite fonts are more objects of the class: 47 of the +1,251 trustworthy pairs of the corpus after 2026-10 have them, 1,434 +fonts in all. The entries are objects of class 0xCB03; IDML writes them +as `CompositeFontEntry` with `Self="u"`. IDML lists the composite +fonts in UID order (47 of 47 documents) and each font's entries in the +order of its list (1,434 of 1,434 fonts). Implemented in `src/model/cjk.rs`. -**Composite font (chunk 0xCB02).** A flag byte (1 = built-in key, `$ID/`) -and the name, fields not identified, then a u16 count and the UIDs of -the entries, which end the chunk. The list is the IDML entry order in -76 of 78 pairs; the other two are pairs whose IDML was exported from -another save (their entry UIDs have no INDD object). No sample has -another composite font, so the converter writes only this one. +**Composite font (chunk 0xCB02).** + +| Field | Contents | +|---|---| +| flagged string | name (`Name`; flag 1 → `$ID/`) | +| flagged string | empty | +| flagged string | a PostScript-style name (`ATC-…`) | +| flagged string | the name again, or empty | +| u32, u16 | not identified | +| u16 *n*, *n* × u32 | the entry UIDs, which end the chunk | + +The four strings were found by parsing every 0xCB02 chunk of the pairs, +which then end exactly after the UIDs. A chunk of another layout (files +from InDesign 3.0 have four zero bytes before the name, +`big-endian.md`) is read as the name followed by the first u16 count +whose UIDs end the chunk. That search alone took a wrong position in one +12.1 document, whose name bytes fit the test. **Entry (chunk 0xCB03).** -| Field | IDML | Evidence | +| Field | IDML | Evidence (trustworthy pairs, 8,589 entries) | |---|---|---| -| Flag byte, string | `Name` | 456 of 456 | -| u32 font family UID | `AppliedFont` (Properties): the family's name | 454 of 456; the other 2 are in the pair whose IDML names the family `Minion Pro (OTF)` (above) | -| Flag byte, string | `FontStyle` | 456 of 456 (`$ID/R`, `$ID/Regular`, `$ID/Roman`) | -| Four f64 | `RelativeSize`, `HorizontalScale`, `VerticalScale` 100, `BaselineShift` 0 | (100, 0, 100, 100) in all 1,500 entries of the 250 distinct little-endian files | -| u16 1, u16 count *n*, *n* ranges | `CustomCharacters` | 380 of 380 | -| Four u16 | `ScaleOption`: all 1 `true`, all 0 `false` | 456 of 456 | +| Flag byte, string | `Name` | 8,589 | +| u32 font family UID | `AppliedFont` (Properties): the family's name | 8,553; the other 36 are families that IDML names in another form (below) | +| Flag byte, string | `FontStyle` | 8,589 | +| f64 | `RelativeSize` | 8,589 (55 to 116) | +| f64 | `BaselineShift` | 8,589 (−10 to 38) | +| f64, f64 | `HorizontalScale`, `VerticalScale` | 100 in every entry, so their order is not shown | +| u16 | `Locked`: 1 `true`, 0 `false` | 8,589 (204 `false`) | +| u16 count *n*, *n* ranges | `CustomCharacters` | 7,155 | +| Four u16 | `ScaleOption`: all 1 `true`, all 0 `false` | 8,589 | Each range is three code points (first, last, first again), each one UTF-16 unit or a surrogate pair. `CustomCharacters` is every character -from first to last of each range, in order. IDML never writes -`CustomCharacters` for the `$ID/Kanji` entry (240 of 240 files), whose -ranges cover most of Unicode; the converter leaves it out for that entry. -In one file without IDML the `$ID/kCompFontString_Base` entry covers all -of Unicode (U+0000–U+D7FF and U+E000–U+10FFFF); XML 1.0 does not allow -U+FFFE and U+FFFF, so the converter leaves those two characters out of -every attribute value and text. -The four numbers have one value in every sample, so only the 0 is told -apart (`BaselineShift`); the converter writes the four attributes only -when the numbers are (100, 0, 100, 100). Which of the four u16 is +from first to last of each range, in order. IDML writes no +`CustomCharacters` for the first entry of each font, the base font +(1,434 of 1,434; every other entry has them, 7,155 of 7,155). Its ranges +cover most of Unicode: for example U+0000–U+D7FF and U+E000–U+10FFFF, or +U+0009–U+000A, U+000D, U+0020–U+D7FF and U+E000–U+FFFD. XML 1.0 does not +allow U+FFFE and U+FFFF, so the converter leaves those two characters +out of every attribute value and text. Which of the four u16 is `ScaleOption` is not known; the converter writes it only when all four -agree. `Locked="true"` is in every IDML entry and is written from that -observation (`idml-values.md`). +agree. + +The 36 `AppliedFont` values not reproduced are in one document whose +IDML names its families in English where the converter writes the +native name (family names, above). `PlatformName` is `$ID/` in all 4,464 IDML fonts; the converter writes that value (`idml-values.md`). diff --git a/docs/format/idml-values.md b/docs/format/idml-values.md index f3f2de9..36d0235 100644 --- a/docs/format/idml-values.md +++ b/docs/format/idml-values.md @@ -243,17 +243,6 @@ file has it only from DOM 14, since it is generated per major version; the converter writes it when the header or the last session of the save history is 13.1 or later (`objects.md`, save history). -## Composite font entries - -The converter writes only the built-in composite font `[No composite -font]`. All 5,231 of its `CompositeFontEntry` elements in the corpus -IDML files have `Locked="true"`, `RelativeSize="100"`, -`BaselineShift="0"`, `HorizontalScale="100"` and `VerticalScale="100"`. -No INDD field for `Locked` is identified; the converter writes it on -every entry, and the other four where the entry's stored numbers are -those of every entry (`fonts.md`). Entries of other composite fonts -have other values. - ## Inks Every `Ink` element of the 1,495 corpus IDML files has `InkType="Normal"` diff --git a/src/idml/attrs.rs b/src/idml/attrs.rs index 56f6897..8b899b8 100644 --- a/src/idml/attrs.rs +++ b/src/idml/attrs.rs @@ -390,6 +390,7 @@ pub(super) const TEXT_ATTRS: &[(u32, &str, Kind, bool)] = &[ (0x1BDB, "ParagraphShadingTopOffset", Kind::Number, false), (0x1BDC, "ParagraphShadingBottomOffset", Kind::Number, false), (0x1BF6, "ParagraphBorderColor", Kind::Swatch, true), + (0x1BFA, "ParagraphBorderGapColor", Kind::SwatchOrNone, true), (0x1BF9, "ParagraphBorderOn", Kind::Equals(1), false), (0x1DF03, "ParagraphBorderTopOffset", Kind::Number, false), ( diff --git a/src/idml/kind.rs b/src/idml/kind.rs index d73ec18..77114c4 100644 --- a/src/idml/kind.rs +++ b/src/idml/kind.rs @@ -56,6 +56,8 @@ pub(super) enum Kind { Swatch, /// A swatch, or 0 for "Text Color". SwatchOrText, + /// A swatch, or 0 for the swatch `None`. + SwatchOrNone, /// A font family. Font, /// A font family, or 0 for none (`$ID/`). @@ -202,6 +204,10 @@ impl Writer<'_> { 0 => Some(text("string", "Text Color".into())), u => swatch(u).map(|s| text("object", s)), }, + Kind::SwatchOrNone => match v.as_u32()? { + 0 => Some(text("object", "Swatch/None".into())), + u => swatch(u).map(|s| text("object", s)), + }, Kind::NumberingList => v .as_u32() .and_then(|u| self.doc.numbering_lists.iter().find(|l| l.uid == u)) diff --git a/src/idml/resources.rs b/src/idml/resources.rs index 14bef4f..4a3d641 100644 --- a/src/idml/resources.rs +++ b/src/idml/resources.rs @@ -327,35 +327,36 @@ impl Writer<'_> { } x.end(); } - // Only the built-in composite font occurs in the corpus. - for cf in self - .doc - .composite_fonts - .iter() - .filter(|c| c.name.builtin && c.name.name == "[No composite font]") - { + // Composite fonts in UID order (fonts.md, composite fonts). + let mut fonts: Vec<_> = self.doc.composite_fonts.iter().collect(); + fonts.sort_by_key(|c| c.uid); + for cf in fonts { let name = cf.name.idml(); x.start("CompositeFont") .attr("Self", format!("CompositeFont/{}", self_name(&name))) .attr("Name", &name); - for e in &cf.entries { - // The four numbers are the same in every sample. - let usual = e.numbers == [100.0, 0.0, 100.0, 100.0]; + for (k, e) in cf.entries.iter().enumerate() { + let [size, shift, horizontal, vertical] = e.numbers; x.start("CompositeFontEntry") .attr("Self", uref(Some(e.uid))) .attr("Name", e.name.idml()) - .attr("FontStyle", e.font_style.idml()); - if usual { - x.attr("RelativeSize", "100") - .attr("HorizontalScale", "100") - .attr("VerticalScale", "100"); - } - // IDML gives no characters for the Kanji entry. - if !(e.name.builtin && e.name.name == "Kanji") { + .attr("FontStyle", e.font_style.idml()) + .attr("RelativeSize", num(size)) + .attr("HorizontalScale", num(horizontal)) + .attr("VerticalScale", num(vertical)); + // The first entry is the base font, without characters. + if k > 0 { x.attr("CustomCharacters", e.characters()); } - // In every CompositeFontEntry of the corpus IDML files. - x.attr("Locked", "true"); + match e.locked { + 0 => { + x.attr("Locked", "false"); + } + 1 => { + x.attr("Locked", "true"); + } + _ => {} + } match e.scale { [1, 1, 1, 1] => { x.attr("ScaleOption", "true"); @@ -365,9 +366,7 @@ impl Writer<'_> { } _ => {} } - if usual { - x.attr("BaselineShift", "0"); - } + x.attr("BaselineShift", num(shift)); if let Some(f) = self.doc.fonts.get(&e.font_family) { Self::properties( &mut x, diff --git a/src/model/cjk.rs b/src/model/cjk.rs index 7385410..f6c0f9f 100644 --- a/src/model/cjk.rs +++ b/src/model/cjk.rs @@ -40,9 +40,11 @@ pub struct CompositeFontEntry { pub name: Name, pub font_family: u32, pub font_style: Name, - /// Four f64; (100, 0, 100, 100) in every sample, the 0 being the - /// baseline shift. + /// Four f64: relative size, baseline shift, then the horizontal and + /// vertical scale (100 in every sample, so their order is not shown). pub numbers: [f64; 4], + /// The u16 after the numbers: 1 for `Locked="true"`, 0 for false. + pub locked: u16, /// Character ranges as (first, last) code points. pub ranges: Vec<(u32, u32)>, /// The four u16 after the ranges: all 1 for `ScaleOption="true"`, all 0 @@ -62,8 +64,8 @@ fn code_point(c: &mut Cursor) -> Result { } impl CompositeFontEntry { - /// Chunk 0xCB03: name, u32 font family, font style, four f64, u16 1, - /// u16 range count, ranges (first, last, first), four u16. + /// Chunk 0xCB03: name, u32 font family, font style, four f64, u16 + /// locked, u16 range count, ranges (first, last, first), four u16. pub fn read(uid: u32, obj: &crate::Object) -> Result, Error> { let enc = obj.encoding; let Some(d) = obj.chunk(chunk::COMPOSITE_FONT_ENTRY) else { @@ -74,7 +76,7 @@ impl CompositeFontEntry { let font_family = c.u32()?; let font_style = c.name()?; let numbers = [c.f64()?, c.f64()?, c.f64()?, c.f64()?]; - c.u16()?; + let locked = c.u16()?; let n = c.u16()?; let mut ranges = Vec::new(); for _ in 0..n { @@ -90,6 +92,7 @@ impl CompositeFontEntry { font_family, font_style, numbers, + locked, ranges, scale, })) @@ -105,10 +108,12 @@ impl CompositeFontEntry { } impl CompositeFont { - /// Chunk 0xCB02: the name, fields not identified, then a u16 count and - /// the entry UIDs, which end the chunk. In files from InDesign 3.0 - /// four zero bytes come before the name (`big-endian.md`). Returns the - /// name and the entry UIDs. + /// Chunk 0xCB02: four flagged strings (the name first), a u32 and a + /// u16 not identified, then a u16 count and the entry UIDs, which end + /// the chunk. In files from InDesign 3.0 four zero bytes come before + /// the name (`big-endian.md`). A chunk of another layout gives the + /// first u16 count after the name whose UIDs end the chunk. Returns + /// the name and the entry UIDs. pub fn read(obj: &crate::Object) -> Result)>, Error> { let enc = obj.encoding; let Some(d) = obj.chunk(chunk::COMPOSITE_FONT) else { @@ -125,6 +130,23 @@ impl CompositeFont { Err(e) => return Err(e), }; let start = c.pos(); + let structured = (|| -> Result>, Error> { + for _ in 0..3 { + c.name()?; + } + c.u32()?; + c.u16()?; + let n = c.u16()? as usize; + if c.remaining() != 4 * n { + return Ok(None); + } + Ok(Some( + (0..n).map(|_| c.u32()).collect::, _>>()?, + )) + })(); + if let Ok(Some(entries)) = structured { + return Ok(Some((name, entries))); + } let Some(p) = (start..d.len().saturating_sub(1)).find(|&p| { let n = enc.u16_from([d[p], d[p + 1]]) as usize; n > 0 && p + 2 + 4 * n == d.len() @@ -352,6 +374,29 @@ mod tests { assert_eq!(entries, [0x60, 0x61]); } + #[test] + fn reads_composite_fonts_by_their_four_names() { + let enc = Encoding::default(); + let mut d = flagged_string(enc, 0, "Font A"); + d.extend(flagged_string(enc, 0, "")); + d.extend(flagged_string(enc, 0, "ATC-416e6f74686572basic")); + d.extend(flagged_string(enc, 0, "Font A")); + d.extend(enc.u32_bytes(0)); + d.extend(enc.u16_bytes(0)); + d.extend(enc.u16_bytes(2)); + d.extend(enc.u32_bytes(0x60)); + d.extend(enc.u32_bytes(0x61)); + let obj = object( + 0x5F, + class::COMPOSITE_FONT, + &[(chunk::COMPOSITE_FONT, d)], + enc, + ); + let (name, entries) = CompositeFont::read(&obj).unwrap().unwrap(); + assert_eq!(name.idml(), "Font A"); + assert_eq!(entries, [0x60, 0x61]); + } + #[test] fn reads_custom_mojikumi_settings() { for enc in [Encoding::default(), big_endian()] {