diff --git a/docs/format/objects.md b/docs/format/objects.md index 2eaecf4..061110d 100644 --- a/docs/format/objects.md +++ b/docs/format/objects.md @@ -510,6 +510,28 @@ item. IDML writes the page item element in place of the U+FFFC. A text variable instance (class 0xCA64) is owned by a U+0018 at its position; see `text-variables.md`. +**Anchored object settings (chunk 0x2800).** The anchor object (class +0x262) and object styles have a 62-byte chunk 0x2800: + +| Offset | Contents | IDML `AnchoredObjectSetting` | +|---|---|---| +| 0 | f64 | `AnchorYoffset` | +| 32 | f64, the negative of the value at 0 in every sample | | +| 52 | u16: 0 `TopAlign`, 1 `CenterAlign`, 2 `BottomAlign` | `VerticalAlignment` | + +Evidence: 42 anchored items in the pairs (including those whose IDML is +from an older version), compared with their IDML values or, where the +item has none, its object style's. `AnchorYoffset`: 42 of 42, 11 of +them non-zero in 2 files (−3.54 and −111.46). `VerticalAlignment`: 42 of +42; 4 items in 2 files have 0 and `TopAlign`, the others 2 and +`BottomAlign`. In the 337 object styles, 312 have 2 and `BottomAlign`, +25 have 1 and `CenterAlign`, and all have 0 at offset 0 and +`AnchorYoffset="0"`. IDML writes an item's `AnchoredObjectSetting` with +the values that differ from its object style (14 of the 42 items); the +converter does the same. The other fields of the chunk are not +identified: `PinPosition` and `AnchorPoint` change together with three +other u16 fields in the object styles. + INDD stores a forced line break as U+000A; IDML writes it as U+2028. The last paragraph return of a story is not written to IDML. @@ -621,9 +643,11 @@ or both absent in every style, so either ID gives the value: 0x1B933 and when the two IDs agree. Other `Enable…` attributes vary together with several IDs and are not written. -**Not written.** `AnchoredObjectSetting` `PinPosition`, `AnchorPoint` and -`VerticalAlignment` change together (312 against 25 styles) with four -u16 fields of chunk 0x2800, so the fields cannot be told apart. +**Anchored object settings** are in chunk 0x2800, as for anchors (see +stories). **Not written:** `AnchoredObjectSetting` `PinPosition` and +`AnchorPoint` change together (312 against 25 styles) with +`VerticalAlignment` and three other u16 fields of chunk 0x2800, so they +cannot be told apart. `EnableTransparency` of the effects categories varies and has no identified field. diff --git a/src/idml/mod.rs b/src/idml/mod.rs index 767deaa..9d575ff 100644 --- a/src/idml/mod.rs +++ b/src/idml/mod.rs @@ -59,6 +59,28 @@ fn fitting_value(id: u32, v: &Value) -> Option { } } +/// Anchored object settings from chunk 0x2800 (of an anchor or an object +/// style): f64 `AnchorYoffset` at 0, u16 `VerticalAlignment` at 52. See +/// `docs/format/objects.md`. +fn anchored_settings(d: &[u8]) -> Vec<(&'static str, String)> { + let mut out = Vec::new(); + if d.len() < 54 { + return out; + } + let y = f64::from_le_bytes(d[0..8].try_into().unwrap()); + let align = match u16::from_le_bytes([d[52], d[53]]) { + 0 => Some("TopAlign"), + 1 => Some("CenterAlign"), + 2 => Some("BottomAlign"), + _ => None, + }; + if let Some(a) = align { + out.push(("VerticalAlignment", a.to_string())); + } + out.push(("AnchorYoffset", num(y))); + out +} + /// Frame fitting attributes of `attrs` with IDs in `ids`, in IDML order. fn fitting_attrs(attrs: &Attrs, ids: &[u32]) -> Vec<(&'static str, String)> { FITTING_ATTRS @@ -2287,6 +2309,9 @@ impl Writer<'_> { } let all: Vec = FITTING_ATTRS.iter().map(|(id, _)| *id).collect(); node.set(&["FrameFittingOption"], fitting_attrs(&os.fitting, &all)); + if let Some(d) = &os.anchor { + node.set(&["AnchoredObjectSetting"], anchored_settings(d)); + } node } @@ -2642,6 +2667,19 @@ impl Writer<'_> { { n.write(x); } + if let Some(d) = &item.anchor { + let style = item + .object_style + .and_then(|u| self.doc.object_styles.get(&u)) + .and_then(|s| s.anchor.as_deref()); + let attrs: Vec<_> = anchored_settings(d) + .into_iter() + .filter(|a| style.is_none_or(|s| !anchored_settings(s).contains(a))) + .collect(); + if !attrs.is_empty() { + x.empty("AnchoredObjectSetting", &attrs); + } + } Self::text_wrap_preference(x, item.text_wrap.as_ref(), None); if frame { x.empty( diff --git a/src/model/mod.rs b/src/model/mod.rs index a4458a3..19ff21a 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -96,6 +96,8 @@ pub mod chunk { pub const STYLE_ATTRS: u32 = 0x23F; pub const LANGUAGE_NAME: u32 = 0x2D0F; pub const ANCHOR_CHILDREN: u32 = 0x2C8; + /// Anchored object settings, of an anchor or an object style. + pub const ANCHOR_SETTINGS: u32 = 0x2800; pub const MASTER_NAME: u32 = 0x1402; pub const STYLE_ROOT_CHILDREN: u32 = 0x28DC; pub const STYLE_GROUP_CHILDREN: u32 = 0x28D3; @@ -274,6 +276,9 @@ pub struct PageItem { pub children: Vec, /// Text wrap (chunk 0x3703); `None` if the item has none. pub text_wrap: Option, + /// Anchored object settings (chunk 0x2800 of the anchor), for an item + /// anchored in text. + pub anchor: Option>, } /// Text wrap settings of a page item or graphic (chunk 0x3703). @@ -576,6 +581,8 @@ pub struct ObjectStyle { pub enabled: Option>, /// Paragraph style applied to text frames (chunk 0x1B946). pub paragraph_style: Option, + /// Anchored object settings (chunk 0x2800). + pub anchor: Option>, } /// Reads typed objects from a database, caching them. @@ -778,6 +785,7 @@ impl<'a> Reader<'a> { Some(d) if d.len() >= 4 => Some(Cursor::new(&d).u32()?), _ => None, }, + anchor: self.chunk(uid, chunk::ANCHOR_SETTINGS)?, }, ); } @@ -1440,6 +1448,7 @@ impl<'a> Reader<'a> { object_style, children, text_wrap: self.text_wrap(uid)?, + anchor: None, })) } @@ -1739,8 +1748,10 @@ impl<'a> Reader<'a> { text_variables.insert(pos, v); } class::ANCHOR => { + let settings = self.chunk(item, chunk::ANCHOR_SETTINGS)?; for child in self.children(item, chunk::ANCHOR_CHILDREN)? { - if let Some(pi) = self.page_item(child, None)? { + if let Some(mut pi) = self.page_item(child, None)? { + pi.anchor = settings.clone(); anchors.entry(pos).or_default().push(pi); } }