mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-22 18:20:45 +01:00
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
This commit is contained in:
1 parent
1842f3568d
commit
dccfc4a5ce
4 files changed
+45
-2
No files matched your search
@@ -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
|
||||
|
||||
+10
-2
@@ -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 {
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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<u32>,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user