feat: convert ruby text

Character runs that set attribute 0x422D to 1 carry their ruby text in
0x422E (u32 length, then text segments). In a vertically typeset
sample's print PDF that text is set small beside the run's characters.
The converter writes RubyFlag and RubyString.
This commit is contained in:
aiongg committed 2026-10-07 04:31:04 +00:00
1 parent 4bc6768fb0
commit 4bf1094489
2 files changed
+48 -7

No files matched your search

+22
View File
@@ -206,6 +206,8 @@ styles with INDD styles of the same name (486 styles), then checked with
| 0x1DF21 | `SameParaStyleSpacing` (Properties) | f64; −1 = SetIgnore | 15/15 ranges, 100/100 styles |
| 0x4265 | `GridAlignFirstLineOnly` | 1 = true | 81/81 styles |
| 0x4266 | `GridAlignment` | 0 None, 1 AlignBaseline | 86/86 styles |
| 0x422D | `RubyFlag` | number; written when not 0 | a sample and its print PDF; see below |
| 0x422E | `RubyString` | u32 length, text segments; written when not empty | a sample and its print PDF; see below |
| 0x1A401 | `BulletsAndNumberingListType` | 0 NoList, 1 BulletList | 10/12 ranges |
| 0x1A406 | `BulletChar` (Properties) | u32 type, u32 value; see below | 1/1 ranges, 84/84 styles |
| 0x1A413 | `BulletsFont` (Properties) | font family UID, 0 = `$ID/` | 1/1 ranges, 84/84 styles |
@@ -374,6 +376,26 @@ there. The rest of the evidence is a sample and its print PDF:
A layout of the converted sample with these two attributes reproduces
noticeably more of the PDF's line breaks than one without them.
**Ruby (0x422D, 0x422E).** IDML writes neither attribute on the root
style, and no corpus story has them. In every pair the root style stores
0 for 0x422D and a 4-byte 0 for 0x422E. The evidence is a sample typeset
vertically and its print PDF:
- Character runs of the sample set 0x422D to 1 together with 0x422E,
whose value is a u32 length in characters followed by text segments
(as story text, `objects.md`). The text is a short reading of the
run's characters.
- In the PDF, each such text appears in small type in a narrow column
right beside the run's characters and centred on them, as ruby is set
beside vertical text.
- Values of 8 bytes cannot be told from a number by their length, so the
converter rebuilds the bytes before reading the text.
The converter writes `RubyString` and writes `RubyFlag` with the stored
number (1 in every such run; the schema type is an integer). The other
ruby settings (`RubyType`, `RubyAlignment`, `RubyPosition`, font and
size) are not identified.
**`StartParagraph` (0x1B37).** In every pair the root style has 0 and
IDML writes `StartParagraph="Anywhere"`; no pair has another value. Code
2 rests on a sample and its print PDF:
+26 -7
View File
@@ -177,6 +177,10 @@ enum TextKind {
StringOrNothing,
/// u32 bullet character type and u32 character value (`BulletChar`).
BulletChar,
/// u32 length in characters, then text segments; left out when empty.
Text,
/// A number, left out when 0.
NonZero,
}
/// Text attributes: ID, IDML name, kind, written in `<Properties>`.
@@ -358,6 +362,8 @@ const TEXT_ATTRS: &[(u32, &str, TextKind, bool)] = &[
true,
),
(0x4265, "GridAlignFirstLineOnly", TextKind::Bool(1), false),
(0x422D, "RubyFlag", TextKind::NonZero, false),
(0x422E, "RubyString", TextKind::Text, false),
(
0x4266,
"GridAlignment",
@@ -1543,6 +1549,19 @@ impl Writer<'_> {
Some(u) => self.doc.fonts.get(&u).map(|f| ("string", f.name.clone())),
None => None,
},
TextKind::NonZero => v
.as_u32()
.filter(|&u| u != 0)
.map(|u| ("long", u.to_string())),
TextKind::Text => {
let b = raw_bytes(v);
let mut c = Cursor::new(&b);
let n = c.u32().ok()? as usize;
c.segments(n)
.ok()
.filter(|t| !t.is_empty())
.map(|t| ("string", t))
}
TextKind::StringOrNothing => v.as_string().map(|s| {
if s.is_empty() {
("enumeration", "Nothing".into())
@@ -3605,6 +3624,13 @@ mod tests {
assert_eq!(lower_roman(1994), "mcmxciv");
}
#[test]
fn names_pages_in_kanji_digits() {
assert_eq!(kanji_digits(8), "八");
assert_eq!(kanji_digits(10), "一〇");
assert_eq!(kanji_digits(102), "一〇二");
}
#[test]
fn formats_numbers_like_idml() {
assert_eq!(num(205.2), "205.2");
@@ -3634,13 +3660,6 @@ mod tests {
);
}
#[test]
fn names_pages_in_kanji_digits() {
assert_eq!(kanji_digits(8), "八");
assert_eq!(kanji_digits(10), "一〇");
assert_eq!(kanji_digits(102), "一〇二");
}
#[test]
fn decodes_tab_stops() {
// Two stops: 12 pt left aligned, 237.5 pt right aligned with "." leader.