diff --git a/bower.json b/bower.json index c9d0c0d82..fcc034475 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "pdfjs-dist", - "version": "1.0.672", + "version": "1.0.674", "keywords": [ "Mozilla", "pdf", diff --git a/build/pdf.combined.js b/build/pdf.combined.js index abf3d21dc..c03f39ff3 100644 --- a/build/pdf.combined.js +++ b/build/pdf.combined.js @@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') { (typeof window !== 'undefined' ? window : this).PDFJS = {}; } -PDFJS.version = '1.0.672'; -PDFJS.build = '90afb70'; +PDFJS.version = '1.0.674'; +PDFJS.build = 'cd5bd9f'; (function pdfjsWrapper() { // Use strict in our context only - users might not want it @@ -23816,12 +23816,16 @@ var Font = (function FontClosure() { // Horizontal metrics builder.addTable('hmtx', (function fontFieldsHmtx() { var charstrings = font.charstrings; + var cffWidths = font.cff ? font.cff.widths : null; var hmtx = '\x00\x00\x00\x00'; // Fake .notdef for (var i = 1, ii = numGlyphs; i < ii; i++) { - // TODO: For CFF fonts the width should technically match th x in - // the glyph, but it doesn't seem to matter. - var charstring = charstrings ? charstrings[i - 1] : {}; - var width = 'width' in charstring ? charstring.width : 0; + var width = 0; + if (charstrings) { + var charstring = charstrings[i - 1]; + width = 'width' in charstring ? charstring.width : 0; + } else if (cffWidths) { + width = Math.ceil(cffWidths[i] || 0); + } hmtx += string16(width) + string16(0); } return hmtx; @@ -25223,10 +25227,10 @@ var CFFFont = (function CFFFontClosure() { var CFFParser = (function CFFParserClosure() { var CharstringValidationData = [ null, - { id: 'hstem', min: 2, resetStack: true, stem: true }, + { id: 'hstem', min: 2, stackClearing: true, stem: true }, null, - { id: 'vstem', min: 2, resetStack: true, stem: true }, - { id: 'vmoveto', min: 1, resetStack: true }, + { id: 'vstem', min: 2, stackClearing: true, stem: true }, + { id: 'vmoveto', min: 1, stackClearing: true }, { id: 'rlineto', min: 2, resetStack: true }, { id: 'hlineto', min: 1, resetStack: true }, { id: 'vlineto', min: 1, resetStack: true }, @@ -25236,16 +25240,16 @@ var CFFParser = (function CFFParserClosure() { { id: 'return', min: 0, undefStack: true }, null, // 12 null, - null, // endchar + { id: 'endchar', min: 0, stackClearing: true }, null, null, null, - { id: 'hstemhm', min: 2, resetStack: true, stem: true }, - null, // hintmask - null, // cntrmask - { id: 'rmoveto', min: 2, resetStack: true }, - { id: 'hmoveto', min: 1, resetStack: true }, - { id: 'vstemhm', min: 2, resetStack: true, stem: true }, + { id: 'hstemhm', min: 2, stackClearing: true, stem: true }, + { id: 'hintmask', min: 0, stackClearing: true }, + { id: 'cntrmask', min: 0, stackClearing: true }, + { id: 'rmoveto', min: 2, stackClearing: true }, + { id: 'hmoveto', min: 1, stackClearing: true }, + { id: 'vstemhm', min: 2, stackClearing: true, stem: true }, { id: 'rcurveline', min: 8, resetStack: true }, { id: 'rlinecurve', min: 8, resetStack: true }, { id: 'vvcurveto', min: 4, resetStack: true }, @@ -25351,6 +25355,7 @@ var CFFParser = (function CFFParserClosure() { var charStringsAndSeacs = this.parseCharStrings(charStringOffset); cff.charStrings = charStringsAndSeacs.charStrings; cff.seacs = charStringsAndSeacs.seacs; + cff.widths = charStringsAndSeacs.widths; var fontMatrix = topDict.getByName('FontMatrix'); if (fontMatrix) { @@ -25568,6 +25573,7 @@ var CFFParser = (function CFFParserClosure() { parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) { var charStrings = this.parseIndex(charStringOffset).obj; var seacs = []; + var widths = []; var count = charStrings.count; for (var i = 0; i < count; i++) { var charstring = charStrings.get(i); @@ -25579,6 +25585,7 @@ var CFFParser = (function CFFParserClosure() { var valid = true; var data = charstring; var length = data.length; + var firstStackClearing = true; for (var j = 0; j < length;) { var value = data[j++]; var validationCommand = null; @@ -25608,6 +25615,7 @@ var CFFParser = (function CFFParserClosure() { valid = false; } } + validationCommand = CharstringValidationData[value]; } else if (value >= 32 && value <= 246) { // number stack[stackSize] = value - 139; stackSize++; @@ -25625,7 +25633,8 @@ var CFFParser = (function CFFParserClosure() { } else if (value === 19 || value === 20) { hints += stackSize >> 1; j += (hints + 7) >> 3; // skipping right amount of hints flag data - stackSize = 0; + stackSize %= 2; + validationCommand = CharstringValidationData[value]; } else { validationCommand = CharstringValidationData[value]; } @@ -25642,17 +25651,35 @@ var CFFParser = (function CFFParserClosure() { break; } } + if (firstStackClearing && validationCommand.stackClearing) { + firstStackClearing = false; + // the optional character width can be found before the first + // stack-clearing command arguments + stackSize -= validationCommand.min; + if (stackSize >= 2 && validationCommand.stem) { + // there are even amount of arguments for stem commands + stackSize %= 2; + } else if (stackSize > 1) { + warn('Found too many parameters for stack-clearing command'); + } + if (stackSize > 0 && stack[stackSize - 1] >= 0) { + widths[i] = stack[stackSize - 1]; + } + } if ('stackDelta' in validationCommand) { if ('stackFn' in validationCommand) { validationCommand.stackFn(stack, stackSize); } stackSize += validationCommand.stackDelta; + } else if (validationCommand.stackClearing) { + stackSize = 0; } else if (validationCommand.resetStack) { stackSize = 0; undefStack = false; } else if (validationCommand.undefStack) { stackSize = 0; undefStack = true; + firstStackClearing = false; } } } @@ -25661,7 +25688,7 @@ var CFFParser = (function CFFParserClosure() { charStrings.set(i, new Uint8Array([14])); } } - return { charStrings: charStrings, seacs: seacs }; + return { charStrings: charStrings, seacs: seacs, widths: widths }; }, emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(parentDict) { diff --git a/build/pdf.js b/build/pdf.js index 8169f0bae..e40e6e88e 100644 --- a/build/pdf.js +++ b/build/pdf.js @@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') { (typeof window !== 'undefined' ? window : this).PDFJS = {}; } -PDFJS.version = '1.0.672'; -PDFJS.build = '90afb70'; +PDFJS.version = '1.0.674'; +PDFJS.build = 'cd5bd9f'; (function pdfjsWrapper() { // Use strict in our context only - users might not want it diff --git a/build/pdf.worker.js b/build/pdf.worker.js index 3488c62ae..9382c3ea0 100644 --- a/build/pdf.worker.js +++ b/build/pdf.worker.js @@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') { (typeof window !== 'undefined' ? window : this).PDFJS = {}; } -PDFJS.version = '1.0.672'; -PDFJS.build = '90afb70'; +PDFJS.version = '1.0.674'; +PDFJS.build = 'cd5bd9f'; (function pdfjsWrapper() { // Use strict in our context only - users might not want it @@ -17833,12 +17833,16 @@ var Font = (function FontClosure() { // Horizontal metrics builder.addTable('hmtx', (function fontFieldsHmtx() { var charstrings = font.charstrings; + var cffWidths = font.cff ? font.cff.widths : null; var hmtx = '\x00\x00\x00\x00'; // Fake .notdef for (var i = 1, ii = numGlyphs; i < ii; i++) { - // TODO: For CFF fonts the width should technically match th x in - // the glyph, but it doesn't seem to matter. - var charstring = charstrings ? charstrings[i - 1] : {}; - var width = 'width' in charstring ? charstring.width : 0; + var width = 0; + if (charstrings) { + var charstring = charstrings[i - 1]; + width = 'width' in charstring ? charstring.width : 0; + } else if (cffWidths) { + width = Math.ceil(cffWidths[i] || 0); + } hmtx += string16(width) + string16(0); } return hmtx; @@ -19240,10 +19244,10 @@ var CFFFont = (function CFFFontClosure() { var CFFParser = (function CFFParserClosure() { var CharstringValidationData = [ null, - { id: 'hstem', min: 2, resetStack: true, stem: true }, + { id: 'hstem', min: 2, stackClearing: true, stem: true }, null, - { id: 'vstem', min: 2, resetStack: true, stem: true }, - { id: 'vmoveto', min: 1, resetStack: true }, + { id: 'vstem', min: 2, stackClearing: true, stem: true }, + { id: 'vmoveto', min: 1, stackClearing: true }, { id: 'rlineto', min: 2, resetStack: true }, { id: 'hlineto', min: 1, resetStack: true }, { id: 'vlineto', min: 1, resetStack: true }, @@ -19253,16 +19257,16 @@ var CFFParser = (function CFFParserClosure() { { id: 'return', min: 0, undefStack: true }, null, // 12 null, - null, // endchar + { id: 'endchar', min: 0, stackClearing: true }, null, null, null, - { id: 'hstemhm', min: 2, resetStack: true, stem: true }, - null, // hintmask - null, // cntrmask - { id: 'rmoveto', min: 2, resetStack: true }, - { id: 'hmoveto', min: 1, resetStack: true }, - { id: 'vstemhm', min: 2, resetStack: true, stem: true }, + { id: 'hstemhm', min: 2, stackClearing: true, stem: true }, + { id: 'hintmask', min: 0, stackClearing: true }, + { id: 'cntrmask', min: 0, stackClearing: true }, + { id: 'rmoveto', min: 2, stackClearing: true }, + { id: 'hmoveto', min: 1, stackClearing: true }, + { id: 'vstemhm', min: 2, stackClearing: true, stem: true }, { id: 'rcurveline', min: 8, resetStack: true }, { id: 'rlinecurve', min: 8, resetStack: true }, { id: 'vvcurveto', min: 4, resetStack: true }, @@ -19368,6 +19372,7 @@ var CFFParser = (function CFFParserClosure() { var charStringsAndSeacs = this.parseCharStrings(charStringOffset); cff.charStrings = charStringsAndSeacs.charStrings; cff.seacs = charStringsAndSeacs.seacs; + cff.widths = charStringsAndSeacs.widths; var fontMatrix = topDict.getByName('FontMatrix'); if (fontMatrix) { @@ -19585,6 +19590,7 @@ var CFFParser = (function CFFParserClosure() { parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) { var charStrings = this.parseIndex(charStringOffset).obj; var seacs = []; + var widths = []; var count = charStrings.count; for (var i = 0; i < count; i++) { var charstring = charStrings.get(i); @@ -19596,6 +19602,7 @@ var CFFParser = (function CFFParserClosure() { var valid = true; var data = charstring; var length = data.length; + var firstStackClearing = true; for (var j = 0; j < length;) { var value = data[j++]; var validationCommand = null; @@ -19625,6 +19632,7 @@ var CFFParser = (function CFFParserClosure() { valid = false; } } + validationCommand = CharstringValidationData[value]; } else if (value >= 32 && value <= 246) { // number stack[stackSize] = value - 139; stackSize++; @@ -19642,7 +19650,8 @@ var CFFParser = (function CFFParserClosure() { } else if (value === 19 || value === 20) { hints += stackSize >> 1; j += (hints + 7) >> 3; // skipping right amount of hints flag data - stackSize = 0; + stackSize %= 2; + validationCommand = CharstringValidationData[value]; } else { validationCommand = CharstringValidationData[value]; } @@ -19659,17 +19668,35 @@ var CFFParser = (function CFFParserClosure() { break; } } + if (firstStackClearing && validationCommand.stackClearing) { + firstStackClearing = false; + // the optional character width can be found before the first + // stack-clearing command arguments + stackSize -= validationCommand.min; + if (stackSize >= 2 && validationCommand.stem) { + // there are even amount of arguments for stem commands + stackSize %= 2; + } else if (stackSize > 1) { + warn('Found too many parameters for stack-clearing command'); + } + if (stackSize > 0 && stack[stackSize - 1] >= 0) { + widths[i] = stack[stackSize - 1]; + } + } if ('stackDelta' in validationCommand) { if ('stackFn' in validationCommand) { validationCommand.stackFn(stack, stackSize); } stackSize += validationCommand.stackDelta; + } else if (validationCommand.stackClearing) { + stackSize = 0; } else if (validationCommand.resetStack) { stackSize = 0; undefStack = false; } else if (validationCommand.undefStack) { stackSize = 0; undefStack = true; + firstStackClearing = false; } } } @@ -19678,7 +19705,7 @@ var CFFParser = (function CFFParserClosure() { charStrings.set(i, new Uint8Array([14])); } } - return { charStrings: charStrings, seacs: seacs }; + return { charStrings: charStrings, seacs: seacs, widths: widths }; }, emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(parentDict) { diff --git a/package.json b/package.json index 4d80971de..0b4ea41eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pdfjs-dist", - "version": "1.0.672", + "version": "1.0.674", "description": "Generic build of Mozilla's PDF.js library.", "keywords": [ "Mozilla",