Fixing defaultWidth; variables names
This commit is contained in:
parent
1347db797c
commit
10a2fa66c2
33
fonts.js
33
fonts.js
@ -472,6 +472,7 @@ var Font = (function Font() {
|
||||
this.data = data;
|
||||
this.type = properties.type;
|
||||
this.textMatrix = properties.textMatrix;
|
||||
this.defaultWidth = properties.defaultWidth;
|
||||
this.loadedName = getUniqueName();
|
||||
this.composite = properties.composite;
|
||||
this.loading = true;
|
||||
@ -1298,13 +1299,13 @@ var Font = (function Font() {
|
||||
|
||||
charsToGlyphs: function fonts_chars2Glyphs(chars) {
|
||||
var charsCache = this.charsCache;
|
||||
var str;
|
||||
var glyphs;
|
||||
|
||||
// if we translated this string before, just grab it from the cache
|
||||
if (charsCache) {
|
||||
str = charsCache[chars];
|
||||
if (str)
|
||||
return str;
|
||||
glyphs = charsCache[chars];
|
||||
if (glyphs)
|
||||
return glyphs;
|
||||
}
|
||||
|
||||
// lazily create the translation cache
|
||||
@ -1315,7 +1316,8 @@ var Font = (function Font() {
|
||||
var encoding = this.encoding;
|
||||
if (!encoding)
|
||||
return chars;
|
||||
var glyphs = [];
|
||||
|
||||
glyphs = [];
|
||||
|
||||
if (this.composite) {
|
||||
// composite fonts have multi-byte strings convert the string from
|
||||
@ -1326,23 +1328,28 @@ var Font = (function Font() {
|
||||
// loop should never end on the last byte
|
||||
for (var i = 0; i < length; i++) {
|
||||
var charcode = int16([chars.charCodeAt(i++), chars.charCodeAt(i)]);
|
||||
var unicode = encoding[charcode];
|
||||
if ('undefined' == typeof(unicode)) {
|
||||
var glyph = encoding[charcode];
|
||||
if ('undefined' == typeof(glyph)) {
|
||||
warn('Unencoded charcode ' + charcode);
|
||||
unicode = { unicode: charcode };
|
||||
glyph = { unicode: charcode };
|
||||
}
|
||||
glyphs.push(unicode);
|
||||
glyphs.push(glyph);
|
||||
// placing null after each word break charcode (ASCII SPACE)
|
||||
if (charcode == 0x20)
|
||||
glyphs.push(null);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var i = 0; i < chars.length; ++i) {
|
||||
var charcode = chars.charCodeAt(i);
|
||||
var unicode = encoding[charcode];
|
||||
if ('undefined' == typeof(unicode)) {
|
||||
var glyph = encoding[charcode];
|
||||
if ('undefined' == typeof(glyph)) {
|
||||
warn('Unencoded charcode ' + charcode);
|
||||
unicode = { unicode: charcode };
|
||||
glyph = { unicode: charcode };
|
||||
}
|
||||
glyphs.push(unicode);
|
||||
glyphs.push(glyph);
|
||||
if (charcode == 0x20)
|
||||
glyphs.push(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
15
pdf.js
15
pdf.js
@ -4294,7 +4294,6 @@ var PartialEvaluator = (function() {
|
||||
};
|
||||
}
|
||||
} else if (type == 'CIDFontType0') {
|
||||
encoding = xref.fetchIfRef(dict.get('Encoding'));
|
||||
if (IsName(encoding)) {
|
||||
// Encoding is a predefined CMap
|
||||
if (encoding.name == 'Identity-H') {
|
||||
@ -4521,8 +4520,7 @@ var PartialEvaluator = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO implement default widths for standard fonts metrics
|
||||
var defaultWidth = 1000;
|
||||
var defaultWidth = 0;
|
||||
var widths = Metrics[stdFontMap[baseFontName] || baseFontName];
|
||||
if (IsNum(widths)) {
|
||||
defaultWidth = widths;
|
||||
@ -4994,6 +4992,12 @@ var CanvasGraphics = (function() {
|
||||
var width = 0;
|
||||
for (var i = 0; i < glyphs.length; i++) {
|
||||
var glyph = glyphs[i];
|
||||
if (glyph === null) {
|
||||
// word break
|
||||
width += wordSpacing;
|
||||
continue;
|
||||
}
|
||||
|
||||
var unicode = glyph.unicode;
|
||||
var char = unicode >= 0x10000 ?
|
||||
String.fromCharCode(0xD800 | ((unicode - 0x10000) >> 10),
|
||||
@ -5001,11 +5005,8 @@ var CanvasGraphics = (function() {
|
||||
|
||||
var charWidth = (glyph.width || defaultCharWidth) * fontSize * 0.001;
|
||||
charWidth += charSpacing;
|
||||
if (unicode == 32)
|
||||
charWidth += wordSpacing;
|
||||
|
||||
ctx.fillText(char, 0, 0);
|
||||
ctx.translate(charWidth, 0);
|
||||
ctx.fillText(char, width, 0);
|
||||
width += charWidth;
|
||||
}
|
||||
current.x += width;
|
||||
|
Loading…
Reference in New Issue
Block a user