Skip to content

Commit

Permalink
Merge branch 'master' into images
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaskello committed Nov 25, 2021
2 parents 33c39da + 17ef9da commit ec294b8
Show file tree
Hide file tree
Showing 37 changed files with 2,076 additions and 1,872 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
*.out
node_modules/
target/
.idea
.npmrc

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "4.5.0"
- "14.18.0"
18 changes: 11 additions & 7 deletions base/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,17 @@ var Page = (function PageClosure() {


var opList = new OperatorList(handler, self.pageIndex);

handler.send('StartRenderPage', {
transparency: partialEvaluator.hasBlendModes(self.resources),
pageIndex: self.pageIndex
});
partialEvaluator.getOperatorList(contentStream, self.resources, opList);
pageListPromise.resolve(opList);
try {
handler.send('StartRenderPage', {
transparency: partialEvaluator.hasBlendModes(self.resources),
pageIndex: self.pageIndex
});
partialEvaluator.getOperatorList(contentStream, self.resources, opList);
pageListPromise.resolve(opList);
}
catch(e) {
pageListPromise.reject(e);
}
});

var annotationsPromise = pdfManager.ensure(this, 'annotations');
Expand Down
6 changes: 3 additions & 3 deletions base/core/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,17 +553,17 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
function CipherTransformFactory(dict, fileId, password) {
var filter = dict.get('Filter');
if (!isName(filter) || filter.name != 'Standard')
error('unknown encryption method');
error('Error: unknown encryption method');
this.dict = dict;
var algorithm = dict.get('V');
if (!isInt(algorithm) ||
(algorithm != 1 && algorithm != 2 && algorithm != 4))
error('unsupported encryption algorithm');
error('Error: unsupported encryption algorithm');
this.algorithm = algorithm;
var keyLength = dict.get('Length') || 40;
if (!isInt(keyLength) ||
keyLength < 40 || (keyLength % 8) !== 0)
error('invalid key length');
error('Error: invalid key length');
// prepare keys
var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
Expand Down
1 change: 1 addition & 0 deletions base/core/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ var XRef = (function XRefClosure() {
throw e;
}
log('(while reading XRef): ' + e);
error(e);
}

if (recoveryMode)
Expand Down
5 changes: 2 additions & 3 deletions base/core/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,8 @@ var Lexer = (function LexerClosure() {
str += String.fromCharCode(ch);
}
}
if (str.length > 128) {
error('Warning: name token is longer than allowed by the spec: ' +
str.length);
if (str.length > 127) {
warn('Name token is longer than allowed by the spec: ' + str.length);
}
return new Name(str);
},
Expand Down
9 changes: 7 additions & 2 deletions base/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,13 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
return;
}
stats.time('Rendering');
internalRenderTask.initalizeGraphics(transparency);
internalRenderTask.operatorListChanged();
try {//MQZ. catch canvas drawing exceptions
internalRenderTask.initalizeGraphics(transparency);
internalRenderTask.operatorListChanged();
}
catch(err) {
complete(err);
}
},
function pageDisplayReadPromiseError(reason) {
complete(reason);
Expand Down
21 changes: 14 additions & 7 deletions base/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
showText: function CanvasGraphics_showText(glyphs, skipTextSelection) {
var ctx = this.ctx;
var current = this.current;
var font = current.font;
var font = current.font || {};
var fontSize = current.fontSize;
var fontSizeScale = current.fontSizeScale;
var charSpacing = current.charSpacing;
Expand Down Expand Up @@ -1095,19 +1095,20 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.processingType3 = null;
} else {
ctx.save();
var tx = 0;

//MQZ Dec.04.2013 handles leading word spacing
var tx = 0;
if (wordSpacing !== 0) {
var firstGlyph = _.find(glyphs, function(g) { return _.isObject(g);});
var firstGlyph = glyphs.filter(g => g && ('fontChar' in g || 'unicode' in g))[0];
if (firstGlyph && (firstGlyph.fontChar === ' ' || firstGlyph.unicode === ' ')) {
if (_.find(glyphs, function(g) { return _.isObject(g) && g.unicode !== ' ';})) {
current.x += wordSpacing * fontSize * textHScale;
}
tx = wordSpacing * fontSize * textHScale;
}
}

current.x += tx
this.applyTextTransforms();
current.x -= tx
// MQZ-GYJ Apr.20.2017 handles leading word spacing over

var lineWidth = current.lineWidth;
var a1 = current.textMatrix[0], b1 = current.textMatrix[1];
Expand Down Expand Up @@ -1286,7 +1287,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}
}
else {
if (-e >= spaceWidth) {
//MQZ-GYJ. Apr.20.2017 split word when spacing is a positive number but very big
if (Math.abs(e) >= spaceWidth) {
if (vertical) {
current.y += spacingLength;
} else {
Expand Down Expand Up @@ -1533,6 +1535,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var depth = this.current.paintFormXObjectDepth;
do {
this.restore();
this.current.paintFormXObjectDepth--;
// some pdf don't close all restores inside object
// closing those for them
} while (this.current.paintFormXObjectDepth >= depth);
Expand Down Expand Up @@ -1616,6 +1619,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
},

endGroup: function CanvasGraphics_endGroup(group) {
//MQZ. make sure endGroup is always invoked after beginGroup
if (this.groupLevel == 0)
this.beginGroup(group);

this.groupLevel--;
var groupCtx = this.ctx;
this.ctx = this.groupStack.pop();
Expand Down
2 changes: 1 addition & 1 deletion base/display/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var Metadata = PDFJS.Metadata = (function MetadataClosure() {
var doc = this.metaDocument;
var rdf = doc.documentElement;

if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
if (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
rdf = rdf.firstChild;
while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf')
rdf = rdf.nextSibling;
Expand Down
2 changes: 1 addition & 1 deletion base/shared/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ var LinkAnnotation = (function LinkAnnotationClosure() {

// Lets URLs beginning with 'www.' default to using the 'http://' protocol.
function addDefaultProtocolToUrl(url) {
if (url.indexOf('www.') === 0) {
if (url && url.indexOf('www.') === 0) {
return ('http://' + url);
}
return url;
Expand Down
16 changes: 8 additions & 8 deletions base/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1244,18 +1244,18 @@ nodeUtil.p2jinfo = info;
nodeUtil.p2jwarn = warn;
nodeUtil.p2jerror = error;
nodeUtil.verbosity = function(verbo) {
if (!isNaN(verbo)) {
if (isNaN(verbo)) {
verbosity = WARNINGS;
}
else {
if (verbo <= ERRORS) {
verbo = ERRORS;
verbosity = ERRORS;
}
else if (verbo >= INFOS) {
verbo = INFOS;
verbosity = INFOS;
}

verbosity = verbo;
}
else {
verbosity = ERRORS;
else
verbosity = verbo;
}
};
nodeUtil.verbosity();
Expand Down
4 changes: 1 addition & 3 deletions bin/pdf2json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env node

'use strict';

var P2JCMD = require('../lib/p2jcmd');
const P2JCMD = require('../lib/p2jcmd');
new P2JCMD().start();
Loading

0 comments on commit ec294b8

Please sign in to comment.