Merge pull request #7078 from Snuffleupagus/refactor-toFontChar-without-file
Refactor the building of `toFontChar` for non-embedded fonts
This commit is contained in:
commit
13d440df61
@ -462,7 +462,7 @@ var ProblematicCharRanges = new Int32Array([
|
|||||||
*/
|
*/
|
||||||
var Font = (function FontClosure() {
|
var Font = (function FontClosure() {
|
||||||
function Font(name, file, properties) {
|
function Font(name, file, properties) {
|
||||||
var charCode, glyphName, unicode, fontChar;
|
var charCode, glyphName, unicode;
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.loadedName = properties.loadedName;
|
this.loadedName = properties.loadedName;
|
||||||
@ -568,53 +568,19 @@ var Font = (function FontClosure() {
|
|||||||
this.toFontChar = map;
|
this.toFontChar = map;
|
||||||
this.toUnicode = new ToUnicodeMap(map);
|
this.toUnicode = new ToUnicodeMap(map);
|
||||||
} else if (/Symbol/i.test(fontName)) {
|
} else if (/Symbol/i.test(fontName)) {
|
||||||
var symbols = SymbolSetEncoding;
|
this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
|
||||||
glyphsUnicodeMap = getGlyphsUnicode();
|
properties.differences);
|
||||||
for (charCode in symbols) {
|
|
||||||
fontChar = glyphsUnicodeMap[symbols[charCode]];
|
|
||||||
if (!fontChar) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
this.toFontChar[charCode] = fontChar;
|
|
||||||
}
|
|
||||||
for (charCode in properties.differences) {
|
|
||||||
fontChar = glyphsUnicodeMap[properties.differences[charCode]];
|
|
||||||
if (!fontChar) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
this.toFontChar[charCode] = fontChar;
|
|
||||||
}
|
|
||||||
} else if (/Dingbats/i.test(fontName)) {
|
} else if (/Dingbats/i.test(fontName)) {
|
||||||
glyphsUnicodeMap = getDingbatsGlyphsUnicode();
|
|
||||||
if (/Wingdings/i.test(name)) {
|
if (/Wingdings/i.test(name)) {
|
||||||
warn('Wingdings font without embedded font file, ' +
|
warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
|
||||||
'falling back to the ZapfDingbats encoding.');
|
|
||||||
}
|
|
||||||
var dingbats = ZapfDingbatsEncoding;
|
|
||||||
for (charCode in dingbats) {
|
|
||||||
fontChar = glyphsUnicodeMap[dingbats[charCode]];
|
|
||||||
if (!fontChar) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
this.toFontChar[charCode] = fontChar;
|
|
||||||
}
|
|
||||||
for (charCode in properties.differences) {
|
|
||||||
fontChar = glyphsUnicodeMap[properties.differences[charCode]];
|
|
||||||
if (!fontChar) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
this.toFontChar[charCode] = fontChar;
|
|
||||||
}
|
}
|
||||||
|
this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
|
||||||
|
getDingbatsGlyphsUnicode(),
|
||||||
|
properties.differences);
|
||||||
} else if (isStandardFont) {
|
} else if (isStandardFont) {
|
||||||
glyphsUnicodeMap = getGlyphsUnicode();
|
this.toFontChar = buildToFontChar(properties.defaultEncoding,
|
||||||
for (charCode in properties.defaultEncoding) {
|
getGlyphsUnicode(),
|
||||||
glyphName = (properties.differences[charCode] ||
|
properties.differences);
|
||||||
properties.defaultEncoding[charCode]);
|
|
||||||
unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
|
|
||||||
if (unicode !== -1) {
|
|
||||||
this.toFontChar[charCode] = unicode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
glyphsUnicodeMap = getGlyphsUnicode();
|
glyphsUnicodeMap = getGlyphsUnicode();
|
||||||
this.toUnicode.forEach(function(charCode, unicodeCharCode) {
|
this.toUnicode.forEach(function(charCode, unicodeCharCode) {
|
||||||
@ -767,6 +733,23 @@ var Font = (function FontClosure() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
|
||||||
|
var toFontChar = [], unicode;
|
||||||
|
for (var i = 0, ii = encoding.length; i < ii; i++) {
|
||||||
|
unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
|
||||||
|
if (unicode !== -1) {
|
||||||
|
toFontChar[i] = unicode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var charCode in differences) {
|
||||||
|
unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
|
||||||
|
if (unicode !== -1) {
|
||||||
|
toFontChar[+charCode] = unicode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toFontChar;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function for |adjustMapping|.
|
* Helper function for |adjustMapping|.
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
|
Loading…
Reference in New Issue
Block a user