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