mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-29 17:43:59 +01:00
feat: write clipping path settings of every type, their geometry, and those of placed pages
Chunk 0x2C1A gives the clipping type (None, DetectEdges, AlphaChannel, PhotoshopPath) and a flags byte (high-resolution image, invert and restrict to frame). Graphics of types 1 to 3 write their chunk 0x162B paths as ClippingPathGeometry; PhotoshopPath names come from key 0x7D of the image properties when ASCII, AlphaChannel names from chunk 0x177C. Placed pages get the element with the values of graphics without the chunk.
This commit is contained in:
1 parent
c16b1ac9d2
commit
3e8ea49d4a
6 files changed
+194
-82
No files matched your search
@@ -177,14 +177,14 @@ samples typeset in Japanese, every IDML had `n`.
|
||||
corpus IDML files:
|
||||
`ClippingType="None"`, `InvertPath="false"`, `IncludeInsideEdges="false"`,
|
||||
`RestrictToFrame="false"` and `AppliedPathName="$ID/"` (and for PDF and
|
||||
EPS also the values the converter reads for images). The converter writes
|
||||
the element only for clipping type 0 in chunk 0x2C1A, which IDML writes
|
||||
as `None` (`objects.md`), so `tools/element_values.py` collects only those
|
||||
elements (`WRITTEN_FOR`). The 8 images with another `ClippingType` (7
|
||||
with `AppliedPathName` set, 1 with `InvertPath` and `RestrictToFrame`
|
||||
`true`) are the only elements with other values in the corpus before
|
||||
2026-10; the 12,280 elements with `None` in the current corpus (8,993
|
||||
images, 2,213 PDF, 1,074 EPS) have the values above. Every `ImageIOPreference` has `AllowAutoEmbedding="true"`. The
|
||||
EPS also the values the converter reads for images).
|
||||
`tools/element_values.py` collects only the elements with `None`
|
||||
(`WRITTEN_FOR`); the 12,280 such elements in the current corpus (8,993
|
||||
images, 2,213 PDF, 1,074 EPS) have the values above. The converter
|
||||
writes every attribute of the element from chunk 0x2C1A and the rules
|
||||
in `objects.md` (clipping path settings), which give these values for
|
||||
clipping type 0, and does not use these rows.
|
||||
Every `ImageIOPreference` has `AllowAutoEmbedding="true"`. The
|
||||
converter writes the values read from the INDD first (`objects.md`,
|
||||
clipping path settings).
|
||||
|
||||
|
||||
+77
-19
@@ -1548,29 +1548,87 @@ Images, PDF and EPS graphics may have chunk 0x2C1A (37 bytes):
|
||||
|
||||
| Offset | Contents | IDML `ClippingPathSettings` |
|
||||
|---|---|---|
|
||||
| 0 | u32, 0 in every sample | `ClippingType="None"` |
|
||||
| 0 | u32: 0 `None`, 1 `DetectEdges`, 2 `AlphaChannel`, 3 `PhotoshopPath` | `ClippingType` |
|
||||
| 4 | f64 | `Tolerance` |
|
||||
| 12 | f64 | `InsetFrame` |
|
||||
| 20 | u8 | `Threshold` |
|
||||
| 23 | i16 | `Index` |
|
||||
| 25 | u8: 2 true, 0 false | `UseHighResolutionImage` |
|
||||
| 23 | i16 | `Index` (not for type 2, below) |
|
||||
| 25 | u8 flags: 0x02 `UseHighResolutionImage`; 0x01 and 0x08 `InvertPath` and `RestrictToFrame` | |
|
||||
| 26 | 11 bytes, 0 in every sample | |
|
||||
|
||||
Evidence: 75 of 235 images in the same-version pairs have the chunk, and
|
||||
all 75 match on these fields (tolerance 2 or 0, threshold 25 or 0). The
|
||||
byte at 25 changes together with the threshold and tolerance in the same
|
||||
5 images, so it is identified only as the field that is left. PDF (153
|
||||
of 206) and EPS (6 of 18) graphics have the chunk with the same values as
|
||||
images that use the defaults. Graphics without the chunk (160 images, 53
|
||||
PDF, 12 EPS) have `UseHighResolutionImage="true"`, `Threshold="25"`,
|
||||
`Tolerance="2"`, `InsetFrame="0"` and `Index="-1"` in IDML, and the
|
||||
converter writes those values for them. The converter leaves out the
|
||||
element for a type other than 0.
|
||||
all 75 match on the tolerance, inset, threshold and index (tolerance 2
|
||||
or 0, threshold 25 or 0). PDF (153 of 206) and EPS (6 of 18) graphics
|
||||
have the chunk with the same values as images that use the defaults.
|
||||
Graphics without the chunk (160 images, 53 PDF, 12 EPS) have
|
||||
`UseHighResolutionImage="true"`, `Threshold="25"`, `Tolerance="2"`,
|
||||
`InsetFrame="0"` and `Index="-1"` in IDML, and the converter writes
|
||||
those values for them.
|
||||
|
||||
`InvertPath="false"`, `IncludeInsideEdges="false"`,
|
||||
`RestrictToFrame="false"` and `AppliedPathName="$ID/"` have no
|
||||
identified field. All 496 images, 386 PDF and 49 EPS graphics with the
|
||||
element in the corpus IDML files have these values, and the converter
|
||||
writes them (`idml-values.md`).
|
||||
Over the trustworthy pairs of the corpus after 2026-10, every graphic
|
||||
with the chunk was compared with its IDML element (2,686 graphics):
|
||||
|
||||
| INDD | IDML | Graphics |
|
||||
|---|---|---|
|
||||
| Type 0 | `ClippingType="None"` | 2,655 of 2,655 |
|
||||
| Type 1 | `DetectEdges` | 2 of 2 (2 pairs) |
|
||||
| Type 2 | `AlphaChannel` | 1 of 1 |
|
||||
| Type 3 | `PhotoshopPath` | 28 of 28 (12 pairs) |
|
||||
| Flags 0x02 | `UseHighResolutionImage="true"`, `InvertPath="false"`, `RestrictToFrame="false"` | 2,680 of 2,680 |
|
||||
| Flags 0x00 | `UseHighResolutionImage="false"`, `InvertPath="false"`, `RestrictToFrame="false"` | 5 of 5 |
|
||||
| Flags 0x09 | `UseHighResolutionImage="false"`, `InvertPath="true"`, `RestrictToFrame="true"` | 1 of 1 (type 1, threshold 111, tolerance 3.9) |
|
||||
| i16 at 23, types 0, 1 and 3 | `Index` (-1, or 0 in 9 type 3 images) | all |
|
||||
|
||||
Bits 0x01 and 0x08 are set together in the one sample, so which is
|
||||
`InvertPath` and which `RestrictToFrame` is not shown. The converter
|
||||
writes both when the two bits are equal and leaves both out otherwise.
|
||||
Other type codes have no sample; the converter leaves out the element
|
||||
for them.
|
||||
|
||||
The one type 2 image stores -1 at 23, and its IDML has `Index="0"`. No
|
||||
other field of the chunk differs from the type 1 and 3 images, so the
|
||||
index of the alpha channel is not in this chunk; the converter leaves
|
||||
`Index` out for type 2.
|
||||
|
||||
`IncludeInsideEdges="false"` has no identified field: all 11,823
|
||||
`ClippingPathSettings` elements in the IDML files of the 1,462 corpus
|
||||
pairs have it, and the converter writes it.
|
||||
|
||||
**Path name.** `AppliedPathName` names the image's path or channel:
|
||||
|
||||
| Type | `AppliedPathName` | Graphics |
|
||||
|---|---|---|
|
||||
| 0 | `$ID/` | all 12,280 `None` elements of the corpus IDML files |
|
||||
| 1 | `$ID/` | 2 of 2 |
|
||||
| 2 | the first channel name of image chunk 0x177C (text wrap, contour) | 1 of 1 |
|
||||
| 3 | the name in key 0x7D of image chunk 0x1708 | 17 of 17 with an ASCII name |
|
||||
|
||||
Key 0x7D of the image properties (13 bytes in all samples) holds a u8
|
||||
length *n*, *n* bytes of name, then 6 bytes (`00 00 33 33 00 01` or
|
||||
`00 00 00 00 00 01`). The name bytes are not Unicode. The other 11 type
|
||||
3 images name their path in a legacy code page: in 5 (Korean documents)
|
||||
key 0x7D holds bytes that decode in code page 949 to the IDML name; the
|
||||
other 6 (Japanese documents) have no key 0x7D, and key 0x80 of the same
|
||||
chunk holds the name as bytes that decode in Shift-JIS. None of these
|
||||
INDD files has the name as UTF-16 or UTF-8 text, except two where it is
|
||||
part of a longer text in another record. The file does not record the
|
||||
code page, so the converter writes the name only when every byte is
|
||||
printable ASCII (0x20 to 0x7E) and leaves `AppliedPathName` out
|
||||
otherwise.
|
||||
|
||||
**Geometry.** IDML writes `Properties/ClippingPathGeometry` for every
|
||||
graphic of type 1, 2 or 3 (31 of 31 images, 13 pairs), and for no
|
||||
graphic of type 0. The paths are those of the graphic's own chunk
|
||||
0x162B, in the layout of page item paths: the converter's output equals
|
||||
the IDML element exactly, number for number, in all 31 (1 to 8 paths of
|
||||
4 to 179 points). The 2,655 graphics of type 0 with chunk 0x162B (1,797
|
||||
images, 329 PDF, 528 EPS, 1 WMF graphic) have no `ClippingPathGeometry`.
|
||||
IDML puts it before `GraphicBounds`.
|
||||
|
||||
**Placed pages.** IDML has `ClippingPathSettings` on every
|
||||
`ImportedPage` (42 in 8 pairs, 38 in 7 trustworthy pairs). No placed
|
||||
page has chunk 0x2C1A, and all 42 have the values of graphics without
|
||||
the chunk; the converter writes those values for them.
|
||||
|
||||
**ImageIOPreference.** Chunk 0x1714 of an image:
|
||||
|
||||
@@ -2050,8 +2108,8 @@ Format Name`), `Properties/GraphicBounds`, `TextWrapPreference` and
|
||||
`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`.
|
||||
that chunk 0x12629 names), `GraphicLayerOption` and `PDFAttribute`.
|
||||
`ClippingPathSettings` is described under clipping path settings.
|
||||
|
||||
Evidence: 42 `ImportedPage` elements in 8 pairs (38 in 7 trustworthy
|
||||
pairs). `ItemTransform`, `GraphicBounds` and `PageNumber` equal the
|
||||
|
||||
@@ -83,6 +83,9 @@ Status values:
|
||||
| `MinimumFirstBaselineOffset` | text frame settings | – | open: never varies | 0 on every frame and style; written by the category rule | `objects.md`, text frame preferences |
|
||||
| Flex padding order | chunk 0x1E244 | – | open: never varies | the four paddings are equal in every style, and so are the two gaps | `objects.md`, object style settings |
|
||||
| `BeforeGroupingLayerReference` | page items (21.4 on) | 12 | open: not examined | 50 values | `objects.md`, page item settings |
|
||||
| Path names in a legacy code page | keys 0x7D and 0x80 of image chunk 0x1708 | 10 pairs | open: not decoded | 11 `PhotoshopPath` images whose path name is stored as code page 949 or Shift-JIS bytes; the file does not record the code page, and `AppliedPathName` is left out | `objects.md`, clipping path settings |
|
||||
| `Index` of an `AlphaChannel` clipping | chunk 0x2C1A | 1 pair | open: no field found | the image stores -1 at 23 and IDML has 0; left out | `objects.md`, clipping path settings |
|
||||
| `InvertPath` and `RestrictToFrame` bits | chunk 0x2C1A, byte 25 | 1 pair | open: never varies | bits 0x01 and 0x08 are set together in the one sample; written only when both are equal | `objects.md`, clipping path settings |
|
||||
| Unlinked images without chunk 0x8C23 | placed graphics | 25 pairs | open: no field found | IDML has `Contents` (362 values); the bytes were not located | `objects.md`, graphics pasted without a link |
|
||||
| EPS `Contents` that differ | placed graphics | – | open: not examined | 18 of 515 | `objects.md`, graphics pasted without a link |
|
||||
| Anchored settings of some nested items | `AnchoredObjectSetting` | 3 | open: not examined | 388 values | `objects.md`, items inside an anchored item |
|
||||
|
||||
+60
-38
@@ -5,7 +5,7 @@
|
||||
//! path settings, graphic layers) and `idml-values.md`.
|
||||
|
||||
use super::*;
|
||||
use crate::model::{GraphicLayer, Name};
|
||||
use crate::model::{ClippingPath, GraphicLayer, Name};
|
||||
|
||||
/// `Space` of an image by its colour space code (and whether it has a
|
||||
/// colour table).
|
||||
@@ -65,42 +65,62 @@ fn scales(m: &Matrix) -> (f64, f64) {
|
||||
}
|
||||
|
||||
impl Writer<'_> {
|
||||
/// `ClippingPathSettings` of an image, PDF or EPS graphic, and
|
||||
/// `ImageIOPreference` of an image. Values without an INDD field are
|
||||
/// those every exported IDML has, and a graphic without chunk 0x2C1A
|
||||
/// has the values every such graphic has in IDML. See
|
||||
/// `docs/format/objects.md`.
|
||||
pub(super) fn clipping(&self, x: &mut Xml, g: &Graphic, tag: &str) {
|
||||
let (high_resolution, threshold, tolerance, inset, index) = match &g.clipping {
|
||||
Some(c) if c.kind == 0 => (
|
||||
match c.high_resolution {
|
||||
2 => Some("true"),
|
||||
0 => Some("false"),
|
||||
_ => None,
|
||||
},
|
||||
c.threshold.to_string(),
|
||||
num(c.tolerance),
|
||||
num(c.inset),
|
||||
c.index.to_string(),
|
||||
),
|
||||
Some(_) => return,
|
||||
None => (
|
||||
Some("true"),
|
||||
"25".into(),
|
||||
"2".into(),
|
||||
"0".into(),
|
||||
"-1".into(),
|
||||
),
|
||||
/// `ClippingPathSettings` of an image, PDF, EPS or placed page, from
|
||||
/// chunk 0x2C1A; a graphic without the chunk has the values every such
|
||||
/// graphic has in IDML. A value that the stored fields do not settle is
|
||||
/// left out. See `docs/format/objects.md`, clipping path settings.
|
||||
pub(super) fn clipping(x: &mut Xml, g: &Graphic) {
|
||||
let default = ClippingPath {
|
||||
kind: 0,
|
||||
tolerance: 2.0,
|
||||
inset: 0.0,
|
||||
threshold: 25,
|
||||
index: -1,
|
||||
flags: 2,
|
||||
};
|
||||
x.start("ClippingPathSettings");
|
||||
if let Some(h) = high_resolution {
|
||||
x.attr("UseHighResolutionImage", h);
|
||||
let c = g.clipping.as_ref().unwrap_or(&default);
|
||||
let kind = match c.kind {
|
||||
0 => "None",
|
||||
1 => "DetectEdges",
|
||||
2 => "AlphaChannel",
|
||||
3 => "PhotoshopPath",
|
||||
_ => return,
|
||||
};
|
||||
let path_name = match c.kind {
|
||||
0 | 1 => Some("$ID/"),
|
||||
2 => g.alpha_channel.as_deref(),
|
||||
_ => g
|
||||
.image
|
||||
.as_ref()
|
||||
.and_then(|i| i.clipping_path_name.as_deref()),
|
||||
};
|
||||
// Bits 0x01 and 0x08 are invert and restrict to frame, in an order
|
||||
// not shown: only both set or both clear are read.
|
||||
let invert_restrict = match c.flags & 0x09 {
|
||||
0 => Some("false"),
|
||||
0x09 => Some("true"),
|
||||
_ => None,
|
||||
};
|
||||
x.start("ClippingPathSettings")
|
||||
.attr("UseHighResolutionImage", (c.flags & 0x02 != 0).to_string())
|
||||
.attr("Threshold", c.threshold.to_string())
|
||||
.attr("Tolerance", num(c.tolerance))
|
||||
.attr("InsetFrame", num(c.inset));
|
||||
// The i16 is not the index of an alpha channel (objects.md).
|
||||
if c.kind != 2 {
|
||||
x.attr("Index", c.index.to_string());
|
||||
}
|
||||
x.attr("ClippingType", kind);
|
||||
if let Some(v) = invert_restrict {
|
||||
x.attr("InvertPath", v);
|
||||
}
|
||||
x.attr("IncludeInsideEdges", "false");
|
||||
if let Some(v) = invert_restrict {
|
||||
x.attr("RestrictToFrame", v);
|
||||
}
|
||||
if let Some(name) = path_name {
|
||||
x.attr("AppliedPathName", name);
|
||||
}
|
||||
x.attr("Threshold", threshold)
|
||||
.attr("Tolerance", tolerance)
|
||||
.attr("InsetFrame", inset)
|
||||
.attr("Index", index);
|
||||
x.attrs_missing(self.observed(&format!("{tag}/ClippingPathSettings")).iter());
|
||||
x.end();
|
||||
}
|
||||
|
||||
@@ -329,6 +349,9 @@ impl Writer<'_> {
|
||||
.cdata(&base64_lines(data), CDATA_SECTION)
|
||||
.end();
|
||||
}
|
||||
if !g.clipping_paths.is_empty() {
|
||||
Self::geometry_paths(x, "ClippingPathGeometry", &g.clipping_paths);
|
||||
}
|
||||
x.empty(
|
||||
"GraphicBounds",
|
||||
&[
|
||||
@@ -339,9 +362,8 @@ impl Writer<'_> {
|
||||
],
|
||||
);
|
||||
x.end();
|
||||
// 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::Svg {
|
||||
Self::clipping(x, g);
|
||||
}
|
||||
if g.kind == GraphicKind::Image {
|
||||
Self::image_io(x, g);
|
||||
|
||||
+6
-1
@@ -304,7 +304,12 @@ impl Writer<'_> {
|
||||
|
||||
/// The `PathGeometry` element of `paths`, without `Properties`.
|
||||
pub(super) fn path_geometry_element(x: &mut Xml, paths: &[Path]) {
|
||||
x.start("PathGeometry");
|
||||
Self::geometry_paths(x, "PathGeometry", paths);
|
||||
}
|
||||
|
||||
/// Element `tag` with one `GeometryPathType` per path.
|
||||
pub(super) fn geometry_paths(x: &mut Xml, tag: &str, paths: &[Path]) {
|
||||
x.start(tag);
|
||||
for p in paths {
|
||||
x.start("GeometryPathType")
|
||||
.attr("PathOpen", p.open.to_string());
|
||||
|
||||
+40
-16
@@ -390,6 +390,9 @@ pub struct Graphic {
|
||||
pub contour: Option<Contour>,
|
||||
/// Clipping path settings (chunk 0x2C1A), if stored.
|
||||
pub clipping: Option<ClippingPath>,
|
||||
/// The clipping path (the graphic's chunk 0x162B), read only for a
|
||||
/// clipping type other than 0.
|
||||
pub clipping_paths: Vec<Path>,
|
||||
/// Name, visibility, change counts and the other page item settings.
|
||||
pub props: ItemProps,
|
||||
/// Chunk 0x1B916.
|
||||
@@ -443,6 +446,9 @@ pub struct ImageProperties {
|
||||
pub indexed: bool,
|
||||
/// Keys 0x6C and 0x6D, 16.16 fixed point.
|
||||
pub resolution: Option<[f64; 2]>,
|
||||
/// Key 0x7D: the name of the image's clipping path, when its bytes are
|
||||
/// printable ASCII (the encoding of other bytes is not known).
|
||||
pub clipping_path_name: Option<String>,
|
||||
}
|
||||
|
||||
/// Layers of a placed graphic (chunk 0x177A).
|
||||
@@ -468,7 +474,8 @@ pub struct GraphicLayer {
|
||||
|
||||
/// Clipping path settings of a graphic (chunk 0x2C1A, 37 bytes): u32 type
|
||||
/// at 0, f64 tolerance at 4, f64 inset at 12, u8 threshold at 20, i16
|
||||
/// index at 23, u8 at 25 (2 = use the high-resolution image). See
|
||||
/// index at 23, u8 flags at 25 (0x02 = use the high-resolution image,
|
||||
/// 0x01 and 0x08 = invert the path and restrict it to the frame). See
|
||||
/// `docs/format/objects.md`.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ClippingPath {
|
||||
@@ -477,7 +484,7 @@ pub struct ClippingPath {
|
||||
pub inset: f64,
|
||||
pub threshold: u8,
|
||||
pub index: i16,
|
||||
pub high_resolution: u8,
|
||||
pub flags: u8,
|
||||
}
|
||||
|
||||
/// Text frame settings, from the frame's multi-column frame object.
|
||||
@@ -1358,6 +1365,27 @@ impl<'a> Reader<'a> {
|
||||
(None, data)
|
||||
}
|
||||
};
|
||||
let clipping = match self.chunk(uid, chunk::CLIPPING_PATH)? {
|
||||
Some(d) if d.len() >= 26 => {
|
||||
let f = |o: usize| self.cursor(&d[o..]).f64();
|
||||
Some(ClippingPath {
|
||||
kind: self.cursor(&d).u32()?,
|
||||
tolerance: f(4)?,
|
||||
inset: f(12)?,
|
||||
threshold: d[20],
|
||||
index: self.enc().i16_from([d[23], d[24]]),
|
||||
flags: d[25],
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let clipping_paths = match &clipping {
|
||||
Some(c) if c.kind != 0 => self.paths(uid).unwrap_or_else(|e| {
|
||||
self.warn(format!("graphic {uid}: clipping path not read ({e})"));
|
||||
Vec::new()
|
||||
}),
|
||||
_ => Vec::new(),
|
||||
};
|
||||
Ok(Some(Graphic {
|
||||
uid,
|
||||
kind,
|
||||
@@ -1370,20 +1398,8 @@ impl<'a> Reader<'a> {
|
||||
Some(d) => Contour::read(self.enc(), &d),
|
||||
None => None,
|
||||
},
|
||||
clipping: match self.chunk(uid, chunk::CLIPPING_PATH)? {
|
||||
Some(d) if d.len() >= 26 => {
|
||||
let f = |o: usize| self.cursor(&d[o..]).f64();
|
||||
Some(ClippingPath {
|
||||
kind: self.cursor(&d).u32()?,
|
||||
tolerance: f(4)?,
|
||||
inset: f(12)?,
|
||||
threshold: d[20],
|
||||
index: self.enc().i16_from([d[23], d[24]]),
|
||||
high_resolution: d[25],
|
||||
})
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
clipping,
|
||||
clipping_paths,
|
||||
props: self.item_props(uid).unwrap_or_else(|e| {
|
||||
self.warn(format!("graphic {uid}: settings left out: {e}"));
|
||||
ItemProps::default()
|
||||
@@ -1474,6 +1490,14 @@ impl<'a> Reader<'a> {
|
||||
0x6C => resolution[0] = value().map(|v| f64::from(v) / 65536.0),
|
||||
0x6D => resolution[1] = value().map(|v| f64::from(v) / 65536.0),
|
||||
0x6F => p.indexed = true,
|
||||
// u8 length n, n bytes of name, then 6 bytes.
|
||||
0x7D => {
|
||||
p.clipping_path_name = data
|
||||
.split_first()
|
||||
.and_then(|(&n, rest)| rest.get(..usize::from(n)))
|
||||
.filter(|b| !b.is_empty() && b.iter().all(|c| (0x20..0x7F).contains(c)))
|
||||
.map(|b| b.iter().map(|&c| char::from(c)).collect());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user