1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Add a fake canvas for scaling fonts to improve perfs

This commit is contained in:
Vivien Nicolas 2011-06-28 18:24:16 +02:00
parent 63e1601464
commit 80f650b6bb
2 changed files with 21 additions and 9 deletions

11
pdf.js
View file

@ -2797,19 +2797,20 @@ var CanvasGraphics = (function() {
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");
@ -2851,11 +2852,7 @@ var CanvasGraphics = (function() {
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();