Remove direct access to the underlying map object of dict in the fonts builder

This commit is contained in:
Vivien Nicolas 2011-06-14 21:51:11 +02:00
parent bd2e756100
commit c8c4326ca8

View File

@ -135,25 +135,25 @@ Font.prototype = {
canvas.setAttribute("heigth", 70); canvas.setAttribute("heigth", 70);
document.body.appendChild(canvas); document.body.appendChild(canvas);
// Get the first character of the font // Retrieve font charset
var charset = null;
var page = pdfDocument.getPage(pageNum); var page = pdfDocument.getPage(pageNum);
var xref = page.xref; var xref = page.xref;
var resources = xref.fetchIfRef(page.resources);
var fontResource = resources.get("Font"); var fonts = page.fonts;
var charset = ""; fonts.forEach(function(fontKey, fontData) {
for (var id in fontResource.map) { var descriptor = xref.fetch(fontData.get("FontDescriptor"));
var res = xref.fetch(fontResource.get(id));
var descriptor = xref.fetch(res.get("FontDescriptor"));
var name = descriptor.get("FontName").toString(); var name = descriptor.get("FontName").toString();
var font = Fonts[name.replace("+", "_")]; var font = Fonts[name.replace("+", "_")];
if (font && font.loading && name == fontName.replace("_", "+")) { if (font && font.loading && name == fontName.replace("_", "+")) {
charset = descriptor.get("CharSet").split("/"); charset = descriptor.get("CharSet");
break; charset = charset ? charset.split("/") : null;
return;
} }
} });
// Warn if the charset is not found, this is likely a bug! // Warn if the charset is not found, this is likely
var testCharset = charset; var testCharset = charset || [];
if (!charset) { if (!charset) {
warn("No charset found for: " + fontName); warn("No charset found for: " + fontName);
} else { } else {
@ -1358,26 +1358,26 @@ CFF.prototype = {
}, },
getOrderedCharStrings: function(aFont) { getOrderedCharStrings: function(aFont) {
var dict = aFont.get("CharStrings")
var charstrings = []; var charstrings = [];
for (var glyph in dict.map) {
var glyphs = aFont.get("CharStrings")
glyphs.forEach(function(glyph, glyphData) {
var unicode = GlyphsUnicode[glyph]; var unicode = GlyphsUnicode[glyph];
if (!unicode) { if (!unicode) {
if (glyph != ".notdef") if (glyph != ".notdef")
warn(glyph + " does not have an entry in the glyphs unicode dictionary"); warn(glyph + " does not have an entry in the glyphs unicode dictionary");
continue; } else {
var b1 = parseInt("0x" + unicode[0] + unicode[1]);
var b2 = parseInt("0x" + unicode[2] + unicode[3]);
unicode = FontsUtils.bytesToInteger([b1, b2]);
charstrings.push({
glyph: glyph,
unicode: unicode,
charstring: glyphData.slice()
});
} }
});
var b1 = parseInt("0x" + unicode[0] + unicode[1]);
var b2 = parseInt("0x" + unicode[2] + unicode[3]);
unicode = FontsUtils.bytesToInteger([b1, b2]);
charstrings.push({
glyph: glyph,
unicode: unicode,
charstring: dict.map[glyph].slice()
});
}
charstrings.sort(function(a, b) { charstrings.sort(function(a, b) {
return a.unicode > b.unicode; return a.unicode > b.unicode;