From: notmasteryet Date: Thu, 29 Sep 2011 01:55:06 +0000 (-0500) Subject: Merge branch 'master' of https://github.com/andreasgal/pdf.js.git into cid0 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=078433fecd61f270530bcd71818f104332b7f698;p=pdf.js.git Merge branch 'master' of https://github.com/andreasgal/pdf.js.git into cid0 Conflicts: pdf.js --- 078433fecd61f270530bcd71818f104332b7f698 diff --cc pdf.js index 212769d,ff0488f..66e575a --- a/pdf.js +++ b/pdf.js @@@ -4437,107 -4444,72 +4444,107 @@@ var PartialEvaluator = (function partia properties) { var type = properties.type, encoding; if (properties.composite) { - if (type == 'CIDFontType2') { - var defaultWidth = xref.fetchIfRef(dict.get('DW')) || 1000; - properties.defaultWidth = defaultWidth; - - var glyphsWidths = {}; - var widths = xref.fetchIfRef(dict.get('W')); - if (widths) { - var start = 0, end = 0; - for (var i = 0; i < widths.length; i++) { - var code = widths[i]; - if (isArray(code)) { - for (var j = 0; j < code.length; j++) - glyphsWidths[start++] = code[j]; - start = 0; - } else if (start) { - var width = widths[++i]; - for (var j = start; j <= code; j++) - glyphsWidths[j] = width; - start = 0; - } else { - start = code; - } + var defaultWidth = xref.fetchIfRef(dict.get('DW')) || 1000; + properties.defaultWidth = defaultWidth; + + var glyphsWidths = {}; + var widths = xref.fetchIfRef(dict.get('W')); + if (widths) { + var start = 0, end = 0; + for (var i = 0; i < widths.length; i++) { + var code = widths[i]; - if (IsArray(code)) { ++ if (isArray(code)) { + for (var j = 0; j < code.length; j++) + glyphsWidths[start++] = code[j]; + start = 0; + } else if (start) { + var width = widths[++i]; + for (var j = start; j <= code; j++) + glyphsWidths[j] = width; + start = 0; + } else { + start = code; } } - properties.widths = glyphsWidths; - - var cidToGidMap = dict.get('CIDToGIDMap'); - if (!cidToGidMap || !isRef(cidToGidMap)) { - return Object.create(GlyphsUnicode); - } - - // Extract the encoding from the CIDToGIDMap - var glyphsStream = xref.fetchIfRef(cidToGidMap); - var glyphsData = glyphsStream.getBytes(0); - - // Glyph ids are big-endian 2-byte values - encoding = properties.encoding; - - // Set encoding 0 to later verify the font has an encoding - encoding[0] = { unicode: 0, width: 0 }; - for (var j = 0; j < glyphsData.length; j++) { - var glyphID = (glyphsData[j++] << 8) | glyphsData[j]; - if (glyphID == 0) - continue; - - var code = j >> 1; - var width = glyphsWidths[code]; - encoding[code] = { - unicode: glyphID, - width: isNum(width) ? width : defaultWidth - }; + } + properties.widths = glyphsWidths; + + // Glyph ids are big-endian 2-byte values + encoding = properties.encoding; + + var cidToGidMap = dict.get('CIDToGIDMap'); - if (!cidToGidMap || !IsRef(cidToGidMap)) { ++ if (!cidToGidMap || !isRef(cidToGidMap)) { + // trying to guess encoding from CIDSystemInfo + var cidSystemInfo = dict.get('CIDSystemInfo'); + var cidToUnicode; - if (IsDict(cidSystemInfo)) { ++ if (isDict(cidSystemInfo)) { + cidToUnicode = CIDToUnicodeMaps[ + cidSystemInfo.get('Registry') + '-' + + cidSystemInfo.get('Ordering')]; } - } else if (type == 'CIDFontType0') { - if (isName(encoding)) { - // Encoding is a predefined CMap - if (encoding.name == 'Identity-H') { - TODO('Need to create an identity cmap'); - } else { - TODO('Need to support predefined CMaps see PDF 32000-1:2008 ' + - '9.7.5.2 Predefined CMaps'); + if (cidToUnicode) { + encoding[0] = { unicode: 0, width: 0 }; + var glyph = 1, i, j; + for (i = 0; i < cidToUnicode.length; ++i) { + var unicode = cidToUnicode[i]; - if (IsArray(unicode)) { ++ if (isArray(unicode)) { + var length = unicode.length; + if (glyph in glyphsWidths) { + for (j = 0; j < length; j++) { + encoding[unicode[j]] = { + unicode: unicode[j], + width: glyphsWidths[glyph] + }; + } + } + glyph++; + } else if (typeof unicode === 'object') { + var fillLength = unicode.f; + if (fillLength) { + unicode = unicode.c; + for (j = 0; j < fillLength; ++j) { + if (!(glyph in glyphsWidths)) + continue; + encoding[unicode] = { + unicode: unicode, + width: glyphsWidths[glyph] + }; + unicode++; + glyph++; + } + } else + glyph += unicode.s; + } else if (unicode) { + encoding[unicode] = { + unicode: unicode, + width: glyphsWidths[glyph++] + }; + } } - } else { - TODO('Need to support encoding streams see PDF 32000-1:2008 ' + - '9.7.5.3'); } + + return Object.create(GlyphsUnicode); } + + // Extract the encoding from the CIDToGIDMap + var glyphsStream = xref.fetchIfRef(cidToGidMap); + var glyphsData = glyphsStream.getBytes(0); + + // Set encoding 0 to later verify the font has an encoding + encoding[0] = { unicode: 0, width: 0 }; + for (var j = 0; j < glyphsData.length; j++) { + var glyphID = (glyphsData[j++] << 8) | glyphsData[j]; + if (glyphID == 0) + continue; + + var code = j >> 1; + var width = glyphsWidths[code]; + encoding[code] = { + unicode: glyphID, - width: IsNum(width) ? width : defaultWidth ++ width: isNum(width) ? width : defaultWidth + }; + } + return Object.create(GlyphsUnicode); }