Skip to content

Instantly share code, notes, and snippets.

@pcwalton
Last active July 4, 2020 01:43
Show Gist options
  • Save pcwalton/04cecd4a5db4d1f0bb663674ae937117 to your computer and use it in GitHub Desktop.
Save pcwalton/04cecd4a5db4d1f0bb663674ae937117 to your computer and use it in GitHub Desktop.
diff --git a/gulpfile.js b/gulpfile.js
index a850f717..ba7cf4ad 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -211,7 +211,7 @@ function createWebpackConfig(defines, output) {
// `web-streams-polyfill` (already using a transpiled file), and
// `src/core/{glyphlist,unicode}.js` (Babel is too slow for those)
// should be excluded from processing.
- exclude: /(node_modules[\\\/]core-js|node_modules[\\\/]web-streams-polyfill|src[\\\/]core[\\\/](glyphlist|unicode))/,
+ exclude: /(node_modules[\\\/]core-js|node_modules[\\\/]web-streams-polyfill|src[\\\/]core[\\\/](glyphlist|unicode))|(\.wasm$)/,
options: {
presets: skipBabel ? undefined : ["@babel/preset-env"],
plugins: [
@@ -234,6 +234,7 @@ function createWebpackConfig(defines, output) {
},
{
loader: path.join(__dirname, "external/webpack/pdfjsdev-loader.js"),
+ exclude: /\.wasm$/,
options: {
rootPath: __dirname,
saveComments: false,
diff --git a/test/webserver.js b/test/webserver.js
index 417dff25..a764efbd 100644
--- a/test/webserver.js
+++ b/test/webserver.js
@@ -35,6 +35,7 @@ var mimeTypes = {
".log": "text/plain",
".bcmap": "application/octet-stream",
".properties": "text/plain",
+ ".wasm": "application/wasm",
};
var defaultMimeType = "application/octet-stream";
diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js
index ecf0326f..944a5748 100644
--- a/web/pdf_page_view.js
+++ b/web/pdf_page_view.js
@@ -30,6 +30,7 @@ import {
} from "pdfjs-lib";
import { RenderingStates } from "./pdf_rendering_queue.js";
import { viewerCompatibilityParams } from "./viewer_compatibility.js";
+import { createContext } from "./pathfinder_web_canvas/pathfinder_web_canvas.js";
/**
* @typedef {Object} PDFPageViewOptions
@@ -574,6 +575,7 @@ class PDFPageView {
canvas.setAttribute("hidden", "hidden");
let isCanvasHidden = true;
const showCanvas = function () {
+ ctx.flush();
if (isCanvasHidden) {
canvas.removeAttribute("hidden");
isCanvasHidden = false;
@@ -590,7 +592,7 @@ class PDFPageView {
canvas.mozOpaque = true;
}
- const ctx = canvas.getContext("2d", { alpha: false });
+ const ctx = createContext(canvas);
const outputScale = getOutputScale(ctx);
this.outputScale = outputScale;
diff --git a/web/viewer.js b/web/viewer.js
index f51cdd44..926b3cf4 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -15,6 +15,9 @@
"use strict";
+// FIXME(pcwalton): This is probably not the best place to do this!
+import initPFWebCanvas from "./pathfinder_web_canvas/pathfinder_web_canvas.js";
+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
var defaultUrl; // eslint-disable-line no-var
@@ -185,7 +188,7 @@ function getViewerConfiguration() {
};
}
-function webViewerLoad() {
+function realWebViewerLoad() {
const config = getViewerConfiguration();
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
Promise.all([
@@ -231,6 +234,10 @@ function webViewerLoad() {
}
}
+function webViewerLoad() {
+ initPFWebCanvas().then(() => realWebViewerLoad());
+}
+
if (
document.readyState === "interactive" ||
document.readyState === "complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment