Skip to content

Commit

Permalink
Use vertical variant of a char when it's in a missing vertical font (…
Browse files Browse the repository at this point in the history
…bug 1905623)
  • Loading branch information
calixteman committed Jul 2, 2024
1 parent ccad2f8 commit 37c55f8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/core/core_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,50 @@ function getSizeInBytes(x) {
return Math.ceil(Math.ceil(Math.log2(1 + x)) / 8);
}

function getVerticalPresentationForm() {
return getLookupTableFactory(lookup => {
for (const [key, value] of [
// This table has been found at
// https://searchfox.org/mozilla-central/rev/cbdfa503a87597b20719aae5f6a1efccd6cb3b7b/gfx/thebes/gfxHarfBuzzShaper.cpp#251-294
[0x2013, 0xfe32], // EN DASH
[0x2014, 0xfe31], // EM DASH
[0x2025, 0xfe30], // TWO DOT LEADER
[0x2026, 0xfe19], // HORIZONTAL ELLIPSIS
[0x3001, 0xfe11], // IDEOGRAPHIC COMMA
[0x3002, 0xfe12], // IDEOGRAPHIC FULL STOP
[0x3008, 0xfe3f], // LEFT ANGLE BRACKET
[0x3009, 0xfe40], // RIGHT ANGLE BRACKET
[0x300a, 0xfe3d], // LEFT DOUBLE ANGLE BRACKET
[0x300b, 0xfe3e], // RIGHT DOUBLE ANGLE BRACKET
[0x300c, 0xfe41], // LEFT CORNER BRACKET
[0x300d, 0xfe42], // RIGHT CORNER BRACKET
[0x300e, 0xfe43], // LEFT WHITE CORNER BRACKET
[0x300f, 0xfe44], // RIGHT WHITE CORNER BRACKET
[0x3010, 0xfe3b], // LEFT BLACK LENTICULAR BRACKET
[0x3011, 0xfe3c], // RIGHT BLACK LENTICULAR BRACKET
[0x3014, 0xfe39], // LEFT TORTOISE SHELL BRACKET
[0x3015, 0xfe3a], // RIGHT TORTOISE SHELL BRACKET
[0x3016, 0xfe17], // LEFT WHITE LENTICULAR BRACKET
[0x3017, 0xfe18], // RIGHT WHITE LENTICULAR BRACKET
[0xfe4f, 0xfe34], // WAVY LOW LINE
[0xff01, 0xfe15], // FULLWIDTH EXCLAMATION MARK
[0xff08, 0xfe35], // FULLWIDTH LEFT PARENTHESIS
[0xff09, 0xfe36], // FULLWIDTH RIGHT PARENTHESIS
[0xff0c, 0xfe10], // FULLWIDTH COMMA
[0xff1a, 0xfe13], // FULLWIDTH COLON
[0xff1b, 0xfe14], // FULLWIDTH SEMICOLON
[0xff1f, 0xfe16], // FULLWIDTH QUESTION MARK
[0xff3b, 0xfe47], // FULLWIDTH LEFT SQUARE BRACKET
[0xff3d, 0xfe48], // FULLWIDTH RIGHT SQUARE BRACKET
[0xff3f, 0xfe33], // FULLWIDTH LOW LINE
[0xff5b, 0xfe37], // FULLWIDTH LEFT CURLY BRACKET
[0xff5d, 0xfe38],
]) {
lookup[key] = value;
}
})();
}

export {
arrayBuffersToBytes,
codePointIter,
Expand All @@ -682,6 +726,7 @@ export {
getNewAnnotationsMap,
getRotationMatrix,
getSizeInBytes,
getVerticalPresentationForm,
isAscii,
isBooleanArray,
isNumberArray,
Expand Down
9 changes: 8 additions & 1 deletion src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ import {
getSupplementalGlyphMapForArialBlack,
getSupplementalGlyphMapForCalibri,
} from "./standard_fonts.js";
import { getVerticalPresentationForm, readUint32 } from "./core_utils.js";
import { IdentityToUnicodeMap, ToUnicodeMap } from "./to_unicode_map.js";
import { CFFFont } from "./cff_font.js";
import { FontRendererFactory } from "./font_renderer.js";
import { getFontBasicMetrics } from "./metrics.js";
import { GlyfTable } from "./glyf.js";
import { IdentityCMap } from "./cmap.js";
import { OpenTypeFileBuilder } from "./opentype_file_builder.js";
import { readUint32 } from "./core_utils.js";
import { Stream } from "./stream.js";
import { Type1Font } from "./type1_font.js";

Expand Down Expand Up @@ -3366,6 +3366,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,
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/bug1905623.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9410429
10 changes: 10 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]

0 comments on commit 37c55f8

Please sign in to comment.