mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-20 01:00:46 +01:00
feat: convert the bullet character list
The preferences object lists the bullet characters offered for lists in chunk 0x1A488. Write them as ABullet elements.
This commit is contained in:
1 parent
44c85c5a54
commit
537af3af4d
3 files changed
+103
No files matched your search
@@ -834,3 +834,22 @@ swatches, in order; the other two are in the pairs whose IDML was
|
||||
exported from another save. The converter writes 907 of the 942 IDML
|
||||
swatches, all with the IDML reference. A swatch without a reference is
|
||||
left out, and the indices of the others are kept.
|
||||
|
||||
## Bullet characters
|
||||
|
||||
The preferences object (class 0x2202) lists the bullet characters
|
||||
offered for lists in chunk 0x1A488: u16 1, u32 count, then for each
|
||||
bullet u32 character type (0 `UnicodeOnly`, 1 `UnicodeWithFont`, 2
|
||||
`GlyphWithFont`, as in `attributes.md`), u32 character value, u32 font
|
||||
family UID (0 = none), a flag byte (1 = built-in key, `$ID/`) and the
|
||||
font style as an in-object string, and a byte that is 0 in every sample.
|
||||
IDML writes one `ABullet` per entry in `designmap.xml`, with
|
||||
`Self="dABullet<index>"`, `CharacterType`, `CharacterValue` and the
|
||||
`BulletsFont` (the family name, `$ID/` for none) and `BulletsFontStyle`
|
||||
properties.
|
||||
|
||||
Evidence: all 78 pairs have the chunk; the count equals the number of
|
||||
IDML `ABullet` elements in 78 of 78 and the records end the chunk. All
|
||||
396 bullets match on type, value and font style, and 395 on the font;
|
||||
the other is in the pair whose IDML names the family `Minion Pro (OTF)`
|
||||
(`fonts.md`).
|
||||
@@ -980,6 +980,31 @@ impl Writer<'_> {
|
||||
}
|
||||
self.hyperlinks(&mut x);
|
||||
self.color_groups(&mut x);
|
||||
for (i, b) in doc.bullets.iter().enumerate() {
|
||||
const KINDS: [&str; 3] = ["UnicodeOnly", "UnicodeWithFont", "GlyphWithFont"];
|
||||
let Some(kind) = KINDS.get(b.kind as usize) else {
|
||||
continue;
|
||||
};
|
||||
let font = match b.font {
|
||||
0 => "$ID/".to_string(),
|
||||
f => match doc.fonts.get(&f) {
|
||||
Some(f) => f.name.clone(),
|
||||
None => continue,
|
||||
},
|
||||
};
|
||||
x.start("ABullet")
|
||||
.attr("Self", format!("dABullet{i}"))
|
||||
.attr("CharacterType", *kind)
|
||||
.attr("CharacterValue", b.value.to_string());
|
||||
Self::properties(
|
||||
&mut x,
|
||||
&[
|
||||
("BulletsFont", "string", font.into()),
|
||||
("BulletsFontStyle", "string", b.font_style.clone().into()),
|
||||
],
|
||||
);
|
||||
x.end();
|
||||
}
|
||||
x.end();
|
||||
x.finish()
|
||||
}
|
||||
|
||||
@@ -106,6 +106,8 @@ pub mod chunk {
|
||||
pub const ROOT_GROUP_KIND: u32 = 0x28C2;
|
||||
pub const SECTION_INFO: u32 = 0x4C02;
|
||||
pub const DOCUMENT_PREFERENCES: u32 = 0x533;
|
||||
/// Bullet characters, in the preferences object.
|
||||
pub const BULLETS: u32 = 0x1A488;
|
||||
pub const FRAME_COLUMNS: u32 = 0x2D1;
|
||||
pub const FRAME_JUSTIFICATION: u32 = 0x2CE;
|
||||
pub const GRAPHIC_BOUNDS: u32 = 0x1633;
|
||||
@@ -467,6 +469,8 @@ pub struct Document {
|
||||
pub inks: Vec<Ink>,
|
||||
/// Colour groups in document order, the root group first.
|
||||
pub color_groups: Vec<ColorGroup>,
|
||||
/// The bullet characters offered for lists (preferences chunk 0x1A488).
|
||||
pub bullets: Vec<Bullet>,
|
||||
}
|
||||
|
||||
/// Document setup, from chunk 0x533 of the preferences object.
|
||||
@@ -535,6 +539,19 @@ pub mod numbering {
|
||||
pub const LOWER_ROMAN: u32 = 0x4C17;
|
||||
}
|
||||
|
||||
/// A bullet character of the document's list (IDML `ABullet`): u32
|
||||
/// character type, u32 character value, u32 font family (0 = none), the
|
||||
/// font style as a flag byte and string, then a byte (0 in every sample).
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Bullet {
|
||||
/// 0 `UnicodeOnly`, 1 `UnicodeWithFont`, 2 `GlyphWithFont`.
|
||||
pub kind: u32,
|
||||
pub value: u32,
|
||||
pub font: u32,
|
||||
/// The IDML font style, with `$ID/` for a built-in name.
|
||||
pub font_style: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ObjectStyle {
|
||||
pub uid: u32,
|
||||
@@ -957,9 +974,51 @@ impl<'a> Reader<'a> {
|
||||
.into_iter()
|
||||
.filter_map(|u| color_groups.remove(&u))
|
||||
.collect(),
|
||||
bullets: self.bullets()?,
|
||||
})
|
||||
}
|
||||
|
||||
/// The bullet characters in the preferences object (chunk 0x1A488):
|
||||
/// u16 1, u32 count, then the bullets.
|
||||
fn bullets(&self) -> Result<Vec<Bullet>, Error> {
|
||||
let Some(&(uid, _)) = self
|
||||
.db
|
||||
.classes()
|
||||
.iter()
|
||||
.find(|(_, c)| *c == class::PREFERENCES)
|
||||
else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
let Some(d) = self.chunk(uid, chunk::BULLETS)? else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
let mut c = Cursor::new(&d);
|
||||
if c.u16()? != 1 {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let n = c.u32()?;
|
||||
let mut out = Vec::new();
|
||||
for _ in 0..n {
|
||||
let kind = c.u32()?;
|
||||
let value = c.u32()?;
|
||||
let font = c.u32()?;
|
||||
let builtin = c.u8()? == 1;
|
||||
let style = c.string()?;
|
||||
c.u8()?;
|
||||
out.push(Bullet {
|
||||
kind,
|
||||
value,
|
||||
font,
|
||||
font_style: if builtin {
|
||||
format!("$ID/{style}")
|
||||
} else {
|
||||
style
|
||||
},
|
||||
});
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The colour groups listed in the preferences object (chunk 0x1F61).
|
||||
fn color_group_order(&self) -> Result<Vec<u32>, Error> {
|
||||
let Some(&(uid, _)) = self
|
||||
|
||||
Reference in new issue
Block a user