var charcode = chars.charCodeAt(i);
var unicode = encoding[charcode];
if ('undefined' == typeof(unicode)) {
- // FIXME/issue 233: we're hitting this in test/pdf/sizes.pdf
- // at the moment, for unknown reasons.
warn('Unencoded charcode ' + charcode);
unicode = charcode;
}
while (i < count && (eexecStr[i] == ' ' || eexecStr[i] == '\n'))
++i;
- var t = '';
+ var token = '';
while (i < count && !(eexecStr[i] == ' ' || eexecStr[i] == '\n'))
- t += eexecStr[i++];
-
- return t;
- }
+ token += eexecStr[i++];
+ return token;
+ };
var c = eexecStr[i];
if ((glyphsSection || subrsSection) && c == 'R') {
return program;
},
- this.extractFontHeader = function t1_extractFontProgram(stream) {
+ this.extractFontHeader = function t1_extractFontHeader(stream, properties) {
var headerString = '';
for (var i = 0; i < stream.length; i++)
headerString += String.fromCharCode(stream[i]);
- var info = {
- textMatrix: null
- };
-
var token = '';
var count = headerString.length;
for (var i = 0; i < count; i++) {
+ var getToken = function() {
+ var char = headerString[i];
+ while (i < count && (char == ' ' || char == '\n' || char == '/'))
+ char = headerString[++i];
+
+ var token = '';
+ while (i < count && !(char == ' ' || char == '\n' || char == '/')) {
+ token += char;
+ char = headerString[++i];
+ }
+
+ return token;
+ };
+
var c = headerString[i];
if (c == ' ' || c == '\n') {
switch (token) {
// Make the angle into the right direction
matrix[2] *= -1;
- info.textMatrix = matrix;
+ properties.textMatrix = matrix;
+ break;
+ case '/Encoding':
+ if (!properties.builtInEncoding)
+ break;
+
+ var size = parseInt(getToken());
+ getToken(); // read in 'array'
+
+ for (var j = 0; j < size; j++) {
+ var token = getToken();
+ if (token == 'dup') {
+ var index = parseInt(getToken());
+ var glyph = getToken();
+ properties.encoding[index] = GlyphsUnicode[glyph];
+ getToken(); // read the in 'put'
+ j = index;
+ }
+ }
break;
}
token = '';
token += c;
}
}
-
- return info;
};
};
var length2 = file.dict.get('Length2');
var headerBlock = file.getBytes(length1);
- var header = type1Parser.extractFontHeader(headerBlock);
- for (var info in header)
- properties[info] = header[info];
+ type1Parser.extractFontHeader(headerBlock, properties);
// Decrypt the data blocks and retrieve it's content
var eexecBlock = file.getBytes(length2);
- var data = type1Parser.extractFontProgram(eexecBlock);
+ var data = type1Parser.extractFontProgram(eexecBlock, properties);
for (var info in data.properties)
properties[info] = data.properties[info];
getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs) {
var charstrings = [];
+ var missings = [];
for (var i = 0; i < glyphs.length; i++) {
var glyph = glyphs[i];
var unicode = GlyphsUnicode[glyph.glyph];
if (!unicode) {
- if (glyph.glyph != '.notdef') {
- warn(glyph.glyph +
- ' does not have an entry in the glyphs unicode dictionary');
- }
+ if (glyph.glyph != '.notdef')
+ missings.push(glyph.glyph);
} else {
charstrings.push({
glyph: glyph,
}
}
+ if (missings.length)
+ warn(missings + ' does not have unicode in the glyphs dictionary');
+
charstrings.sort(function charstrings_sort(a, b) {
return a.unicode - b.unicode;
});
fd = fontDict.get('FontDescriptor');
}
+ var builtInEncoding = false;
var encodingMap = {};
var glyphMap = {};
var charset = [];
if (!baseEncoding) {
var type = subType.name;
if (type == 'TrueType') {
- baseEncoding = Encodings.WinAnsiEncoding.slice(0);
+ baseEncoding = Encodings.WinAnsiEncoding.slice();
} else if (type == 'Type1') {
- baseEncoding = Encodings.StandardEncoding.slice(0);
+ baseEncoding = Encodings.StandardEncoding.slice();
+ if (!diffEncoding.length)
+ builtInEncoding = true;
} else {
error('Unknown type of font');
}
subtype: fileType,
widths: glyphWidths,
encoding: encodingMap,
+ builtInEncoding: builtInEncoding,
charset: charset,
firstChar: fontDict.get('FirstChar'),
lastChar: fontDict.get('LastChar'),