From 832fc93aa4b882ff304a2c78d91418afbc0465fc Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 2 Jul 2024 22:38:10 +0200 Subject: [PATCH] Use vertical variant of a char when it's in a missing vertical font (bug 1905623) --- src/core/fonts.js | 8 +++++++ src/core/fonts_utils.js | 40 +++++++++++++++++++++++++++++++++++ test/pdfs/bug1905623.pdf.link | 1 + test/test_manifest.json | 10 +++++++++ 4 files changed, 59 insertions(+) create mode 100644 test/pdfs/bug1905623.pdf.link diff --git a/src/core/fonts.js b/src/core/fonts.js index 52994267da462..0301d49ad35e5 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -26,6 +26,7 @@ import { import { CFFCompiler, CFFParser } from "./cff_parser.js"; import { FontFlags, + getVerticalPresentationForm, MacStandardGlyphOrdering, normalizeFontName, recoverGlyphName, @@ -3366,6 +3367,13 @@ class Font { } } + if (this.missingFile && this.vertical && fontChar.length === 1) { + const vertical = getVerticalPresentationForm()[fontChar.charCodeAt(0)]; + if (vertical) { + fontChar = unicode = String.fromCharCode(vertical); + } + } + glyph = new Glyph( charcode, fontChar, diff --git a/src/core/fonts_utils.js b/src/core/fonts_utils.js index e5067d8e6ca8f..20c8e87e81905 100644 --- a/src/core/fonts_utils.js +++ b/src/core/fonts_utils.js @@ -15,6 +15,7 @@ import { getEncoding, StandardEncoding } from "./encodings.js"; import { getGlyphsUnicode } from "./glyphlist.js"; +import { getLookupTableFactory } from "./core_utils.js"; import { getUnicodeForGlyph } from "./unicode.js"; import { info } from "../shared/util.js"; @@ -168,8 +169,47 @@ function normalizeFontName(name) { return name.replaceAll(/[,_]/g, "-").replaceAll(/\s/g, ""); } +const getVerticalPresentationForm = getLookupTableFactory(t => { + // This table has been found at + // https://searchfox.org/mozilla-central/rev/cbdfa503a87597b20719aae5f6a1efccd6cb3b7b/gfx/thebes/gfxHarfBuzzShaper.cpp#251-294 + t[0x2013] = 0xfe32; // EN DASH + t[0x2014] = 0xfe31; // EM DASH + t[0x2025] = 0xfe30; // TWO DOT LEADER + t[0x2026] = 0xfe19; // HORIZONTAL ELLIPSIS + t[0x3001] = 0xfe11; // IDEOGRAPHIC COMMA + t[0x3002] = 0xfe12; // IDEOGRAPHIC FULL STOP + t[0x3008] = 0xfe3f; // LEFT ANGLE BRACKET + t[0x3009] = 0xfe40; // RIGHT ANGLE BRACKET + t[0x300a] = 0xfe3d; // LEFT DOUBLE ANGLE BRACKET + t[0x300b] = 0xfe3e; // RIGHT DOUBLE ANGLE BRACKET + t[0x300c] = 0xfe41; // LEFT CORNER BRACKET + t[0x300d] = 0xfe42; // RIGHT CORNER BRACKET + t[0x300e] = 0xfe43; // LEFT WHITE CORNER BRACKET + t[0x300f] = 0xfe44; // RIGHT WHITE CORNER BRACKET + t[0x3010] = 0xfe3b; // LEFT BLACK LENTICULAR BRACKET + t[0x3011] = 0xfe3c; // RIGHT BLACK LENTICULAR BRACKET + t[0x3014] = 0xfe39; // LEFT TORTOISE SHELL BRACKET + t[0x3015] = 0xfe3a; // RIGHT TORTOISE SHELL BRACKET + t[0x3016] = 0xfe17; // LEFT WHITE LENTICULAR BRACKET + t[0x3017] = 0xfe18; // RIGHT WHITE LENTICULAR BRACKET + t[0xfe4f] = 0xfe34; // WAVY LOW LINE + t[0xff01] = 0xfe15; // FULLWIDTH EXCLAMATION MARK + t[0xff08] = 0xfe35; // FULLWIDTH LEFT PARENTHESIS + t[0xff09] = 0xfe36; // FULLWIDTH RIGHT PARENTHESIS + t[0xff0c] = 0xfe10; // FULLWIDTH COMMA + t[0xff1a] = 0xfe13; // FULLWIDTH COLON + t[0xff1b] = 0xfe14; // FULLWIDTH SEMICOLON + t[0xff1f] = 0xfe16; // FULLWIDTH QUESTION MARK + t[0xff3b] = 0xfe47; // FULLWIDTH LEFT SQUARE BRACKET + t[0xff3d] = 0xfe48; // FULLWIDTH RIGHT SQUARE BRACKET + t[0xff3f] = 0xfe33; // FULLWIDTH LOW LINE + t[0xff5b] = 0xfe37; // FULLWIDTH LEFT CURLY BRACKET + t[0xff5d] = 0xfe38; // FULLWIDTH RIGHT CURLY BRACKET +}); + export { FontFlags, + getVerticalPresentationForm, MacStandardGlyphOrdering, normalizeFontName, recoverGlyphName, diff --git a/test/pdfs/bug1905623.pdf.link b/test/pdfs/bug1905623.pdf.link new file mode 100644 index 0000000000000..0c249d74b4846 --- /dev/null +++ b/test/pdfs/bug1905623.pdf.link @@ -0,0 +1 @@ +https://bugzilla.mozilla.org/attachment.cgi?id=9410429 diff --git a/test/test_manifest.json b/test/test_manifest.json index a8fedcd4b1318..78c4d8f592b83 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -10113,5 +10113,15 @@ "rounds": 1, "link": true, "type": "eq" + }, + { + "id": "bug1905623", + "file": "pdfs/bug1905623.pdf", + "md5": "6c180a4353bda6b3cb0c693c5e5b32c4", + "rounds": 1, + "link": true, + "firstPage": 2, + "lastPage": 2, + "type": "eq" } ]