M3: the Mac OS Roman reading is decided once per font and stays off for a base encoding name the renderer doesn't know (hayro-interpret patch 101)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyCHD1R3rywQBPCHXZA
This commit is contained in:
mtlcl410
2026-11-08 14:24:52 +08:00
co-authored by Claude Opus 5.5
parent 04f87b5b82
commit 93a8233b22
3 changed files with 40 additions and 16 deletions
@@ -258,7 +258,7 @@ fn a_symbol_or_zapfdingbats_font_in_the_macintosh_order_gets_no_mac_roman_readin
let font = font(&[AGRAVE, EACUTE], Some(&map), &map, false);
for name in ["ZapfDingbats", "AAAAAA+Symbol"] {
let text = extracted_with(&font, &[0x88, 0x8E], name, "");
assert!(!text.contains(['à', 'é']), "{name}: {text:?}");
assert_eq!(text, "ˆŽ", "{name}: the codes read as WinAnsi, as before");
}
}
@@ -268,5 +268,14 @@ fn differences_naming_notdef_clear_the_mac_roman_reading_for_its_code() {
let map = [(0x88, AGRAVE), (0x8E, EACUTE)];
let font = font(&[AGRAVE, EACUTE], Some(&map), &map, false);
let text = extracted_with(&font, &[0x88, 0x8E], "AAAAAA+Sym", "/Encoding << /Differences [142 /.notdef] >> ");
assert!(text.starts_with('à') && !text.contains('é'), "{text:?}");
assert_eq!(text, "à", "0x8E reads as nothing");
}
#[test]
fn a_base_encoding_name_this_reader_does_not_know_keeps_the_mac_roman_reading_off() {
// An unknown `/Encoding` name is read as the built-in encoding, but it names a base encoding all the same, so the
// editor gives it no Mac OS Roman reading and neither does the renderer: the codes read as WinAnsi, as before.
let map = [(0x88, AGRAVE), (0x8E, EACUTE)];
let font = font(&[AGRAVE, EACUTE], Some(&map), &map, false);
assert_eq!(extracted_with(&font, &[0x88, 0x8E], "AAAAAA+Sym", "/Encoding /NoSuchEncoding "), "ˆŽ");
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+28 -13
View File
@@ -221,6 +221,9 @@ struct EmbeddedKind {
cached_mappings: RefCell<HashMap<u8, GlyphId>>,
/// PostScript name from the PDF.
postscript_name: Option<String>,
/// PdfCraft patch (101): whether the font may take the Mac OS Roman reading at all, worked out
/// once when it is loaded (`EmbeddedKind::mac_roman_name`).
mac_roman_eligible: bool,
}
impl EmbeddedKind {
@@ -248,6 +251,27 @@ impl EmbeddedKind {
.get::<Name<'_>>(BASE_FONT)
.map(|n| strip_subset_prefix(n.as_str()).to_string());
// PdfCraft patch (101): the font names no base encoding, not even one this reader doesn't
// know (which `read_encoding` reads as the built-in one), and isn't Symbol or ZapfDingbats,
// whose built-in encodings aren't Latin (ISO 32000-2 §9.6.6.1). Both as the editor's
// `unicode_map` decides them, Symbol and ZapfDingbats recognised by name as there.
let names_base_encoding = dict.get::<Name<'_>>(ENCODING).is_some()
|| dict
.get::<Dict<'_>>(ENCODING)
.is_some_and(|d| d.get::<Name<'_>>(BASE_ENCODING).is_some());
let symbolic_builtin = dict.get::<Name<'_>>(BASE_FONT).is_some_and(|n| {
let name = n.as_str();
let flat: String = name
.rsplit('+')
.next()
.unwrap_or(name)
.chars()
.filter(char::is_ascii_alphanumeric)
.map(|c| c.to_ascii_lowercase())
.collect();
flat.contains("symbol") || flat.contains("zapf") || flat.contains("dingbat")
});
Some(Self {
base_font,
differences,
@@ -259,6 +283,7 @@ impl EmbeddedKind {
encoding,
cached_mappings: RefCell::new(HashMap::new()),
postscript_name,
mac_roman_eligible: !names_base_encoding && !symbolic_builtin,
})
}
@@ -420,25 +445,15 @@ impl EmbeddedKind {
/// `iacute`), and reading every such code as Mac OS Roman turned "USDA’s" into "USDAís".
/// A font that names its glyphs in its `post` table needn't keep the order (a Wingdings subset
/// draws code 0x83 with glyph 101, `Eacute` in the order, which it names `threesans`).
/// `None` when the font is non-symbolic, names an encoding, is Symbol or ZapfDingbats (whose
/// `None` when the font is non-symbolic, names a base encoding (one this reader doesn't know
/// too), is Symbol or ZapfDingbats (whose
/// built-in encodings aren't Latin, ISO 32000-2 §9.6.6.1; recognised by name as the editor's
/// `unicode_map` recognises them), is a CFF program, names its glyphs, or either test fails
/// (SAS's AMT fonts carry a wrong (1, 0) table, #4156): the code then reads as before. Glyph
/// selection is unchanged.
fn mac_roman_name(&self, code: u8) -> Option<&'static str> {
let symbolic_builtin = self.postscript_name.as_deref().is_some_and(|name| {
let flat: String = name
.rsplit('+')
.next()
.unwrap_or(name)
.chars()
.filter(char::is_ascii_alphanumeric)
.map(|c| c.to_ascii_lowercase())
.collect();
flat.contains("symbol") || flat.contains("zapf") || flat.contains("dingbat")
});
if self.is_non_symbolic()
|| symbolic_builtin
|| !self.mac_roman_eligible
|| !matches!(self.encoding, Encoding::BuiltIn)
|| self.cff_blob.is_some()
|| !self.glyph_names.is_empty()