[api-major] Remove the enhanceTextSelection functionality (PR 15145 follow-up)

For the `gulp mozcentral` command, this reduces the size of the *built* `pdf.js` file by `> 10` kB.
This commit is contained in:
Jonas Jenwald 2022-01-18 18:09:12 +01:00
parent 3f8b5449e8
commit 571ce13dd6
13 changed files with 34 additions and 559 deletions

View File

@ -109,17 +109,10 @@ limitations under the License.
} }
// Migration code for https://github.com/mozilla/pdf.js/pull/9479. // Migration code for https://github.com/mozilla/pdf.js/pull/9479.
if (typeof items.disableTextLayer === "boolean") { if (typeof items.disableTextLayer === "boolean") {
var textLayerMode = 1;
if (items.disableTextLayer) { if (items.disableTextLayer) {
textLayerMode = 0;
} else if (items.enhanceTextSelection) {
textLayerMode = 2;
}
if (textLayerMode !== 1) {
// Overwrite if computed textLayerMode is not the default value (1).
storageSync.set( storageSync.set(
{ {
textLayerMode, textLayerMode: 0,
}, },
function () { function () {
if (!chrome.runtime.lastError) { if (!chrome.runtime.lastError) {

View File

@ -126,7 +126,6 @@ body {
<select> <select>
<option value="0">Disable text selection</option> <option value="0">Disable text selection</option>
<option value="1">Enable text selection</option> <option value="1">Enable text selection</option>
<option value="2">Enable enhanced mode (experimental)</option>
</select> </select>
</label> </label>
</div> </div>

View File

@ -102,19 +102,13 @@
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"enhanceTextSelection": {
"description": "DEPRECATED. Set textLayerMode to 2 to use the enhanced text selection layer by default.",
"type": "boolean",
"default": false
},
"textLayerMode": { "textLayerMode": {
"title": "Text layer mode", "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.", "description": "Controls if the text layer is enabled, and the selection mode that is used.\n 0 = Disabled.\n 1 = Enabled.",
"type": "integer", "type": "integer",
"enum": [ "enum": [
0, 0,
1, 1
2
], ],
"default": 1 "default": 1
}, },

View File

@ -18,7 +18,6 @@ import {
createPromiseCapability, createPromiseCapability,
Util, Util,
} from "../shared/util.js"; } from "../shared/util.js";
import { deprecated } from "./display_utils.js";
/** /**
* Text layer render parameters. * Text layer render parameters.
@ -40,15 +39,12 @@ import { deprecated } from "./display_utils.js";
* This is output and shall initially be set to an empty array. * This is output and shall initially be set to an empty array.
* @property {number} [timeout] - Delay in milliseconds before rendering of the * @property {number} [timeout] - Delay in milliseconds before rendering of the
* text runs occurs. * text runs occurs.
* @property {boolean} [enhanceTextSelection] - Whether to turn on the text
* selection enhancement.
*/ */
const MAX_TEXT_DIVS_TO_RENDER = 100000; const MAX_TEXT_DIVS_TO_RENDER = 100000;
const DEFAULT_FONT_SIZE = 30; const DEFAULT_FONT_SIZE = 30;
const DEFAULT_FONT_ASCENT = 0.8; const DEFAULT_FONT_ASCENT = 0.8;
const ascentCache = new Map(); const ascentCache = new Map();
const AllWhitespaceRegexp = /^\s+$/g;
function getAscent(fontFamily, ctx) { function getAscent(fontFamily, ctx) {
const cachedAscent = ascentCache.get(fontFamily); const cachedAscent = ascentCache.get(fontFamily);
@ -120,28 +116,13 @@ function getAscent(fontFamily, ctx) {
function appendText(task, geom, styles, ctx) { function appendText(task, geom, styles, ctx) {
// Initialize all used properties to keep the caches monomorphic. // Initialize all used properties to keep the caches monomorphic.
const textDiv = document.createElement("span"); const textDiv = document.createElement("span");
const textDivProperties = task._enhanceTextSelection const textDivProperties = {
? {
angle: 0,
canvasWidth: 0,
hasText: geom.str !== "",
hasEOL: geom.hasEOL,
originalTransform: null,
paddingBottom: 0,
paddingLeft: 0,
paddingRight: 0,
paddingTop: 0,
scale: 1,
fontSize: 0,
}
: {
angle: 0, angle: 0,
canvasWidth: 0, canvasWidth: 0,
hasText: geom.str !== "", hasText: geom.str !== "",
hasEOL: geom.hasEOL, hasEOL: geom.hasEOL,
fontSize: 0, fontSize: 0,
}; };
task._textDivs.push(textDiv); task._textDivs.push(textDiv);
const tx = Util.transform(task._viewport.transform, geom.transform); const tx = Util.transform(task._viewport.transform, geom.transform);
@ -189,10 +170,7 @@ function appendText(task, geom, styles, ctx) {
// little effect on text highlighting. This makes scrolling on docs with // little effect on text highlighting. This makes scrolling on docs with
// lots of such divs a lot faster. // lots of such divs a lot faster.
let shouldScaleText = false; let shouldScaleText = false;
if ( if (geom.str.length > 1) {
geom.str.length > 1 ||
(task._enhanceTextSelection && AllWhitespaceRegexp.test(geom.str))
) {
shouldScaleText = true; shouldScaleText = true;
} else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) { } else if (geom.str !== " " && geom.transform[0] !== geom.transform[3]) {
const absScaleX = Math.abs(geom.transform[0]), const absScaleX = Math.abs(geom.transform[0]),
@ -217,36 +195,6 @@ function appendText(task, geom, styles, ctx) {
if (task._textContentStream) { if (task._textContentStream) {
task._layoutText(textDiv); task._layoutText(textDiv);
} }
if (task._enhanceTextSelection && textDivProperties.hasText) {
let angleCos = 1,
angleSin = 0;
if (angle !== 0) {