mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-24 03:00:47 +01:00
feat: write the baseline frame grid colour and two text preferences
Write TextPreference UseCidMojikumi and UseNewVerticalScaling from bytes 168 and 170 of preferences chunk 0x280 when they are equal (803 of 803 pairs). Write BaselineFrameGridColor in the preferences and in every object style by an observed rule over stored data: the interface colour of chunk 0x2834 (u32 at 20) when not 0, otherwise Charcoal if byte 168 of chunk 0x280 is 1 and LightBlue if it is 0 (803 of 803 pairs). Evidence in preferences.md. compare.py --exclude own/, trustworthy pairs: coverage 98.15 % -> 98.16 % (wrong values fixed: object style colours 581, preference colour 132, UseCidMojikumi and UseNewVerticalScaling 129 each), documents >= 99 % 184 -> 187; all pairs 96.29 % -> 96.30 %. Extras unchanged (8,968), no new failures or warnings, schema failures 0 on pairs. diff_outputs.py: 4,077 outputs differ, only in Resources/Preferences.xml and Resources/Styles.xml: the two text preferences now come from the INDD (order of attributes; values change where byte 168 is 1), and the colour changes where the rule gives Charcoal.
This commit is contained in:
1 parent
a5de84e81f
commit
5ee17cb100
5 files changed
+136
-1
No files matched your search
@@ -163,7 +163,30 @@ attribute too, except where the files show different values: positions
|
||||
differ in 2 files, which tells 24 from 32; the sizes are equal in every
|
||||
file, so 8 and 16 follow the order of the positions. Offsets 168 and 170
|
||||
match both `UseCidMojikumi` and `UseNewVerticalScaling`, which are equal
|
||||
in every file; they are not written.
|
||||
in every file. In the corpus of 2026-10 the two bytes are equal to each
|
||||
other and to both IDML values in 803 of 803 pairs (161 `true`, 642
|
||||
`false`). Which byte is which is not known, so the converter writes
|
||||
both attributes only when the bytes are equal (0 `false`, 1 `true`).
|
||||
|
||||
**Baseline frame grid colour.** The `BaselineFrameGridColor` of the
|
||||
`BaselineFrameGridOption` preference follows an observed rule over
|
||||
stored data, not a decoded field. Over the 803 pairs of the corpus of
|
||||
2026-10:
|
||||
|
||||
| Stored data | Pairs | IDML colour |
|
||||
|---|---:|---|
|
||||
| Chunk 0x2834 (24 bytes), u32 at 20 not 0: the UID of an interface colour object (as for layers, `objects.md`) | 11 | that colour (`Charcoal` in all 11) |
|
||||
| u32 at 20 is 0, offset 168 of chunk 0x280 is 1 | 154 | `Charcoal` |
|
||||
| u32 at 20 is 0, offset 168 is 0 | 513 | `LightBlue` |
|
||||
| No chunk 0x2834 (offset 168 is 0 in all) | 125 | `LightBlue` |
|
||||
|
||||
No stored field was found that holds the colour when the u32 is 0. Both
|
||||
the colour and offset 168 appear to be defaults of the edition that
|
||||
created the document. Every object style's `BaselineFrameGridColor`
|
||||
equals the preference's in 803 of 803 pairs (3,515 object styles), so
|
||||
the converter writes this colour in the preference and in every object
|
||||
style. A UID that is not an interface colour, or another byte at 168,
|
||||
leaves the observed value (`LightBlue`).
|
||||
|
||||
Chunk 0x28BE (14 bytes, 16 from InDesign 18), u8 flags: 4
|
||||
`SmartTextReflow`, 6 `LimitToMasterTextFrames`, 8 `DeleteEmptyPages`, 10
|
||||
|
||||
@@ -67,6 +67,46 @@ pub(super) fn page_color(c: &UiColorRef) -> Option<Node> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The `BaselineFrameGridColor` property of a baseline frame grid colour
|
||||
/// (preferences.md, baseline frame grid colour).
|
||||
pub(super) fn frame_grid_color(c: crate::model::prefs::FrameGridColor) -> Option<Node> {
|
||||
use crate::model::prefs::FrameGridColor;
|
||||
let name = match c {
|
||||
FrameGridColor::Rgb(rgb) => return ui_color_property("BaselineFrameGridColor", rgb),
|
||||
FrameGridColor::Charcoal => "Charcoal",
|
||||
FrameGridColor::LightBlue => "LightBlue",
|
||||
};
|
||||
Some(Node {
|
||||
tag: "BaselineFrameGridColor".into(),
|
||||
attrs: vec![("type".into(), "enumeration".into())],
|
||||
text: Some(name.into()),
|
||||
children: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Put `property` in the `Properties` of `node`, in place of a property
|
||||
/// of the same name.
|
||||
pub(super) fn set_property(node: &mut Node, property: Node) {
|
||||
let i = match node.children.iter().position(|c| c.tag == "Properties") {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
node.children.insert(
|
||||
0,
|
||||
Node {
|
||||
tag: "Properties".into(),
|
||||
..Node::default()
|
||||
},
|
||||
);
|
||||
0
|
||||
}
|
||||
};
|
||||
let props = &mut node.children[i].children;
|
||||
match props.iter_mut().find(|c| c.tag == property.tag) {
|
||||
Some(c) => *c = property,
|
||||
None => props.push(property),
|
||||
}
|
||||
}
|
||||
|
||||
/// A `Properties` child as a values node.
|
||||
pub(super) fn prop_node(p: &Property) -> Node {
|
||||
let (name, ty, value) = p;
|
||||
@@ -360,6 +400,27 @@ impl Writer<'_> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn sets_the_baseline_frame_grid_colour() {
|
||||
use crate::model::prefs::FrameGridColor;
|
||||
let mut node = Node {
|
||||
tag: "BaselineFrameGridOption".into(),
|
||||
..Node::default()
|
||||
};
|
||||
set_property(
|
||||
&mut node,
|
||||
frame_grid_color(FrameGridColor::LightBlue).unwrap(),
|
||||
);
|
||||
set_property(
|
||||
&mut node,
|
||||
frame_grid_color(FrameGridColor::Charcoal).unwrap(),
|
||||
);
|
||||
let props = &node.children[0];
|
||||
assert_eq!(props.tag, "Properties");
|
||||
assert_eq!(props.children.len(), 1);
|
||||
assert_eq!(props.children[0].text.as_deref(), Some("Charcoal"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_without_text_are_written_as_zero() {
|
||||
assert_eq!(num(1.5), "1.5");
|
||||
|
||||
@@ -863,6 +863,10 @@ impl Writer<'_> {
|
||||
.push(("BetweenEntriesSeparator".into(), separator.into()));
|
||||
}
|
||||
ours.push(self.footnote_option());
|
||||
if let Some(c) = prefs.baseline_frame_grid_color.and_then(frame_grid_color) {
|
||||
let i = ours_of(&mut ours, "BaselineFrameGridOption");
|
||||
set_property(&mut ours[i], c);
|
||||
}
|
||||
for mut n in ours {
|
||||
match nodes.iter_mut().find(|m| m.tag == n.tag) {
|
||||
Some(m) => {
|
||||
|
||||
@@ -379,6 +379,20 @@ impl Writer<'_> {
|
||||
} else {
|
||||
values::object_style(major)
|
||||
};
|
||||
// Every object style has the preferences' baseline frame grid
|
||||
// colour (preferences.md, baseline frame grid colour).
|
||||
if let Some(c) = self
|
||||
.doc
|
||||
.prefs
|
||||
.baseline_frame_grid_color
|
||||
.and_then(frame_grid_color)
|
||||
&& let Some(b) = node
|
||||
.children
|
||||
.iter_mut()
|
||||
.find(|c| c.tag == "BaselineFrameGridOption")
|
||||
{
|
||||
set_property(b, c);
|
||||
}
|
||||
// The export options of the version (idml-values.md) in place of
|
||||
// those of the value files.
|
||||
node.children.retain(|c| c.tag != "ObjectExportOption");
|
||||
|
||||
@@ -55,6 +55,19 @@ pub struct Prefs {
|
||||
/// Layout and story grid defaults: element, grid settings and, for
|
||||
/// the story grid, `CharacterCountSize`.
|
||||
pub grids: Vec<(&'static str, super::GridData, Option<f64>)>,
|
||||
/// The colour of baseline frame grids, for the preferences and every
|
||||
/// object style.
|
||||
pub baseline_frame_grid_color: Option<FrameGridColor>,
|
||||
}
|
||||
|
||||
/// The colour of baseline frame grids (`preferences.md`, baseline frame
|
||||
/// grid colour).
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum FrameGridColor {
|
||||
/// An interface colour object.
|
||||
Rgb([f64; 3]),
|
||||
Charcoal,
|
||||
LightBlue,
|
||||
}
|
||||
|
||||
/// The document's endnote options (preferences chunk 0x2261E). See
|
||||
@@ -729,6 +742,8 @@ mod id {
|
||||
pub const COLOR_POLICIES: u32 = 0x7C44;
|
||||
pub const WATERMARK: u32 = 0x16344;
|
||||
pub const TEXT: u32 = 0x280;
|
||||
/// Baseline frame grid settings: u32 at 20 an interface colour or 0.
|
||||
pub const BASELINE_FRAME_GRID: u32 = 0x2834;
|
||||
pub const SMART_TEXT_REFLOW: u32 = 0x28BE;
|
||||
pub const MARGINS: u32 = 0x550;
|
||||
pub const COLUMNS: u32 = 0x555;
|
||||
@@ -1042,7 +1057,24 @@ impl Reader<'_> {
|
||||
}
|
||||
|
||||
// Text preferences and the default text frame columns.
|
||||
let mut baseline_frame_grid_color = None;
|
||||
if let Some(d) = get(id::TEXT)?.filter(|d| d.len() >= 174) {
|
||||
// Bytes 168 and 170 are `UseCidMojikumi` and
|
||||
// `UseNewVerticalScaling` in an order not known; they are
|
||||
// equal in every sample. Byte 168 also gives the default
|
||||
// colour of baseline frame grids (preferences.md).
|
||||
if d[168] == d[170] && d[168] <= 1 {
|
||||
let on = (d[168] == 1).to_string();
|
||||
set("TextPreference", "UseCidMojikumi", on.clone());
|
||||
set("TextPreference", "UseNewVerticalScaling", on);
|
||||
}
|
||||
let ui = get(id::BASELINE_FRAME_GRID)?.and_then(|g| self.enc().u32_at(&g, 20));
|
||||
baseline_frame_grid_color = match (ui, d[168]) {
|
||||
(Some(u), _) if u != 0 => self.ui_color(u)?.map(FrameGridColor::Rgb),
|
||||
(_, 1) => Some(FrameGridColor::Charcoal),
|
||||
(_, 0) => Some(FrameGridColor::LightBlue),
|
||||
_ => None,
|
||||
};
|
||||
let f = |o: usize| self.cursor(&d[o..]).f64();
|
||||
let b = |o: usize| (d[o] != 0).to_string();
|
||||
for (o, name) in [
|
||||
@@ -1638,6 +1670,7 @@ impl Reader<'_> {
|
||||
);
|
||||
}
|
||||
Ok(Prefs {
|
||||
baseline_frame_grid_color,
|
||||
values,
|
||||
colors,
|
||||
text_defaults,
|
||||
|
||||
Reference in new issue
Block a user