M2: a non-embedded Times New Roman draws the glyphs its codes name (hayro-interpret patch 88)

A Times New Roman the PDF doesn't embed, written as a Type 0 font with a
CIDFontType2 descendant (TimesNewRoman,Bold, TimesNewRomanPSMT and the
other faces) and no /ToUnicode, now goes through the rule of patch (76):
each CID gives, through /CIDToGIDMap (ISO 32000-2 Table 115), a glyph
index in the author's font, and the substitute draws that glyph by its
name in the standard Macintosh order of the TrueType post table. Before,
the CID was taken as one of the substitute's own glyph indexes, which
ISO 32000-2 9.7.4.2 notes "are not defined consistently from one font to
another", and the ameli.fr mutation form drew "Salarié(e) du régime
général" as "Salari²*g+f w't²i lo g'ì²p²tcn".

Times New Roman numbers its first 258 glyphs in that order: the same
form's embedded Times New Roman subsets keep their glyph indexes, and 941
of their 942 /ToUnicode entries below 258 name that order's character.
Times and Times New Roman MT Std are other fonts and keep the old path.

Fixes #6449

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq7HyDBXygTf7jcqdsjcfn
This commit is contained in:
mtlcl410
2026-11-07 07:09:33 +08:00
co-authored by Claude Opus 5.5
parent 546a808e1a
commit 49f200f99d
5 changed files with 62 additions and 28 deletions
+2
View File
@@ -230,6 +230,8 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md
## Progress log
- **2026-11-07 (M2, #6449):** A non-embedded Times New Roman set as a TrueType CID font (`TimesNewRoman,Bold`, `TimesNewRomanPSMT` and the other faces) draws the glyphs its codes name, as the non-embedded Arial does: its first 258 glyphs follow the same standard Macintosh order, which the embedded Times New Roman subsets of a public French form confirm in 941 of 942 `/ToUnicode` entries (vendored hayro-interpret patch 88). That form drew "Salarié(e) du régime général" as "Salari²*g+f w't²i lo g'ì²p²tcn" and "changement" as "ej angement". Times and Times New Roman MT Std are not read this way.
- **2026-11-05 (M2, #5889):** A non-embedded Arial set as a TrueType CID font (`CIDFontType2`, `Identity-H`, as Word and PDFMaker write it) draws the glyphs its codes name. Those codes are glyph indexes in the author's Arial, whose first 258 glyphs follow the standard Macintosh order, so the standard substitute now draws each glyph by name (vendored hayro-interpret patch 76). Before, it took each code as one of its own glyph indexes, and "Low Power" drew as "@ck 'Dck Yf". Arial Narrow, Black and Unicode MS, and `CIDFontType0` fonts, are not read this way. Copying or searching those runs still needs a `/ToUnicode`.
- **2026-10-28 (M10, #4119 partial):** Scan & OCR ▸ Enhance scanned file cleans scanned pages in place: background removal (level 0–100, as the camera clean-up), edge shadow removal (book gutters, copier borders) and despeckle. Each scan image is decoded, cleaned and written back into its own object at the same size and colour space (JPEG stays JPEG, others lossless, 1-bit stays 1-bit), so the OCR text layer, comments and links stay; one undo step, shared images once, unsupported images (CMYK, indexed, JPEG 2000, JBIG2, CCITT, broken data) reported. `page_enhance_scan` drives it headlessly. Not yet an option of Recognize text. Estimates unchanged.
@@ -1,9 +1,10 @@
//! An Arial the PDF doesn't embed draws the glyphs its codes name (vendored hayro-interpret
//! patch 76, #5889). Word and PDFMaker write such a font as a Type 0 `CIDFontType2` with
//! `Identity-H`, often without `/ToUnicode`, so each code is a glyph index in the author's Arial.
//! Arial numbers its first 258 glyphs in the standard Macintosh order of the TrueType `post`
//! table (`L` is 47, `o` 82, `w` 90). The standard substitute numbers its glyphs another way, and
//! "Low Power" drew as "@ck 'Dck Yf".
//! An Arial or a Times New Roman the PDF doesn't embed draws the glyphs its codes name (vendored
//! hayro-interpret patches 76 and 88, #5889, #6449). Word and PDFMaker write such a font as a
//! Type 0 `CIDFontType2` with `Identity-H`, often without `/ToUnicode`, so each code is a glyph
//! index in the author's font. Both number their first 258 glyphs in the standard Macintosh order
//! of the TrueType `post` table (`L` is 47, `o` 82, `w` 90). The standard substitute numbers its
//! glyphs another way: "Low Power" drew as "@ck 'Dck Yf", and "Salarié(e) du régime général" as
//! "Salari²*g+f w't²i lo g'ì²p²tcn".
//!
//! Each document is drawn twice, once as such a file has it and once with a `/ToUnicode` that
//! names each code's character, which draws through the substitute's glyph for that character.
@@ -106,18 +107,44 @@ fn an_arial_the_pdf_does_not_embed_draws_the_glyphs_its_codes_name() {
}
}
/// Only Arial's own faces are read in its order: Arial Narrow, Arial Black and Arial Unicode MS
/// are other fonts, and a `CIDFontType0` font's CIDs aren't TrueType glyph indexes.
/// Each Times New Roman face, as Windows exporters name it and as Word names a face it doesn't
/// embed (`TimesNewRoman,Bold` in #6449), draws "Low É" from its glyph indexes.
#[test]
fn codes_of_other_fonts_are_not_read_in_arials_order() {
fn a_times_new_roman_the_pdf_does_not_embed_draws_the_glyphs_its_codes_name() {
for base_font in [
"TimesNewRomanPSMT",
"TimesNewRomanPS-BoldMT",
"TimesNewRomanPS-ItalicMT",
"TimesNewRomanPS-BoldItalicMT",
"TimesNewRoman",
"TimesNewRoman,Bold",
"TimesNewRoman,Italic",
"TimesNewRoman,BoldItalic",
"WFXLUF+TimesNewRoman,Bold",
] {
for mapped in [false, true] {
let (without, with) = without_and_with_unicode(Font { base_font, subtype: "CIDFontType2", mapped, to_unicode: false });
assert!(without == with, "{base_font} (CIDToGIDMap {}): the codes draw \"Low É\"", if mapped { "stream" } else { "/Identity" });
}
}
}
/// Only the faces of Arial and Times New Roman are read in that order: Arial Narrow, Arial Black,
/// Arial Unicode MS, Times and Times New Roman MT Std are other fonts, and a `CIDFontType0` font's
/// CIDs aren't TrueType glyph indexes.
#[test]
fn codes_of_other_fonts_are_not_read_in_the_macintosh_order() {
for (base_font, subtype) in [
("ArialNarrow", "CIDFontType2"),
("ArialNarrow-Bold", "CIDFontType2"),
("Arial-Black", "CIDFontType2"),
("ArialUnicodeMS", "CIDFontType2"),
("ArialMT", "CIDFontType0"),
("Times-Bold", "CIDFontType2"),
("TimesNewRomanMTStd", "CIDFontType2"),
("TimesNewRoman,Bold", "CIDFontType0"),
] {
let (without, with) = without_and_with_unicode(Font { base_font, subtype, mapped: false, to_unicode: false });
assert!(without != with, "{base_font} ({subtype}) is not read as Arial");
assert!(without != with, "{base_font} ({subtype}) is not read in the Macintosh order");
}
}
+2 -2
View File
@@ -794,8 +794,8 @@ milestone = "M2"
status = "partial"
commands = []
tools = []
evidence = ["crates/render/src/raster/tests.rs::huge_cid_width_ranges_terminate", "crates/render/src/raster/tests.rs::non_embedded_japanese_cid_fonts_draw_with_a_craft_fonts_face", "crates/render/src/raster/tests.rs::mincho_substitute_covers_half_width_katakana", "crates/render/src/raster/tests.rs::non_embedded_chinese_and_korean_cid_fonts_draw_with_an_installed_face", "crates/engine/src/tests.rs::installed_cjk_fonts_draw_in_the_viewer_but_not_in_an_export", "crates/render/src/text/tests.rs::identity_to_unicode_names_give_text", "crates/fonts/src/pdf/tests.rs::identity_to_unicode_names_read_codes_as_unicode", "crates/render/src/raster/tests.rs::a_soft_hyphen_a_substitute_lacks_draws_its_hyphen", "crates/render/src/raster/tests/non_embedded_arial.rs::an_arial_the_pdf_does_not_embed_draws_the_glyphs_its_codes_name", "crates/render/src/raster/tests/non_embedded_arial.rs::codes_of_other_fonts_are_not_read_in_arials_order"]
notes = "CID-to-Unicode tables are M2.4; a non-embedded Adobe-Japan1 font is drawn in a craft-fonts Japanese face (Mincho or Gothic by name, else by the descendant font descriptor's Serif flag; bold Gothic for a Bold name or a `/FontWeight` of 600 or more; BIZ UDMincho for Mincho, which covers half-width katakana) when built with craft-fonts; the desktop viewer can fall back to an installed CJK face for GB1, CNS1, Korea1 and Japan1, including GBK-EUC-H TrueType CID fonts without ToUnicode. Windows preserves installed SimSun, SimHei, KaiTi and FangSong families, including subset-prefixed Founder aliases. Combine thumbnails and accessibility figure previews use the same on-screen fallback. System faces are display-only, disabled by PDFCRAFT_SYSTEM_FONTS=0, and not used by export, printing, OCR or automation; machines without a candidate and web builds remain unsupported. A `/ToUnicode` given as the name `/Identity-H` or `/Identity-V` (WSCAD) reads codes as Unicode for selection, search and editing, without control characters. A non-embedded Identity font whose `/ToUnicode` gives a soft hyphen (U+00AD, as Windows exporters write Arial's hyphen) draws the standard substitute's hyphen (#5888). A non-embedded Arial (`CIDFontType2`; ArialMT, Arial-BoldMT, Arial,Bold and the other two faces) whose codes no Unicode route draws is read as glyph indexes of the author's Arial, whose first 258 glyphs follow the standard Macintosh order: the substitute draws each glyph by that name, .notdef when it has none (#5889, #5726). Its text still can't be selected, searched or copied without a `/ToUnicode`, Times New Roman, Courier New and other faces whose numbering isn't confirmed aren't read this way, and Arial glyphs past the first 258 (Cyrillic, Greek) and every other font's characters the substitute lacks still fall back to the CID taken as one of the substitute's glyph indexes, an unrelated glyph (#3529, #5726)"
evidence = ["crates/render/src/raster/tests.rs::huge_cid_width_ranges_terminate", "crates/render/src/raster/tests.rs::non_embedded_japanese_cid_fonts_draw_with_a_craft_fonts_face", "crates/render/src/raster/tests.rs::mincho_substitute_covers_half_width_katakana", "crates/render/src/raster/tests.rs::non_embedded_chinese_and_korean_cid_fonts_draw_with_an_installed_face", "crates/engine/src/tests.rs::installed_cjk_fonts_draw_in_the_viewer_but_not_in_an_export", "crates/render/src/text/tests.rs::identity_to_unicode_names_give_text", "crates/fonts/src/pdf/tests.rs::identity_to_unicode_names_read_codes_as_unicode", "crates/render/src/raster/tests.rs::a_soft_hyphen_a_substitute_lacks_draws_its_hyphen", "crates/render/src/raster/tests/non_embedded_arial.rs::an_arial_the_pdf_does_not_embed_draws_the_glyphs_its_codes_name", "crates/render/src/raster/tests/non_embedded_arial.rs::a_times_new_roman_the_pdf_does_not_embed_draws_the_glyphs_its_codes_name", "crates/render/src/raster/tests/non_embedded_arial.rs::codes_of_other_fonts_are_not_read_in_the_macintosh_order"]
notes = "CID-to-Unicode tables are M2.4; a non-embedded Adobe-Japan1 font is drawn in a craft-fonts Japanese face (Mincho or Gothic by name, else by the descendant font descriptor's Serif flag; bold Gothic for a Bold name or a `/FontWeight` of 600 or more; BIZ UDMincho for Mincho, which covers half-width katakana) when built with craft-fonts; the desktop viewer can fall back to an installed CJK face for GB1, CNS1, Korea1 and Japan1, including GBK-EUC-H TrueType CID fonts without ToUnicode. Windows preserves installed SimSun, SimHei, KaiTi and FangSong families, including subset-prefixed Founder aliases. Combine thumbnails and accessibility figure previews use the same on-screen fallback. System faces are display-only, disabled by PDFCRAFT_SYSTEM_FONTS=0, and not used by export, printing, OCR or automation; machines without a candidate and web builds remain unsupported. A `/ToUnicode` given as the name `/Identity-H` or `/Identity-V` (WSCAD) reads codes as Unicode for selection, search and editing, without control characters. A non-embedded Identity font whose `/ToUnicode` gives a soft hyphen (U+00AD, as Windows exporters write Arial's hyphen) draws the standard substitute's hyphen (#5888). A non-embedded Arial or Times New Roman (`CIDFontType2`; ArialMT, Arial-BoldMT, Arial,Bold, TimesNewRomanPSMT, TimesNewRoman,Bold and their other faces) whose codes no Unicode route draws is read as glyph indexes of the author's font, whose first 258 glyphs follow the standard Macintosh order: the substitute draws each glyph by that name, .notdef when it has none (#5889, #5726, #6449). Its text still can't be selected, searched or copied without a `/ToUnicode`, Courier New and other faces whose numbering isn't confirmed aren't read this way, and Arial and Times New Roman glyphs past the first 258 (Cyrillic, Greek) and every other font's characters the substitute lacks still fall back to the CID taken as one of the substitute's glyph indexes, an unrelated glyph (#3529, #5726)"
[[feature]]
id = "view.render-image-codecs"
+1 -1
View File
File diff suppressed because one or more lines are too long
+20 -15
View File
@@ -51,10 +51,10 @@ pub(crate) struct Type0Font {
/// such text as the code's Unicode value; the identity CMap the name resolves to maps codes
/// to CIDs only and gave no text at all.
identity_to_unicode: bool,
/// PdfCraft patch: an Arial the PDF doesn't embed, as a TrueType CID font (`CIDFontType2`)
/// whose CIDs aren't of an Adobe character collection. Its CIDToGIDMap gives glyph indexes
/// in the author's Arial, which numbers its first 258 glyphs in the standard Macintosh order
/// of the TrueType `post` table (#5889).
/// PdfCraft patch: an Arial or a Times New Roman the PDF doesn't embed, as a TrueType CID
/// font (`CIDFontType2`) whose CIDs aren't of an Adobe character collection. Its CIDToGIDMap
/// gives glyph indexes in the author's font, which numbers its first 258 glyphs in the
/// standard Macintosh order of the TrueType `post` table (#5889, #6449).
mac_glyph_order: bool,
}
@@ -168,7 +168,7 @@ impl Type0Font {
.is_some_and(|s| s.deref() == CID_FONT_TYPE2)
&& descendant_font
.get::<Name<'_>>(BASE_FONT)
.is_some_and(|n| is_arial(strip_subset_prefix(n.as_str())));
.is_some_and(|n| numbers_glyphs_in_mac_order(strip_subset_prefix(n.as_str())));
// Extract font flags from descriptor
let font_flags = font_descriptor
@@ -216,9 +216,10 @@ impl Type0Font {
return glyph;
}
// PdfCraft patch: the CID of an Arial the PDF doesn't embed names an Arial glyph, which
// the substitute draws by that name. Taken as the substitute's own glyph index it drew
// an unrelated glyph: "Low Power" as "@ck 'Dck Yf" (#5889).
// PdfCraft patch: the CID of an Arial or a Times New Roman the PDF doesn't embed names
// one of that font's glyphs, which the substitute draws by that name. Taken as the
// substitute's own glyph index it drew an unrelated glyph: "Low Power" as
// "@ck 'Dck Yf" (#5889), "Salarié(e) du régime" as "Salari²*g+f w't²i lo" (#6449).
if self.mac_glyph_order
&& let Some(glyph) = self.map_via_mac_glyph_name(cid)
{
@@ -334,7 +335,7 @@ impl Type0Font {
}
}
/// PdfCraft patch: the substitute's glyph for the Arial glyph that `cid` gives, found by
/// PdfCraft patch: the substitute's glyph for the author's glyph that `cid` gives, found by
/// that glyph's name in the standard Macintosh order. `None` past the 258 glyphs the order
/// names, and for a substitute that isn't a name-keyed CFF font (the standard substitutes
/// are); .notdef for a name the substitute has no glyph for.
@@ -631,17 +632,21 @@ fn is_variation_selector(c: char) -> bool {
}
/// PdfCraft patch: whether `name`, a `/BaseFont` without its subset tag, is one of the four
/// Arial faces as exporters name them: `ArialMT`, `Arial-BoldMT`, `Arial-ItalicMT`,
/// `Arial-BoldItalicMT`, or `Arial` followed by `,Bold`, `,Italic` or `,BoldItalic`. Arial
/// Narrow, Arial Black, Arial Unicode MS and Arial Rounded are other fonts, numbered their own
/// way. Letter case doesn't matter, `MT` included.
fn is_arial(name: &str) -> bool {
/// faces of Arial or Times New Roman as exporters name them: `ArialMT`, `Arial-BoldMT`,
/// `Arial-ItalicMT`, `Arial-BoldItalicMT`, `TimesNewRomanPSMT`, `TimesNewRomanPS-BoldMT` and so
/// on, or `Arial` or `TimesNewRoman` followed by `,Bold`, `,Italic` or `,BoldItalic`. Both
/// number their first 258 glyphs in the standard Macintosh order. Arial Narrow, Arial Black,
/// Arial Unicode MS and Arial Rounded are other fonts, numbered their own way. Letter case
/// doesn't matter, `MT` included.
fn numbers_glyphs_in_mac_order(name: &str) -> bool {
let (family, style) = name.split_once([',', '-', ' ']).unwrap_or((name, ""));
let style: String = style
.chars()
.filter(|c| !matches!(c, ',' | '-' | ' '))
.collect();
without_mt(family).eq_ignore_ascii_case("Arial")
["Arial", "TimesNewRoman", "TimesNewRomanPS"]
.iter()
.any(|f| without_mt(family).eq_ignore_ascii_case(f))
&& ["", "Regular", "Bold", "Italic", "BoldItalic"]
.iter()
.any(|s| without_mt(&style).eq_ignore_ascii_case(s))