Kill Flatten - part 1

This commit is contained in:
Vivien Nicolas 2011-06-26 10:04:56 +02:00
parent 8241d5fe02
commit bcf5ade41c

103
fonts.js
View File

@ -980,16 +980,8 @@ var Type1Parser = function() {
"12": "div", "12": "div",
// callothersubr is a mechanism to make calls on the postscript // callothersubr is a mechanism to make calls on the postscript
// interpreter. // interpreter, this is not supported by Type2 charstring but hopefully
// TODO When decodeCharstring encounter such a command it should // most of the default commands can be ignored safely.
// directly do:
// - pop the previous charstring[] command into 'index'
// - pop the previous charstring[] command and ignore it, it is
// normally the number of element to push on the stack before
// the command but since everything will be pushed on the stack
// by the PS interpreter when it will read them that is safe to
// ignore this command
// - push the content of the OtherSubrs[index] inside charstring[]
"16": "callothersubr", "16": "callothersubr",
"17": "pop", "17": "pop",
@ -1009,9 +1001,12 @@ var Type1Parser = function() {
"31": "hvcurveto" "31": "hvcurveto"
}; };
function decodeCharString(array) { var kEscapeCommand = 12;
var charString = [];
function decodeCharString(array) {
var charstring = [];
var z = 0;
var value = ""; var value = "";
var count = array.length; var count = array.length;
for (var i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
@ -1019,10 +1014,44 @@ var Type1Parser = function() {
if (value < 32) { if (value < 32) {
var command = null; var command = null;
if (value == 12) { if (value == kEscapeCommand) {
var escape = array[++i]; var escape = array[++i];
// TODO Clean this code
if (escape == 16) {
var index = charstring.pop();
var argc = charstring.pop();
var data = charstring.pop();
// If the flex mechanishm is not used in a font program, Adobe
// state that that entries 0, 1 and 2 can simply be replace by
// {}, which means that we can simply ignore them.
if (index < 3) {
continue;
}
// This is the same things about hint replacement, if it is not used
// entry 3 can be replaced by {3}
if (index == 3) {
charstring.push(3);
i++;
continue;
}
}
command = charStringDictionary["12"][escape]; command = charStringDictionary["12"][escape];
} else { } else {
// TODO Clean this code
if (value == 13) {
var charWidthVector = charstring[1];
var leftSidebearing = charstring[0];
charstring.push(leftSidebearing, "hmoveto");
charstring.splice(0, 1);
continue;
}
command = charStringDictionary[value]; command = charStringDictionary[value];
} }
@ -1044,16 +1073,14 @@ var Type1Parser = function() {
} else if (value <= 254) { } else if (value <= 254) {
value = -((value - 251) * 256) - parseInt(array[++i]) - 108; value = -((value - 251) * 256) - parseInt(array[++i]) - 108;
} else { } else {
var byte = array[++i]; value = (array[++i] & 0xff) << 24 | (array[++i] & 0xff) << 16 |
var high = (byte >> 1); (array[++i] & 0xff) << 8 | (array[++i] & 0xff) << 0;
value = (byte - high) << 24 | array[++i] << 16 |
array[++i] << 8 | array[++i];
} }
charString.push(value); charstring.push(value);
} }
return charString; return charstring;
}; };
/** /**
@ -1305,46 +1332,8 @@ CFF.prototype = {
var i = 0; var i = 0;
while (true) { while (true) {
var obj = charstring[i]; var obj = charstring[i];
if (obj == null)
return [];
if (obj.charAt) { if (obj.charAt) {
switch (obj) { switch (obj) {
case "callothersubr":
var index = charstring[i - 1];
var count = charstring[i - 2];
var data = charstring[i - 3];
// If the flex mechanishm is not used in a font program, Adobe
// state that that entries 0, 1 and 2 can simply be replace by
// {}, which means that we can simply ignore them.
if (index < 3) {
i -= 3;
continue;
}
// This is the same things about hint replacment, if it is not used
// entry 3 can be replaced by {}
if (index == 3) {
if (!data) {
charstring.splice(i - 2, 4, 3);
i -= 3;
} else {
// 5 to remove the arguments, the callothersubr call and the pop command
charstring.splice(i - 3, 5, 3);
i -= 3;
}
}
break;
case "hsbw":
var charWidthVector = charstring[1];
var leftSidebearing = charstring[0];
charstring.splice(i, 1, leftSidebearing, "hmoveto");
charstring.splice(0, 1);
break;
case "endchar": case "endchar":
case "return": case "return":
// CharString is ready to be re-encode to commands number at this point // CharString is ready to be re-encode to commands number at this point