Skip to content

Commit 7ec6bec

Browse files
committed
chore: remove dead MuPDF inline helpers + orphaned tile-renderer.js
- renderer.js:21-90 had a never-wired-up MuPDF WASM prototype block (loadMupdf / isMupdfAvailable / getMupdfDocument / renderPageWithMupdf). The active rendering path is the Rust vector renderer via extract_draw_commands + vector-renderer.js, with PDF.js fallback. Replaced the dead block with a brief explanatory comment. - mupdf-renderer.js stays — it's still imported once for closeDocument() cleanup (no-op when WASM never loaded). - tile-renderer.js was a 300-line orphan (8 exports, 0 importers); fully superseded by vector-renderer + page-bitmap-cache. Deleted. renderer.js: 1458 → 1394 lines. No behavior change.
1 parent 87f3b66 commit 7ec6bec

2 files changed

Lines changed: 9 additions & 394 deletions

File tree

open-pdf-studio/js/pdf/renderer.js

Lines changed: 9 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,79 +17,15 @@ import { onPageRendered, clearHighlights } from '../search/find-bar.js';
1717
// Hi-DPI support: render canvases at device pixel ratio for sharp text
1818
export function getCanvasDPR() { return window.devicePixelRatio || 1; }
1919

20-
// ─── MuPDF WASM Rendering ─────────────────────────────────────────────────
21-
// Uses MuPDF compiled to WASM for 50-100x faster PDF rendering than PDF.js.
22-
// Falls back to PDF.js if mupdf is not available.
23-
24-
let _mupdfModule = null;
25-
let _mupdfAvailable = null;
26-
let _mupdfDocument = null;
27-
let _mupdfDocPath = null; // track which file is loaded
28-
29-
async function loadMupdf() {
30-
if (_mupdfModule) return _mupdfModule;
31-
try {
32-
_mupdfModule = await import('mupdf');
33-
return _mupdfModule;
34-
} catch (e) {
35-
console.warn('[mupdf] WASM module not available:', e);
36-
return null;
37-
}
38-
}
39-
40-
async function isMupdfAvailable() {
41-
if (_mupdfAvailable !== null) return _mupdfAvailable;
42-
const mod = await loadMupdf();
43-
_mupdfAvailable = mod !== null;
44-
return _mupdfAvailable;
45-
}
46-
47-
// Open or reuse a MuPDF document from cached PDF bytes
48-
async function getMupdfDocument(pdfBytes) {
49-
const mupdf = await loadMupdf();
50-
if (!mupdf) return null;
51-
// Reuse if same bytes (check by length — imperfect but fast)
52-
if (_mupdfDocument && _mupdfDocPath === pdfBytes.length) {
53-
return _mupdfDocument;
54-
}
55-
try {
56-
if (_mupdfDocument) { try { _mupdfDocument.destroy(); } catch {} }
57-
_mupdfDocument = mupdf.Document.openDocument(pdfBytes, 'application/pdf');
58-
_mupdfDocPath = pdfBytes.length;
59-
return _mupdfDocument;
60-
} catch (e) {
61-
console.warn('[mupdf] Failed to open document:', e);
62-
return null;
63-
}
64-
}
65-
66-
// Render a page with MuPDF WASM — returns Pixmap as RGBA
67-
async function renderPageWithMupdf(pdfBytes, pageIndex, scale) {
68-
const mupdf = await loadMupdf();
69-
if (!mupdf) return null;
70-
71-
const doc = await getMupdfDocument(pdfBytes);
72-
if (!doc) return null;
73-
74-
const page = doc.loadPage(pageIndex);
75-
const dpr = getCanvasDPR();
76-
const matrix = mupdf.Matrix.scale(scale * dpr, scale * dpr);
77-
const pixmap = page.toPixmap(matrix, mupdf.ColorSpace.DeviceRGB, true, true);
78-
79-
const w = pixmap.getWidth();
80-
const h = pixmap.getHeight();
81-
const samples = pixmap.getPixels(); // Uint8ClampedArray RGBA
82-
83-
// Copy samples before destroying pixmap (pixmap owns the memory)
84-
const rgba = new Uint8ClampedArray(samples);
85-
86-
page.destroy();
87-
pixmap.destroy();
88-
89-
return { rgba, width: w, height: h };
90-
}
91-
92-
// PDF.js rendering helper — used as fallback when pdfium is not available
20+
// NOTE: an earlier prototype embedded MuPDF WASM rendering helpers here
21+
// (loadMupdf / isMupdfAvailable / getMupdfDocument / renderPageWithMupdf).
22+
// They were never wired up — the active path is the Rust vector renderer
23+
// via `extract_draw_commands` + `vector-renderer.js`, with PDF.js as the
24+
// fallback for raster-only pages. The unused helpers have been removed.
25+
// `mupdf-renderer.js` is still imported once below for `closeDocument()`
26+
// cleanup (no-op when the runtime never loaded the WASM module).
27+
28+
// PDF.js rendering helper — used as fallback when the vector path is unavailable
9329
async function _renderPageWithPdfJs(page, viewport, pdfCanvas, bufferW, bufferH, dpr) {
9430
const offscreen = document.createElement('canvas');
9531
offscreen.width = bufferW;

0 commit comments

Comments
 (0)