Move the imageResourcesPath option to a BaseViewer/PDFPageView/AnnotationLayerBuilder option

This removes the `PDFJS.imageResourcesPath` dependency from the viewer components and the test-suite, but please note that as a *temporary* solution the default viewer still uses it.
This commit is contained in:
Jonas Jenwald 2018-02-13 13:17:11 +01:00
parent fdf99c6af5
commit c45c394364
9 changed files with 42 additions and 24 deletions

View File

@ -14,8 +14,7 @@
*/ */
import { import {
addLinkAttributes, DOMSVGFactory, getDefaultSetting, getFilenameFromUrl, addLinkAttributes, DOMSVGFactory, getFilenameFromUrl, LinkTarget
LinkTarget
} from './dom_utils'; } from './dom_utils';
import { import {
AnnotationBorderStyleType, AnnotationType, stringToPDFString, unreachable, AnnotationBorderStyleType, AnnotationType, stringToPDFString, unreachable,
@ -30,7 +29,8 @@ import {
* @property {PageViewport} viewport * @property {PageViewport} viewport
* @property {IPDFLinkService} linkService * @property {IPDFLinkService} linkService
* @property {DownloadManager} downloadManager * @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 {boolean} renderInteractiveForms
* @property {Object} svgFactory * @property {Object} svgFactory
*/ */
@ -1183,7 +1183,9 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
* @property {Array} annotations * @property {Array} annotations
* @property {PDFPage} page * @property {PDFPage} page
* @property {IPDFLinkService} linkService * @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 * @property {boolean} renderInteractiveForms
*/ */
@ -1208,8 +1210,7 @@ class AnnotationLayer {
viewport: parameters.viewport, viewport: parameters.viewport,
linkService: parameters.linkService, linkService: parameters.linkService,
downloadManager: parameters.downloadManager, downloadManager: parameters.downloadManager,
imageResourcesPath: parameters.imageResourcesPath || imageResourcesPath: parameters.imageResourcesPath || '',
getDefaultSetting('imageResourcesPath'),
renderInteractiveForms: parameters.renderInteractiveForms || false, renderInteractiveForms: parameters.renderInteractiveForms || false,
svgFactory: new DOMSVGFactory(), svgFactory: new DOMSVGFactory(),
}); });

View File

@ -363,8 +363,6 @@ function getDefaultSetting(id) {
return globalSettings ? globalSettings.workerSrc : null; return globalSettings ? globalSettings.workerSrc : null;
case 'maxImageSize': case 'maxImageSize':
return globalSettings ? globalSettings.maxImageSize : -1; return globalSettings ? globalSettings.maxImageSize : -1;
case 'imageResourcesPath':
return globalSettings ? globalSettings.imageResourcesPath : '';
case 'isEvalSupported': case 'isEvalSupported':
return globalSettings ? globalSettings.isEvalSupported : true; return globalSettings ? globalSettings.isEvalSupported : true;
case 'externalLinkTarget': case 'externalLinkTarget':

View File

@ -120,14 +120,6 @@ PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ? PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
false : PDFJS.disableFontFace); 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 * Path and filename of the worker file. Required when the worker is enabled
* in development mode. If unspecified in the production build, the worker * in development mode. If unspecified in the production build, the worker

View File

