Resolve the char->glyphs mapping issue
This commit is contained in:
parent
2e87e8ca83
commit
3dbfde89a3
@ -31,7 +31,7 @@ var fontCount = 0;
|
||||
var Fonts = {
|
||||
_active: null,
|
||||
get active() {
|
||||
return this._active || { encoding: {} };
|
||||
return this._active || { encoding: [] };
|
||||
},
|
||||
|
||||
set active(aName) {
|
||||
|
11
pdf.js
11
pdf.js
@ -795,7 +795,6 @@ var Lexer = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
x = Fonts.unicodeFromCode(x);
|
||||
str += String.fromCharCode(x);
|
||||
break;
|
||||
case '\r':
|
||||
@ -811,8 +810,7 @@ var Lexer = (function() {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
var unicode = Fonts.unicodeFromCode(ch.charCodeAt(0));
|
||||
str += String.fromCharCode(unicode);
|
||||
str += ch;
|
||||
break;
|
||||
}
|
||||
} while (!done);
|
||||
@ -2054,7 +2052,12 @@ var CanvasGraphics = (function() {
|
||||
this.ctx.scale(1, -1);
|
||||
this.ctx.transform.apply(this.ctx, this.current.textMatrix);
|
||||
|
||||
this.ctx.fillText(text, this.current.x, this.current.y);
|
||||
// Replace characters code by glyphs code
|
||||
var glyphs = [];
|
||||
for (var i = 0; i < text.length; i++)
|
||||
glyphs[i] = String.fromCharCode(Fonts.unicodeFromCode(text[i].charCodeAt(0)));
|
||||
|
||||
this.ctx.fillText(glyphs.join(""), this.current.x, this.current.y);
|
||||
this.current.x += this.ctx.measureText(text).width;
|
||||
|
||||
this.ctx.restore();
|
||||
|
19
test.js
19
test.js
@ -1,7 +1,7 @@
|
||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- /
|
||||
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
||||
|
||||
var pdfDocument, canvas, pageDisplay, pageNum, pageTimeout;
|
||||
var pdfDocument, canvas, pageDisplay, pageNum, pageInterval;
|
||||
function load() {
|
||||
canvas = document.getElementById("canvas");
|
||||
canvas.mozOpaque = true;
|
||||
@ -48,7 +48,7 @@ function gotoPage(num) {
|
||||
|
||||
function displayPage(num) {
|
||||
if (pageNum != num)
|
||||
window.clearTimeout(pageTimeout);
|
||||
window.clearTimeout(pageInterval);
|
||||
|
||||
document.getElementById("pageNumber").value = num;
|
||||
|
||||
@ -57,7 +57,6 @@ function displayPage(num) {
|
||||
var page = pdfDocument.getPage(pageNum = num);
|
||||
|
||||
var t1 = Date.now();
|
||||
|
||||
var ctx = canvas.getContext("2d");
|
||||
ctx.save();
|
||||
ctx.fillStyle = "rgb(255, 255, 255)";
|
||||
@ -73,17 +72,21 @@ function displayPage(num) {
|
||||
page.compile(gfx, fonts);
|
||||
var t2 = Date.now();
|
||||
|
||||
var interval = setInterval(function() {
|
||||
// FIXME This need to be replaced by an event
|
||||
pageInterval = setInterval(function() {
|
||||
for (var i = 0; i < fonts.length; i++) {
|
||||
if (fonts[i].loading)
|
||||
return;
|
||||
}
|
||||
|
||||
page.display(gfx);
|
||||
var t3 = Date.now();
|
||||
|
||||
clearInterval(pageInterval);
|
||||
page.display(gfx);
|
||||
|
||||
var t4 = Date.now();
|
||||
|
||||
var infoDisplay = document.getElementById("info");
|
||||
infoDisplay.innerHTML = "Time to load/compile/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + " ms";
|
||||
clearInterval(interval);
|
||||
infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
|
||||
}, 10);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user