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.
This commit is contained in:
Jonas Jenwald 2018-02-13 15:01:55 +01:00
parent 3a6f6d23d6
commit a1cfa5f4d7
7 changed files with 46 additions and 41 deletions

View file

@ -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,