[api-minor] Stop exposing the createObjectURL helper function in the API

With recent changes, specifically PR 14515 *and* the previous patch, the `createObjectURL` helper function is now only used with the SVG back-end.
All other call-sites, throughout the code-base, are now using `URL.createObjectURL(...)` directly and it no longer seems necessary to keep exposing the helper function in the API.
Finally, the `createObjectURL` helper function is moved into the `src/display/svg.js` file to avoid unnecessarily duplicating this code on both the main- and worker-threads.
This commit is contained in:
Jonas Jenwald 2022-02-10 11:42:50 +01:00
parent 0daab88a48
commit b87a243222
3 changed files with 30 additions and 26 deletions

View File

@ -15,7 +15,6 @@
/* globals __non_webpack_require__ */ /* globals __non_webpack_require__ */
import { import {
createObjectURL,
FONT_IDENTITY_MATRIX, FONT_IDENTITY_MATRIX,
IDENTITY_MATRIX, IDENTITY_MATRIX,
ImageKind, ImageKind,
@ -50,6 +49,36 @@ if (
const LINE_CAP_STYLES = ["butt", "round", "square"]; const LINE_CAP_STYLES = ["butt", "round", "square"];
const LINE_JOIN_STYLES = ["miter", "round", "bevel"]; const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
const createObjectURL = function (
data,
contentType = "",
forceDataSchema = false
) {
if (
URL.createObjectURL &&
typeof Blob !== "undefined" &&
!forceDataSchema
) {
return URL.createObjectURL(new Blob([data], { type: contentType }));
}
// Blob/createObjectURL is not available, falling back to data schema.
const digits =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
let buffer = `data:${contentType};base64,`;
for (let i = 0, ii = data.length; i < ii; i += 3) {
const b1 = data[i] & 0xff;
const b2 = data[i + 1] & 0xff;
const b3 = data[i + 2] & 0xff;
const d1 = b1 >> 2,
d2 = ((b1 & 3) << 4) | (b2 >> 4);
const d3 = i + 1 < ii ? ((b2 & 0xf) << 2) | (b3 >> 6) : 64;
const d4 = i + 2 < ii ? b3 & 0x3f : 64;
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
}
return buffer;
};
const convertImgDataToPng = (function () { const convertImgDataToPng = (function () {
const PNG_HEADER = new Uint8Array([ const PNG_HEADER = new Uint8Array([
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,

View File

@ -23,7 +23,6 @@
import { import {
AnnotationMode, AnnotationMode,
CMapCompressionType, CMapCompressionType,
createObjectURL,
createPromiseCapability, createPromiseCapability,
createValidAbsoluteUrl, createValidAbsoluteUrl,
InvalidPDFException, InvalidPDFException,
@ -109,7 +108,6 @@ export {
AnnotationMode, AnnotationMode,
build, build,
CMapCompressionType, CMapCompressionType,
createObjectURL,
createPromiseCapability, createPromiseCapability,
createValidAbsoluteUrl, createValidAbsoluteUrl,
getDocument, getDocument,

View File

@ -1109,28 +1109,6 @@ function createPromiseCapability() {
return capability; return capability;
} }
function createObjectURL(data, contentType = "", forceDataSchema = false) {
if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
return URL.createObjectURL(new Blob([data], { type: contentType }));
}
// Blob/createObjectURL is not available, falling back to data schema.
const digits =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
let buffer = `data:${contentType};base64,`;
for (let i = 0, ii = data.length; i < ii; i += 3) {
const b1 = data[i] & 0xff;
const b2 = data[i + 1] & 0xff;
const b3 = data[i + 2] & 0xff;
const d1 = b1 >> 2,
d2 = ((b1 & 3) << 4) | (b2 >> 4);
const d3 = i + 1 < ii ? ((b2 & 0xf) << 2) | (b3 >> 6) : 64;
const d4 = i + 2 < ii ? b3 & 0x3f : 64;
buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
}
return buffer;
}
export { export {
AbortException, AbortException,
AnnotationActionEventType, AnnotationActionEventType,
@ -1149,7 +1127,6 @@ export {
BaseException, BaseException,
bytesToString, bytesToString,
CMapCompressionType, CMapCompressionType,
createObjectURL,
createPromiseCapability, createPromiseCapability,
createValidAbsoluteUrl, createValidAbsoluteUrl,
DocumentActionEventType, DocumentActionEventType,