diff --git a/src/canvas.js b/src/canvas.js index 3fd55b45d..0ad02dc24 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -557,7 +557,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { (fontObj.bold ? 'bold' : 'normal'); var italic = fontObj.italic ? 'italic' : 'normal'; - var serif = fontObj.serif ? 'serif' : 'sans-serif'; + var serif = fontObj.isSerifFont ? 'serif' : 'sans-serif'; var typeface = '"' + name + '", ' + serif; var rule = italic + ' ' + bold + ' ' + size + 'px ' + typeface; this.ctx.font = rule; diff --git a/src/evaluator.js b/src/evaluator.js index 198659201..60ab66560 100644 --- a/src/evaluator.js +++ b/src/evaluator.js @@ -758,10 +758,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { baseFontName = baseFontName.name.replace(/[,_]/g, '-'); var metrics = this.getBaseFontMetrics(baseFontName); + // Simulating descriptor flags attribute + var fontNameWoStyle = baseFontName.split('-')[0]; + var flags = (serifFonts[fontNameWoStyle] || + (fontNameWoStyle.search(/serif/gi) != -1) ? 2 : 0) | + (symbolsFonts[fontNameWoStyle] ? 4 : 32); + var properties = { type: type.name, widths: metrics.widths, defaultWidth: metrics.defaultWidth, + flags: flags, firstChar: 0, lastChar: maxCharIndex }; diff --git a/src/fonts.js b/src/fonts.js index 1b959d6c2..329d7ad77 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -386,6 +386,10 @@ var serifFonts = { 'Wide Latin': true, 'Windsor': true, 'XITS': true }; +var symbolsFonts = { + 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true +}; + var FontLoader = { listeningForFontLoad: false, @@ -742,7 +746,8 @@ var Font = (function FontClosure() { var names = name.split('+'); names = names.length > 1 ? names[1] : names[0]; names = names.split(/[-,_]/g)[0]; - this.serif = serifFonts[names] || (name.search(/serif/gi) != -1); + this.isSerifFont = !!(properties.flags & 2); + this.isSymbolicFont = !!(properties.flags & 4); var type = properties.type; this.type = type; @@ -750,7 +755,7 @@ var Font = (function FontClosure() { // If the font is to be ignored, register it like an already loaded font // to avoid the cost of waiting for it be be loaded by the platform. if (properties.ignore) { - this.loadedName = this.serif ? 'serif' : 'sans-serif'; + this.loadedName = this.isSerifFont ? 'serif' : 'sans-serif'; this.loading = false; return; } @@ -830,7 +835,6 @@ var Font = (function FontClosure() { this.widthMultiplier = !properties.fontMatrix ? 1.0 : 1.0 / properties.fontMatrix[0]; this.encoding = properties.baseEncoding; - this.hasShortCmap = properties.hasShortCmap; this.loadedName = getUniqueName(); this.loading = true; }; @@ -1800,7 +1804,32 @@ var Font = (function FontClosure() { this.useToUnicode = true; } } - properties.hasShortCmap = hasShortCmap; + + if (hasShortCmap && this.hasEncoding && !this.isSymbolicFont) { + // Re-encode short map encoding to unicode -- that simplifies the + // resolution of MacRoman encoded glyphs logic for TrueType fonts: + // copying all characters to private use area, all mapping all known + // glyphs to the unicodes. The glyphs and ids arrays will grow. + var usedUnicodes = []; + for (var i = 0, ii = glyphs.length; i < ii; i++) { + var code = glyphs[i].unicode; + glyphs[i].unicode += kCmapGlyphOffset; + + var glyphName = properties.baseEncoding[code]; + if (glyphName in GlyphsUnicode) { + var unicode = GlyphsUnicode[glyphName]; + if (unicode in usedUnicodes) + continue; + + usedUnicodes[unicode] = true; + glyphs.push({ + unicode: unicode, + code: glyphs[i].code + }); + ids.push(ids[i]); + } + } + } // remove glyph references outside range of avaialable glyphs for (var i = 0, ii = ids.length; i < ii; i++) { @@ -2184,19 +2213,15 @@ var Font = (function FontClosure() { unicode = GlyphsUnicode[glyphName] || charcode; break; } - if (!this.hasEncoding) { + if (!this.hasEncoding || this.isSymbolicFont) { unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode; break; } - if (this.hasShortCmap && false) { - var j = Encodings.MacRomanEncoding.indexOf(glyphName); - unicode = j >= 0 ? j : - this.glyphNameMap[glyphName]; - } else { - unicode = glyphName in GlyphsUnicode ? - GlyphsUnicode[glyphName] : - this.glyphNameMap[glyphName]; - } + + // MacRoman encoding address by re-encoding the cmap table + unicode = glyphName in GlyphsUnicode ? + GlyphsUnicode[glyphName] : + this.glyphNameMap[glyphName]; break; default: warn('Unsupported font type: ' + this.type);