1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

XFA - An image can be a stream in the pdf (bug 1718521)

- hrefs can be found in catalog > Names > XFAImages
This commit is contained in:
Calixte Denizet 2021-07-02 20:05:23 +02:00
parent d80651e572
commit f16828be49
10 changed files with 127 additions and 49 deletions

View file

@ -2932,56 +2932,58 @@ class Image extends StringObject {
}
[$toHTML]() {
if (this.href || !this[$content]) {
// TODO: href can be a Name referring to an internal stream
// containing a picture.
let buffer = this[$globalData].images.get(this.href);
if (!buffer && (this.href || !this[$content])) {
// In general, we don't get remote data and use what we have
// in the pdf itself, so no picture for non null href.
return HTMLResult.EMPTY;
}
// 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 });
let style;
switch (this.aspect) {
case "fit":
case "actual":
// TODO: check what to do with actual.
// Normally we should return {auto, auto} for it but
// it implies some wrong rendering (see xfa_bug1716816.pdf).
break;
case "height":
style = {
width: "auto",
height: "100%",
};
break;
case "none":
style = {
width: "100%",
height: "100%",
};
break;
case "width":
style = {
width: "100%",
height: "auto",
};
break;
}
return HTMLResult.success({
name: "img",
attributes: {
class: ["xfaImage"],
style,
src: URL.createObjectURL(blob),
},
});
if (!buffer && this.transferEncoding === "base64") {
buffer = stringToBytes(atob(this[$content]));
}
return HTMLResult.EMPTY;
if (!buffer) {
return HTMLResult.EMPTY;
}
// TODO: Firefox doesn't support natively tiff (and tif) format.
const blob = new Blob([buffer], { type: this.contentType });
let style;
switch (this.aspect) {
case "fit":
case "actual":
// TODO: check what to do with actual.
// Normally we should return {auto, auto} for it but
// it implies some wrong rendering (see xfa_bug1716816.pdf).
break;
case "height":
style = {
width: "auto",
height: "100%",
};
break;
case "none":
style = {
width: "100%",
height: "100%",
};
break;
case "width":
style = {
width: "100%",
height: "auto",
};
break;
}
return HTMLResult.success({
name: "img",
attributes: {
class: ["xfaImage"],
style,
src: URL.createObjectURL(blob),
},
});
}
}