|
|
@ -76,47 +76,37 @@ function displayPage(num) { |
|
|
|
// of the page to be fully loaded before loading the page
|
|
|
|
// of the page to be fully loaded before loading the page
|
|
|
|
var fontsReady = true; |
|
|
|
var fontsReady = true; |
|
|
|
var fonts = page.fonts; |
|
|
|
var fonts = page.fonts; |
|
|
|
for (var i = 0; i < fonts.length; i++) { |
|
|
|
var xref = page.xref; |
|
|
|
var fontName = fonts[i].replace("+", "_"); |
|
|
|
fonts.forEach(function(fontKey, fontDict) { |
|
|
|
var font = Fonts[fontName]; |
|
|
|
var descriptor = xref.fetch(fontDict.get("FontDescriptor")); |
|
|
|
if (!font) { |
|
|
|
var fontName = descriptor.get("FontName").name; |
|
|
|
// load the new font
|
|
|
|
fontName = fontName.replace("+", "_"); |
|
|
|
var xref = page.xref; |
|
|
|
|
|
|
|
var resources = xref.fetchIfRef(page.resources); |
|
|
|
// Check if the font has been loaded or is still loading
|
|
|
|
var fontResource = resources.get("Font"); |
|
|
|
var font = Fonts[fontName]; |
|
|
|
for (var id in fontResource.map) { |
|
|
|
if (!font) { |
|
|
|
var res = xref.fetch(fontResource.get(id)); |
|
|
|
var fontFile = xref.fetchIfRef(descriptor.get2("FontFile", "FontFile2")); |
|
|
|
var descriptor = xref.fetch(res.get("FontDescriptor")); |
|
|
|
// Generate the custom cmap of the font if needed
|
|
|
|
var name = descriptor.get("FontName").toString(); |
|
|
|
|
|
|
|
if (name == fontName.replace("_", "+")) { |
|
|
|
|
|
|
|
var subtype = res.get("Subtype").name; |
|
|
|
|
|
|
|
var fontFile = page.xref.fetchIfRef(descriptor.get("FontFile")); |
|
|
|
|
|
|
|
if (!fontFile) |
|
|
|
|
|
|
|
fontFile = page.xref.fetchIfRef(descriptor.get("FontFile2")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generate the custom cmap of the font
|
|
|
|
|
|
|
|
var encoding = xref.fetch(res.get("Encoding")); |
|
|
|
|
|
|
|
var differences = encoding.get("Differences"); |
|
|
|
|
|
|
|
var encodingMap = {}; |
|
|
|
var encodingMap = {}; |
|
|
|
var index = 0; |
|
|
|
if (fontDict.has("Encoding")) { |
|
|
|
for (var j = 0; j < differences.length; j++) { |
|
|
|
var encoding = xref.fetchIfRef(fontDict.get("Encoding")); |
|
|
|
var data = differences[j]; |
|
|
|
if (IsDict(encoding)) { |
|
|
|
if (IsNum(data)) |
|
|
|
var differences = encoding.get("Differences"); |
|
|
|
index = data; |
|
|
|
var index = 0; |
|
|
|
else |
|
|
|
for (var j = 0; j < differences.length; j++) { |
|
|
|
encodingMap[index++] = data; |
|
|
|
var data = differences[j]; |
|
|
|
|
|
|
|
IsNum(data) ? index = data : encodingMap[index++] = data; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var subtype = fontDict.get("Subtype").name; |
|
|
|
new Font(fontName, fontFile, encodingMap, subtype); |
|
|
|
new Font(fontName, fontFile, encodingMap, subtype); |
|
|
|
fontsReady = false; |
|
|
|
return fontsReady = false; |
|
|
|
break; |
|
|
|
} else if (font.loading) { |
|
|
|
} |
|
|
|
return fontsReady = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (font.loading) { |
|
|
|
}); |
|
|
|
fontsReady = false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If everything is ready do not delayed the page loading any more
|
|
|
|
// If everything is ready do not delayed the page loading any more
|
|
|
|
if (fontsReady) |
|
|
|
if (fontsReady) |
|
|
|