Remove the, strictly unnecessary, closure and variable shadowing from createObjectURL

Note that this particular helper function is, with the exception of the `GENERIC` default viewer and the (unsupported) SVG-backend, mostly unused at this point in time. Hence we should be able to clean-up this helper function slightly.

Also, fixes a small inconsistency in the `SVGGraphics` initialization in the viewer, by passing in the `disableCreateObjectURL` compatibility-option. Given that the SVG-backend isn't officially supported/recommended this shouldn't have been an issue, but given that I spotted this it can't hurt to fix it.
This commit is contained in:
Jonas Jenwald 2021-02-25 13:11:05 +01:00
parent 8b7dee0aae
commit 70d1869fe5
2 changed files with 22 additions and 23 deletions

View File

@ -940,18 +940,14 @@ function createPromiseCapability() {
return capability; return capability;
} }
const createObjectURL = (function createObjectURLClosure() { function createObjectURL(data, contentType = "", forceDataSchema = false) {
if (URL.createObjectURL && !forceDataSchema) {
return URL.createObjectURL(new Blob([data], { type: contentType }));
}
// Blob/createObjectURL is not available, falling back to data schema. // Blob/createObjectURL is not available, falling back to data schema.
const digits = const digits =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
// eslint-disable-next-line no-shadow
return function createObjectURL(data, contentType, forceDataSchema = false) {
if (!forceDataSchema && URL.createObjectURL) {
const blob = new Blob([data], { type: contentType });
return URL.createObjectURL(blob);
}
let buffer = `data:${contentType};base64,`; let buffer = `data:${contentType};base64,`;
for (let i = 0, ii = data.length; i < ii; i += 3) { for (let i = 0, ii = data.length; i < ii; i += 3) {
const b1 = data[i] & 0xff; const b1 = data[i] & 0xff;
@ -964,8 +960,7 @@ const createObjectURL = (function createObjectURLClosure() {
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4]; buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
} }
return buffer; return buffer;
}; }
})();
export { export {
AbortException, AbortException,

View File

@ -701,7 +701,11 @@ class PDFPageView {
const actualSizeViewport = this.viewport.clone({ scale: CSS_UNITS }); const actualSizeViewport = this.viewport.clone({ scale: CSS_UNITS });
const promise = pdfPage.getOperatorList().then(opList => { const promise = pdfPage.getOperatorList().then(opList => {
ensureNotCancelled(); ensureNotCancelled();
const svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs); const svgGfx = new SVGGraphics(
pdfPage.commonObjs,
pdfPage.objs,
/* forceDataSchema = */ viewerCompatibilityParams.disableCreateObjectURL
);
return svgGfx.getSVG(opList, actualSizeViewport).then(svg => { return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
ensureNotCancelled(); ensureNotCancelled();
this.svg = svg; this.svg = svg;