mirror of
https://github.com/storytold/indd-utils.git
synced 2026-11-19 16:50:48 +01:00
feat: write an empty font style as the family's Regular or first style
A text attribute list that stores an empty FontStyle is written with the style of its AppliedFont family's Regular font, or of the family's first font if it has no Regular one. compare.py --exclude own/, trustworthy pairs: ParagraphStyle FontStyle 4,017 -> 4,080/4,086, CharacterStyle 1,310 -> 1,334/1,345, TextDefault 1,240 -> 1,250/1,251, text ranges 76,473 -> 76,619/76,652. No value that matched before changes; no extra values.
This commit is contained in:
1 parent
129f5b1dca
commit
dec1d99ce4
2 files changed
+34
-1
No files matched your search
@@ -318,7 +318,7 @@ styles with INDD styles of the same name (486 styles), then checked with
|
||||
| ID | IDML attribute | Encoding | Evidence |
|
||||
|---|---|---|---|
|
||||
| 0x1B01 | `FillColor` | swatch UID | 354/354 ranges, 226/226 styles |
|
||||
| 0x1B02 | `FontStyle` | flag + string | 474/474 ranges, 202/202 styles |
|
||||
| 0x1B02 | `FontStyle` | flag + string; empty: below | 474/474 ranges, 202/202 styles |
|
||||
| 0x1B03 | `PointSize` | f64 | 1,090/1,090 ranges |
|
||||
| 0x1B06 | `HorizontalScale` | fraction ×100 | 2/2 ranges, 75/75 styles |
|
||||
| 0x1B07 | `KerningMethod` | code: 15972 Metrics, 79875 Optical, 0x3E65 `$ID/Metrics - Roman Only` (27 styles) | 20/20 ranges, 81/81 styles |
|
||||
@@ -1118,6 +1118,20 @@ of these pairs aligns:
|
||||
`NextEvenPage` occurs in no IDML. Its code is not known, and the
|
||||
converter leaves other codes out.
|
||||
|
||||
**Empty font styles.** A list can store an empty `FontStyle` (0x1B02).
|
||||
IDML then writes the style of a font of the list's `AppliedFont` family:
|
||||
the font whose style is `Regular`, or the family's first font if none
|
||||
is. Over the 1,251 trustworthy pairs, writing the stored empty string
|
||||
gave 294 wrong `FontStyle` values (ParagraphStyle 69, CharacterStyle 35,
|
||||
TextDefault 11, text ranges 179); with this rule 243 of them match and
|
||||
no value that matched before changes. 20 of the 243 come from the
|
||||
first-font case (a family of `Light` and `LightItalic`, IDML `Light`).
|
||||
So every empty value that IDML also writes empty is in a list without
|
||||
an `AppliedFont`, or in a family without a `Regular` font whose first
|
||||
font has an empty style. Not explained: 22 empty values that IDML writes as
|
||||
`Nothing`, and lists without an `AppliedFont`, which keep the empty
|
||||
string.
|
||||
|
||||
**Font family names.** `AppliedFont` and `BulletsFont` name a font family
|
||||
(class 0x3E03), and IDML writes the family's name. An `AppliedFont`
|
||||
whose family stands for a composite font is written as a reference to
|
||||
|
||||
@@ -1511,6 +1511,25 @@ impl Writer<'_> {
|
||||
None => attrs.unknown_code(ids[0], a),
|
||||
}
|
||||
}
|
||||
// An empty font style is written as the style of the list's font
|
||||
// family named `Regular`, else of its first font
|
||||
// (`docs/format/attributes.md`, empty font styles).
|
||||
if let Some(style) = plain
|
||||
.iter_mut()
|
||||
.find(|(n, v)| *n == "FontStyle" && v.is_empty())
|
||||
.map(|(_, v)| v)
|
||||
&& let Some(f) = attrs
|
||||
.get(0x1B2B)
|
||||
.and_then(Value::as_u32)
|
||||
.and_then(|u| self.doc.fonts.get(&u))
|
||||
&& let Some(font) = f
|
||||
.fonts
|
||||
.iter()
|
||||
.find(|x| x.style == "Regular")
|
||||
.or(f.fonts.first())
|
||||
{
|
||||
style.clone_from(&font.style);
|
||||
}
|
||||
(plain, props)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user