Merge pull request #2615 from vyv03354/master
Fixes CFF parser failure when CharStrings contains cntrmask
This commit is contained in:
commit
9af6e05456
18
src/fonts.js
18
src/fonts.js
@ -5379,9 +5379,9 @@ var CFFFont = (function CFFFontClosure() {
|
|||||||
var CFFParser = (function CFFParserClosure() {
|
var CFFParser = (function CFFParserClosure() {
|
||||||
var CharstringValidationData = [
|
var CharstringValidationData = [
|
||||||
null,
|
null,
|
||||||
{ id: 'hstem', min: 2, resetStack: true },
|
{ id: 'hstem', min: 2, resetStack: true, stem: true },
|
||||||
null,
|
null,
|
||||||
{ id: 'vstem', min: 2, resetStack: true },
|
{ id: 'vstem', min: 2, resetStack: true, stem: true },
|
||||||
{ id: 'vmoveto', min: 1, resetStack: true },
|
{ id: 'vmoveto', min: 1, resetStack: true },
|
||||||
{ id: 'rlineto', min: 2, resetStack: true },
|
{ id: 'rlineto', min: 2, resetStack: true },
|
||||||
{ id: 'hlineto', min: 1, resetStack: true },
|
{ id: 'hlineto', min: 1, resetStack: true },
|
||||||
@ -5389,19 +5389,19 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
{ id: 'rrcurveto', min: 6, resetStack: true },
|
{ id: 'rrcurveto', min: 6, resetStack: true },
|
||||||
null,
|
null,
|
||||||
{ id: 'callsubr', min: 1, undefStack: true },
|
{ id: 'callsubr', min: 1, undefStack: true },
|
||||||
{ id: 'return', min: 0, resetStack: true },
|
{ id: 'return', min: 0, undefStack: true },
|
||||||
null, // 12
|
null, // 12
|
||||||
null,
|
null,
|
||||||
null, // endchar
|
null, // endchar
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
{ id: 'hstemhm', min: 2, resetStack: true },
|
{ id: 'hstemhm', min: 2, resetStack: true, stem: true },
|
||||||
null, // hintmask
|
null, // hintmask
|
||||||
null, // cntrmask
|
null, // cntrmask
|
||||||
{ id: 'rmoveto', min: 2, resetStack: true },
|
{ id: 'rmoveto', min: 2, resetStack: true },
|
||||||
{ id: 'hmoveto', min: 1, resetStack: true },
|
{ id: 'hmoveto', min: 1, resetStack: true },
|
||||||
{ id: 'vstemhm', min: 2, resetStack: true },
|
{ id: 'vstemhm', min: 2, resetStack: true, stem: true },
|
||||||
{ id: 'rcurveline', min: 8, resetStack: true },
|
{ id: 'rcurveline', min: 8, resetStack: true },
|
||||||
{ id: 'rlinecurve', min: 8, resetStack: true },
|
{ id: 'rlinecurve', min: 8, resetStack: true },
|
||||||
{ id: 'vvcurveto', min: 4, resetStack: true },
|
{ id: 'vvcurveto', min: 4, resetStack: true },
|
||||||
@ -5417,7 +5417,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
null,
|
null,
|
||||||
{ id: 'and', min: 2, stackDelta: -1 },
|
{ id: 'and', min: 2, stackDelta: -1 },
|
||||||
{ id: 'or', min: 2, stackDelta: -1 },
|
{ id: 'or', min: 2, stackDelta: -1 },
|
||||||
{ id: 'not', min: 2, stackDelta: -1 },
|
{ id: 'not', min: 1, stackDelta: 0 },
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
@ -5737,9 +5737,6 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
} else if (value == 255) { // number (32 bit)
|
} else if (value == 255) { // number (32 bit)
|
||||||
j += 4;
|
j += 4;
|
||||||
stackSize++;
|
stackSize++;
|
||||||
} else if (value == 18 || value == 23) {
|
|
||||||
hints += stackSize >> 1;
|
|
||||||
validationCommand = CharstringValidationData[value];
|
|
||||||
} else if (value == 19 || value == 20) {
|
} else if (value == 19 || value == 20) {
|
||||||
hints += stackSize >> 1;
|
hints += stackSize >> 1;
|
||||||
j += (hints + 7) >> 3; // skipping right amount of hints flag data
|
j += (hints + 7) >> 3; // skipping right amount of hints flag data
|
||||||
@ -5748,6 +5745,9 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
validationCommand = CharstringValidationData[value];
|
validationCommand = CharstringValidationData[value];
|
||||||
}
|
}
|
||||||
if (validationCommand) {
|
if (validationCommand) {
|
||||||
|
if (validationCommand.stem) {
|
||||||
|
hints += stackSize >> 1;
|
||||||
|
}
|
||||||
if ('min' in validationCommand) {
|
if ('min' in validationCommand) {
|
||||||
if (!undefStack && stackSize < validationCommand.min) {
|
if (!undefStack && stackSize < validationCommand.min) {
|
||||||
warn('Not enough parameters for ' + validationCommand.id +
|
warn('Not enough parameters for ' + validationCommand.id +
|
||||||
|
@ -96,6 +96,28 @@ describe('font', function() {
|
|||||||
expect(topDict.getByName('Private')).toEqual([45, 102]);
|
expect(topDict.getByName('Private')).toEqual([45, 102]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses a CharString having cntrmask', function() {
|
||||||
|
var bytes = new Uint8Array([0, 1, // count
|
||||||
|
1, // offsetSize
|
||||||
|
0, // offset[0]
|
||||||
|
38, // end
|
||||||
|
149, 149, 149, 149, 149, 149, 149, 149,
|
||||||
|
149, 149, 149, 149, 149, 149, 149, 149,
|
||||||
|
1, // hstem
|
||||||
|
149, 149, 149, 149, 149, 149, 149, 149,
|
||||||
|
149, 149, 149, 149, 149, 149, 149, 149,
|
||||||
|
3, // vstem
|
||||||
|
20, // cntrmask
|
||||||
|
22, 22, // fail if misparsed as hmoveto
|
||||||
|
14 // endchar
|
||||||
|
]);
|
||||||
|
parser.bytes = bytes;
|
||||||
|
var charStrings = parser.parseCharStrings(0);
|
||||||
|
expect(charStrings.count).toEqual(1);
|
||||||
|
// shoudn't be sanitized
|
||||||
|
expect(charStrings.get(0).length).toEqual(38);
|
||||||
|
});
|
||||||
|
|
||||||
it('parses predefined charsets', function() {
|
it('parses predefined charsets', function() {
|
||||||
var charset = parser.parseCharsets(0, 0, null, true);
|
var charset = parser.parseCharsets(0, 0, null, true);
|
||||||
expect(charset.predefined).toEqual(true);
|
expect(charset.predefined).toEqual(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user