Skip to content

Commit ec294b8

Browse files
committed
Merge branch 'master' into images
2 parents 33c39da + 17ef9da commit ec294b8

37 files changed

+2076
-1872
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
*.out
77
node_modules/
88
target/
9+
.idea
10+
.npmrc
911

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
language: node_js
22
node_js:
3-
- "4.5.0"
3+
- "14.18.0"

base/core/core.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,17 @@ var Page = (function PageClosure() {
170170

171171

172172
var opList = new OperatorList(handler, self.pageIndex);
173-
174-
handler.send('StartRenderPage', {
175-
transparency: partialEvaluator.hasBlendModes(self.resources),
176-
pageIndex: self.pageIndex
177-
});
178-
partialEvaluator.getOperatorList(contentStream, self.resources, opList);
179-
pageListPromise.resolve(opList);
173+
try {
174+
handler.send('StartRenderPage', {
175+
transparency: partialEvaluator.hasBlendModes(self.resources),
176+
pageIndex: self.pageIndex
177+
});
178+
partialEvaluator.getOperatorList(contentStream, self.resources, opList);
179+
pageListPromise.resolve(opList);
180+
}
181+
catch(e) {
182+
pageListPromise.reject(e);
183+
}
180184
});
181185

182186
var annotationsPromise = pdfManager.ensure(this, 'annotations');

base/core/crypto.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,17 +553,17 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
553553
function CipherTransformFactory(dict, fileId, password) {
554554
var filter = dict.get('Filter');
555555
if (!isName(filter) || filter.name != 'Standard')
556-
error('unknown encryption method');
556+
error('Error: unknown encryption method');
557557
this.dict = dict;
558558
var algorithm = dict.get('V');
559559
if (!isInt(algorithm) ||
560560
(algorithm != 1 && algorithm != 2 && algorithm != 4))
561-
error('unsupported encryption algorithm');
561+
error('Error: unsupported encryption algorithm');
562562
this.algorithm = algorithm;
563563
var keyLength = dict.get('Length') || 40;
564564
if (!isInt(keyLength) ||
565565
keyLength < 40 || (keyLength % 8) !== 0)
566-
error('invalid key length');
566+
error('Error: invalid key length');
567567
// prepare keys
568568
var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
569569
var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);

base/core/obj.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ var XRef = (function XRefClosure() {
10011001
throw e;
10021002
}
10031003
log('(while reading XRef): ' + e);
1004+
error(e);
10041005
}
10051006

10061007
if (recoveryMode)

base/core/parser.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,8 @@ var Lexer = (function LexerClosure() {
534534
str += String.fromCharCode(ch);
535535
}
536536
}
537-
if (str.length > 128) {
538-
error('Warning: name token is longer than allowed by the spec: ' +
539-
str.length);
537+
if (str.length > 127) {
538+
warn('Name token is longer than allowed by the spec: ' + str.length);
540539
}
541540
return new Name(str);
542541
},

base/display/api.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,13 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
412412
return;
413413
}
414414
stats.time('Rendering');
415-
internalRenderTask.initalizeGraphics(transparency);
416-
internalRenderTask.operatorListChanged();
415+
try {//MQZ. catch canvas drawing exceptions
416+
internalRenderTask.initalizeGraphics(transparency);
417+
internalRenderTask.operatorListChanged();
418+
}
419+
catch(err) {
420+
complete(err);
421+
}
417422
},
418423
function pageDisplayReadPromiseError(reason) {
419424
complete(reason);

base/display/canvas.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
10361036
showText: function CanvasGraphics_showText(glyphs, skipTextSelection) {
10371037
var ctx = this.ctx;
10381038
var current = this.current;
1039-
var font = current.font;
1039+
var font = current.font || {};
10401040
var fontSize = current.fontSize;
10411041
var fontSizeScale = current.fontSizeScale;
10421042
var charSpacing = current.charSpacing;
@@ -1095,19 +1095,20 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
10951095
this.processingType3 = null;
10961096
} else {
10971097
ctx.save();
1098-
var tx = 0;
10991098

11001099
//MQZ Dec.04.2013 handles leading word spacing
1100+
var tx = 0;
11011101
if (wordSpacing !== 0) {
1102-
var firstGlyph = _.find(glyphs, function(g) { return _.isObject(g);});
1102+
var firstGlyph = glyphs.filter(g => g && ('fontChar' in g || 'unicode' in g))[0];
11031103
if (firstGlyph && (firstGlyph.fontChar === ' ' || firstGlyph.unicode === ' ')) {
1104-
if (_.find(glyphs, function(g) { return _.isObject(g) && g.unicode !== ' ';})) {
1105-
current.x += wordSpacing * fontSize * textHScale;
1106-
}
1104+
tx = wordSpacing * fontSize * textHScale;
11071105
}
11081106
}
11091107

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

11121113
var lineWidth = current.lineWidth;
11131114
var a1 = current.textMatrix[0], b1 = current.textMatrix[1];
@@ -1286,7 +1287,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
12861287
}
12871288
}
12881289
else {
1289-
if (-e >= spaceWidth) {
1290+
//MQZ-GYJ. Apr.20.2017 split word when spacing is a positive number but very big
1291+
if (Math.abs(e) >= spaceWidth) {
12901292
if (vertical) {
12911293
current.y += spacingLength;
12921294
} else {
@@ -1533,6 +1535,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
15331535
var depth = this.current.paintFormXObjectDepth;
15341536
do {
15351537
this.restore();
1538+
this.current.paintFormXObjectDepth--;
15361539
// some pdf don't close all restores inside object
15371540
// closing those for them
15381541
} while (this.current.paintFormXObjectDepth >= depth);
@@ -1616,6 +1619,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
16161619
},
16171620

16181621
endGroup: function CanvasGraphics_endGroup(group) {
1622+
//MQZ. make sure endGroup is always invoked after beginGroup
1623+
if (this.groupLevel == 0)
1624+
this.beginGroup(group);
1625+
16191626
this.groupLevel--;
16201627
var groupCtx = this.ctx;
16211628
this.ctx = this.groupStack.pop();

base/display/metadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var Metadata = PDFJS.Metadata = (function MetadataClosure() {
5757
var doc = this.metaDocument;
5858
var rdf = doc.documentElement;
5959

60-
if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
60+
if (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
6161
rdf = rdf.firstChild;
6262
while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf')
6363
rdf = rdf.nextSibling;

base/shared/annotation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
667667

668668
// Lets URLs beginning with 'www.' default to using the 'http://' protocol.
669669
function addDefaultProtocolToUrl(url) {
670-
if (url.indexOf('www.') === 0) {
670+
if (url && url.indexOf('www.') === 0) {
671671
return ('http://' + url);
672672
}
673673
return url;

0 commit comments

Comments
 (0)