diff --git a/src/js/actions/attachments.js b/src/js/actions/attachments.js index 5d5b9873..6e99e2f2 100644 --- a/src/js/actions/attachments.js +++ b/src/js/actions/attachments.js @@ -151,7 +151,7 @@ const exportAttachmentWithAnnotations = itemKey => { const attachmentURL = await dispatch(getAttachmentUrl(itemKey)); await dispatch(fetchAllChildItems(itemKey)); const state = getState(); - const { pdfWorkerURL, pdfReaderCMapsRoot } = state.config; + const { pdfWorkerURL, pdfReaderCMapsURL, pdfReaderStandardFontsURL } = state.config; const childItems = state.libraries[state.current.libraryKey]?.itemsByParent[itemKey]?.keys ?? []; const allItems = state.libraries[state.current.libraryKey]?.items; const attachmentItem = allItems[itemKey]; @@ -162,7 +162,7 @@ const exportAttachmentWithAnnotations = itemKey => { .map(childItemKey => allItems[childItemKey]) .filter(item => !item.deleted && item.itemType === 'annotation'); - const pdfWorker = new PDFWorker({ pdfWorkerURL, pdfReaderCMapsRoot }); + const pdfWorker = new PDFWorker({ pdfWorkerURL, pdfReaderCMapsURL, pdfReaderStandardFontsURL }); const data = await (await fetch(attachmentURL)).arrayBuffer(); const buf = await pdfWorker.export(data, annotations); const blob = new Blob([buf], { type: 'application/pdf' }); diff --git a/src/js/common/pdf-worker.js b/src/js/common/pdf-worker.js index c935e30a..2977e003 100644 --- a/src/js/common/pdf-worker.js +++ b/src/js/common/pdf-worker.js @@ -71,8 +71,8 @@ export class PDFWorker { let respData = null; try { if (message.action === 'FetchBuiltInCMap') { - let response = await fetch(this.config.pdfReaderCMapsRoot + message.data + '.bcmap'); - let arrayBuffer = await response.arrayBuffer(); + const response = await fetch(this.config.pdfReaderCMapsURL + message.data + '.bcmap'); + const arrayBuffer = await response.arrayBuffer(); respData = { compressionType: 1, cMapData: new Uint8Array(arrayBuffer) @@ -83,6 +83,19 @@ export class PDFWorker { console.log('Failed to fetch CMap data:'); console.log(e); } + + try { + if (message.action === 'FetchStandardFontData') { + const response = await fetch(this.config.pdfReaderStandardFontsURL + message.data); + const arrayBuffer = await response.arrayBuffer(); + respData = new Uint8Array(arrayBuffer); + } + } + catch (e) { + console.log('Failed to fetch standard font data:'); + console.log(e); + } + this._worker.postMessage({ responseID: event.data.id, data: respData }); } }); diff --git a/src/js/component/reader.jsx b/src/js/component/reader.jsx index 687fe0ae..1ed17c3a 100644 --- a/src/js/component/reader.jsx +++ b/src/js/component/reader.jsx @@ -167,7 +167,8 @@ const Reader = () => { const currentUserID = useSelector(state => state.config.userId); const currentUserSlug = useSelector(state => state.config.userSlug); const pdfWorkerURL = useSelector(state => state.config.pdfWorkerURL); - const pdfReaderCMapsRoot = useSelector(state => state.config.pdfReaderCMapsRoot); + const pdfReaderCMapsURL = useSelector(state => state.config.pdfReaderCMapsURL); + const pdfReaderStandardFontsURL = useSelector(state => state.config.pdfReaderStandardFontsURL); const tagColors = useSelector(state => state.libraries[libraryKey]?.tagColors?.value ?? []); const { isGroupLibrary: isGroup, isReadOnly } = useSelector(state => state.config.libraries.find(l => l.key === libraryKey)); const pdfReaderURL = useSelector(state => state.config.pdfReaderURL); @@ -185,7 +186,7 @@ const Reader = () => { const isFetchingUserLibrarySettings = useSelector(state => state.libraries[userLibraryKey]?.settings?.isFetching); const colorScheme = useSelector(state => state.preferences.colorScheme); const useDarkModeForContent = useSelector(state => colorScheme !== 'light' && (state.preferences.useDarkModeForContent ?? true)); - const pdfWorker = useMemo(() => new PDFWorker({ pdfWorkerURL, pdfReaderCMapsRoot }), [pdfReaderCMapsRoot, pdfWorkerURL]); + const pdfWorker = useMemo(() => new PDFWorker({ pdfWorkerURL, pdfReaderCMapsURL, pdfReaderStandardFontsURL }), [pdfReaderCMapsURL, pdfReaderStandardFontsURL, pdfWorkerURL]); const [state, dispatchState] = useReducer(readerReducer, { action: null, diff --git a/src/js/constants/defaults.js b/src/js/constants/defaults.js index adc5ebfb..8839db78 100644 --- a/src/js/constants/defaults.js +++ b/src/js/constants/defaults.js @@ -15,7 +15,8 @@ export const stylesSourceUrl = 'https://www.zotero.org/styles-files/styles.json' export const streamingApiUrl = 'wss://stream.zotero.org/'; export const translateUrl = 'location' in window ? window.location.origin : ''; export const pdfReaderURL = '/static/pdf-reader/reader.html'; -export const pdfReaderCMapsRoot = '/static/pdf-reader/pdf/web/cmaps/'; +export const pdfReaderCMapsURL = '/static/pdf-reader/pdf/web/cmaps/'; +export const pdfReaderStandardFontsURL = '/static/pdf-reader/pdf/web/standard_fonts/'; export const pdfWorkerURL = '/static/pdf-worker/worker.js'; export const noteEditorURL = '/static/note-editor/editor.html';