*/
var kDisableFonts = false;
+
/**
* Hold a map of decoded fonts and of the standard fourteen Type1 fonts and
* their acronyms.
* TODO Add the standard fourteen Type1 fonts list by default
* http://cgit.freedesktop.org/poppler/poppler/tree/poppler/GfxFont.cc#n65
*/
+
+var kScalePrecision = 100;
var Fonts = {
_active: null,
return this._active;
},
- set active(name) {
+ setActive: function fonts_setActive(name, size) {
this._active = this[name];
+ this.ctx.font = (size * kScalePrecision) + 'px "' + name + '"';
},
charsToUnicode: function fonts_chars2Unicode(chars) {
// Enter the translated string into the cache
return active.cache[chars] = str;
+ },
+
+ get ctx() {
+ delete this.ctx;
+ var ctx = document.createElement("canvas").getContext("2d");
+ ctx.scale(1 / kScalePrecision, 1);
+ return this.ctx = ctx;
+ },
+
+ measureText: function fonts_measureText(text) {
+ return this.ctx.measureText(text).width / kScalePrecision;
}
};
var glyph = glyphs[i];
var unicode = GlyphsUnicode[glyph.glyph];
if (!unicode) {
- if (glyph != ".notdef")
+ if (glyph.glyph != ".notdef")
warn(glyph + " does not have an entry in the glyphs unicode dictionary");
} else {
charstrings.push({
if (fontDescriptor && fontDescriptor.num) {
var fontDescriptor = this.xref.fetchIfRef(fontDescriptor);
fontName = fontDescriptor.get("FontName").name.replace("+", "_");
- Fonts.active = fontName;
+ Fonts.setActive(fontName, size);
}
if (!fontName) {
// TODO: fontDescriptor is not available, fallback to default font
this.current.fontSize = size;
this.ctx.font = this.current.fontSize + 'px sans-serif';
+ Fonts.setActive("sans-serif", this.current.fontSize);
return;
}
this.current.fontName = fontName;
this.current.fontSize = size;
- this.ctx.font = this.current.fontSize +'px "' + fontName + '", Symbol';
+ this.ctx.font = this.current.fontSize + 'px "' + this.current.fontName + '"';
},
setTextRenderingMode: function(mode) {
TODO("text rendering mode");
text = Fonts.charsToUnicode(text);
this.ctx.translate(this.current.x, -1 * this.current.y);
this.ctx.fillText(text, 0, 0);
-
- this.ctx.scale(0.05, 1);
- this.ctx.font = (this.current.fontSize * 20) + 'px "' + this.current.fontName + '", Symbol';
- this.current.x += this.ctx.measureText(text).width / 20;
- this.ctx.scale(1, 1);
+ this.current.x += Fonts.measureText(text);
}
this.ctx.restore();