Leave div commands on stack and change evaluation.
This commit is contained in:
parent
ac005ed359
commit
8fccd19948
57
src/fonts.js
57
src/fonts.js
@ -3422,25 +3422,35 @@ var Type1Parser = function type1Parser() {
|
|||||||
|
|
||||||
var kEscapeCommand = 12;
|
var kEscapeCommand = 12;
|
||||||
|
|
||||||
// The initial stack can have numbers expressed with the div command which
|
// Breaks up the stack by arguments and also calculates the value.
|
||||||
// need to be calculated before conversion. Looking at the spec it doesn't
|
function breakUpArgs(stack, numArgs) {
|
||||||
// appear div should even be allowed as a first command but there have been
|
var args = [];
|
||||||
// a number of fonts that have this.
|
var index = stack.length - 1;
|
||||||
function evaluateStack(stack) {
|
for (var i = 0; i < numArgs; i++) {
|
||||||
var newStack = [];
|
if (index < 0) {
|
||||||
for (var i = 0, ii = stack.length; i < ii; i++) {
|
args.unshift({ arg: [0],
|
||||||
var token = stack[i];
|
value: 0 });
|
||||||
if (token === 'div') {
|
warn('Malformed charstring stack: not enough values on stack.');
|
||||||
var b = newStack.pop();
|
continue;
|
||||||
var a = newStack.pop();
|
}
|
||||||
newStack.push(a / b);
|
if (stack[index] === 'div') {
|
||||||
} else if (isInt(token)) {
|
var a = stack[index - 2];
|
||||||
newStack.push(token);
|
var b = stack[index - 1];
|
||||||
|
if (!isInt(a) || !isInt(b)) {
|
||||||
|
warn('Malformed charsting stack: expected ints on stack for div.');
|
||||||
|
a = 0;
|
||||||
|
b = 1;
|
||||||
|
}
|
||||||
|
args.unshift({ arg: [a, b, 'div'],
|
||||||
|
value: a / b });
|
||||||
|
index -= 3;
|
||||||
} else {
|
} else {
|
||||||
warn('Unsupported initial stack ' + stack);
|
args.unshift({ arg: stack.slice(index, index + 1),
|
||||||
|
value: stack[index] });
|
||||||
|
index--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newStack;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodeCharString(array) {
|
function decodeCharString(array) {
|
||||||
@ -3493,13 +3503,14 @@ var Type1Parser = function type1Parser() {
|
|||||||
command = charStringDictionary['12'][escape];
|
command = charStringDictionary['12'][escape];
|
||||||
} else {
|
} else {
|
||||||
if (value == 13) { // hsbw
|
if (value == 13) { // hsbw
|
||||||
charstring = evaluateStack(charstring);
|
var args = breakUpArgs(charstring, 2);
|
||||||
if (charstring.length !== 2)
|
lsb = args[0]['value'];
|
||||||
warn('Unsupported hsbw format.');
|
width = args[1]['value'];
|
||||||
lsb = charstring[0];
|
// To convert to type2 we have to move the width value to the first
|
||||||
width = charstring[1];
|
// part of the charstring and then use hmoveto with lsb.
|
||||||
charstring.splice(0, 1);
|
charstring = args[1]['arg'];
|
||||||
charstring.push(lsb, 'hmoveto');
|
charstring = charstring.concat(args[0]['arg']);
|
||||||
|
charstring.push('hmoveto');
|
||||||
continue;
|
continue;
|
||||||
} else if (value == 10) { // callsubr
|
} else if (value == 10) { // callsubr
|
||||||
if (charstring[charstring.length - 1] < 3) { // subr #0..2
|
if (charstring[charstring.length - 1] < 3) { // subr #0..2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user