diff --git a/docs/format/attributes.md b/docs/format/attributes.md index b189452..370a798 100644 --- a/docs/format/attributes.md +++ b/docs/format/attributes.md @@ -87,9 +87,68 @@ the same tag all equal the style (17,501 text frames, 7,070 rectangles, 2,074 polygons, 297 ovals, 27 lines); the others are on shapes written as another element type. The converter leaves out these attributes, and the four corner radii and options, when they equal the style's value -(numbers to 6 significant digits). `StrokeWeight="1"` on an item with -`[None]` and no stroke weight of its own (`objects.md`, page item -settings) differs from `[None]`'s 0 and is still written. +(numbers to 6 significant digits). + +### Values an item does not store + +Every document has one object of class 0x6E02 (606 of 606 trustworthy +pairs). Its chunk 0x6E03 is a page item attribute list with every fill, +stroke and corner attribute. An item whose own list lacks an attribute +has the value of this base list, not that of its object style. IDML +writes that value where it differs from the object style's effective +value, the same rule as for stored values. + +The base lists differ in two ways across the trustworthy pairs, always +together: 481 documents have `StrokeWeight` 1 and corner radii 12, 125 +have 0.2835 (0.1 mm) and 14.1732 (5 mm). All have `StrokeColor` and +`FillColor` naming the swatch `None`, `FillTint` −1, `MiterLimit` 4, +`StrokeType` `Solid`, `StrokeAlignment` `CenterAlignment` and corner +options `None`. + +Evidence: an analysis script looked for the field that tells the +documents whose items have `StrokeWeight="0.2834645669291339"` apart +from those whose items have 1, by testing every f64 of every object +whose class occurs once per document; the `StrokeWeight` of this list +matched 294 of 295 documents. With the base values and the rule above, +the converter reproduces, over the rectangles, ovals, polygons, graphic +lines and text frames of the trustworthy pairs (anchored ones +included), 8,790 of 8,794 `StrokeColor` values, 54,694 of 54,694 +`StrokeWeight`, 42,500 of 42,504 `MiterLimit` and 6,383 of 6,387 +`CornerRadius`, with no extra value. The values not reproduced are on 4 +text frames without an object style, and on items whose stored value +the converter does not decode (77 `FillTint`, stored fills such as +pasted smooth shades, the stroke alignment `OutsideAlignment`, custom +stroke types). Over all pairs, 4 extra `StrokeWeight` values appear, +in 3 stale pairs. + +Groups are left out: their fill and stroke attributes in IDML were not +studied (1,844 groups of the trustworthy pairs have a `StrokeWeight` +that the converter does not write). IDML writes no corner attributes +for EPS text (class 0x660B; none in 634 elements), so only its other +attributes follow the rule. + +**Category turned off.** When the item's object style (other than the +root `[None]`) turns a category off, IDML writes the item's values of +that category even where they equal the style's, stored or from the +base list: + +| Category (ID in chunk 0x1B92E) | Attributes | +|---|---| +| `EnableFill` (0x1B933) | `FillColor`, `FillTint` | +| `EnableStroke` (0x1B934) | `StrokeColor` | +| `EnableStrokeAndCornerOptions` (0x1B935, 0x1B936) | `StrokeWeight`, `MiterLimit`, `StrokeAlignment`, corner radii and options | +| both stroke categories | `StrokeType` | + +Evidence over the trustworthy pairs: 66 items with styles that turn all +three off and 2 with styles that turn off both stroke categories have +every such attribute in IDML, with the stored or base value; 12 items +whose style turns off only `EnableStrokeAndCornerOptions` have +`StrokeWeight`, `MiterLimit`, `StrokeAlignment` and the corners, but +no `StrokeColor` or `StrokeType`. No sample turns off only +`EnableStroke`, so the category of `StrokeType` is not shown; the +converter writes it when both are off. The 68 items also have +`StrokeTint`, `EndCap`, `EndJoin`, `GapColor` and `GapTint`, and the 12 +items `EndCap` and `EndJoin`; their IDs are not identified. Transparency attributes (IDs 0x108xx and 0x1EBxx) are described in `transparency.md`. diff --git a/docs/format/objects.md b/docs/format/objects.md index 93f7454..e94b737 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -849,16 +849,12 @@ chunk 0x1424 the master item is 0; in 197 of them the list still holds IDs, and IDML writes the attribute empty. **Stroke weight without an attribute.** An item whose attribute list has -no stroke weight (attribute 0x6E65) and whose object style is `[None]` -has `StrokeWeight="1"` in IDML: in the trustworthy pairs, 31,252 of -31,252 polygons, 5,294 of 5,294 rectangles, 702 of 702 ovals, 214 of -214 graphic lines and 4,248 of 4,263 text frames (15 have 0.28). With -another object style the attribute is absent in IDML (the style supplies -it), apart from 160 text frames with `[Normal Text Frame]` and 10 lines -with styles of their own, which have 1. Groups vary (1,166 without the -attribute, 625 with 1 and 30 with other values, in 200 of the pairs) -and get none. The converter -writes 1 for items other than groups with the style `[None]`. +no stroke weight (attribute 0x6E65) takes it from the document's base +list (class 0x6E02, `attributes.md`, values an item does not store): +1 in most documents, 0.2835 in others. IDML writes it when it differs +from the object style's, so items with `[None]` (stroke weight 0) have +it. Groups vary (1,166 without the attribute, 625 with 1 and 30 with +other values, in 200 of the pairs) and get none. ## Object export options diff --git a/src/idml/spread.rs b/src/idml/spread.rs index 06dce01..23b0f73 100644 --- a/src/idml/spread.rs +++ b/src/idml/spread.rs @@ -58,6 +58,23 @@ const STYLE_COMPARED: &[&str] = &[ "BottomRightCornerOption", ]; +/// Whether an object style whose category list is `on` turns off the +/// category of a fill, stroke or corner attribute: `EnableFill` (0x1B933) +/// for the fill, `EnableStroke` (0x1B934) for the stroke colour, +/// `EnableStrokeAndCornerOptions` (0x1B935 and 0x1B936) for the other +/// stroke and corner attributes, both for `StrokeType` (attributes.md, +/// values an item does not store). +fn category_off(name: &str, on: &[u32]) -> bool { + let off = |id: u32| !on.contains(&id); + let corners = off(0x1B935) && off(0x1B936); + match name { + "FillColor" | "FillTint" => off(0x1B933), + "StrokeColor" => off(0x1B934), + "StrokeType" => off(0x1B934) && corners, + _ => corners, + } +} + /// The category of a `TextFramePreference` attribute: the ID that turns /// it on in an object style's category list (objects.md, text frame /// preferences). @@ -478,10 +495,28 @@ impl Writer<'_> { x.attr("ContentType", content); } let applied = item.object_style.and_then(|u| self.style_values(u)); + // A category that the item's object style (not the root) turns + // off: IDML writes the item's values of that category even where + // they equal the style's (attributes.md, values an item does not + // store). + let on = match (&applied, item.object_style) { + (Some(a), Some(u)) + if !self + .doc + .object_styles + .get(&u) + .is_some_and(Self::is_root_object_style) => + { + a.enabled.as_deref() + } + _ => None, + }; + let forced = |name: &str| on.is_some_and(|on| category_off(name, on)); for (name, v) in self.item_attr_values(&item.attrs) { // Fill, stroke and corner values equal to the object style's // are left out (attributes.md, page item attributes). let same = STYLE_COMPARED.contains(&name) + && !forced(name) && applied .as_ref() .and_then(|s| s.item(name)) @@ -490,17 +525,30 @@ impl Writer<'_> { x.attr(name, v); } } - let style = item - .object_style - .and_then(|u| self.doc.object_styles.get(&u)); - // An item without a stroke weight of its own and with the object - // style [None] has `StrokeWeight="1"` in IDML (objects.md, page - // item settings); groups vary. + // A fill, stroke or corner attribute that the item does not store + // has the value of the document's base list; IDML writes it where + // it differs from the object style's (attributes.md, values an + // item does not store). Groups vary. if tag != "Group" - && item.attrs.values.iter().all(|(id, _)| *id != 0x6E65) - && style.is_some_and(|os| os.builtin && os.name == "[None]") + && let Some(applied) = &applied + && let Some(base) = &self.doc.prefs.item_base { - x.attr("StrokeWeight", "1"); + let mut rest = base.clone(); + rest.values.retain(|(id, _)| item.attrs.get(*id).is_none()); + for (name, v) in self.item_attr_values(&rest) { + // IDML writes no corner attributes for EPS text. + if tag == "EPSText" && name.contains("Corner") { + continue; + } + if (STYLE_COMPARED.contains(&name) + || matches!(name, "StrokeType" | "StrokeAlignment")) + && applied + .item(name) + .is_some_and(|s| forced(name) || !applied::same_value(s, &v)) + { + x.attr(name, v); + } + } } if let Some(r) = item.object_style.and_then(|u| self.object_style_ref(u)) { x.attr("AppliedObjectStyle", r); diff --git a/src/model/ids.rs b/src/model/ids.rs index 0684dfc..8642758 100644 --- a/src/model/ids.rs +++ b/src/model/ids.rs @@ -76,6 +76,9 @@ pub mod class { pub const COLOR_PROFILE: u32 = 0x7D03; /// Page item defaults. pub const ITEM_DEFAULTS: u32 = 0x6E07; + /// The page item attribute list that items take the attributes + /// they do not store from (chunk 0x6E03). + pub const ITEM_BASE: u32 = 0x6E02; } /// Chunk IDs. diff --git a/src/model/prefs.rs b/src/model/prefs.rs index 7460665..e761f1c 100644 --- a/src/model/prefs.rs +++ b/src/model/prefs.rs @@ -31,6 +31,9 @@ pub struct Prefs { pub anchor: Option, /// Page item defaults (class 0x6E07), a page item attribute list. pub item_defaults: Option, + /// The values of page item attributes that an item does not store + /// (class 0x6E02, chunk 0x6E03; attributes.md). + pub item_base: Option, /// The entries of the two tables around that list: class, UID, UID /// (`objects.md`, page item defaults). pub item_default_entries: Vec<(u32, u32, u32)>, @@ -1267,6 +1270,24 @@ impl Reader<'_> { None => None, }; + // The attributes of items that do not store them (attributes.md, + // values an item does not store). + let item_base = match self + .db + .classes() + .iter() + .find(|(_, c)| *c == class::ITEM_BASE) + { + Some(&(u, _)) => match self.chunk(u, crate::model::ids::chunk::ITEM_ATTRS)? { + Some(d) => self.attrs_or_warn( + || format!("page item attribute base {u}"), + Attrs::parse(self.enc(), &d, List::Item, self.db.recorder()), + ), + None => None, + }, + None => None, + }; + // The swatches of chunk 0x6E06 of the page item defaults. let mut item_default_swatches = Vec::new(); if let Some(&(u, _)) = self @@ -1678,6 +1699,7 @@ impl Reader<'_> { .as_deref() .map(|d| super::AnchorSettings::read(self.enc(), d)), item_defaults, + item_base, item_default_entries, item_default_swatches, props,