From 9e0a31f6624578e1bc5fc41fb0ed667f2624c3d6 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 12:24:33 +0100 Subject: [PATCH 01/10] Move viewer specific compatibility options from `src/shared/compatibility.js` and into a separate file Unfortunately, as far as I can tell, we still need the ability to adjust certain viewer options depending on the browser environment in PDF.js version `2.0`. However, we should be able to separate this from the general compatibility code in the `src/shared/compatibility.js` file. --- src/shared/compatibility.js | 35 +---------------------------- web/app.js | 3 ++- web/ui_utils.js | 10 +-------- web/viewer_compatibility.js | 44 +++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 44 deletions(-) create mode 100644 web/viewer_compatibility.js diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index 3b2221f6f..86ec6e1d2 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -26,12 +26,10 @@ if ((typeof PDFJSDev === 'undefined' || // users - https://github.com/mozilla/pdf.js/issues/9397 if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) { -var globalScope = require('./global_scope'); - +const globalScope = require('./global_scope'); const isNodeJS = require('./is_node'); var userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || ''; -var isAndroid = /Android/.test(userAgent); var isIOSChrome = userAgent.indexOf('CriOS') >= 0; var isIE = userAgent.indexOf('Trident') >= 0; var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent); @@ -80,18 +78,6 @@ PDFJS.compatibilityChecked = true; } })(); -// Checks if navigator.language is supported -// Support: IE<11 -(function checkNavigatorLanguage() { - if (typeof navigator === 'undefined') { - return; - } - if ('language' in navigator) { - return; - } - PDFJS.locale = navigator.userLanguage || 'en-US'; -})(); - // Support: Safari 6.0+, iOS (function checkRangeRequests() { // Safari has issues with cached range requests see: @@ -103,25 +89,6 @@ PDFJS.compatibilityChecked = true; } })(); -// Support: Android, iOS -(function checkCanvasSizeLimitation() { - if (isIOS || isAndroid) { - // 5MP - PDFJS.maxCanvasPixels = 5242880; - } -})(); - -// Disable fullscreen support for certain problematic configurations. -// Support: IE11+ (when embedded). -(function checkFullscreenSupport() { - if (!hasDOM) { - return; - } - if (isIE && window.parent !== window) { - PDFJS.disableFullscreen = true; - } -})(); - // Provides document.currentScript support // Support: IE, Chrome<29. (function checkCurrentScript() { diff --git a/web/app.js b/web/app.js index e3128b118..a21b443f4 100644 --- a/web/app.js +++ b/web/app.js @@ -44,6 +44,7 @@ import { PDFThumbnailViewer } from './pdf_thumbnail_viewer'; import { PDFViewer } from './pdf_viewer'; import { SecondaryToolbar } from './secondary_toolbar'; import { Toolbar } from './toolbar'; +import { viewerCompatibilityParams } from './viewer_compatibility'; import { ViewHistory } from './view_history'; const DEFAULT_SCALE_DELTA = 1.1; @@ -561,7 +562,7 @@ let PDFViewerApplication = { support = false; } } - if (support && PDFJS.disableFullscreen === true) { + if (support && viewerCompatibilityParams['disableFullscreen'] === true) { support = false; } diff --git a/web/ui_utils.js b/web/ui_utils.js index bfff86ae5..9119147cb 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -65,14 +65,6 @@ let NullL10n = { }, }; -/** - * Disables fullscreen support, and by extension Presentation Mode, - * in browsers which support the fullscreen API. - * @var {boolean} - */ -PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ? - false : PDFJS.disableFullscreen); - /** * Enables CSS only zooming. * @var {boolean} @@ -110,7 +102,7 @@ if (typeof PDFJSDev === 'undefined' || */ PDFJS.locale = (PDFJS.locale === undefined && typeof navigator !== 'undefined' ? - navigator.language : PDFJS.locale); + navigator.language : PDFJS.locale) || 'en-US'; } /** diff --git a/web/viewer_compatibility.js b/web/viewer_compatibility.js new file mode 100644 index 000000000..e6aadea80 --- /dev/null +++ b/web/viewer_compatibility.js @@ -0,0 +1,44 @@ +/* Copyright 2018 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let compatibilityParams = Object.create(null); +if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { + const userAgent = + (typeof navigator !== 'undefined' && navigator.userAgent) || ''; + const isAndroid = /Android/.test(userAgent); + const isIE = /Trident/.test(userAgent); + const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent); + + // Disable fullscreen support for certain problematic configurations. + // Support: IE11+ (when embedded). + (function checkFullscreenSupport() { + if (isIE && window.parent !== window) { + compatibilityParams.disableFullscreen = true; + } + })(); + + // Limit canvas size to 5 mega-pixels on mobile. + // Support: Android, iOS + (function checkCanvasSizeLimitation() { + if (isIOS || isAndroid) { + compatibilityParams.maxCanvasPixels = 5242880; + } + })(); +} +const viewerCompatibilityParams = Object.freeze(compatibilityParams); + +export { + viewerCompatibilityParams, +}; From f4280368f7087a488f3f81d44de576633a874f77 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 12:52:42 +0100 Subject: [PATCH 02/10] Move the `useOnlyCssZoom` option to a `BaseViewer`/`PDFPageView` option This removes the `PDFJS.useOnlyCssZoom` dependency from the viewer components, but please note that as a *temporary* solution the default viewer still uses it. --- examples/mobile-viewer/viewer.js | 3 ++- web/app.js | 1 + web/base_viewer.js | 4 ++++ web/pdf_page_view.js | 7 +++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/mobile-viewer/viewer.js b/examples/mobile-viewer/viewer.js index 15037fc77..01d2a097e 100644 --- a/examples/mobile-viewer/viewer.js +++ b/examples/mobile-viewer/viewer.js @@ -21,7 +21,7 @@ if (typeof PDFJS === 'undefined' || !PDFJS.PDFViewer || !PDFJS.getDocument) { ' `gulp dist-install`'); } -PDFJS.useOnlyCssZoom = true; +var USE_ONLY_CSS_ZOOM = true; PDFJS.disableTextLayer = true; PDFJS.maxImageSize = 1024 * 1024; PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js'; @@ -298,6 +298,7 @@ var PDFViewerApplication = { container: container, linkService: linkService, l10n: this.l10n, + useOnlyCssZoom: USE_ONLY_CSS_ZOOM, }); this.pdfViewer = pdfViewer; linkService.setViewer(pdfViewer); diff --git a/web/app.js b/web/app.js index a21b443f4..80d64f220 100644 --- a/web/app.js +++ b/web/app.js @@ -398,6 +398,7 @@ let PDFViewerApplication = { enhanceTextSelection: viewerPrefs['enhanceTextSelection'], renderInteractiveForms: viewerPrefs['renderInteractiveForms'], enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'], + useOnlyCssZoom: PDFJS.useOnlyCssZoom, }); pdfRenderingQueue.setViewer(this.pdfViewer); pdfLinkService.setViewer(this.pdfViewer); diff --git a/web/base_viewer.js b/web/base_viewer.js index 521b193a7..acc2d439f 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -48,6 +48,8 @@ const DEFAULT_CACHE_SIZE = 10; * rotation of pages whose orientation differ from the first page upon * printing. The default is `false`. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. + * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. + * The default value is `false`. * @property {IL10n} l10n - Localization service. */ @@ -111,6 +113,7 @@ class BaseViewer { this.renderInteractiveForms = options.renderInteractiveForms || false; this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; this.renderer = options.renderer || RendererType.CANVAS; + this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.l10n = options.l10n || NullL10n; this.defaultRenderingQueue = !options.renderingQueue; @@ -377,6 +380,7 @@ class BaseViewer { enhanceTextSelection: this.enhanceTextSelection, renderInteractiveForms: this.renderInteractiveForms, renderer: this.renderer, + useOnlyCssZoom: this.useOnlyCssZoom, l10n: this.l10n, }); bindOnAfterAndBeforeDraw(pageView); diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 50e1ac1a3..df2cdd9ab 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -38,6 +38,8 @@ import { RenderingStates } from './pdf_rendering_queue'; * @property {boolean} renderInteractiveForms - Turns on rendering of * interactive form elements. The default is `false`. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. + * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. + * The default value is `false`. * @property {IL10n} l10n - Localization service. */ @@ -64,6 +66,7 @@ class PDFPageView { this.hasRestrictedScaling = false; this.enhanceTextSelection = options.enhanceTextSelection || false; this.renderInteractiveForms = options.renderInteractiveForms || false; + this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.eventBus = options.eventBus || getGlobalEventBus(); this.renderingQueue = options.renderingQueue; @@ -218,7 +221,7 @@ class PDFPageView { } if (this.canvas) { - if (PDFJS.useOnlyCssZoom || + if (this.useOnlyCssZoom || (this.hasRestrictedScaling && isScalingRestricted)) { this.cssTransform(this.canvas, true); @@ -517,7 +520,7 @@ class PDFPageView { let outputScale = getOutputScale(ctx); this.outputScale = outputScale; - if (PDFJS.useOnlyCssZoom) { + if (this.useOnlyCssZoom) { let actualSizeViewport = viewport.clone({ scale: CSS_UNITS, }); // Use a scale that makes the canvas have the originally intended size // of the page. From fdf99c6af524a7b2fee675dc0cf80e04c7bb6cc5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 13:02:15 +0100 Subject: [PATCH 03/10] Move the `maxCanvasPixels` option to a `BaseViewer`/`PDFPageView` option This removes the `PDFJS.maxCanvasPixels` dependency from the viewer components, but please note that as a *temporary* solution the default viewer still uses it. --- web/app.js | 1 + web/base_viewer.js | 5 +++++ web/pdf_page_view.js | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/web/app.js b/web/app.js index 80d64f220..1d7fed31e 100644 --- a/web/app.js +++ b/web/app.js @@ -399,6 +399,7 @@ let PDFViewerApplication = { renderInteractiveForms: viewerPrefs['renderInteractiveForms'], enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'], useOnlyCssZoom: PDFJS.useOnlyCssZoom, + maxCanvasPixels: PDFJS.maxCanvasPixels, }); pdfRenderingQueue.setViewer(this.pdfViewer); pdfLinkService.setViewer(this.pdfViewer); diff --git a/web/base_viewer.js b/web/base_viewer.js index acc2d439f..259817da9 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -50,6 +50,9 @@ const DEFAULT_CACHE_SIZE = 10; * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. * The default value is `false`. + * @property {number} maxCanvasPixels - (optional) The maximum supported canvas + * size in total pixels, i.e. width * height. Use -1 for no limit. + * The default value is 4096 * 4096 (16 mega-pixels). * @property {IL10n} l10n - Localization service. */ @@ -114,6 +117,7 @@ class BaseViewer { this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; this.renderer = options.renderer || RendererType.CANVAS; this.useOnlyCssZoom = options.useOnlyCssZoom || false; + this.maxCanvasPixels = options.maxCanvasPixels; this.l10n = options.l10n || NullL10n; this.defaultRenderingQueue = !options.renderingQueue; @@ -381,6 +385,7 @@ class BaseViewer { renderInteractiveForms: this.renderInteractiveForms, renderer: this.renderer, useOnlyCssZoom: this.useOnlyCssZoom, + maxCanvasPixels: this.maxCanvasPixels, l10n: this.l10n, }); bindOnAfterAndBeforeDraw(pageView); diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index df2cdd9ab..5abbf0703 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -18,10 +18,11 @@ import { RendererType, roundToDivide } from './ui_utils'; import { - createPromiseCapability, PDFJS, RenderingCancelledException, SVGGraphics + createPromiseCapability, RenderingCancelledException, SVGGraphics } from 'pdfjs-lib'; import { getGlobalEventBus } from './dom_events'; import { RenderingStates } from './pdf_rendering_queue'; +import { viewerCompatibilityParams } from './viewer_compatibility'; /** * @typedef {Object} PDFPageViewOptions @@ -40,9 +41,14 @@ import { RenderingStates } from './pdf_rendering_queue'; * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. * The default value is `false`. + * @property {number} maxCanvasPixels - (optional) The maximum supported canvas + * size in total pixels, i.e. width * height. Use -1 for no limit. + * The default value is 4096 * 4096 (16 mega-pixels). * @property {IL10n} l10n - Localization service. */ +const MAX_CANVAS_PIXELS = viewerCompatibilityParams.maxCanvasPixels || 16777216; + /** * @implements {IRenderableView} */ @@ -67,6 +73,7 @@ class PDFPageView { this.enhanceTextSelection = options.enhanceTextSelection || false; this.renderInteractiveForms = options.renderInteractiveForms || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false; + this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS; this.eventBus = options.eventBus || getGlobalEventBus(); this.renderingQueue = options.renderingQueue; @@ -211,11 +218,11 @@ class PDFPageView { } let isScalingRestricted = false; - if (this.canvas && PDFJS.maxCanvasPixels > 0) { + if (this.canvas && this.maxCanvasPixels > 0) { let outputScale = this.outputScale; if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) * ((Math.floor(this.viewport.height) * outputScale.sy) | 0) > - PDFJS.maxCanvasPixels) { + this.maxCanvasPixels) { isScalingRestricted = true; } } @@ -529,9 +536,9 @@ class PDFPageView { outputScale.scaled = true; } - if (PDFJS.maxCanvasPixels > 0) { + if (this.maxCanvasPixels > 0) { let pixelsInViewport = viewport.width * viewport.height; - let maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport); + let maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport); if (outputScale.sx > maxScale || outputScale.sy > maxScale) { outputScale.sx = maxScale; outputScale.sy = maxScale; From c45c3943649c3c10dab1c610a2b26cb6f69e92e6 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 13:17:11 +0100 Subject: [PATCH 04/10] 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. --- src/display/annotation_layer.js | 13 +++++++------ src/display/dom_utils.js | 2 -- src/display/global.js | 8 -------- test/driver.js | 8 ++++++-- web/annotation_layer_builder.js | 13 +++++++++++-- web/app.js | 1 + web/base_viewer.js | 10 +++++++++- web/interfaces.js | 6 ++++-- web/pdf_page_view.js | 5 ++++- 9 files changed, 42 insertions(+), 24 deletions(-) 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'); From 3a6f6d23d6190483ba7c8b4ca298e2bd209c6809 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 14:03:52 +0100 Subject: [PATCH 05/10] Move the `externalLinkTarget` and `externalLinkRel` options to `PDFLinkService` options This removes the `PDFJS.externalLinkTarget`/`PDFJS.externalLinkRel` dependency from the viewer components, but please note that as a *temporary* solution the default viewer still uses it. --- src/display/annotation_layer.js | 16 +++++---- src/display/dom_utils.js | 61 +++++++-------------------------- src/display/global.js | 11 ++---- src/pdf.js | 1 + test/unit/dom_utils_spec.js | 38 +------------------- web/app.js | 11 +++--- web/pdf_link_service.js | 16 ++++++++- web/pdf_outline_viewer.js | 28 +++++++-------- 8 files changed, 62 insertions(+), 120 deletions(-) diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index edb500d75..048bfb562 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -281,17 +281,21 @@ class LinkAnnotationElement extends AnnotationElement { render() { this.container.className = 'linkAnnotation'; + let { data, linkService, } = this; let link = document.createElement('a'); + addLinkAttributes(link, { - url: this.data.url, - target: (this.data.newWindow ? LinkTarget.BLANK : undefined), + url: data.url, + target: (data.newWindow ? + LinkTarget.BLANK : linkService.externalLinkTarget), + rel: linkService.externalLinkRel, }); - if (!this.data.url) { - if (this.data.action) { - this._bindNamedAction(link, this.data.action); + if (!data.url) { + if (data.action) { + this._bindNamedAction(link, data.action); } else { - this._bindLink(link, this.data.dest); + this._bindLink(link, data.dest); } } diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index 0551c90ce..52bcf4895 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -274,7 +274,7 @@ var RenderingCancelledException = (function RenderingCancelledException() { return RenderingCancelledException; })(); -var LinkTarget = { +const LinkTarget = { NONE: 0, // Default value. SELF: 1, BLANK: 2, @@ -282,7 +282,7 @@ var LinkTarget = { TOP: 4, }; -var LinkTargetStringMap = [ +const LinkTargetStringMap = [ '', '_self', '_blank', @@ -294,8 +294,10 @@ var LinkTargetStringMap = [ * @typedef ExternalLinkParameters * @typedef {Object} ExternalLinkParameters * @property {string} url - An absolute URL. - * @property {LinkTarget} target - The link target. - * @property {string} rel - The link relationship. + * @property {LinkTarget} target - (optional) The link target. + * The default value is `LinkTarget.NONE`. + * @property {string} rel - (optional) The link relationship. + * The default value is `DEFAULT_LINK_REL`. */ /** @@ -303,22 +305,16 @@ var LinkTargetStringMap = [ * @param {HTMLLinkElement} link - The link element. * @param {ExternalLinkParameters} params */ -function addLinkAttributes(link, params) { - var url = params && params.url; +function addLinkAttributes(link, { url, target, rel, } = {}) { link.href = link.title = (url ? removeNullCharacters(url) : ''); if (url) { - var target = params.target; - if (typeof target === 'undefined') { - target = getDefaultSetting('externalLinkTarget'); - } - link.target = LinkTargetStringMap[target]; + const LinkTargetValues = Object.values(LinkTarget); + let targetIndex = + LinkTargetValues.includes(target) ? target : LinkTarget.NONE; + link.target = LinkTargetStringMap[targetIndex]; - var rel = params.rel; - if (typeof rel === 'undefined') { - rel = getDefaultSetting('externalLinkRel'); - } - link.rel = rel; + link.rel = (typeof rel === 'string' ? rel : DEFAULT_LINK_REL); } } @@ -365,25 +361,6 @@ function getDefaultSetting(id) { return globalSettings ? globalSettings.maxImageSize : -1; case 'isEvalSupported': return globalSettings ? globalSettings.isEvalSupported : true; - case 'externalLinkTarget': - if (!globalSettings) { - return LinkTarget.NONE; - } - switch (globalSettings.externalLinkTarget) { - case LinkTarget.NONE: - case LinkTarget.SELF: - case LinkTarget.BLANK: - case LinkTarget.PARENT: - case LinkTarget.TOP: - return globalSettings.externalLinkTarget; - } - warn('PDFJS.externalLinkTarget is invalid: ' + - globalSettings.externalLinkTarget); - // Reset the external link target, to suppress further warnings. - globalSettings.externalLinkTarget = LinkTarget.NONE; - return LinkTarget.NONE; - case 'externalLinkRel': - return globalSettings ? globalSettings.externalLinkRel : DEFAULT_LINK_REL; case 'enableStats': return !!(globalSettings && globalSettings.enableStats); default: @@ -391,19 +368,6 @@ function getDefaultSetting(id) { } } -function isExternalLinkTargetSet() { - var externalLinkTarget = getDefaultSetting('externalLinkTarget'); - switch (externalLinkTarget) { - case LinkTarget.NONE: - return false; - case LinkTarget.SELF: - case LinkTarget.BLANK: - case LinkTarget.PARENT: - case LinkTarget.TOP: - return true; - } -} - class StatTimer { constructor(enable = true) { this.enabled = !!enable; @@ -481,7 +445,6 @@ class DummyStatTimer { export { RenderingCancelledException, addLinkAttributes, - isExternalLinkTargetSet, getFilenameFromUrl, LinkTarget, getDefaultSetting, diff --git a/src/display/global.js b/src/display/global.js index 199b87831..e764752a8 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -13,10 +13,6 @@ * limitations under the License. */ -import { - addLinkAttributes, DEFAULT_LINK_REL, getFilenameFromUrl, - isExternalLinkTargetSet, isValidUrl, LinkTarget -} from './dom_utils'; import { createBlob, createObjectURL, createPromiseCapability, getVerbosityLevel, InvalidPDFException, isLittleEndian, MissingPDFException, OPS, PageViewport, @@ -24,6 +20,7 @@ import { shadow, UnexpectedResponseException, UnknownErrorException, UNSUPPORTED_FEATURES, Util, VERBOSITY_LEVELS } from '../shared/util'; +import { DEFAULT_LINK_REL, getFilenameFromUrl, LinkTarget } from './dom_utils'; import { getDocument, LoopbackPort, PDFDataRangeTransport, PDFWorker } from './api'; @@ -67,7 +64,6 @@ Object.defineProperty(PDFJS, 'verbosity', { PDFJS.VERBOSITY_LEVELS = VERBOSITY_LEVELS; PDFJS.OPS = OPS; PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES; -PDFJS.isValidUrl = isValidUrl; PDFJS.shadow = shadow; PDFJS.createBlob = createBlob; PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) { @@ -193,7 +189,7 @@ PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ? /** * Specifies the |target| attribute for external links. - * The constants from PDFJS.LinkTarget should be used: + * The constants from {LinkTarget} should be used: * - NONE [default] * - SELF * - BLANK @@ -225,10 +221,7 @@ PDFJS.LoopbackPort = LoopbackPort; PDFJS.PDFDataRangeTransport = PDFDataRangeTransport; PDFJS.PDFWorker = PDFWorker; -PDFJS.LinkTarget = LinkTarget; -PDFJS.addLinkAttributes = addLinkAttributes; PDFJS.getFilenameFromUrl = getFilenameFromUrl; -PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet; PDFJS.AnnotationLayer = AnnotationLayer; diff --git a/src/pdf.js b/src/pdf.js index 38e5e458c..644ff8a37 100644 --- a/src/pdf.js +++ b/src/pdf.js @@ -91,4 +91,5 @@ exports.createBlob = pdfjsSharedUtil.createBlob; exports.RenderingCancelledException = pdfjsDisplayDOMUtils.RenderingCancelledException; exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl; +exports.LinkTarget = pdfjsDisplayDOMUtils.LinkTarget; exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes; diff --git a/test/unit/dom_utils_spec.js b/test/unit/dom_utils_spec.js index 314459450..938aafd83 100644 --- a/test/unit/dom_utils_spec.js +++ b/test/unit/dom_utils_spec.js @@ -13,11 +13,8 @@ * limitations under the License. */ -import { - DOMSVGFactory, getFilenameFromUrl, isExternalLinkTargetSet, LinkTarget -} from '../../src/display/dom_utils'; +import { DOMSVGFactory, getFilenameFromUrl } from '../../src/display/dom_utils'; import isNodeJS from '../../src/shared/is_node'; -import { PDFJS } from '../../src/display/global'; describe('dom_utils', function() { describe('DOMSVGFactory', function() { @@ -95,37 +92,4 @@ describe('dom_utils', function() { expect(result).toEqual(expected); }); }); - - describe('isExternalLinkTargetSet', function() { - var savedExternalLinkTarget; - - beforeAll(function (done) { - savedExternalLinkTarget = PDFJS.externalLinkTarget; - done(); - }); - - afterAll(function () { - PDFJS.externalLinkTarget = savedExternalLinkTarget; - }); - - it('handles the predefined LinkTargets', function() { - for (var key in LinkTarget) { - var linkTarget = LinkTarget[key]; - PDFJS.externalLinkTarget = linkTarget; - - expect(isExternalLinkTargetSet()).toEqual(!!linkTarget); - } - }); - - it('handles incorrect LinkTargets', function() { - var targets = [true, '', false, -1, '_blank', null]; - - for (var i = 0, ii = targets.length; i < ii; i++) { - var linkTarget = targets[i]; - PDFJS.externalLinkTarget = linkTarget; - - expect(isExternalLinkTargetSet()).toEqual(false); - } - }); - }); }); diff --git a/web/app.js b/web/app.js index 35a1da2db..df983f181 100644 --- a/web/app.js +++ b/web/app.js @@ -22,7 +22,7 @@ import { } from './ui_utils'; import { build, createBlob, getDocument, getFilenameFromUrl, InvalidPDFException, - MissingPDFException, OPS, PDFJS, PDFWorker, shadow, + LinkTarget, MissingPDFException, OPS, PDFJS, PDFWorker, shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, version } from 'pdfjs-lib'; import { CursorTool, PDFCursorTools } from './pdf_cursor_tools'; @@ -184,10 +184,11 @@ let PDFViewerApplication = { this.eventBus.dispatch('localized'); }); - if (this.isViewerEmbedded && !PDFJS.isExternalLinkTargetSet()) { + if (this.isViewerEmbedded && + PDFJS.externalLinkTarget === LinkTarget.NONE) { // Prevent external links from "replacing" the viewer, // when it's embedded in e.g. an iframe or an object. - PDFJS.externalLinkTarget = PDFJS.LinkTarget.TOP; + PDFJS.externalLinkTarget = LinkTarget.TOP; } this.initialized = true; @@ -250,7 +251,7 @@ let PDFViewerApplication = { PDFJS.useOnlyCssZoom = value; }), preferences.get('externalLinkTarget').then(function resolved(value) { - if (PDFJS.isExternalLinkTargetSet()) { + if (PDFJS.externalLinkTarget !== LinkTarget.NONE) { return; } PDFJS.externalLinkTarget = value; @@ -378,6 +379,8 @@ let PDFViewerApplication = { let pdfLinkService = new PDFLinkService({ eventBus, + externalLinkTarget: PDFJS.externalLinkTarget, + externalLinkRel: PDFJS.externalLinkRel, }); this.pdfLinkService = pdfLinkService; diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index 7062a69ae..91df46320 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -19,6 +19,11 @@ import { parseQueryString } from './ui_utils'; /** * @typedef {Object} PDFLinkServiceOptions * @property {EventBus} eventBus - The application event bus. + * @property {number} externalLinkTarget - (optional) Specifies the `target` + * attribute for external links. Must use one of the values from {LinkTarget}. + * Defaults to using no target. + * @property {string} externalLinkRel - (optional) Specifies the `rel` attribute + * for external links. Defaults to stripping the referrer. */ /** @@ -30,8 +35,12 @@ class PDFLinkService { /** * @param {PDFLinkServiceOptions} options */ - constructor({ eventBus, } = {}) { + constructor({ eventBus, externalLinkTarget = null, + externalLinkRel = null, } = {}) { this.eventBus = eventBus || getGlobalEventBus(); + this.externalLinkTarget = externalLinkTarget; + this.externalLinkRel = externalLinkRel; + this.baseUrl = null; this.pdfDocument = null; this.pdfViewer = null; @@ -409,6 +418,11 @@ function isValidExplicitDestination(dest) { } class SimpleLinkService { + constructor() { + this.externalLinkTarget = null; + this.externalLinkRel = null; + } + /** * @returns {number} */ diff --git a/web/pdf_outline_viewer.js b/web/pdf_outline_viewer.js index 7aee5b626..05b94016c 100644 --- a/web/pdf_outline_viewer.js +++ b/web/pdf_outline_viewer.js @@ -13,9 +13,7 @@ * limitations under the License. */ -import { - addLinkAttributes, PDFJS, removeNullCharacters -} from 'pdfjs-lib'; +import { addLinkAttributes, LinkTarget, removeNullCharacters } from 'pdfjs-lib'; const DEFAULT_TITLE = '\u2013'; @@ -68,20 +66,22 @@ class PDFOutlineViewer { /** * @private */ - _bindLink(element, item) { - if (item.url) { + _bindLink(element, { url, newWindow, dest, }) { + let { linkService, } = this; + + if (url) { addLinkAttributes(element, { - url: item.url, - target: (item.newWindow ? PDFJS.LinkTarget.BLANK : undefined), + url, + target: (newWindow ? LinkTarget.BLANK : linkService.externalLinkTarget), + rel: linkService.externalLinkRel, }); return; } - let destination = item.dest; - element.href = this.linkService.getDestinationHash(destination); + element.href = this.linkService.getDestinationHash(dest); element.onclick = () => { - if (destination) { - this.linkService.navigateTo(destination); + if (dest) { + this.linkService.navigateTo(dest); } return false; }; @@ -90,12 +90,12 @@ class PDFOutlineViewer { /** * @private */ - _setStyles(element, item) { + _setStyles(element, { bold, italic, }) { let styleStr = ''; - if (item.bold) { + if (bold) { styleStr += 'font-weight: bold;'; } - if (item.italic) { + if (italic) { styleStr += 'font-style: italic;'; } From a1cfa5f4d7c8fcf55e9f3b51a23885dca8782915 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 15:01:55 +0100 Subject: [PATCH 06/10] Replace the `disableTextLayer` and `enhanceTextSelection` options/preferences with a single `textLayerMode` option/preference Rather than having two different (but connected) options for the textLayer, I think that it makes sense to try and unify this. For example: currently if `disableTextLayer === true`, then the value of `enhanceTextSelection` is simply ignored. Since PDF.js version `2.0` already won't be backwards compatible in lots of ways, I don't think that we need to worry about migrating existing preferences here. --- examples/mobile-viewer/viewer.js | 3 ++- extensions/chromium/preferences_schema.json | 19 ++++++++++--------- web/app.js | 17 +++++++---------- web/base_viewer.js | 16 ++++++++++------ web/default_preferences.json | 3 +-- web/pdf_page_view.js | 15 +++++++++------ web/ui_utils.js | 14 +++++++------- 7 files changed, 46 insertions(+), 41 deletions(-) diff --git a/examples/mobile-viewer/viewer.js b/examples/mobile-viewer/viewer.js index 01d2a097e..dc3276ce4 100644 --- a/examples/mobile-viewer/viewer.js +++ b/examples/mobile-viewer/viewer.js @@ -22,7 +22,7 @@ if (typeof PDFJS === 'undefined' || !PDFJS.PDFViewer || !PDFJS.getDocument) { } var USE_ONLY_CSS_ZOOM = true; -PDFJS.disableTextLayer = true; +var TEXT_LAYER_MODE = 0; // DISABLE PDFJS.maxImageSize = 1024 * 1024; PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js'; PDFJS.cMapUrl = '../../node_modules/pdfjs-dist/cmaps/'; @@ -299,6 +299,7 @@ var PDFViewerApplication = { linkService: linkService, l10n: this.l10n, useOnlyCssZoom: USE_ONLY_CSS_ZOOM, + textLayerMode: TEXT_LAYER_MODE, }); this.pdfViewer = pdfViewer; linkService.setViewer(pdfViewer); diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json index 16cf475eb..1ccf98db7 100644 --- a/extensions/chromium/preferences_schema.json +++ b/extensions/chromium/preferences_schema.json @@ -75,11 +75,16 @@ "type": "boolean", "default": false }, - "disableTextLayer": { - "title": "Disable text selection layer", - "description": "Whether to disable the text selection layer.", - "type": "boolean", - "default": false + "textLayerMode": { + "title": "Text layer mode", + "description": "Controls if the text layer is enabled, and the selection mode that is used.\n 0 = Disabled.\n 1 = Enabled.\n 2 = (Experimental) Enabled, with enhanced text selection.", + "type": "integer", + "enum": [ + 0, + 1, + 2 + ], + "default": 1 }, "useOnlyCssZoom": { "type": "boolean", @@ -112,10 +117,6 @@ "description": "Whether to prevent the extension from reporting the extension and browser version to the extension developers.", "default": false }, - "enhanceTextSelection": { - "type": "boolean", - "default": false - }, "renderer": { "type": "string", "enum": [ diff --git a/web/app.js b/web/app.js index df983f181..cd4cc1495 100644 --- a/web/app.js +++ b/web/app.js @@ -18,7 +18,7 @@ import { animationStarted, DEFAULT_SCALE_VALUE, getPDFFileNameFromURL, isFileSchema, isValidRotation, MAX_SCALE, MIN_SCALE, noContextMenuHandler, normalizeWheelEventDelta, parseQueryString, PresentationModeState, - ProgressBar, RendererType + ProgressBar, RendererType, TextLayerMode } from './ui_utils'; import { build, createBlob, getDocument, getFilenameFromUrl, InvalidPDFException, @@ -146,7 +146,7 @@ let PDFViewerApplication = { disablePageMode: false, disablePageLabels: false, renderer: 'canvas', - enhanceTextSelection: false, + textLayerMode: TextLayerMode.ENABLE, renderInteractiveForms: false, enablePrintAutoRotate: false, }, @@ -217,14 +217,11 @@ let PDFViewerApplication = { preferences.get('defaultZoomValue').then(function resolved(value) { viewerPrefs['defaultZoomValue'] = value; }), - preferences.get('enhanceTextSelection').then(function resolved(value) { - viewerPrefs['enhanceTextSelection'] = value; - }), - preferences.get('disableTextLayer').then(function resolved(value) { - if (PDFJS.disableTextLayer === true) { + preferences.get('textLayerMode').then(function resolved(value) { + if (viewerPrefs['textLayerMode'] === TextLayerMode.DISABLE) { return; } - PDFJS.disableTextLayer = value; + viewerPrefs['textLayerMode'] = value; }), preferences.get('disableRange').then(function resolved(value) { if (PDFJS.disableRange === true) { @@ -323,7 +320,7 @@ let PDFViewerApplication = { if ('textlayer' in hashParams) { switch (hashParams['textlayer']) { case 'off': - PDFJS.disableTextLayer = true; + viewerPrefs['textLayerMode'] = TextLayerMode.DISABLE; break; case 'visible': case 'shadow': @@ -398,7 +395,7 @@ let PDFViewerApplication = { downloadManager, renderer: viewerPrefs['renderer'], l10n: this.l10n, - enhanceTextSelection: viewerPrefs['enhanceTextSelection'], + textLayerMode: viewerPrefs['textLayerMode'], imageResourcesPath: PDFJS.imageResourcesPath, renderInteractiveForms: viewerPrefs['renderInteractiveForms'], enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'], diff --git a/web/base_viewer.js b/web/base_viewer.js index de63579e3..b9e2e2591 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -17,7 +17,7 @@ import { createPromiseCapability, PDFJS } from 'pdfjs-lib'; import { CSS_UNITS, DEFAULT_SCALE, DEFAULT_SCALE_VALUE, isValidRotation, MAX_AUTO_SCALE, NullL10n, PresentationModeState, RendererType, - SCROLLBAR_PADDING, UNKNOWN_SCALE, VERTICAL_PADDING, watchScroll + SCROLLBAR_PADDING, TextLayerMode, UNKNOWN_SCALE, VERTICAL_PADDING, watchScroll } from './ui_utils'; import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue'; import { AnnotationLayerBuilder } from './annotation_layer_builder'; @@ -39,9 +39,11 @@ const DEFAULT_CACHE_SIZE = 10; * @property {PDFRenderingQueue} renderingQueue - (optional) The rendering * queue object. * @property {boolean} removePageBorders - (optional) Removes the border shadow - * around the pages. The default is false. - * @property {boolean} enhanceTextSelection - (optional) Enables the improved - * text selection behaviour. The default is `false`. + * around the pages. The default value is `false`. + * @property {number} textLayerMode - (optional) Controls if the text layer used + * for selection and searching is created, and if the improved text selection + * behaviour is enabled. The constants from {TextLayerMode} should be used. + * The default value is `TextLayerMode.ENABLE`. * @property {string} imageResourcesPath - (optional) Path for image resources, * mainly for annotation icons. Include trailing slash. * @property {boolean} renderInteractiveForms - (optional) Enables rendering of @@ -114,6 +116,8 @@ class BaseViewer { this.linkService = options.linkService || new SimpleLinkService(); this.downloadManager = options.downloadManager || null; this.removePageBorders = options.removePageBorders || false; + this.textLayerMode = Number.isInteger(options.textLayerMode) ? + options.textLayerMode : TextLayerMode.ENABLE; this.enhanceTextSelection = options.enhanceTextSelection || false; this.imageResourcesPath = options.imageResourcesPath || ''; this.renderInteractiveForms = options.renderInteractiveForms || false; @@ -372,7 +376,7 @@ class BaseViewer { let viewport = pdfPage.getViewport(scale * CSS_UNITS); for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { let textLayerFactory = null; - if (!PDFJS.disableTextLayer) { + if (this.textLayerMode !== TextLayerMode.DISABLE) { textLayerFactory = this; } let pageView = new PDFPageView({ @@ -383,8 +387,8 @@ class BaseViewer { defaultViewport: viewport.clone(), renderingQueue: this.renderingQueue, textLayerFactory, + textLayerMode: this.textLayerMode, annotationLayerFactory: this, - enhanceTextSelection: this.enhanceTextSelection, imageResourcesPath: this.imageResourcesPath, renderInteractiveForms: this.renderInteractiveForms, renderer: this.renderer, diff --git a/web/default_preferences.json b/web/default_preferences.json index 425de07c3..9aa83132a 100644 --- a/web/default_preferences.json +++ b/web/default_preferences.json @@ -10,10 +10,9 @@ "disableStream": false, "disableAutoFetch": false, "disableFontFace": false, - "disableTextLayer": false, + "textLayerMode": 1, "useOnlyCssZoom": false, "externalLinkTarget": 0, - "enhanceTextSelection": false, "renderer": "canvas", "renderInteractiveForms": false, "enablePrintAutoRotate": false, diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 644857b21..65e1b46af 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -15,7 +15,7 @@ import { approximateFraction, CSS_UNITS, DEFAULT_SCALE, getOutputScale, NullL10n, - RendererType, roundToDivide + RendererType, roundToDivide, TextLayerMode } from './ui_utils'; import { createPromiseCapability, RenderingCancelledException, SVGGraphics @@ -33,9 +33,11 @@ import { viewerCompatibilityParams } from './viewer_compatibility'; * @property {PageViewport} defaultViewport - The page viewport. * @property {PDFRenderingQueue} renderingQueue - The rendering queue object. * @property {IPDFTextLayerFactory} textLayerFactory + * @property {number} textLayerMode - (optional) Controls if the text layer used + * for selection and searching is created, and if the improved text selection + * behaviour is enabled. The constants from {TextLayerMode} should be used. + * The default value is `TextLayerMode.ENABLE`. * @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 @@ -72,7 +74,8 @@ class PDFPageView { this.viewport = defaultViewport; this.pdfPageRotate = defaultViewport.rotation; this.hasRestrictedScaling = false; - this.enhanceTextSelection = options.enhanceTextSelection || false; + this.textLayerMode = Number.isInteger(options.textLayerMode) ? + options.textLayerMode : TextLayerMode.ENABLE; this.imageResourcesPath = options.imageResourcesPath || ''; this.renderInteractiveForms = options.renderInteractiveForms || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false; @@ -384,7 +387,7 @@ class PDFPageView { } let textLayer = null; - if (this.textLayerFactory) { + if (this.textLayerMode !== TextLayerMode.DISABLE && this.textLayerFactory) { let textLayerDiv = document.createElement('div'); textLayerDiv.className = 'textLayer'; textLayerDiv.style.width = canvasWrapper.style.width; @@ -398,7 +401,7 @@ class PDFPageView { textLayer = this.textLayerFactory. createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, - this.enhanceTextSelection); + this.textLayerMode === TextLayerMode.ENABLE_ENHANCE); } this.textLayer = textLayer; diff --git a/web/ui_utils.js b/web/ui_utils.js index 9119147cb..ec45ac04c 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -37,6 +37,12 @@ const RendererType = { SVG: 'svg', }; +const TextLayerMode = { + DISABLE: 0, + ENABLE: 1, + ENABLE_ENHANCE: 2, +}; + // Replaces {{arguments}} with their values. function formatL10nValue(text, args) { if (!args) { @@ -87,13 +93,6 @@ PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ? PDFJS.disableHistory = (PDFJS.disableHistory === undefined ? false : PDFJS.disableHistory); -/** - * Disables creation of the text layer that used for text selection and search. - * @var {boolean} - */ -PDFJS.disableTextLayer = (PDFJS.disableTextLayer === undefined ? - false : PDFJS.disableTextLayer); - if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('FIREFOX || MOZCENTRAL')) { /** @@ -669,6 +668,7 @@ export { cloneObj, PresentationModeState, RendererType, + TextLayerMode, mozL10n, NullL10n, EventBus, From 77efed6626af11bd77ee7ef535c6e84ed060bca1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 14:16:10 +0100 Subject: [PATCH 07/10] Replace the `PDFJS.disableWebGL` option with a `enableWebGL` option passed, via `BaseViewer`/`PDFPageView`, to `PDFPageProxy.render` Please note that the, pre-existing, viewer preference is already named `enableWebGL`; fixes 4919. --- src/display/api.js | 6 +++--- src/display/dom_utils.js | 2 -- src/display/global.js | 7 ------- web/app.js | 8 +++++--- web/base_viewer.js | 4 ++++ web/pdf_page_view.js | 4 ++++ 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index cfa95f00d..e5befbb5f 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -707,6 +707,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() { * calling of PDFPage.getViewport method. * @property {string} intent - Rendering intent, can be 'display' or 'print' * (default value is 'display'). + * @property {boolean} enableWebGL - (optional) Enables WebGL accelerated + * rendering for some operations. The default value is `false`. * @property {boolean} renderInteractiveForms - (optional) Whether or not * interactive form elements are rendered in the display * layer. If so, we do not render them on canvas as well. @@ -828,9 +830,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() { var renderingIntent = (params.intent === 'print' ? 'print' : 'display'); var canvasFactory = params.canvasFactory || new DOMCanvasFactory(); let webGLContext = new WebGLContext({ - // TODO: When moving this parameter from `PDFJS` to {RenderParameters}, - // change its name to `enableWebGL` instead. - enable: !getDefaultSetting('disableWebGL'), + enable: params.enableWebGL, }); if (!this.intentStates[renderingIntent]) { diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index 52bcf4895..e82a5b83f 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -345,8 +345,6 @@ function getDefaultSetting(id) { return globalSettings ? globalSettings.disableFontFace : false; case 'disableCreateObjectURL': return globalSettings ? globalSettings.disableCreateObjectURL : false; - case 'disableWebGL': - return globalSettings ? globalSettings.disableWebGL : true; case 'cMapUrl': return globalSettings ? globalSettings.cMapUrl : null; case 'cMapPacked': diff --git a/src/display/global.js b/src/display/global.js index e764752a8..a7a99f5fb 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -180,13 +180,6 @@ PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ? PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL); -/** - * Disables WebGL usage. - * @var {boolean} - */ -PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ? - true : PDFJS.disableWebGL); - /** * Specifies the |target| attribute for external links. * The constants from {LinkTarget} should be used: diff --git a/web/app.js b/web/app.js index cd4cc1495..da44cd7d1 100644 --- a/web/app.js +++ b/web/app.js @@ -139,6 +139,7 @@ let PDFViewerApplication = { isInitialViewSet: false, downloadComplete: false, viewerPrefs: { + enableWebGL: false, sidebarViewOnLoad: SidebarView.NONE, pdfBugEnabled: false, showPreviousViewOnLoad: true, @@ -203,7 +204,7 @@ let PDFViewerApplication = { return Promise.all([ preferences.get('enableWebGL').then(function resolved(value) { - PDFJS.disableWebGL = !value; + viewerPrefs['enableWebGL'] = value; }), preferences.get('sidebarViewOnLoad').then(function resolved(value) { viewerPrefs['sidebarViewOnLoad'] = value; @@ -304,7 +305,7 @@ let PDFViewerApplication = { PDFJS.disableHistory = (hashParams['disablehistory'] === 'true'); } if ('webgl' in hashParams) { - PDFJS.disableWebGL = (hashParams['webgl'] !== 'true'); + viewerPrefs['enableWebGL'] = (hashParams['webgl'] === 'true'); } if ('useonlycsszoom' in hashParams) { PDFJS.useOnlyCssZoom = (hashParams['useonlycsszoom'] === 'true'); @@ -394,6 +395,7 @@ let PDFViewerApplication = { linkService: pdfLinkService, downloadManager, renderer: viewerPrefs['renderer'], + enableWebGL: viewerPrefs['enableWebGL'], l10n: this.l10n, textLayerMode: viewerPrefs['textLayerMode'], imageResourcesPath: PDFJS.imageResourcesPath, @@ -1172,7 +1174,7 @@ let PDFViewerApplication = { info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (version || '-') + - (!PDFJS.disableWebGL ? ' [WebGL]' : '') + ')'); + (this.viewerPrefs['enableWebGL'] ? ' [WebGL]' : '') + ')'); let pdfTitle; if (metadata && metadata.has('dc:title')) { diff --git a/web/base_viewer.js b/web/base_viewer.js index b9e2e2591..2b966379a 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -52,6 +52,8 @@ const DEFAULT_CACHE_SIZE = 10; * rotation of pages whose orientation differ from the first page upon * printing. The default is `false`. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. + * @property {boolean} enableWebGL - (optional) Enables WebGL accelerated + * rendering for some operations. The default value is `false`. * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. * The default value is `false`. * @property {number} maxCanvasPixels - (optional) The maximum supported canvas @@ -123,6 +125,7 @@ class BaseViewer { this.renderInteractiveForms = options.renderInteractiveForms || false; this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; this.renderer = options.renderer || RendererType.CANVAS; + this.enableWebGL = options.enableWebGL || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.maxCanvasPixels = options.maxCanvasPixels; this.l10n = options.l10n || NullL10n; @@ -392,6 +395,7 @@ class BaseViewer { imageResourcesPath: this.imageResourcesPath, renderInteractiveForms: this.renderInteractiveForms, renderer: this.renderer, + enableWebGL: this.enableWebGL, useOnlyCssZoom: this.useOnlyCssZoom, maxCanvasPixels: this.maxCanvasPixels, l10n: this.l10n, diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 65e1b46af..3b4f91425 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -43,6 +43,8 @@ import { viewerCompatibilityParams } from './viewer_compatibility'; * @property {boolean} renderInteractiveForms - Turns on rendering of * interactive form elements. The default is `false`. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. + * @property {boolean} enableWebGL - (optional) Enables WebGL accelerated + * rendering for some operations. The default value is `false`. * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. * The default value is `false`. * @property {number} maxCanvasPixels - (optional) The maximum supported canvas @@ -86,6 +88,7 @@ class PDFPageView { this.textLayerFactory = options.textLayerFactory; this.annotationLayerFactory = options.annotationLayerFactory; this.renderer = options.renderer || RendererType.CANVAS; + this.enableWebGL = options.enableWebGL || false; this.l10n = options.l10n || NullL10n; this.paintTask = null; @@ -571,6 +574,7 @@ class PDFPageView { canvasContext: ctx, transform, viewport: this.viewport, + enableWebGL: this.enableWebGL, renderInteractiveForms: this.renderInteractiveForms, }; let renderTask = this.pdfPage.render(renderContext); From 74ffd1d86596b5a67c4934333fcc127bea610a36 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 14:22:14 +0100 Subject: [PATCH 08/10] Pass in the `PDFJS.locale` option to `ExternalServices.createL10n` This allows us to remove an otherwise unnecessary `PDFJS` dependency from the `web/genericcom.js` file. --- web/app.js | 4 +++- web/chromecom.js | 2 +- web/firefoxcom.js | 2 +- web/genericcom.js | 5 ++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/web/app.js b/web/app.js index da44cd7d1..900a89129 100644 --- a/web/app.js +++ b/web/app.js @@ -353,7 +353,9 @@ let PDFViewerApplication = { * @private */ _initializeL10n() { - this.l10n = this.externalServices.createL10n(); + this.l10n = this.externalServices.createL10n({ + locale: PDFJS.locale, + }); return this.l10n.getDirection().then((dir) => { document.getElementsByTagName('html')[0].dir = dir; }); diff --git a/web/chromecom.js b/web/chromecom.js index 9afeab538..533361467 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -342,7 +342,7 @@ ChromeExternalServices.createDownloadManager = function() { ChromeExternalServices.createPreferences = function() { return new ChromePreferences(); }; -ChromeExternalServices.createL10n = function() { +ChromeExternalServices.createL10n = function(options) { return new GenericL10n(navigator.language); }; PDFViewerApplication.externalServices = ChromeExternalServices; diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 9853867b7..c5cb40640 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -264,7 +264,7 @@ PDFViewerApplication.externalServices = { return new FirefoxPreferences(); }, - createL10n() { + createL10n(options) { let mozL10n = document.mozL10n; // TODO refactor mozL10n.setExternalLocalizerServices return new MozL10n(mozL10n); diff --git a/web/genericcom.js b/web/genericcom.js index 29d131c5b..36412a809 100644 --- a/web/genericcom.js +++ b/web/genericcom.js @@ -17,7 +17,6 @@ import { DefaultExternalServices, PDFViewerApplication } from './app'; import { BasePreferences } from './preferences'; import { DownloadManager } from './download_manager'; import { GenericL10n } from './genericl10n'; -import { PDFJS } from 'pdfjs-lib'; if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('GENERIC')) { throw new Error('Module "pdfjs-web/genericcom" shall not be used outside ' + @@ -49,8 +48,8 @@ GenericExternalServices.createDownloadManager = function() { GenericExternalServices.createPreferences = function() { return new GenericPreferences(); }; -GenericExternalServices.createL10n = function () { - return new GenericL10n(PDFJS.locale); +GenericExternalServices.createL10n = function(options) { + return new GenericL10n(options.locale); }; PDFViewerApplication.externalServices = GenericExternalServices; From 6bc3e1fb930a8d2239be4785cf800b021d40e30b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 14:24:44 +0100 Subject: [PATCH 09/10] Remove `version`/`build` from the global `PDFJS` object There's no need to expose these properties multiple times, since they're already exported by `src/display/api.js`. --- src/display/global.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/display/global.js b/src/display/global.js index a7a99f5fb..23627c439 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -39,11 +39,6 @@ if (!globalScope.PDFJS) { } var PDFJS = globalScope.PDFJS; -if (typeof PDFJSDev !== 'undefined') { - PDFJS.version = PDFJSDev.eval('BUNDLE_VERSION'); - PDFJS.build = PDFJSDev.eval('BUNDLE_BUILD'); -} - PDFJS.pdfBug = false; if (PDFJS.verbosity !== undefined) { From e95c11a7f06f4f3880b02b3a45d2e87551f8a3e7 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 14:34:29 +0100 Subject: [PATCH 10/10] Remove the undocumented `PDFJS.enableStats` option In order to simplify things, the undocumented `enableStats` option was removed and `pdfBug` is now instead used to enabled general debugging *and* page request/rendering stats. Considering that in the default viewer the `stats` was only used when debugging was also enabled, this simplification (code wise) definitely seem worthwhile to me. --- src/display/api.js | 2 +- src/display/dom_utils.js | 2 -- test/driver.js | 2 +- web/app.js | 9 +++------ web/debugger.js | 1 - 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index e5befbb5f..e73515d6b 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -745,7 +745,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() { this.pageIndex = pageIndex; this.pageInfo = pageInfo; this.transport = transport; - this._stats = (getDefaultSetting('enableStats') ? + this._stats = (getDefaultSetting('pdfBug') ? new StatTimer() : DummyStatTimer); this.commonObjs = transport.commonObjs; this.objs = new PDFObjects(); diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index e82a5b83f..f5e130d26 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -359,8 +359,6 @@ function getDefaultSetting(id) { return globalSettings ? globalSettings.maxImageSize : -1; case 'isEvalSupported': return globalSettings ? globalSettings.isEvalSupported : true; - case 'enableStats': - return !!(globalSettings && globalSettings.enableStats); default: throw new Error('Unknown default setting: ' + id); } diff --git a/test/driver.js b/test/driver.js index 348f453be..ee5e3c5db 100644 --- a/test/driver.js +++ b/test/driver.js @@ -254,7 +254,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars PDFJS.workerSrc = '../build/generic/build/pdf.worker.js'; PDFJS.cMapPacked = true; PDFJS.cMapUrl = '../external/bcmaps/'; - PDFJS.enableStats = true; + PDFJS.pdfBug = true; // Set the passed options this.inflight = options.inflight; diff --git a/web/app.js b/web/app.js index 900a89129..e1891650d 100644 --- a/web/app.js +++ b/web/app.js @@ -333,8 +333,7 @@ let PDFViewerApplication = { } if ('pdfbug' in hashParams) { PDFJS.pdfBug = true; - let pdfBug = hashParams['pdfbug']; - let enabled = pdfBug.split(','); + let enabled = hashParams['pdfbug'].split(','); waitOn.push(loadAndEnablePDFBug(enabled)); } // Locale can be changed only when special debugging flags is present in @@ -1558,7 +1557,6 @@ function loadAndEnablePDFBug(enabledTabs) { script.onload = function () { PDFBug.enable(enabledTabs); PDFBug.init({ - PDFJS, OPS, }, appConfig.mainContainer); resolve(); @@ -1723,8 +1721,7 @@ function webViewerPageRendered(evt) { thumbnailView.setImage(pageView); } - if (PDFJS.pdfBug && typeof Stats !== 'undefined' && Stats.enabled && - pageView.stats) { + if (typeof Stats !== 'undefined' && Stats.enabled && pageView.stats) { Stats.add(pageNumber, pageView.stats); } @@ -2013,7 +2010,7 @@ function webViewerPageChanging(evt) { } // we need to update stats - if (PDFJS.pdfBug && typeof Stats !== 'undefined' && Stats.enabled) { + if (typeof Stats !== 'undefined' && Stats.enabled) { let pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1); if (pageView && pageView.stats) { Stats.add(page, pageView.stats); diff --git a/web/debugger.js b/web/debugger.js index c02f86d10..57a4ed4e4 100644 --- a/web/debugger.js +++ b/web/debugger.js @@ -462,7 +462,6 @@ var Stats = (function Stats() { manager: null, init(pdfjsLib) { this.panel.setAttribute('style', 'padding: 5px;'); - pdfjsLib.PDFJS.enableStats = true; }, enabled: false, active: false,