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:
aiongg committed 2026-10-10 14:11:48 +00:00
1 parent 129f5b1dca
commit dec1d99ce4
2 files changed
+34 -1

No files matched your search

+19
View File
@@ -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)
}