Merge pull request #1051 from notmasteryet/fonts-3
Using the encoding instead of predefined MacRoman in TrueType fonts;
This commit is contained in:
commit
be2f973be8
@ -557,7 +557,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
(fontObj.bold ? 'bold' : 'normal');
|
(fontObj.bold ? 'bold' : 'normal');
|
||||||
|
|
||||||
var italic = fontObj.italic ? 'italic' : '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 typeface = '"' + name + '", ' + serif;
|
||||||
var rule = italic + ' ' + bold + ' ' + size + 'px ' + typeface;
|
var rule = italic + ' ' + bold + ' ' + size + 'px ' + typeface;
|
||||||
this.ctx.font = rule;
|
this.ctx.font = rule;
|
||||||
|
@ -758,10 +758,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
baseFontName = baseFontName.name.replace(/[,_]/g, '-');
|
baseFontName = baseFontName.name.replace(/[,_]/g, '-');
|
||||||
var metrics = this.getBaseFontMetrics(baseFontName);
|
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 = {
|
var properties = {
|
||||||
type: type.name,
|
type: type.name,
|
||||||
widths: metrics.widths,
|
widths: metrics.widths,
|
||||||
defaultWidth: metrics.defaultWidth,
|
defaultWidth: metrics.defaultWidth,
|
||||||
|
flags: flags,
|
||||||
firstChar: 0,
|
firstChar: 0,
|
||||||
lastChar: maxCharIndex
|
lastChar: maxCharIndex
|
||||||
};
|
};
|
||||||
|
53
src/fonts.js
53
src/fonts.js
@ -386,6 +386,10 @@ var serifFonts = {
|
|||||||
'Wide Latin': true, 'Windsor': true, 'XITS': true
|
'Wide Latin': true, 'Windsor': true, 'XITS': true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var symbolsFonts = {
|
||||||
|
'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
|
||||||
|
};
|
||||||
|
|
||||||
var FontLoader = {
|
var FontLoader = {
|
||||||
listeningForFontLoad: false,
|
listeningForFontLoad: false,
|
||||||
|
|
||||||
@ -742,7 +746,8 @@ var Font = (function FontClosure() {
|
|||||||
var names = name.split('+');
|
var names = name.split('+');
|
||||||
names = names.length > 1 ? names[1] : names[0];
|
names = names.length > 1 ? names[1] : names[0];
|
||||||
names = names.split(/[-,_]/g)[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;
|
var type = properties.type;
|
||||||
this.type = 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
|
// 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.
|
// to avoid the cost of waiting for it be be loaded by the platform.
|
||||||
if (properties.ignore) {
|
if (properties.ignore) {
|
||||||
this.loadedName = this.serif ? 'serif' : 'sans-serif';
|
this.loadedName = this.isSerifFont ? 'serif' : 'sans-serif';
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -830,7 +835,6 @@ var Font = (function FontClosure() {
|
|||||||
this.widthMultiplier = !properties.fontMatrix ? 1.0 :
|
this.widthMultiplier = !properties.fontMatrix ? 1.0 :
|
||||||
1.0 / properties.fontMatrix[0];
|
1.0 / properties.fontMatrix[0];
|
||||||
this.encoding = properties.baseEncoding;
|
this.encoding = properties.baseEncoding;
|
||||||
this.hasShortCmap = properties.hasShortCmap;
|
|
||||||
this.loadedName = getUniqueName();
|
this.loadedName = getUniqueName();
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
};
|
};
|
||||||
@ -1800,7 +1804,32 @@ var Font = (function FontClosure() {
|
|||||||
this.useToUnicode = true;
|
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
|
// remove glyph references outside range of avaialable glyphs
|
||||||
for (var i = 0, ii = ids.length; i < ii; i++) {
|
for (var i = 0, ii = ids.length; i < ii; i++) {
|
||||||
@ -2184,19 +2213,15 @@ var Font = (function FontClosure() {
|
|||||||
unicode = GlyphsUnicode[glyphName] || charcode;
|
unicode = GlyphsUnicode[glyphName] || charcode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!this.hasEncoding) {
|
if (!this.hasEncoding || this.isSymbolicFont) {
|
||||||
unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode;
|
unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.hasShortCmap && false) {
|
|
||||||
var j = Encodings.MacRomanEncoding.indexOf(glyphName);
|
// MacRoman encoding address by re-encoding the cmap table
|
||||||
unicode = j >= 0 ? j :
|
unicode = glyphName in GlyphsUnicode ?
|
||||||
this.glyphNameMap[glyphName];
|
GlyphsUnicode[glyphName] :
|
||||||
} else {
|
this.glyphNameMap[glyphName];
|
||||||
unicode = glyphName in GlyphsUnicode ?
|
|
||||||
GlyphsUnicode[glyphName] :
|
|
||||||
this.glyphNameMap[glyphName];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
warn('Unsupported font type: ' + this.type);
|
warn('Unsupported font type: ' + this.type);
|
||||||
|
Loading…
Reference in New Issue
Block a user