Merge pull request #13672 from mozilla/revert-13654-images

Revert "XFA - An image can be a stream in the pdf (bug 1718521)"
This commit is contained in:
calixteman 2021-07-05 12:47:35 +02:00 committed by GitHub
commit fcd4c8151c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 127 deletions

View File

@ -915,22 +915,6 @@ class Catalog {
return shadow(this, "attachments", attachments); return shadow(this, "attachments", attachments);
} }
get xfaImages() {
const obj = this._catDict.get("Names");
let xfaImages = null;
if (obj instanceof Dict && obj.has("XFAImages")) {
const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref);
for (const [key, value] of nameTree.getAll()) {
if (!xfaImages) {
xfaImages = new Dict(this.ref);
}
xfaImages.set(key, value);
}
}
return shadow(this, "xfaImages", xfaImages);
}
_collectJavaScript() { _collectJavaScript() {
const obj = this._catDict.get("Names"); const obj = this._catDict.get("Names");
let javaScript = null; let javaScript = null;

View File

@ -869,28 +869,6 @@ class PDFDocument {
return null; return null;
} }
async loadXfaImages() {
const xfaImagesDict = await this.pdfManager.ensureCatalog("xfaImages");
if (!xfaImagesDict) {
return;
}
const keys = xfaImagesDict.getKeys();
const objectLoader = new ObjectLoader(xfaImagesDict, keys, this.xref);
await objectLoader.load();
const xfaImages = new Map();
for (const key of keys) {
const stream = xfaImagesDict.get(key);
if (!isStream(stream)) {
continue;
}
xfaImages.set(key, stream.getBytes());
}
this.xfaFactory.setImages(xfaImages);
}
async loadXfaFonts(handler, task) { async loadXfaFonts(handler, task) {
const acroForm = await this.pdfManager.ensureCatalog("acroForm"); const acroForm = await this.pdfManager.ensureCatalog("acroForm");
if (!acroForm) { if (!acroForm) {

View File

@ -77,10 +77,6 @@ class BasePdfManager {
return this.pdfDocument.loadXfaFonts(handler, task); return this.pdfDocument.loadXfaFonts(handler, task);
} }
loadXfaImages() {
return this.pdfDocument.loadXfaImages();
}
serializeXfaData(annotationStorage) { serializeXfaData(annotationStorage) {
return this.pdfDocument.serializeXfaData(annotationStorage); return this.pdfDocument.serializeXfaData(annotationStorage);
} }

View File

@ -191,15 +191,12 @@ class WorkerMessageHandler {
if (isPureXfa) { if (isPureXfa) {
const task = new WorkerTask("loadXfaFonts"); const task = new WorkerTask("loadXfaFonts");
startWorkerTask(task); startWorkerTask(task);
await Promise.all([ await pdfManager
pdfManager
.loadXfaFonts(handler, task) .loadXfaFonts(handler, task)
.catch(reason => { .catch(reason => {
// Ignore errors, to allow the document to load. // Ignore errors, to allow the document to load.
}) })
.then(() => finishWorkerTask(task)), .then(() => finishWorkerTask(task));
pdfManager.loadXfaImages(),
]);
} }
const [numPages, fingerprints] = await Promise.all([ const [numPages, fingerprints] = await Promise.all([

View File

@ -61,10 +61,6 @@ class XFAFactory {
return this.dims.length; return this.dims.length;
} }
setImages(images) {
this.form[$globalData].images = images;
}
setFonts(fonts) { setFonts(fonts) {
this.form[$globalData].fontFinder = new FontFinder(fonts); this.form[$globalData].fontFinder = new FontFinder(fonts);
const missingFonts = []; const missingFonts = [];

View File

@ -2932,22 +2932,17 @@ class Image extends StringObject {
} }
[$toHTML]() { [$toHTML]() {
let buffer = this[$globalData].images.get(this.href); if (this.href || !this[$content]) {
if (!buffer && (this.href || !this[$content])) { // TODO: href can be a Name referring to an internal stream
// containing a picture.
// In general, we don't get remote data and use what we have // In general, we don't get remote data and use what we have
// in the pdf itself, so no picture for non null href. // in the pdf itself, so no picture for non null href.
return HTMLResult.EMPTY; return HTMLResult.EMPTY;
} }
if (!buffer && this.transferEncoding === "base64") {
buffer = stringToBytes(atob(this[$content]));
}
if (!buffer) {
return HTMLResult.EMPTY;
}
// TODO: Firefox doesn't support natively tiff (and tif) format. // TODO: Firefox doesn't support natively tiff (and tif) format.
if (this.transferEncoding === "base64") {
const buffer = stringToBytes(atob(this[$content]));
const blob = new Blob([buffer], { type: this.contentType }); const blob = new Blob([buffer], { type: this.contentType });
let style; let style;
switch (this.aspect) { switch (this.aspect) {
@ -2985,6 +2980,9 @@ class Image extends StringObject {
}, },
}); });
} }
return HTMLResult.EMPTY;
}
} }
class ImageEdit extends XFAObject { class ImageEdit extends XFAObject {

View File

@ -1 +0,0 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9229396

View File

@ -1 +0,0 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9229409

View File

@ -1 +0,0 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9229430

View File

@ -938,30 +938,6 @@
"lastPage": 2, "lastPage": 2,
"type": "eq" "type": "eq"
}, },
{ "id": "xfa_bug1718521_1",
"file": "pdfs/xfa_bug1718521_1.pdf",
"md5": "9b89dd9e6a4c6c3258ca24debd806863",
"link": true,
"rounds": 1,
"enableXfa": true,
"type": "eq"
},
{ "id": "xfa_bug1718521_2",
"file": "pdfs/xfa_bug1718521_2.pdf",
"md5": "c23beb39e1c91a780da9d4b60cbd157f",
"link": true,
"rounds": 1,
"enableXfa": true,
"type": "eq"
},
{ "id": "xfa_bug1718521_3",
"file": "pdfs/xfa_bug1718521_3.pdf",
"md5": "5cc6fb1a65515518e3e64baa81e7a21e",
"link": true,
"rounds": 1,
"enableXfa": true,
"type": "eq"
},
{ "id": "xfa_bug1718735", { "id": "xfa_bug1718735",
"file": "pdfs/xfa_bug1718735.pdf", "file": "pdfs/xfa_bug1718735.pdf",
"md5": "1001f5c02c026943cbd37f646725d82f", "md5": "1001f5c02c026943cbd37f646725d82f",