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:
parent
fdf99c6af5
commit
c45c394364
@ -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(),
|
||||
});
|
||||
|
@ -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':
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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) {}
|
||||
}
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user