Fix CIMM6/CIIM9

This commit is contained in:
Vivien Nicolas 2011-06-17 08:36:52 +02:00
parent 75baff40f4
commit f8696259b7

View File

@ -1223,31 +1223,25 @@ CFF.prototype = {
"hvcurveto": 31, "hvcurveto": 31,
}, },
flattenCharstring: function(aCharstring, aSubrs) { flattenCharstring: function(aGlyph, aCharstring, aSubrs) {
var original = aCharstring.slice(); var original = aCharstring.slice();
var i = 0; var i = 0;
while (true) { while (true) {
var obj = aCharstring[i]; var obj = aCharstring[i];
if (obj == null)
return [];
if (obj.charAt) { if (obj.charAt) {
switch (obj) { switch (obj) {
case "callsubr": case "callsubr":
if (aCharstring[i - 1] == 351) {
log(original);
log(aCharstring);
error("...");
aCharstring.splice(i - 1, 2);
continue;
}
var subr = aSubrs[aCharstring[i - 1]].slice(); var subr = aSubrs[aCharstring[i - 1]].slice();
if (subr.length > 1) { if (subr.length > 1) {
subr = this.flattenCharstring(subr, aSubrs); subr = this.flattenCharstring(aGlyph, subr, aSubrs);
subr.pop(); subr.pop();
aCharstring.splice(i - 1, 2, subr); aCharstring.splice(i - 1, 2, subr);
} } else {
else
aCharstring.splice(i - 1, 2); aCharstring.splice(i - 1, 2);
}
i -= 1; i -= 1;
break; break;
@ -1262,8 +1256,8 @@ CFF.prototype = {
error("callothersubr for index: " + index + " (" + aCharstring + ")"); error("callothersubr for index: " + index + " (" + aCharstring + ")");
if (!data) { if (!data) {
aCharstring.splice(i - 2, 3, "pop", 3); aCharstring.splice(i - 2, 4, "pop", 3);
i -= 2; i -= 3;
} else { } else {
// 5 to remove the arguments, the callothersubr call and the pop command // 5 to remove the arguments, the callothersubr call and the pop command
aCharstring.splice(i - 3, 5, 3); aCharstring.splice(i - 3, 5, 3);
@ -1279,7 +1273,10 @@ CFF.prototype = {
break; break;
case "pop": case "pop":
aCharstring.splice(i - 2, 2); if (i)
aCharstring.splice(i - 2, 2);
else
aCharstring.splice(i - 1, 1);
i -= 1; i -= 1;
break; break;
@ -1287,7 +1284,11 @@ CFF.prototype = {
case "hsbw": case "hsbw":
var charWidthVector = aCharstring[i - 1]; var charWidthVector = aCharstring[i - 1];
var leftSidebearing = aCharstring[i - 2]; var leftSidebearing = aCharstring[i - 2];
aCharstring.splice(i - 2, 3, charWidthVector, leftSidebearing, "hmoveto");
if (leftSidebearing)
aCharstring.splice(i - 2, 3, charWidthVector, leftSidebearing, "hmoveto");
else
aCharstring.splice(i - 2, 3, charWidthVector);
break; break;
case "endchar": case "endchar":
@ -1345,7 +1346,7 @@ CFF.prototype = {
var charstring = charstrings[i].charstring.slice(); var charstring = charstrings[i].charstring.slice();
var glyph = charstrings[i].glyph; var glyph = charstrings[i].glyph;
var flattened = this.flattenCharstring(charstring, aFontInfo.subrs); var flattened = this.flattenCharstring(glyph, charstring, aFontInfo.subrs);
glyphs.push(flattened); glyphs.push(flattened);
charstringsCount++; charstringsCount++;
charstringsDataLength += flattened.length; charstringsDataLength += flattened.length;