var fontName = descriptor.get("FontName").name;
fontName = fontName.replace("+", "_");
- var font = Fonts[fontName];
- if (!font) {
- var fontFile = descriptor.get2("FontFile", "FontFile2");
- fontFile = xref.fetchIfRef(fontFile);
-
- // Generate the custom cmap of the font if needed
- var encodingMap = {};
- if (fontDict.has("Encoding")) {
-
- var encoding = xref.fetchIfRef(fontDict.get("Encoding"));
- if (IsDict(encoding)) {
- // Build an map between codes and glyphs
- var differences = encoding.get("Differences");
- var index = 0;
- for (var j = 0; j < differences.length; j++) {
- var data = differences[j];
- IsNum(data) ? index = data : encodingMap[index++] = data;
- }
-
- // Get the font charset
- var charset = descriptor.get("CharSet").split("/");
-
- } else if (IsName(encoding)) {
- var encoding = Encodings[encoding];
- var widths = xref.fetchIfRef(fontDict.get("Widths"));
- var firstchar = xref.fetchIfRef(fontDict.get("FirstChar"));
-
- var charset = [];
- for (var j = 0; j < widths.length; j++) {
- var index = widths[j];
- if (!index)
- continue;
- charset.push(encoding[j + firstchar]);
- }
- }
- }
-
- var properties = {
+ var fontFile = descriptor.get2("FontFile", "FontFile2");
+ if (!fontFile)
+ errort("FontFile not found for font: " + fontName);
+ fontFile = xref.fetchIfRef(fontFile);
+
+ // Generate the custom cmap of the font if needed
+ var encodingMap = {};
+ if (fontDict.has("Encoding")) {
+ var encoding = xref.fetchIfRef(fontDict.get("Encoding"));
+ if (IsDict(encoding)) {
+ // Build an map between codes and glyphs
+ var differences = encoding.get("Differences");
+ var index = 0;
+ for (var j = 0; j < differences.length; j++) {
+ var data = differences[j];
+ IsNum(data) ? index = data : encodingMap[index++] = data;
+ }
+
+ // Get the font charset if any
+ var charset = descriptor.get("CharSet");
+ if (charset)
+ charset = charset.split("/");
+
+ } else if (IsName(encoding)) {
+ var encoding = Encodings[encoding];
+ var widths = xref.fetchIfRef(fontDict.get("Widths"));
+ var firstchar = xref.fetchIfRef(fontDict.get("FirstChar"));
+
+ var charset = [];
+ for (var j = 0; j < widths.length; j++) {
+ var index = widths[j];
+ if (!index)
+ continue;
+
+ charset.push(encoding[j + firstchar]);
+ }
+ }
+ }
+
+ var properties = {
type: fontDict.get("Subtype").name,
encoding: encodingMap,
charset: charset,
bbox: descriptor.get("FontBBox")
- };
- new Font(fontName, fontFile, properties);
- }
- return Fonts[fontName];
+ };
+
+ return {
+ name: fontName,
+ file: fontFile,
+ properties: properties
+ }
},
beginDrawing: function(mediaBox) {
page.compile(gfx, fonts);
var t2 = Date.now();
- var interval = 0;
- for (var i = 0; i < fonts.length; i++) {
- if (fonts[i].loading) {
- interval = 10;
- break;
+ var fontsReady = true;
+
+ // Inspect fonts and translate the missing one
+ var count = fonts.length;
+ for (var i = 0; i < count; i++) {
+ var font = fonts[i];
+ if (Fonts[font.name]) {
+ fontsReady = fontsReady && !Fonts[font.name].loading;
+ continue;
}
- };
- // 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;
- }
- var t3 = Date.now();
+ new Font(font.name, font.file, font.properties);
+ fontsReady = false;
+ }
+
+ function delayLoadFont() {
+ for (var i = 0; i < count; i++) {
+ if (Fonts[font.name].loading)
+ return;
+ }
+ clearInterval(pageInterval);
+
+ var t3 = Date.now();
+
+ page.display(gfx);
- clearInterval(pageInterval);
- page.display(gfx);
+ var t4 = Date.now();
- var t4 = Date.now();
+ var infoDisplay = document.getElementById("info");
+ infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
+ };
- var infoDisplay = document.getElementById("info");
- 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() {