1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 09:08:07 +02:00

[api-major] Add openjpeg.wasm to pdf.js (bug 1935076)

In order to fix bug 1935076, we'll have to add a pure js fallback in case wasm is disabled
or simd isn't supported. Unfortunately, this fallback will take some space.

So, the main goal of this patch is to reduce the overall size (by ~93k).
As a side effect, it should make easier to use an other wasm file (which must export
_jp2_decode, _malloc and _free).
This commit is contained in:
Calixte Denizet 2025-01-15 20:20:11 +01:00
parent 711bf2bd12
commit 94b4b54ef6
21 changed files with 274 additions and 19 deletions

View file

@ -31,6 +31,7 @@ const { GenericL10n, parseQueryString, SimpleLinkService } = pdfjsViewer;
const WAITING_TIME = 100; // ms
const CMAP_URL = "/build/generic/web/cmaps/";
const STANDARD_FONT_DATA_URL = "/build/generic/web/standard_fonts/";
const WASM_URL = "/build/generic/web/wasm/";
const IMAGE_RESOURCES_PATH = "/web/images/";
const VIEWER_CSS = "../build/components/pdf_viewer.css";
const VIEWER_LOCALE = "en-US";
@ -631,6 +632,7 @@ class Driver {
password: task.password,
cMapUrl: CMAP_URL,
standardFontDataUrl: STANDARD_FONT_DATA_URL,
wasmUrl: WASM_URL,
disableAutoFetch: !task.enableAutoFetch,
pdfBug: true,
useSystemFonts: task.useSystemFonts,

View file

@ -6371,6 +6371,14 @@
"rounds": 1,
"type": "eq"
},
{
"id": "issue19326_main_thread_fetch",
"file": "pdfs/issue19326.pdf",
"md5": "b4d937017daf439a6318501428e0c6ba",
"rounds": 1,
"type": "eq",
"useWorkerFetch": false
},
{
"id": "bug1140761",
"file": "pdfs/bug1140761.pdf",

View file

@ -28,6 +28,8 @@ const STANDARD_FONT_DATA_URL = isNodeJS
? "./external/standard_fonts/"
: "../../external/standard_fonts/";
const WASM_URL = isNodeJS ? "./external/openjpeg/" : "../../external/openjpeg/";
class DefaultFileReaderFactory {
static async fetch(params) {
if (isNodeJS) {
@ -44,6 +46,7 @@ function buildGetDocumentParams(filename, options) {
? TEST_PDFS_PATH + filename
: new URL(TEST_PDFS_PATH + filename, window.location).href;
params.standardFontDataUrl = STANDARD_FONT_DATA_URL;
params.wasmUrl = WASM_URL;
for (const option in options) {
params[option] = options[option];

View file

@ -22,6 +22,7 @@
"display-cmap_reader_factory": "../../src/display/cmap_reader_factory.js",
"display-standard_fontdata_factory": "../../src/display/standard_fontdata_factory.js",
"display-wasm_factory": "../../src/display/wasm_factory.js",
"display-fetch_stream": "../../src/display/fetch_stream.js",
"display-network": "../../src/display/network.js",
"display-node_stream": "../../src/display/stubs.js",

View file

@ -38,6 +38,7 @@ const MIME_TYPES = {
".log": "text/plain",
".bcmap": "application/octet-stream",
".ftl": "text/plain",
".wasm": "application/wasm",
};
const DEFAULT_MIME_TYPE = "application/octet-stream";