@ -18,6 +18,7 @@
var WAITING_TIME = 100; // ms var WAITING_TIME = 100; // ms
var PDF_TO_CSS_UNITS = 96.0 / 72.0; var PDF_TO_CSS_UNITS = 96.0 / 72.0;
const IMAGE_RESOURCES_PATH = '/web/images/';
/** /**
* @class * @class
@ -164,6 +165,7 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
} }
function rasterizeAnnotationLayer(ctx, viewport, annotations, page, function rasterizeAnnotationLayer(ctx, viewport, annotations, page,
imageResourcesPath,
renderInteractiveForms) { renderInteractiveForms) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
// Building SVG with size of the viewport. // Building SVG with size of the viewport.
@ -194,6 +196,7 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
annotations, annotations,
page, page,
linkService: new PDFJS.SimpleLinkService(), linkService: new PDFJS.SimpleLinkService(),
imageResourcesPath,
renderInteractiveForms, renderInteractiveForms,
}; };
PDFJS.AnnotationLayer.render(parameters); PDFJS.AnnotationLayer.render(parameters);
@ -252,7 +255,6 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
PDFJS.cMapPacked = true; PDFJS.cMapPacked = true;
PDFJS.cMapUrl = '../external/bcmaps/'; PDFJS.cMapUrl = '../external/bcmaps/';
PDFJS.enableStats = true; PDFJS.enableStats = true;
PDFJS.imageResourcesPath = '/web/images/';
// Set the passed options // Set the passed options
this.inflight = options.inflight; this.inflight = options.inflight;
@ -506,7 +508,9 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
function(annotations) { function(annotations) {
return rasterizeAnnotationLayer(annotationLayerContext, return rasterizeAnnotationLayer(annotationLayerContext,
viewport, annotations, viewport, annotations,
page, renderForms); page,
IMAGE_RESOURCES_PATH,
renderForms);
}); });
} else { } else {
annotationLayerCanvas = null; annotationLayerCanvas = null;

View File

@ -21,6 +21,8 @@ import { SimpleLinkService } from './pdf_link_service';
* @typedef {Object} AnnotationLayerBuilderOptions * @typedef {Object} AnnotationLayerBuilderOptions
* @property {HTMLDivElement} pageDiv * @property {HTMLDivElement} pageDiv
* @property {PDFPage} pdfPage * @property {PDFPage} pdfPage
* @property {string} imageResourcesPath - (optional) Path for image resources,
* mainly for annotation icons. Include trailing slash.
* @property {boolean} renderInteractiveForms * @property {boolean} renderInteractiveForms
* @property {IPDFLinkService} linkService * @property {IPDFLinkService} linkService
* @property {DownloadManager} downloadManager * @property {DownloadManager} downloadManager
@ -32,11 +34,13 @@ class AnnotationLayerBuilder {
* @param {AnnotationLayerBuilderOptions} options * @param {AnnotationLayerBuilderOptions} options
*/ */
constructor({ pageDiv, pdfPage, linkService, downloadManager, constructor({ pageDiv, pdfPage, linkService, downloadManager,
renderInteractiveForms = false, l10n = NullL10n, }) { imageResourcesPath = '', renderInteractiveForms = false,
l10n = NullL10n, }) {
this.pageDiv = pageDiv; this.pageDiv = pageDiv;
this.pdfPage = pdfPage; this.pdfPage = pdfPage;
this.linkService = linkService; this.linkService = linkService;
this.downloadManager = downloadManager; this.downloadManager = downloadManager;
this.imageResourcesPath = imageResourcesPath;
this.renderInteractiveForms = renderInteractiveForms; this.renderInteractiveForms = renderInteractiveForms;
this.l10n = l10n; this.l10n = l10n;
@ -59,6 +63,7 @@ class AnnotationLayerBuilder {
div: this.div, div: this.div,
annotations, annotations,
page: this.pdfPage, page: this.pdfPage,
imageResourcesPath: this.imageResourcesPath,
renderInteractiveForms: this.renderInteractiveForms, renderInteractiveForms: this.renderInteractiveForms,
linkService: this.linkService, linkService: this.linkService,
downloadManager: this.downloadManager, downloadManager: this.downloadManager,
@ -104,15 +109,19 @@ class DefaultAnnotationLayerFactory {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @param {PDFPage} pdfPage
* @param {string} imageResourcesPath - (optional) Path for image resources,
* mainly for annotation icons. Include trailing slash.
* @param {boolean} renderInteractiveForms * @param {boolean} renderInteractiveForms
* @param {IL10n} l10n * @param {IL10n} l10n
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder(pageDiv, pdfPage, renderInteractiveForms = false, createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = '',
renderInteractiveForms = false,
l10n = NullL10n) { l10n = NullL10n) {
return new AnnotationLayerBuilder({ return new AnnotationLayerBuilder({
pageDiv, pageDiv,
pdfPage, pdfPage,
imageResourcesPath,
renderInteractiveForms, renderInteractiveForms,
linkService: new SimpleLinkService(), linkService: new SimpleLinkService(),
l10n, l10n,

View File

@ -396,6 +396,7 @@ let PDFViewerApplication = {
renderer: viewerPrefs['renderer'], renderer: viewerPrefs['renderer'],
l10n: this.l10n, l10n: this.l10n,
enhanceTextSelection: viewerPrefs['enhanceTextSelection'], enhanceTextSelection: viewerPrefs['enhanceTextSelection'],
imageResourcesPath: PDFJS.imageResourcesPath,
renderInteractiveForms: viewerPrefs['renderInteractiveForms'], renderInteractiveForms: viewerPrefs['renderInteractiveForms'],
enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'], enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'],
useOnlyCssZoom: PDFJS.useOnlyCssZoom, useOnlyCssZoom: PDFJS.useOnlyCssZoom,

View File

@ -42,6 +42,8 @@ const DEFAULT_CACHE_SIZE = 10;
* around the pages. The default is false. * around the pages. The default is false.
* @property {boolean} enhanceTextSelection - (optional) Enables the improved * @property {boolean} enhanceTextSelection - (optional) Enables the improved
* text selection behaviour. The default is `false`. * 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 * @property {boolean} renderInteractiveForms - (optional) Enables rendering of
* interactive form elements. The default is `false`. * interactive form elements. The default is `false`.
* @property {boolean} enablePrintAutoRotate - (optional) Enables automatic * @property {boolean} enablePrintAutoRotate - (optional) Enables automatic
@ -113,6 +115,7 @@ class BaseViewer {
this.downloadManager = options.downloadManager || null; this.downloadManager = options.downloadManager || null;
this.removePageBorders = options.removePageBorders || false; this.removePageBorders = options.removePageBorders || false;
this.enhanceTextSelection = options.enhanceTextSelection || false; this.enhanceTextSelection = options.enhanceTextSelection || false;
this.imageResourcesPath = options.imageResourcesPath || '';
this.renderInteractiveForms = options.renderInteractiveForms || false; this.renderInteractiveForms = options.renderInteractiveForms || false;
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
this.renderer = options.renderer || RendererType.CANVAS; this.renderer = options.renderer || RendererType.CANVAS;
@ -382,6 +385,7 @@ class BaseViewer {
textLayerFactory, textLayerFactory,
annotationLayerFactory: this, annotationLayerFactory: this,
enhanceTextSelection: this.enhanceTextSelection, enhanceTextSelection: this.enhanceTextSelection,
imageResourcesPath: this.imageResourcesPath,
renderInteractiveForms: this.renderInteractiveForms, renderInteractiveForms: this.renderInteractiveForms,
renderer: this.renderer, renderer: this.renderer,
useOnlyCssZoom: this.useOnlyCssZoom, useOnlyCssZoom: this.useOnlyCssZoom,
@ -881,15 +885,19 @@ class BaseViewer {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @param {PDFPage} pdfPage
* @param {string} imageResourcesPath - (optional) Path for image resources,
* mainly for annotation icons. Include trailing slash.
* @param {boolean} renderInteractiveForms * @param {boolean} renderInteractiveForms
* @param {IL10n} l10n * @param {IL10n} l10n
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder(pageDiv, pdfPage, renderInteractiveForms = false, createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = '',
renderInteractiveForms = false,
l10n = NullL10n) { l10n = NullL10n) {
return new AnnotationLayerBuilder({ return new AnnotationLayerBuilder({
pageDiv, pageDiv,
pdfPage, pdfPage,
imageResourcesPath,
renderInteractiveForms, renderInteractiveForms,
linkService: this.linkService, linkService: this.linkService,
downloadManager: this.downloadManager, downloadManager: this.downloadManager,

View File

@ -145,11 +145,13 @@ class IPDFAnnotationLayerFactory {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @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 {boolean} renderInteractiveForms
* @param {IL10n} l10n
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder(pageDiv, pdfPage, createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = '',
renderInteractiveForms = false, renderInteractiveForms = false,
l10n = undefined) {} l10n = undefined) {}
} }

View File

@ -36,6 +36,8 @@ import { viewerCompatibilityParams } from './viewer_compatibility';
* @property {IPDFAnnotationLayerFactory} annotationLayerFactory * @property {IPDFAnnotationLayerFactory} annotationLayerFactory
* @property {boolean} enhanceTextSelection - Turns on the text selection * @property {boolean} enhanceTextSelection - Turns on the text selection
* enhancement. The default is `false`. * 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 * @property {boolean} renderInteractiveForms - Turns on rendering of
* interactive form elements. The default is `false`. * interactive form elements. The default is `false`.
* @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
@ -71,6 +73,7 @@ class PDFPageView {
this.pdfPageRotate = defaultViewport.rotation; this.pdfPageRotate = defaultViewport.rotation;
this.hasRestrictedScaling = false; this.hasRestrictedScaling = false;
this.enhanceTextSelection = options.enhanceTextSelection || false; this.enhanceTextSelection = options.enhanceTextSelection || false;
this.imageResourcesPath = options.imageResourcesPath || '';
this.renderInteractiveForms = options.renderInteractiveForms || false; this.renderInteractiveForms = options.renderInteractiveForms || false;
this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false;
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS; this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
@ -475,7 +478,7 @@ class PDFPageView {
if (this.annotationLayerFactory) { if (this.annotationLayerFactory) {
if (!this.annotationLayer) { if (!this.annotationLayer) {
this.annotationLayer = this.annotationLayerFactory. this.annotationLayer = this.annotationLayerFactory.
createAnnotationLayerBuilder(div, pdfPage, createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath,
this.renderInteractiveForms, this.l10n); this.renderInteractiveForms, this.l10n);
} }
this.annotationLayer.render(this.viewport, 'display'); this.annotationLayer.render(this.viewport, 'display');