feat: write the constant shade every document lists

The pasted smooth shade object of lowest UID with a constant shading
becomes a PastedSmoothShade whose contents are its numbers in big-endian
order, with the values every constant shade has in IDML.

Value coverage on trustworthy pairs: 87.08 % to 87.13 %.
This commit is contained in:
aiongg committed 2026-10-07 14:19:32 +00:00
1 parent 44f2d9c1a7
commit deebe0e8a7
6 files changed
+122 -1

No files matched your search

+7
View File
@@ -269,6 +269,13 @@ same value, in at least 3 files (a `Keyed` block of the values file):
63 languages. Romanian and Japanese have two variants each and are left
out.
Pasted smooth shades are keyed the same way by `ContentsType`: every
`ConstantShade` (and every `AxialShade`) has `ContentsVersion="0"`,
`SpotColorList=""`, `ContentsEncoding="Ascii64Encoding"`,
`ColorEditable` and `ColorRemovable` `true`, `Visible="false"` and
`SwatchCreatorID="7937"`; constant shades also
`ContentsMatrix="1 0 0 1 0 0"`.
### Paragraph and character styles
The styles other than the root styles (5,505 paragraph and 2,284
+18
View File
@@ -225,6 +225,24 @@ true in every layer; the two fields that are 1 in every sample may hold
them. The converter reads the fields only when the name starts at offset
19 (in all little-endian corpus pairs, 1,465 layers).
## Pasted smooth shades (0x5533)
Objects of class 0x5533 hold shadings. Chunk 0x5531: a flag byte (1 =
built-in key) and the name, then a u32. Chunk 0x5532 holds the shading;
a constant shade has 92 bytes, with u32 28 (the length of what follows)
at offset 60, then a u32 and three f64. IDML writes it as a
`PastedSmoothShade` with `ContentsType="ConstantShade"` and `Contents`
the base64 of the same u32 and three f64 in big-endian order
(`AAAAAUBv4AAA…` for 1 and 255, 0, 0).
Every trustworthy pair has one constant shade in IDML, and it is the
class 0x5533 object of lowest UID with a constant shade (495 of 495);
in 84 pairs the INDD has two more that IDML leaves out. The converter
writes that one shade, and matches the IDML on all values in 495 of
495 (name `$ID/` from flag 1 and an empty name; two contents values,
255 and 1). The other shades in IDML are `AxialShade`s whose contents
re-encode a longer structure in the same way; they are not decoded.
## Index sort options
Chunk 0x1307E of the preferences object (class 0x2202) holds the index
+4
View File
@@ -308,4 +308,8 @@ tools/element_values.py; evidence in docs/format/idml-values.md.
<Language Name="$ID/ta_IN" SingleQuotes="''" DoubleQuotes='""' />
<Language Name="$ID/te_IN" SingleQuotes="''" DoubleQuotes='""' />
</Keyed>
<Keyed Tag="PastedSmoothShade" Key="ContentsType">
<PastedSmoothShade ContentsType="AxialShade" ContentsVersion="0" SpotColorList="" ContentsEncoding="Ascii64Encoding" Name="$ID/" ColorEditable="true" ColorRemovable="true" Visible="false" SwatchCreatorID="7937" />
<PastedSmoothShade ContentsType="ConstantShade" ContentsVersion="0" SpotColorList="" ContentsEncoding="Ascii64Encoding" ContentsMatrix="1 0 0 1 0 0" ColorEditable="true" ColorRemovable="true" Visible="false" SwatchCreatorID="7937" />
</Keyed>
</ElementValues>
+31
View File
@@ -1882,6 +1882,37 @@ impl Writer<'_> {
]);
x.empty("Ink", &attrs);
}
// The document's constant shade, with the values every IDML has
// on one (idml-values.md); its contents are the stored numbers in
// big-endian order (objects.md, pasted smooth shades).
if let Some(shade) = &self.doc.constant_shade
&& let Some(node) = values::keyed("PastedSmoothShade", "ConstantShade")
{
let reference = format!("PastedSmoothShade/{}", uref(Some(shade.uid)));
let mut data = shade.count.to_be_bytes().to_vec();
for v in shade.values {
data.extend(v.to_be_bytes());
}
x.start("PastedSmoothShade")
.attr("Self", &reference)
.attr("ContentsType", "ConstantShade");
if let Some((builtin, name)) = &shade.name {
let name = if *builtin {
format!("$ID/{name}")
} else {
name.clone()
};
x.attr("Name", name);
}
x.attrs_missing(node.attrs.iter());
group_ref(&mut x, &reference);
x.start("Properties")
.start("Contents")
.cdata(&base64_lines(&data), CDATA_SECTION)
.end()
.end();
x.end();
}
for (t, reference, name) in &self.doc.tints {
let base = self.doc.swatches.get(&t.base).cloned().unwrap_or_default();
x.start("Tint")
+56
View File
@@ -53,6 +53,7 @@ pub mod class {
pub const TOC_STYLE: u32 = 0x11605;
pub const NAMED_GRID: u32 = 0xCD12;
pub const ASSIGNMENT: u32 = 0x1BE01;
pub const SMOOTH_SHADE: u32 = 0x5533;
/// Holds an item anchored in text.
pub const ANCHOR: u32 = 0x262;
pub const TEXT_VARIABLE_INSTANCE: u32 = 0xCA64;
@@ -163,6 +164,9 @@ pub mod chunk {
pub const ROOT_GROUP_KIND: u32 = 0x28C2;
pub const SECTION_INFO: u32 = 0x4C02;
pub const DOCUMENT_PREFERENCES: u32 = 0x533;
/// Shading of a pasted smooth shade.
pub const SMOOTH_SHADE: u32 = 0x5532;
pub const SMOOTH_SHADE_NAME: u32 = 0x5531;
/// Index sort groups, in the preferences object.
pub const INDEX_GROUPS: u32 = 0x1307E;
pub const XML_TAG_NAME: u32 = 0xBF2F;
@@ -597,6 +601,17 @@ pub struct Story {
pub toc_style: Option<u32>,
}
/// A pasted smooth shade with a constant shading. See
/// `docs/format/objects.md`, pasted smooth shades.
#[derive(Debug, Clone, PartialEq)]
pub struct ConstantShade {
pub uid: u32,
pub count: u32,
pub values: [f64; 3],
/// Flag (built-in key) and name.
pub name: Option<(bool, String)>,
}
/// A table of contents style (class 0x11605), from chunk 0x11605: a flag
/// byte and the name, three u32 (the third the title style), a flag byte
/// and the title. See `docs/format/objects.md`.
@@ -667,6 +682,11 @@ pub struct Document {
/// Index sort groups (preferences chunk 0x1307E), in order: name,
/// include flag and header variant.
pub index_groups: Vec<(String, bool, u16)>,
/// The constant shade the document lists (the class 0x5533 object of
/// lowest UID with a constant shade in chunk 0x5532): its UID and its
/// u32 and three f64; and its name (chunk 0x5531: a flag byte, 1 for
/// a built-in key, and the name).
pub constant_shade: Option<ConstantShade>,
/// Assignment objects (class 0x1BE01), in UID order.
pub assignments: Vec<u32>,
/// Named grids (class 0xCD12, chunk 0xCD28: u32, a flag byte, 1 for
@@ -1376,6 +1396,7 @@ impl<'a> Reader<'a> {
toc_styles: self.toc_styles(),
named_grids: self.named_grids(),
index_groups: self.index_groups(),
constant_shade: self.constant_shade(),
assignments: {
let mut a: Vec<u32> = self
.db
@@ -2773,6 +2794,41 @@ impl<'a> Reader<'a> {
}
}
/// The first pasted smooth shade (class 0x5533) whose chunk 0x5532
/// holds a constant shade: 92 bytes, with u32 28 at offset 60 and then
/// a u32 and three f64. See `docs/format/objects.md`.
fn constant_shade(&self) -> Option<ConstantShade> {
let mut uids: Vec<u32> = self
.db
.classes()
.iter()
.filter(|&&(_, c)| c == class::SMOOTH_SHADE)
.map(|&(u, _)| u)
.collect();
uids.sort_unstable();
uids.into_iter().find_map(|uid| {
let d = self.chunk(uid, chunk::SMOOTH_SHADE).ok()??;
if d.len() != 92 || u32_at(&d, 60) != Some(28) {
return None;
}
let name = self
.chunk(uid, chunk::SMOOTH_SHADE_NAME)
.ok()
.flatten()
.and_then(|n| {
let mut c = Cursor::new(&n);
let builtin = c.flag().ok()? == 1;
Some((builtin, c.string().ok()?))
});
Some(ConstantShade {
uid,
count: u32_at(&d, 64)?,
values: [f64_at(&d, 68)?, f64_at(&d, 76)?, f64_at(&d, 84)?],
name,
})
})
}
/// The named grids, in UID order.
fn named_grids(&self) -> Vec<(bool, String)> {
let mut out = Vec::new();
+6 -1
View File
@@ -82,7 +82,12 @@ LISTS = ["TrapPreset"]
# (key attribute, attributes). For each key value, an attribute is kept
# when every such element in every IDML has the same value, in at least
# MIN_KEYED_FILES files.
KEYED = {"Language": ("Name", ["SingleQuotes", "DoubleQuotes"])}
KEYED = {
"Language": ("Name", ["SingleQuotes", "DoubleQuotes"]),
"PastedSmoothShade": ("ContentsType", [
"ContentsVersion", "SpotColorList", "ContentsEncoding", "ContentsMatrix",
"Name", "ColorEditable", "ColorRemovable", "Visible", "SwatchCreatorID"]),
}
MIN_KEYED_FILES = 3
# Attributes that only some elements have, which the converter writes
# where it decides to (for example from DOM 15 on, or when a chunk is