diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 74b5a0c7f..edb500d75 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -14,8 +14,7 @@ */ import { - addLinkAttributes, DOMSVGFactory, getDefaultSetting, getFilenameFromUrl, - LinkTarget + addLinkAttributes, DOMSVGFactory, getFilenameFromUrl, LinkTarget } from './dom_utils'; import { AnnotationBorderStyleType, AnnotationType, stringToPDFString, unreachable, @@ -30,7 +29,8 @@ import { * @property {PageViewport} viewport * @property {IPDFLinkService} linkService * @property {DownloadManager} downloadManager - * @property {string} imageResourcesPath + * @property {string} imageResourcesPath - (optional) Path for image resources, + * mainly for annotation icons. Include trailing slash. * @property {boolean} renderInteractiveForms * @property {Object} svgFactory */ @@ -1183,7 +1183,9 @@ class FileAttachmentAnnotationElement extends AnnotationElement { * @property {Array} annotations * @property {PDFPage} page * @property {IPDFLinkService} linkService - * @property {string} imageResourcesPath + * @property {DownloadManager} downloadManager + * @property {string} imageResourcesPath - (optional) Path for image resources, + * mainly for annotation icons. Include trailing slash. * @property {boolean} renderInteractiveForms */ @@ -1208,8 +1210,7 @@ class AnnotationLayer { viewport: parameters.viewport, linkService: parameters.linkService, downloadManager: parameters.downloadManager, - imageResourcesPath: parameters.imageResourcesPath || - getDefaultSetting('imageResourcesPath'), + imageResourcesPath: parameters.imageResourcesPath || '', renderInteractiveForms: parameters.renderInteractiveForms || false, svgFactory: new DOMSVGFactory(), }); diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index 3cf577c52..0551c90ce 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -363,8 +363,6 @@ function getDefaultSetting(id) { return globalSettings ? globalSettings.workerSrc : null; case 'maxImageSize': return globalSettings ? globalSettings.maxImageSize : -1; - case 'imageResourcesPath': - return globalSettings ? globalSettings.imageResourcesPath : ''; case 'isEvalSupported': return globalSettings ? globalSettings.isEvalSupported : true; case 'externalLinkTarget': diff --git a/src/display/global.js b/src/display/global.js index b6be09482..199b87831 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -120,14 +120,6 @@ PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked; PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ? false : PDFJS.disableFontFace); -/** - * Path for image resources, mainly for annotation icons. Include trailing - * slash. - * @var {string} - */ -PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ? - '' : PDFJS.imageResourcesPath); - /** * Path and filename of the worker file. Required when the worker is enabled * in development mode. If unspecified in the production build, the worker diff --git a/test/driver.js b/test/driver.js index a1274000e..348f453be 100644 --- a/test/driver.js +++ b/test/driver.js @@ -18,6 +18,7 @@ var WAITING_TIME = 100; // ms var PDF_TO_CSS_UNITS = 96.0 / 72.0; +const IMAGE_RESOURCES_PATH = '/web/images/'; /** * @class @@ -164,6 +165,7 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() { } function rasterizeAnnotationLayer(ctx, viewport, annotations, page, + imageResourcesPath, renderInteractiveForms) { return new Promise(function (resolve) { // Building SVG with size of the viewport. @@ -194,6 +196,7 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() { annotations, page, linkService: new PDFJS.SimpleLinkService(), + imageResourcesPath, renderInteractiveForms, }; PDFJS.AnnotationLayer.render(parameters); @@ -252,7 +255,6 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars PDFJS.cMapPacked = true; PDFJS.cMapUrl = '../external/bcmaps/'; PDFJS.enableStats = true; - PDFJS.imageResourcesPath = '/web/images/'; // Set the passed options this.inflight = options.inflight; @@ -506,7 +508,9 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars function(annotations) { return rasterizeAnnotationLayer(annotationLayerContext, viewport, annotations, - page, renderForms); + page, + IMAGE_RESOURCES_PATH, + renderForms); }); } else { annotationLayerCanvas = null; diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index 2c96778ca..10f1eeec0 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -21,6 +21,8 @@ import { SimpleLinkService } from './pdf_link_service'; * @typedef {Object} AnnotationLayerBuilderOptions * @property {HTMLDivElement} pageDiv * @property {PDFPage} pdfPage + * @property {string} imageResourcesPath - (optional) Path for image resources, + * mainly for annotation icons. Include trailing slash. * @property {boolean} renderInteractiveForms * @property {IPDFLinkService} linkService * @property {DownloadManager} downloadManager @@ -32,11 +34,13 @@ class AnnotationLayerBuilder { * @param {AnnotationLayerBuilderOptions} options */ constructor({ pageDiv, pdfPage, linkService, downloadManager, - renderInteractiveForms = false, l10n = NullL10n, }) { + imageResourcesPath = '', renderInteractiveForms = false, + l10n = NullL10n, }) { this.pageDiv = pageDiv; this.pdfPage = pdfPage; this.linkService = linkService; this.downloadManager = downloadManager; + this.imageResourcesPath = imageResourcesPath; this.renderInteractiveForms = renderInteractiveForms; this.l10n = l10n; @@ -59,6 +63,7 @@ class AnnotationLayerBuilder { div: this.div, annotations, page: this.pdfPage, + imageResourcesPath: this.imageResourcesPath, renderInteractiveForms: this.renderInteractiveForms, linkService: this.linkService, downloadManager: this.downloadManager, @@ -104,15 +109,19 @@ class DefaultAnnotationLayerFactory { /** * @param {HTMLDivElement} pageDiv * @param {PDFPage} pdfPage + * @param {string} imageResourcesPath - (optional) Path for image resources, + * mainly for annotation icons. Include trailing slash. * @param {boolean} renderInteractiveForms * @param {IL10n} l10n * @returns {AnnotationLayerBuilder} */ - createAnnotationLayerBuilder(pageDiv, pdfPage, renderInteractiveForms = false, + createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = '', + renderInteractiveForms = false, l10n = NullL10n) { return new AnnotationLayerBuilder({ pageDiv, pdfPage, + imageResourcesPath, renderInteractiveForms, linkService: new SimpleLinkService(), l10n, diff --git a/web/app.js b/web/app.js index 1d7fed31e..35a1da2db 100644 --- a/web/app.js +++ b/web/app.js @@ -396,6 +396,7 @@ let PDFViewerApplication = { renderer: viewerPrefs['renderer'], l10n: this.l10n, enhanceTextSelection: viewerPrefs['enhanceTextSelection'], + imageResourcesPath: PDFJS.imageResourcesPath, renderInteractiveForms: viewerPrefs['renderInteractiveForms'], enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'], useOnlyCssZoom: PDFJS.useOnlyCssZoom, diff --git a/web/base_viewer.js b/web/base_viewer.js index 259817da9..de63579e3 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -42,6 +42,8 @@ const DEFAULT_CACHE_SIZE = 10; * around the pages. The default is false. * @property {boolean} enhanceTextSelection - (optional) Enables the improved * text selection behaviour. The default is `false`. + * @property {string} imageResourcesPath - (optional) Path for image resources, + * mainly for annotation icons. Include trailing slash. * @property {boolean} renderInteractiveForms - (optional) Enables rendering of * interactive form elements. The default is `false`. * @property {boolean} enablePrintAutoRotate - (optional) Enables automatic @@ -113,6 +115,7 @@ class BaseViewer { this.downloadManager = options.downloadManager || null; this.removePageBorders = options.removePageBorders || false; this.enhanceTextSelection = options.enhanceTextSelection || false; + this.imageResourcesPath = options.imageResourcesPath || ''; this.renderInteractiveForms = options.renderInteractiveForms || false; this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; this.renderer = options.renderer || RendererType.CANVAS; @@ -382,6 +385,7 @@ class BaseViewer { textLayerFactory, annotationLayerFactory: this, enhanceTextSelection: this.enhanceTextSelection, + imageResourcesPath: this.imageResourcesPath, renderInteractiveForms: this.renderInteractiveForms, renderer: this.renderer, useOnlyCssZoom: this.useOnlyCssZoom, @@ -881,15 +885,19 @@ class BaseViewer { /** * @param {HTMLDivElement} pageDiv * @param {PDFPage} pdfPage + * @param {string} imageResourcesPath - (optional) Path for image resources, + * mainly for annotation icons. Include trailing slash. * @param {boolean} renderInteractiveForms * @param {IL10n} l10n * @returns {AnnotationLayerBuilder} */ - createAnnotationLayerBuilder(pageDiv, pdfPage, renderInteractiveForms = false, + createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = '', + renderInteractiveForms = false, l10n = NullL10n) { return new AnnotationLayerBuilder({ pageDiv, pdfPage, + imageResourcesPath, renderInteractiveForms, linkService: this.linkService, downloadManager: this.downloadManager, diff --git a/web/interfaces.js b/web/interfaces.js index f694a9086..455185b9b 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -145,11 +145,13 @@ class IPDFAnnotationLayerFactory { /** * @param {HTMLDivElement} pageDiv * @param {PDFPage} pdfPage - * @param {IL10n} l10n + * @param {string} imageResourcesPath - (optional) Path for image resources, + * mainly for annotation icons. Include trailing slash. * @param {boolean} renderInteractiveForms + * @param {IL10n} l10n * @returns {AnnotationLayerBuilder} */ - createAnnotationLayerBuilder(pageDiv, pdfPage, + createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = '', renderInteractiveForms = false, l10n = undefined) {} } diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 5abbf0703..644857b21 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -36,6 +36,8 @@ import { viewerCompatibilityParams } from './viewer_compatibility'; * @property {IPDFAnnotationLayerFactory} annotationLayerFactory * @property {boolean} enhanceTextSelection - Turns on the text selection * enhancement. The default is `false`. + * @property {string} imageResourcesPath - (optional) Path for image resources, + * mainly for annotation icons. Include trailing slash. * @property {boolean} renderInteractiveForms - Turns on rendering of * interactive form elements. The default is `false`. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. @@ -71,6 +73,7 @@ class PDFPageView { this.pdfPageRotate = defaultViewport.rotation; this.hasRestrictedScaling = false; this.enhanceTextSelection = options.enhanceTextSelection || false; + this.imageResourcesPath = options.imageResourcesPath || ''; this.renderInteractiveForms = options.renderInteractiveForms || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS; @@ -475,7 +478,7 @@ class PDFPageView { if (this.annotationLayerFactory) { if (!this.annotationLayer) { this.annotationLayer = this.annotationLayerFactory. - createAnnotationLayerBuilder(div, pdfPage, + createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n); } this.annotationLayer.render(this.viewport, 'display');