From e3223b68fce739418bcd7280b9b820c3b8e9ca93 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 18 Sep 2021 12:39:48 +0200 Subject: [PATCH] Extract some of the glyphMap handling, for non-embedded composite standard fonts, into a helper function This reduces some unnecessary duplication, since we currently have essentially the same code in a handful of places in the `Font.fallbackToSystemFont`-method. --- src/core/fonts.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/core/fonts.js b/src/core/fonts.js index 5a48bbe50..9dd9d3db3 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -376,6 +376,12 @@ function getFontFileType(file, { type, subtype, composite }) { return [fileType, fileSubtype]; } +function applyStandardFontGlyphMap(map, glyphMap) { + for (const charCode in glyphMap) { + map[+charCode] = glyphMap[charCode]; + } +} + function buildToFontChar(encoding, glyphsUnicodeMap, differences) { const toFontChar = []; let unicode; @@ -1052,26 +1058,16 @@ class Font { type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-") ) { - const GlyphMapForStandardFonts = getGlyphMapForStandardFonts(), - cidToGidMap = properties.cidToGidMap; + const cidToGidMap = properties.cidToGidMap; // Standard fonts might be embedded as CID font without glyph mapping. // Building one based on GlyphMapForStandardFonts. const map = []; - for (const charCode in GlyphMapForStandardFonts) { - map[+charCode] = GlyphMapForStandardFonts[charCode]; - } + applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts()); + if (/Arial-?Black/i.test(name)) { - const SupplementalGlyphMapForArialBlack = - getSupplementalGlyphMapForArialBlack(); - for (const charCode in SupplementalGlyphMapForArialBlack) { - map[+charCode] = SupplementalGlyphMapForArialBlack[charCode]; - } + applyStandardFontGlyphMap(map, getSupplementalGlyphMapForArialBlack()); } else if (/Calibri/i.test(name)) { - const SupplementalGlyphMapForCalibri = - getSupplementalGlyphMapForCalibri(); - for (const charCode in SupplementalGlyphMapForCalibri) { - map[+charCode] = SupplementalGlyphMapForCalibri[charCode]; - } + applyStandardFontGlyphMap(map, getSupplementalGlyphMapForCalibri()); } // Always update the glyph mapping with the `cidToGidMap` when it exists @@ -1158,10 +1154,7 @@ class Font { if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) { if (/Verdana/i.test(name)) { // Fixes issue11242_reduced.pdf - const GlyphMapForStandardFonts = getGlyphMapForStandardFonts(); - for (const charCode in GlyphMapForStandardFonts) { - map[+charCode] = GlyphMapForStandardFonts[charCode]; - } + applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts()); } } this.toFontChar = map;