mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-29 17:43:59 +01:00
feat: write the grid starting point, TOC story direction and object style optical margin
- Page GridStartingPoint from the u32 at 0 of chunk 0xCD04 (0 TopOutside, 4 CenterVertical; other codes are in no pair and are left out). - TOCStyle SetStoryDirection from the first u16 field of chunk 0x11605 (0 Horizontal, 1 Vertical). It is no longer a WHEN_WRITTEN key of element_values.py (the regenerated file is unchanged). - ObjectStyle StoryPreference OpticalMarginSize and OpticalMarginAlignment from the f64 at 2 and u16 at 12 of chunk 0x285B, as in the story chunk 0x2EE. Evidence in objects.md. compare.py --exclude own/, trustworthy pairs: coverage 98.32 % -> 98.41 % (Page GridStartingPoint 10,080 missing -> 0, TOCStyle SetStoryDirection 620 missing -> 0, object style OpticalMarginSize 261 and OpticalMarginAlignment 4 wrong -> 0), documents >= 99 % 225 -> 268; all pairs 96.46 % -> 96.54 %. Extras unchanged on trustworthy pairs (8,968); over all pairs +182, the new attribute on pages of stale pairs that the reference does not have. No new failures.
This commit is contained in:
1 parent
29b8757ef6
commit
15d6af5eee
9 files changed
+69
-9
No files matched your search
@@ -408,6 +408,15 @@ impl Writer<'_> {
|
||||
.attr("Name", &name);
|
||||
let major = self.doc.version.major;
|
||||
let flag = |i: usize| t.flags.get(i).copied();
|
||||
match flag(0) {
|
||||
Some(0) => {
|
||||
x.attr("SetStoryDirection", "Horizontal");
|
||||
}
|
||||
Some(1) => {
|
||||
x.attr("SetStoryDirection", "Vertical");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
match flag(1) {
|
||||
Some(0) => {
|
||||
x.attr("NumberedParagraphs", "IncludeFullParagraph");
|
||||
|
||||
@@ -723,6 +723,17 @@ impl Writer<'_> {
|
||||
.flat_map(|&(item, with)| [uref(Some(item)), uref((with != 0).then_some(with))])
|
||||
.collect();
|
||||
x.attr("OverrideList", overrides.join(" "));
|
||||
// Codes 0 and 4 only; the others are in no pair (objects.md, page
|
||||
// settings).
|
||||
match st.grid_start {
|
||||
Some(0) => {
|
||||
x.attr("GridStartingPoint", "TopOutside");
|
||||
}
|
||||
Some(4) => {
|
||||
x.attr("GridStartingPoint", "CenterVertical");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let Some(v) = st.use_master_grid {
|
||||
x.attr("UseMasterGrid", v.to_string());
|
||||
}
|
||||
|
||||
@@ -642,6 +642,12 @@ impl Writer<'_> {
|
||||
1 => story.push(("StoryOrientation", "Horizontal".to_string())),
|
||||
_ => {}
|
||||
}
|
||||
story.push(("OpticalMarginSize", num(st.optical_size)));
|
||||
match st.optical_alignment {
|
||||
0 => story.push(("OpticalMarginAlignment", "false".to_string())),
|
||||
1 => story.push(("OpticalMarginAlignment", "true".to_string())),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
match os.direction {
|
||||
Some(1) => story.push(("StoryDirection", "LeftToRightDirection".into())),
|
||||
|
||||
+2
-1
@@ -123,7 +123,8 @@ pub mod chunk {
|
||||
pub const MASTER_PRIMARY_STORY: u32 = 0x140A;
|
||||
/// Overridden master page items: u32 count, two UID lists.
|
||||
pub const PAGE_OVERRIDES: u32 = 0x1404;
|
||||
/// Layout grid use: six bytes, the last u16 1 to use the master's.
|
||||
/// Layout grid use: six bytes, u32 grid starting point code, then
|
||||
/// u16 1 to use the master's grid.
|
||||
pub const PAGE_GRID_USE: u32 = 0xCD04;
|
||||
/// Layout rule: u32, then u32 code.
|
||||
pub const PAGE_LAYOUT_RULE: u32 = 0x563;
|
||||
|
||||
@@ -69,6 +69,8 @@ pub struct PageSettings {
|
||||
pub overrides: Vec<(u32, u32)>,
|
||||
/// Chunk 0xCD04: whether the page uses its master's layout grid.
|
||||
pub use_master_grid: Option<bool>,
|
||||
/// Chunk 0xCD04: the layout grid starting point code (u32 at 0).
|
||||
pub grid_start: Option<u32>,
|
||||
/// Layout rule code (chunk 0x563); `None` without the chunk.
|
||||
pub layout_rule: Option<u32>,
|
||||
pub color: UiColorRef,
|
||||
@@ -604,6 +606,9 @@ impl<'a> Reader<'a> {
|
||||
.chunk(uid, chunk::PAGE_GRID_USE)?
|
||||
.and_then(|d| self.enc().u16_at(&d, 4))
|
||||
.map(|v| v != 0),
|
||||
grid_start: self
|
||||
.chunk(uid, chunk::PAGE_GRID_USE)?
|
||||
.and_then(|d| self.enc().u32_at(&d, 0)),
|
||||
layout_rule: self
|
||||
.chunk(uid, chunk::PAGE_LAYOUT_RULE)?
|
||||
.and_then(|d| self.enc().u32_at(&d, 4)),
|
||||
|
||||
+6
-1
@@ -476,10 +476,13 @@ impl ObjectStyleFrame {
|
||||
}
|
||||
|
||||
/// Story settings of an object style (chunk 0x285B), if the chunk has 16
|
||||
/// bytes: u16 story orientation at 0 and u16 frame type at 14.
|
||||
/// bytes: u16 story orientation at 0, f64 optical margin size at 2, u16
|
||||
/// optical margin alignment at 12 and u16 frame type at 14.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct StorySettings {
|
||||
pub orientation: u16,
|
||||
pub optical_size: f64,
|
||||
pub optical_alignment: u16,
|
||||
pub frame_type: u16,
|
||||
}
|
||||
|
||||
@@ -487,6 +490,8 @@ impl StorySettings {
|
||||
pub(super) fn read(enc: Encoding, d: &[u8]) -> Option<StorySettings> {
|
||||
Some(StorySettings {
|
||||
orientation: enc.u16_at(d, 0)?,
|
||||
optical_size: enc.f64_at(d, 2)?,
|
||||
optical_alignment: enc.u16_at(d, 12)?,
|
||||
frame_type: enc.u16_at(d, 14)?,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user