mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-21 09:40:47 +01:00
feat: write the transform attributes of object styles
Chunk 0x1E234 of an object style holds four u16 flags and four f64: X, Y, height and width of TransformAttributeOption. IDML writes each value whose flag is 1 (36 styles; 2,390 with all flags 0 have none). compare.py --exclude own/, trustworthy pairs: TransformAttrWidth 0 -> 30/30, TransformAttrHeight 0 -> 11/11, TransformAttrX 0 -> 3/3, TransformAttrY 0 -> 1/1; no extra values.
This commit is contained in:
1 parent
3ba72f54ce
commit
129f5b1dca
4 files changed
+47
No files matched your search
@@ -433,6 +433,21 @@ impl Writer<'_> {
|
||||
if let Some(e) = export::object_export_option(self.doc.version, None, true) {
|
||||
node.children.insert(0, e);
|
||||
}
|
||||
// The transform values the style sets, where IDML has the element
|
||||
// (objects.md, object style settings).
|
||||
let transform: Vec<_> = [
|
||||
"TransformAttrX",
|
||||
"TransformAttrY",
|
||||
"TransformAttrHeight",
|
||||
"TransformAttrWidth",
|
||||
]
|
||||
.into_iter()
|
||||
.zip(os.transform)
|
||||
.filter_map(|(name, v)| Some((name, num(v?))))
|
||||
.collect();
|
||||
if !transform.is_empty() && node.child("TransformAttributeOption").is_some() {
|
||||
node.set(&["TransformAttributeOption"], transform);
|
||||
}
|
||||
let mut attrs = self.item_attr_values(&os.attrs);
|
||||
for (id, name) in [
|
||||
(0x551E, "GradientFillAngle"),
|
||||
|
||||
@@ -312,6 +312,8 @@ pub mod chunk {
|
||||
pub const OBJECT_STYLE_PARAGRAPH_STYLE: u32 = 0x1B946;
|
||||
/// u16 1 when an object style applies the next paragraph style.
|
||||
pub const OBJECT_STYLE_APPLY_NEXT: u32 = 0x1B94D;
|
||||
/// Size and position of an object style's transform attributes.
|
||||
pub const OBJECT_STYLE_TRANSFORM: u32 = 0x1E234;
|
||||
pub const GUIDE: u32 = 0x3308;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,6 +164,9 @@ pub struct ObjectStyle {
|
||||
pub named_grid: Option<Option<u32>>,
|
||||
/// Export settings (chunk 0x28F0).
|
||||
pub export: Option<StyleExport>,
|
||||
/// Transform attributes (chunk 0x1E234): X, Y, height and width, each
|
||||
/// `Some` when the style sets it.
|
||||
pub transform: [Option<f64>; 4],
|
||||
}
|
||||
|
||||
/// Whether `s` has the form of a GUID as styles store it: lowercase
|
||||
@@ -504,10 +507,25 @@ impl<'a> Reader<'a> {
|
||||
}),
|
||||
named_grid: self.applied_named_grid(uid)?,
|
||||
export: self.style_export(uid)?,
|
||||
transform: match self.chunk(uid, chunk::OBJECT_STYLE_TRANSFORM)? {
|
||||
Some(d) => transform_options(self.enc(), &d),
|
||||
None => [None; 4],
|
||||
},
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
/// Chunk 0x1E234 of an object style: u16 flags at 8, 10, 12 and 14 (1 when
|
||||
/// the style sets X, Y, height and width), and those values as f64 at 16,
|
||||
/// 24, 32 and 40. See `docs/format/objects.md`, object style settings.
|
||||
fn transform_options(enc: crate::object::Encoding, d: &[u8]) -> [Option<f64>; 4] {
|
||||
std::array::from_fn(|i| {
|
||||
(enc.u16_at(d, 8 + 2 * i) == Some(1))
|
||||
.then(|| enc.f64_at(d, 16 + 8 * i))
|
||||
.flatten()
|
||||
})
|
||||
}
|
||||
|
||||
/// Anchored object settings (chunk 0x2800, of an anchor, an object style
|
||||
/// or the preferences). See `docs/format/objects.md`, anchored objects.
|
||||
/// A field is `None` where the chunk is too short for it.
|
||||
|
||||
Reference in new issue
Block a user