Implement type2 flex
This commit is contained in:
parent
030b498b6a
commit
2c09fed17c
40
fonts.js
40
fonts.js
@ -1715,6 +1715,7 @@ var Type1Parser = function type1Parser() {
|
||||
var charstring = [];
|
||||
var lsb = 0;
|
||||
var width = 0;
|
||||
var flexState = 0, flexPoints;
|
||||
|
||||
var value = '';
|
||||
var count = array.length;
|
||||
@ -1748,8 +1749,9 @@ var Type1Parser = function type1Parser() {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
} else if (!kHintingEnabled && (value == 1 || value == 2)) {
|
||||
charstring.push('drop', 'drop', 'drop', 'drop', 'drop', 'drop');
|
||||
} else if (escape == 17 || escape == 33) {
|
||||
// pop or setcurrentpoint commands can be ignored
|
||||
// since we are not doing callothersubr
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1775,6 +1777,31 @@ var Type1Parser = function type1Parser() {
|
||||
|
||||
charstring.push(lsb, 'hmoveto');
|
||||
continue;
|
||||
} else if (value == 10) { // callsubr
|
||||
if (charstring[charstring.length - 1] < 3) { // subr #0..2
|
||||
var subrNumber = charstring.pop();
|
||||
switch (subrNumber) {
|
||||
case 1:
|
||||
flexState = 1; // prepare for flex coordinates
|
||||
flexPoints = 0;
|
||||
break;
|
||||
case 2:
|
||||
flexState = 2; // flex in progress
|
||||
flexPoints++;
|
||||
break;
|
||||
case 0:
|
||||
// type2 flex command does not need final coords
|
||||
charstring.push('exch', 'drop', 'exch', 'drop');
|
||||
charstring.push('flex');
|
||||
flexState = 0;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
} else if (value == 21 && flexState > 0) {
|
||||
if (flexState > 1)
|
||||
continue; // ignoring rmoveto
|
||||
value = 5; // first segment replacing with rlineto
|
||||
} else if (!kHintingEnabled && (value == 1 || value == 3)) {
|
||||
charstring.push('drop', 'drop');
|
||||
continue;
|
||||
@ -2271,7 +2298,8 @@ CFF.prototype = {
|
||||
'return': 11,
|
||||
'sub': [12, 11],
|
||||
'div': [12, 12],
|
||||
'pop': [140, 12, 18],
|
||||
'exch': [12, 28],
|
||||
'flex': [12, 35],
|
||||
'drop' : [12, 18],
|
||||
'endchar': 14,
|
||||
'rmoveto': 21,
|
||||
@ -2287,11 +2315,9 @@ CFF.prototype = {
|
||||
var cmd = map[command];
|
||||
assert(cmd, 'Unknow command: ' + command);
|
||||
|
||||
if (isArray(cmd)) {
|
||||
if (isArray(cmd))
|
||||
charstring.splice(i++, 1, cmd[0], cmd[1]);
|
||||
if (cmd.length > 2)
|
||||
charstring.splice(++i, 0, cmd[2]);
|
||||
} else if (cmd !== null)
|
||||
else if (cmd !== null)
|
||||
charstring[i] = cmd;
|
||||
} else {
|
||||
// Type1 charstring use a division for number above 32000
|
||||
|
Loading…
Reference in New Issue
Block a user