From dccfc4a5ced6e47b9f6074e7d585293eb72d4c9c Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Thu, 8 Oct 2026 14:24:50 +0000 Subject: [PATCH] feat: convert placed InDesign pages Read class 0x6607 (a page of another InDesign document placed in a frame) as a placed graphic and write it as ImportedPage: PageNumber (chunk 0x2505 u32 + 1), the attributes of placed graphics, GraphicBounds, the text wrap and the link. ImportedPageCrop, the XMP packet and the PDF-style children are not decoded and left out. compare.py --exclude own/: - trustworthy 97.91% -> 97.92% (+1,475 values; ImportedPage 38 of 38 with transform, bounds and page number, and their links) - all pairs 96.02% -> 96.03%; 9 more links resolved to another file at export (45 values leave the counts) - extra values unchanged - compare.py --all with schemas: 0 conversion and 0 schema failures on pairs; outputs without a reference: the same 11 endnote-markup files --- docs/format/objects.md | 22 ++++++++++++++++++++++ src/idml/graphic.rs | 12 ++++++++++-- src/model/ids.rs | 4 ++++ src/model/item.rs | 9 +++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/docs/format/objects.md b/docs/format/objects.md index fe61a0c..34a0475 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -1297,6 +1297,28 @@ and the text wrap equal the IDML in 634 of 634. `StrokeType` (634), IDML writes `StrokeType="StrokeStyle/$ID/Solid"` on 627 items whose attribute list has no stroke type. +## Placed InDesign pages (class 0x6607) + +A placed page of another InDesign document is a child of a frame, like +an image, and has the chunks of placed graphics (transform 0x151, +bounds 0x1633, link 0x8CBC, text wrap). IDML writes it as +`ImportedPage`. Chunk 0x2505 (68 bytes) holds the page: its u32 at 0 +plus 1 is `PageNumber`. + +The converter writes `ImportedPage` with `PageNumber`, the attributes +of placed graphics (`ImageTypeName` from the link format, `$ID/InDesign +Format Name`), `Properties/GraphicBounds`, `TextWrapPreference` and +`Link`. Not decoded, and left out: `ImportedPageCrop` (41 of 42 are +`CropContent`, 1 `CropBleed`; the byte at 18 of 0x2505 is 0 in 28 and +1 in 13 `CropContent` items, so it is not that field), +`MetadataPacketPreference` (an XMP packet of an object of class 0x12609 +that chunk 0x12629 names), `ClippingPathSettings`, `GraphicLayerOption` +and `PDFAttribute`. + +Evidence: 42 `ImportedPage` elements in 8 pairs (38 in 7 trustworthy +pairs). `ItemTransform`, `GraphicBounds` and `PageNumber` equal the +IDML in 42 of 42. + ## Graphics pasted without a link A graphic with no link (its chunk 0x8CBC names no link) can hold its file diff --git a/src/idml/graphic.rs b/src/idml/graphic.rs index 4b2f167..2a37386 100644 --- a/src/idml/graphic.rs +++ b/src/idml/graphic.rs @@ -215,9 +215,15 @@ impl Writer<'_> { GraphicKind::Pdf => "PDF", GraphicKind::Eps => "EPS", GraphicKind::Svg => "SVG", + GraphicKind::ImportedPage => "ImportedPage", }; let [left, top, right, bottom] = g.bounds; x.start(tag).attr("Self", uref(Some(g.uid))); + // The page number is the stored index + 1 (objects.md, placed + // InDesign pages). + if let Some(i) = g.page_index.and_then(|i| i.checked_add(1)) { + x.attr("PageNumber", i.to_string()); + } match g.kind { GraphicKind::Image => { if g.link.is_some() @@ -254,6 +260,7 @@ impl Writer<'_> { GraphicKind::Svg => { x.attr("UseSVGAs", "EmbedCode"); } + GraphicKind::ImportedPage => {} } x.attr("LocalDisplaySetting", "Default"); if let Some(f) = g.link.as_ref().and_then(|l| l.format.as_ref()) { @@ -281,7 +288,7 @@ impl Writer<'_> { } } } - if major >= 21 && g.kind != GraphicKind::Eps { + if major >= 21 && !matches!(g.kind, GraphicKind::Eps | GraphicKind::ImportedPage) { x.attr("FlexItemWidthMode", "FlexFixed") .attr("FlexItemHeightMode", "FlexFixed"); } @@ -309,7 +316,8 @@ impl Writer<'_> { ], ); x.end(); - if g.kind != GraphicKind::Svg { + // The clipping settings of a placed page are not decoded. + if !matches!(g.kind, GraphicKind::Svg | GraphicKind::ImportedPage) { self.clipping(x, g, tag); } if g.kind == GraphicKind::Image { diff --git a/src/model/ids.rs b/src/model/ids.rs index bcb0e31..57608db 100644 --- a/src/model/ids.rs +++ b/src/model/ids.rs @@ -27,6 +27,8 @@ pub mod class { pub const EPS_TEXT: u32 = 0x660B; /// Text on the path of a shape or frame (IDML `TextPath`). pub const TEXT_PATH: u32 = 0xB320; + /// A placed InDesign page (IDML `ImportedPage`). + pub const IMPORTED_PAGE: u32 = 0x6607; /// The column of a text path's multi-column frame. pub const TEXT_PATH_COLUMN: u32 = 0xB318; /// A plain byte stream, such as the file of an embedded graphic. @@ -254,6 +256,8 @@ pub mod chunk { pub const VECTOR_POLICIES: u32 = 0x7C42; /// PDF placement: page number, transparent background, crop. pub const PDF_PLACEMENT: u32 = 0x251B; + /// Placed InDesign page: u32 page index at 0, other fields. + pub const IMPORTED_PAGE_INFO: u32 = 0x2505; /// Layers of an image, PDF or imported page. pub const GRAPHIC_LAYERS: u32 = 0x177A; /// Applied layer comp of an image (i32 at 4). diff --git a/src/model/item.rs b/src/model/item.rs index 0a593b3..c987002 100644 --- a/src/model/item.rs +++ b/src/model/item.rs @@ -205,6 +205,8 @@ pub enum GraphicKind { Pdf, Eps, Svg, + /// A placed InDesign page (class 0x6607). + ImportedPage, } /// A link (class 0x8C42) and its link resource (class 0x8C41). See @@ -275,6 +277,8 @@ pub struct Graphic { /// Image import options (chunk 0x1714): apply the Photoshop clipping /// path, alpha channel name. pub import: Option<(bool, Name)>, + /// The index of a placed InDesign page (chunk 0x2505, u32 at 0). + pub page_index: Option, } /// Image properties (chunk 0x1708): u32 count, then records of u32 key, @@ -917,6 +921,7 @@ impl<'a> Reader<'a> { Some(class::PDF) => GraphicKind::Pdf, Some(class::EPS) => GraphicKind::Eps, Some(class::SVG) => GraphicKind::Svg, + Some(class::IMPORTED_PAGE) => GraphicKind::ImportedPage, _ => return Ok(None), }; let transform = match self.chunk(uid, chunk::ITEM_TRANSFORM)? { @@ -1039,6 +1044,10 @@ impl<'a> Reader<'a> { } _ => None, }, + page_index: match self.chunk(uid, chunk::IMPORTED_PAGE_INFO)? { + Some(d) if kind == GraphicKind::ImportedPage => self.enc().u32_at(&d, 0), + _ => None, + }, })) }