Skip to content

Commit

Permalink
Merge branch 'modesty:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolabaesso authored Dec 30, 2024
2 parents c69356f + 5cbaa0f commit 0b2d99a
Show file tree
Hide file tree
Showing 11 changed files with 1,770 additions and 1,626 deletions.
32 changes: 23 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
"sourceType": "module",
"project": ["./tsconfig.json"]
},
"ignorePatterns": ["/dist/", "/bin/", "/test/", "/node_modules/", "/base/", "/lib/pdfjs-code.js", "**/*.json"],
"rules": {
"@typescript-eslint/no-unused-expressions": [
"error",
{
"allowShortCircuit": true,
"allowTernary": true,
"allowTaggedTemplates": true
}
]
},
"ignorePatterns": ["/dist/", "/bin/", "/test/", "/node_modules/", "/base/", "/lib/pdfjs-code.js"],
"overrides": [{
"files": ["*.js", "*.ts"],
"rules": {
"files": ["*.js", "*.ts"],
"rules": {
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"@typescript-eslint/naming-convention": [
"error",
Expand Down Expand Up @@ -128,7 +142,7 @@
"prefer-rest-params": ["error"],
"prefer-spread": ["error"],
"prefer-template": ["error"]
}
}
}
}
]
}
44 changes: 19 additions & 25 deletions base/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ var Page = (function PageClosure() {
return promise;
},
getOperatorList: function Page_getOperatorList(handler) {
var self = this;
var promise = new Promise();

function reject(e) {
Expand All @@ -148,8 +147,7 @@ var Page = (function PageClosure() {
var pageListPromise = new Promise();

var pdfManager = this.pdfManager;
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
[]);
var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
var resourcesPromise = this.loadResources([
'ExtGState',
'ColorSpace',
Expand All @@ -166,35 +164,31 @@ var Page = (function PageClosure() {
this.pageIndex, 'p' + this.pageIndex + '_',
this.idCounters, this.fontCache);

var dataPromises = Promise.all(
[contentStreamPromise, resourcesPromise], reject);
dataPromises.then(function(data) {
Promise.all([contentStreamPromise, resourcesPromise]).then(function(data) {
var contentStream = data[0];


var opList = new OperatorList(handler, self.pageIndex);
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);
}
});
try {
var opList = new OperatorList(handler, this.pageIndex);
partialEvaluator.getOperatorList(contentStream, this.resources, opList);
pageListPromise.resolve(opList);

handler.send('StartRenderPage', {
transparency: partialEvaluator.hasBlendModes(this.resources),
pageIndex: this.pageIndex
});
} catch (ex) {
reject(ex);
}
}.bind(this), reject);

var annotationsPromise = pdfManager.ensure(this, 'annotations');
Promise.all([pageListPromise, annotationsPromise]).then(function(datas) {
var pageOpList = datas[0];
var annotations = datas[1];
Promise.all([pageListPromise, annotationsPromise]).then(function(data) {
var pageOpList = data[0];
var annotations = data[1];

if (annotations.length === 0) {
pageOpList.flush(true);
promise.resolve(pageOpList);
return;
return promise;
}

var annotationsReadyPromise = Annotation.appendToOperatorList(
Expand Down
3 changes: 2 additions & 1 deletion base/core/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ var Parser = (function ParserClosure() {
while (stream.pos < stream.end) {
var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
if (scanLength <= 0) break; // no match possible, end of stream or invalid stream
var found = false, i, ii, j;
for (i = 0, j = 0; i < scanLength; i++) {
var b = scanBytes[i];
Expand All @@ -253,7 +254,7 @@ var Parser = (function ParserClosure() {
stream.pos += scanLength;
}
if (!found) {
error('Missing endstream');
error('Missing endstream or invalid stream');
}
length = skipped;

Expand Down
8 changes: 5 additions & 3 deletions base/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.font = fontObj;
this.current.fontSize = size;

if (fontObj.coded)
return; // we don't need ctx.font for Type3 fonts
if (fontObj.coded) {
warn('Unsupported Type3 font (custom Glyph) - ' + fontRefName);
return; // we don't need ctx.font for Type3 fonts
}

var name = fontObj.loadedName || 'sans-serif';
var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
Expand Down Expand Up @@ -1627,7 +1629,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
//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
21 changes: 10 additions & 11 deletions base/display/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,18 @@ var Metadata = (PDFJS.Metadata = (function MetadataClosure() {
}

function Metadata(meta) {
if (typeof meta === 'string') {
this.metadata = {};
if (typeof meta === 'string') {
// Ghostscript produces invalid metadata
meta = fixMetadata(meta);

var parser = new DOMParser();
meta = parser.parseFromString(meta, 'application/xml');
} else if (!(meta instanceof Document)) {
error('Metadata: Invalid metadata object');
}

this.metaDocument = meta;
this.metadata = {};
this.parse();
meta = meta.trim();
if (meta.startsWith('<') && meta.endsWith('>')) {
var parser = new DOMParser();
meta = parser.parseFromString(meta, 'application/xml');
this.metaDocument = meta;
this.parse();
}
}
}

Metadata.prototype = {
Expand Down
4 changes: 2 additions & 2 deletions base/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ function error(msg) {
} else {
//log('Error: ' + msg);
}
//log(backtrace());
//PDFJS.LogManager.notify('error', msg);
// log(backtrace());
PDFJS.LogManager.notify('error', msg);
throw new Error(msg);
}

Expand Down
Loading

0 comments on commit 0b2d99a

Please sign in to comment.