Browse Source

Merge pull request #18 from vingtetun/master

Do not assume charset is defined and move some fonts timing to the right place
Chris Jones 14 years ago
parent
commit
b7d332a682
  1. 19
      pdf.js
  2. 37
      test.js

19
pdf.js

@ -1729,15 +1729,14 @@ var CanvasGraphics = (function() {
var fontName = descriptor.get("FontName").name; var fontName = descriptor.get("FontName").name;
fontName = fontName.replace("+", "_"); fontName = fontName.replace("+", "_");
var font = Fonts[fontName];
if (!font) {
var fontFile = descriptor.get2("FontFile", "FontFile2"); var fontFile = descriptor.get2("FontFile", "FontFile2");
if (!fontFile)
errort("FontFile not found for font: " + fontName);
fontFile = xref.fetchIfRef(fontFile); fontFile = xref.fetchIfRef(fontFile);
// Generate the custom cmap of the font if needed // Generate the custom cmap of the font if needed
var encodingMap = {}; var encodingMap = {};
if (fontDict.has("Encoding")) { if (fontDict.has("Encoding")) {
var encoding = xref.fetchIfRef(fontDict.get("Encoding")); var encoding = xref.fetchIfRef(fontDict.get("Encoding"));
if (IsDict(encoding)) { if (IsDict(encoding)) {
// Build an map between codes and glyphs // Build an map between codes and glyphs
@ -1748,8 +1747,10 @@ var CanvasGraphics = (function() {
IsNum(data) ? index = data : encodingMap[index++] = data; IsNum(data) ? index = data : encodingMap[index++] = data;
} }
// Get the font charset // Get the font charset if any
var charset = descriptor.get("CharSet").split("/"); var charset = descriptor.get("CharSet");
if (charset)
charset = charset.split("/");
} else if (IsName(encoding)) { } else if (IsName(encoding)) {
var encoding = Encodings[encoding]; var encoding = Encodings[encoding];
@ -1761,6 +1762,7 @@ var CanvasGraphics = (function() {
var index = widths[j]; var index = widths[j];
if (!index) if (!index)
continue; continue;
charset.push(encoding[j + firstchar]); charset.push(encoding[j + firstchar]);
} }
} }
@ -1772,9 +1774,12 @@ var CanvasGraphics = (function() {
charset: charset, charset: charset,
bbox: descriptor.get("FontBBox") bbox: descriptor.get("FontBBox")
}; };
new Font(fontName, fontFile, properties);
return {
name: fontName,
file: fontFile,
properties: properties
} }
return Fonts[fontName];
}, },
beginDrawing: function(mediaBox) { beginDrawing: function(mediaBox) {

37
test.js

@ -74,30 +74,43 @@ function displayPage(num) {
page.compile(gfx, fonts); page.compile(gfx, fonts);
var t2 = Date.now(); var t2 = Date.now();
var interval = 0; var fontsReady = true;
for (var i = 0; i < fonts.length; i++) {
if (fonts[i].loading) { // Inspect fonts and translate the missing one
interval = 10; var count = fonts.length;
break; for (var i = 0; i < count; i++) {
var font = fonts[i];
if (Fonts[font.name]) {
fontsReady = fontsReady && !Fonts[font.name].loading;
continue;
}
new Font(font.name, font.file, font.properties);
fontsReady = false;
} }
};
// FIXME This need to be replaced by an event function delayLoadFont() {
pageInterval = setInterval(function() { for (var i = 0; i < count; i++) {
for (var i = 0; i < fonts.length; i++) { if (Fonts[font.name].loading)
if (fonts[i].loading)
return; return;
} }
clearInterval(pageInterval);
var t3 = Date.now(); var t3 = Date.now();
clearInterval(pageInterval);
page.display(gfx); page.display(gfx);
var t4 = Date.now(); var t4 = Date.now();
var infoDisplay = document.getElementById("info"); var infoDisplay = document.getElementById("info");
infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms"; infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
}, interval); };
if (fontsReady) {
delayLoadFont();
} else {
pageInterval = setInterval(delayLoadFont, 10);
}
} }
function nextPage() { function nextPage() {

Loading…
Cancel
Save