2015-11-11 00:45:03 +09:00
|
|
|
/* Copyright 2015 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.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 20:00:16 +09:00
|
|
|
import {
|
|
|
|
AbortException,
|
|
|
|
createPromiseCapability,
|
|
|
|
Util,
|
|
|
|
} from "../shared/util.js";
|
2015-11-22 01:32:47 +09:00
|
|
|
|
2015-11-11 00:45:03 +09:00
|
|
|
/**
|
|
|
|
* Text layer render parameters.
|
|
|
|
*
|
|
|
|
* @typedef {Object} TextLayerRenderParameters
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {TextContent} [textContent] - Text content to render (the object
|
|
|
|
* is returned by the page's `getTextContent` method).
|
|
|
|
* @property {ReadableStream} [textContentStream] - Text content stream to
|
|
|
|
* render (the stream is returned by the page's `streamTextContent` method).
|
2015-11-11 00:45:03 +09:00
|
|
|
* @property {HTMLElement} container - HTML element that will contain text runs.
|
2016-03-29 04:49:22 +09:00
|
|
|
* @property {PageViewport} viewport - The target viewport to properly
|
2015-11-11 00:45:03 +09:00
|
|
|
* layout the text runs.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {Array} [textDivs] - HTML elements that are correspond to the
|
|
|
|
* text items of the textContent input. This is output and shall be
|
2015-11-11 00:45:03 +09:00
|
|
|
* initially be set to empty array.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {Array} [textContentItemsStr] - Strings that correspond to the
|
|
|
|
* `str` property of the text items of textContent input. This is output
|
2017-04-17 21:46:53 +09:00
|
|
|
* and shall be initially be set to empty array.
|
2019-10-12 23:30:32 +09:00
|
|
|
* @property {number} [timeout] - Delay in milliseconds before rendering of the
|
|
|
|
* text runs occurs.
|
|
|
|
* @property {boolean} [enhanceTextSelection] - Whether to turn on the text
|
|
|
|
* selection enhancement.
|
2015-11-11 00:45:03 +09:00
|
|
|
*/
|
|
|
|
var renderTextLayer = (function renderTextLayerClosure() {
|
|
|
|
var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
|
|
|
|
|
|
|
var NonWhitespaceRegexp = /\S/;
|
|
|
|
|
|
|
|
function isAllWhitespace(str) {
|
|
|
|
return !NonWhitespaceRegexp.test(str);
|
|
|
|
}
|
|
|
|
|
2016-09-03 01:10:37 +09:00
|
|
|
function appendText(task, geom, styles) {
|
|
|
|
// Initialize all used properties to keep the caches monomorphic.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var textDiv = document.createElement("span");
|
2016-09-03 01:10:37 +09:00
|
|
|
var textDivProperties = {
|
|
|
|
angle: 0,
|
|
|
|
canvasWidth: 0,
|
|
|
|
isWhitespace: false,
|
[EnhanceTextSelection] Make `expandTextDivs` more efficient by updating all styles at once instead of piecewise
I intended to provide proper benchmarking results here, as outlined in https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes, but after wasting a couple of hours over the weekend getting weird results I gave up.
It appears that there's a lot of, i.e. way too much, variance between subsequent runs of `text` tests for the results to be meaningful.
(Previously I've only benchmarked `eq` tests, so I don't know if the `text` tests has never worked well or if it's a newer problem. For reference, please see the results of back-to-back benchmark runs on the current `master` with a *very* simple manifest file: [link here].)
Instead I used `console.time/timeEnd` in `appendText` and `expandTextDivs` to be able to compare the performance with/without the patch. The entire viewer was (skip-cache) reloaded between measurements, and the result are available here: [link here].
Given the troubles I've had with benchmarking, I've not yet computed any statistics on the results (e.g. mean, variance, confidence intervals, and so on).
However, just by looking at the data I think it's safe to say that this patch first of all doesn't seem to regress the current performance. Secondly it certainly looks *very* likely that this patch actually improves the performance, especially for the one-glyph-per-text-div case (cf. issue 7224).
Re: issue 7584.
2016-09-14 00:04:57 +09:00
|
|
|
originalTransform: null,
|
2016-09-03 01:10:37 +09:00
|
|
|
paddingBottom: 0,
|
|
|
|
paddingLeft: 0,
|
|
|
|
paddingRight: 0,
|
|
|
|
paddingTop: 0,
|
2016-09-05 03:19:31 +09:00
|
|
|
scale: 1,
|
2016-09-03 01:10:37 +09:00
|
|
|
};
|
|
|
|
|
2016-09-03 00:51:13 +09:00
|
|
|
task._textDivs.push(textDiv);
|
2015-11-11 00:45:03 +09:00
|
|
|
if (isAllWhitespace(geom.str)) {
|
2016-09-03 01:10:37 +09:00
|
|
|
textDivProperties.isWhitespace = true;
|
|
|
|
task._textDivProperties.set(textDiv, textDivProperties);
|
2015-11-11 00:45:03 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-09-03 01:10:37 +09:00
|
|
|
|
2016-09-03 00:51:13 +09:00
|
|
|
var tx = Util.transform(task._viewport.transform, geom.transform);
|
2015-11-11 00:45:03 +09:00
|
|
|
var angle = Math.atan2(tx[1], tx[0]);
|
2016-09-03 01:10:37 +09:00
|
|
|
var style = styles[geom.fontName];
|
2015-11-11 00:45:03 +09:00
|
|
|
if (style.vertical) {
|
|
|
|
angle += Math.PI / 2;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
|
2015-11-11 00:45:03 +09:00
|
|
|
var fontAscent = fontHeight;
|
|
|
|
if (style.ascent) {
|
|
|
|
fontAscent = style.ascent * fontAscent;
|
|
|
|
} else if (style.descent) {
|
|
|
|
fontAscent = (1 + style.descent) * fontAscent;
|
|
|
|
}
|
|
|
|
|
2019-08-19 18:02:56 +09:00
|
|
|
let left, top;
|
2015-11-11 00:45:03 +09:00
|
|
|
if (angle === 0) {
|
|
|
|
left = tx[4];
|
|
|
|
top = tx[5] - fontAscent;
|
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
left = tx[4] + fontAscent * Math.sin(angle);
|
|
|
|
top = tx[5] - fontAscent * Math.cos(angle);
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
2019-08-28 23:17:30 +09:00
|
|
|
// Setting the style properties individually, rather than all at once,
|
|
|
|
// should be OK since the `textDiv` isn't appended to the document yet.
|
|
|
|
textDiv.style.left = `${left}px`;
|
|
|
|
textDiv.style.top = `${top}px`;
|
|
|
|
textDiv.style.fontSize = `${fontHeight}px`;
|
|
|
|
textDiv.style.fontFamily = style.fontFamily;
|
2015-11-11 00:45:03 +09:00
|
|
|
|
|
|
|
textDiv.textContent = geom.str;
|
2018-02-18 07:13:49 +09:00
|
|
|
// `fontName` is only used by the FontInspector, and we only use `dataset`
|
|
|
|
// here to make the font name available in the debugger.
|
|
|
|
if (task._fontInspectorEnabled) {
|
2015-11-11 00:45:03 +09:00
|
|
|
textDiv.dataset.fontName = geom.fontName;
|
|
|
|
}
|
|
|
|
if (angle !== 0) {
|
2016-09-03 01:10:37 +09:00
|
|
|
textDivProperties.angle = angle * (180 / Math.PI);
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
|
|
|
// We don't bother scaling single-char text divs, because it has very
|
|
|
|
// little effect on text highlighting. This makes scrolling on docs with
|
|
|
|
// lots of such divs a lot faster.
|
|
|
|
if (geom.str.length > 1) {
|
|
|
|
if (style.vertical) {
|
2016-09-03 01:10:37 +09:00
|
|
|
textDivProperties.canvasWidth = geom.height * task._viewport.scale;
|
2015-11-11 00:45:03 +09:00
|
|
|
} else {
|
2016-09-03 01:10:37 +09:00
|
|
|
textDivProperties.canvasWidth = geom.width * task._viewport.scale;
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
|
|
|
}
|
2016-09-03 01:10:37 +09:00
|
|
|
task._textDivProperties.set(textDiv, textDivProperties);
|
2017-04-17 21:46:53 +09:00
|
|
|
if (task._textContentStream) {
|
|
|
|
task._layoutText(textDiv);
|
|
|
|
}
|
2016-09-03 01:10:37 +09:00
|
|
|
|
2016-09-03 00:51:13 +09:00
|
|
|
if (task._enhanceTextSelection) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var angleCos = 1,
|
|
|
|
angleSin = 0;
|
2016-08-17 08:06:35 +09:00
|
|
|
if (angle !== 0) {
|
|
|
|
angleCos = Math.cos(angle);
|
|
|
|
angleSin = Math.sin(angle);
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var divWidth =
|
|
|
|
(style.vertical ? geom.height : geom.width) * task._viewport.scale;
|
2016-08-17 08:06:35 +09:00
|
|
|
var divHeight = fontHeight;
|
|
|
|
|
|
|
|
var m, b;
|
|
|
|
if (angle !== 0) {
|
|
|
|
m = [angleCos, angleSin, -angleSin, angleCos, left, top];
|
|
|
|
b = Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
|
|
|
|
} else {
|
|
|
|
b = [left, top, left + divWidth, top + divHeight];
|
|
|
|
}
|
|
|
|
|
2016-09-03 00:51:13 +09:00
|
|
|
task._bounds.push({
|
2016-08-17 08:06:35 +09:00
|
|
|
left: b[0],
|
|
|
|
top: b[1],
|
|
|
|
right: b[2],
|
|
|
|
bottom: b[3],
|
|
|
|
div: textDiv,
|
|
|
|
size: [divWidth, divHeight],
|
2017-04-25 23:17:18 +09:00
|
|
|
m,
|
2016-08-17 08:06:35 +09:00
|
|
|
});
|
|
|
|
}
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function render(task) {
|
|
|
|
if (task._canceled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var textDivs = task._textDivs;
|
|
|
|
var capability = task._capability;
|
|
|
|
var textDivsLength = textDivs.length;
|
|
|
|
|
|
|
|
// No point in rendering many divs as it would make the browser
|
|
|
|
// unusable even after the divs are rendered.
|
|
|
|
if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
2016-08-17 08:06:35 +09:00
|
|
|
task._renderingDone = true;
|
2015-11-11 00:45:03 +09:00
|
|
|
capability.resolve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-17 21:46:53 +09:00
|
|
|
if (!task._textContentStream) {
|
|
|
|
for (var i = 0; i < textDivsLength; i++) {
|
|
|
|
task._layoutText(textDivs[i]);
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
2017-04-17 21:46:53 +09:00
|
|
|
|
2016-08-17 08:06:35 +09:00
|
|
|
task._renderingDone = true;
|
|
|
|
capability.resolve();
|
|
|
|
}
|
|
|
|
|
2016-09-03 00:51:13 +09:00
|
|
|
function expand(task) {
|
|
|
|
var bounds = task._bounds;
|
|
|
|
var viewport = task._viewport;
|
|
|
|
|
2016-08-17 08:06:35 +09:00
|
|
|
var expanded = expandBounds(viewport.width, viewport.height, bounds);
|
|
|
|
for (var i = 0; i < expanded.length; i++) {
|
|
|
|
var div = bounds[i].div;
|
2016-09-03 01:10:37 +09:00
|
|
|
var divProperties = task._textDivProperties.get(div);
|
|
|
|
if (divProperties.angle === 0) {
|
|
|
|
divProperties.paddingLeft = bounds[i].left - expanded[i].left;
|
|
|
|
divProperties.paddingTop = bounds[i].top - expanded[i].top;
|
|
|
|
divProperties.paddingRight = expanded[i].right - bounds[i].right;
|
|
|
|
divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
|
|
|
|
task._textDivProperties.set(div, divProperties);
|
2016-08-17 08:06:35 +09:00
|
|
|
continue;
|
2016-03-30 02:32:51 +09:00
|
|
|
}
|
2016-08-17 08:06:35 +09:00
|
|
|
// Box is rotated -- trying to find padding so rotated div will not
|
|
|
|
// exceed its expanded bounds.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var e = expanded[i],
|
|
|
|
b = bounds[i];
|
|
|
|
var m = b.m,
|
|
|
|
c = m[0],
|
|
|
|
s = m[1];
|
2016-08-17 08:06:35 +09:00
|
|
|
// Finding intersections with expanded box.
|
|
|
|
var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
|
|
|
|
var ts = new Float64Array(64);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
points.forEach(function(p, i) {
|
2016-08-17 08:06:35 +09:00
|
|
|
var t = Util.applyTransform(p, m);
|
|
|
|
ts[i + 0] = c && (e.left - t[0]) / c;
|
|
|
|
ts[i + 4] = s && (e.top - t[1]) / s;
|
|
|
|
ts[i + 8] = c && (e.right - t[0]) / c;
|
|
|
|
ts[i + 12] = s && (e.bottom - t[1]) / s;
|
|
|
|
|
|
|
|
ts[i + 16] = s && (e.left - t[0]) / -s;
|
|
|
|
ts[i + 20] = c && (e.top - t[1]) / c;
|
|
|
|
ts[i + 24] = s && (e.right - t[0]) / -s;
|
|
|
|
ts[i + 28] = c && (e.bottom - t[1]) / c;
|
|
|
|
|
|
|
|
ts[i + 32] = c && (e.left - t[0]) / -c;
|
|
|
|
ts[i + 36] = s && (e.top - t[1]) / -s;
|
|
|
|
ts[i + 40] = c && (e.right - t[0]) / -c;
|
|
|
|
ts[i + 44] = s && (e.bottom - t[1]) / -s;
|
|
|
|
|
|
|
|
ts[i + 48] = s && (e.left - t[0]) / s;
|
|
|
|
ts[i + 52] = c && (e.top - t[1]) / -c;
|
|
|
|
ts[i + 56] = s && (e.right - t[0]) / s;
|
|
|
|
ts[i + 60] = c && (e.bottom - t[1]) / -c;
|
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var findPositiveMin = function(ts, offset, count) {
|
2016-08-17 08:06:35 +09:00
|
|
|
var result = 0;
|
2016-09-02 01:07:12 +09:00
|
|
|
for (var i = 0; i < count; i++) {
|
|
|
|
var t = ts[offset++];
|
|
|
|
if (t > 0) {
|
|
|
|
result = result ? Math.min(t, result) : t;
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
2016-09-02 01:07:12 +09:00
|
|
|
}
|
|
|
|
return result;
|
2016-08-17 08:06:35 +09:00
|
|
|
};
|
|
|
|
// Not based on math, but to simplify calculations, using cos and sin
|
|
|
|
// absolute values to not exceed the box (it can but insignificantly).
|
|
|
|
var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
|
2016-09-03 01:10:37 +09:00
|
|
|
divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
|
|
|
|
divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
|
|
|
|
divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
|
|
|
|
divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
|
|
|
|
task._textDivProperties.set(div, divProperties);
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function expandBounds(width, height, boxes) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var bounds = boxes.map(function(box, i) {
|
2016-08-17 08:06:35 +09:00
|
|
|
return {
|
|
|
|
x1: box.left,
|
|
|
|
y1: box.top,
|
|
|
|
x2: box.right,
|
|
|
|
y2: box.bottom,
|
|
|
|
index: i,
|
|
|
|
x1New: undefined,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
x2New: undefined,
|
2016-08-17 08:06:35 +09:00
|
|
|
};
|
|
|
|
});
|
|
|
|
expandBoundsLTR(width, bounds);
|
|
|
|
var expanded = new Array(boxes.length);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
bounds.forEach(function(b) {
|
2016-08-17 08:06:35 +09:00
|
|
|
var i = b.index;
|
|
|
|
expanded[i] = {
|
|
|
|
left: b.x1New,
|
|
|
|
top: 0,
|
|
|
|
right: b.x2New,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
bottom: 0,
|
2016-08-17 08:06:35 +09:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// Rotating on 90 degrees and extending extended boxes. Reusing the bounds
|
|
|
|
// array and objects.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
boxes.map(function(box, i) {
|
|
|
|
var e = expanded[i],
|
|
|
|
b = bounds[i];
|
2016-08-17 08:06:35 +09:00
|
|
|
b.x1 = box.top;
|
|
|
|
b.y1 = width - e.right;
|
|
|
|
b.x2 = box.bottom;
|
|
|
|
b.y2 = width - e.left;
|
|
|
|
b.index = i;
|
|
|
|
b.x1New = undefined;
|
|
|
|
b.x2New = undefined;
|
|
|
|
});
|
|
|
|
expandBoundsLTR(height, bounds);
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
bounds.forEach(function(b) {
|
2016-08-17 08:06:35 +09:00
|
|
|
var i = b.index;
|
|
|
|
expanded[i].top = b.x1New;
|
|
|
|
expanded[i].bottom = b.x2New;
|
|
|
|
});
|
|
|
|
return expanded;
|
|
|
|
}
|
|
|
|
|
|
|
|
function expandBoundsLTR(width, bounds) {
|
|
|
|
// Sorting by x1 coordinate and walk by the bounds in the same order.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
bounds.sort(function(a, b) {
|
2017-02-03 20:58:08 +09:00
|
|
|
return a.x1 - b.x1 || a.index - b.index;
|
|
|
|
});
|
2016-08-17 08:06:35 +09:00
|
|
|
|
|
|
|
// First we see on the horizon is a fake boundary.
|
|
|
|
var fakeBoundary = {
|
|
|
|
x1: -Infinity,
|
|
|
|
y1: -Infinity,
|
|
|
|
x2: 0,
|
|
|
|
y2: Infinity,
|
|
|
|
index: -1,
|
|
|
|
x1New: 0,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
x2New: 0,
|
2016-08-17 08:06:35 +09:00
|
|
|
};
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var horizon = [
|
|
|
|
{
|
|
|
|
start: -Infinity,
|
|
|
|
end: Infinity,
|
|
|
|
boundary: fakeBoundary,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
bounds.forEach(function(boundary) {
|
2016-08-17 08:06:35 +09:00
|
|
|
// Searching for the affected part of horizon.
|
|
|
|
// TODO red-black tree or simple binary search
|
|
|
|
var i = 0;
|
|
|
|
while (i < horizon.length && horizon[i].end <= boundary.y1) {
|
|
|
|
i++;
|
2016-03-30 02:32:51 +09:00
|
|
|
}
|
2016-08-17 08:06:35 +09:00
|
|
|
var j = horizon.length - 1;
|
2016-12-13 04:18:48 +09:00
|
|
|
while (j >= 0 && horizon[j].start >= boundary.y2) {
|
2016-08-17 08:06:35 +09:00
|
|
|
j--;
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
2016-08-17 08:06:35 +09:00
|
|
|
|
|
|
|
var horizonPart, affectedBoundary;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var q,
|
|
|
|
k,
|
|
|
|
maxXNew = -Infinity;
|
2016-08-17 08:06:35 +09:00
|
|
|
for (q = i; q <= j; q++) {
|
|
|
|
horizonPart = horizon[q];
|
|
|
|
affectedBoundary = horizonPart.boundary;
|
|
|
|
var xNew;
|
|
|
|
if (affectedBoundary.x2 > boundary.x1) {
|
|
|
|
// In the middle of the previous element, new x shall be at the
|
2018-04-02 06:20:41 +09:00
|
|
|
// boundary start. Extending if further if the affected boundary
|
2016-08-17 08:06:35 +09:00
|
|
|
// placed on top of the current one.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
xNew =
|
|
|
|
affectedBoundary.index > boundary.index
|
|
|
|
? affectedBoundary.x1New
|
|
|
|
: boundary.x1;
|
2016-08-17 08:06:35 +09:00
|
|
|
} else if (affectedBoundary.x2New === undefined) {
|
|
|
|
// We have some space in between, new x in middle will be a fair
|
|
|
|
// choice.
|
|
|
|
xNew = (affectedBoundary.x2 + boundary.x1) / 2;
|
|
|
|
} else {
|
|
|
|
// Affected boundary has x2new set, using it as new x.
|
|
|
|
xNew = affectedBoundary.x2New;
|
|
|
|
}
|
|
|
|
if (xNew > maxXNew) {
|
|
|
|
maxXNew = xNew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set new x1 for current boundary.
|
|
|
|
boundary.x1New = maxXNew;
|
|
|
|
|
|
|
|
// Adjusts new x2 for the affected boundaries.
|
|
|
|
for (q = i; q <= j; q++) {
|
|
|
|
horizonPart = horizon[q];
|
|
|
|
affectedBoundary = horizonPart.boundary;
|
|
|
|
if (affectedBoundary.x2New === undefined) {
|
|
|
|
// Was not set yet, choosing new x if possible.
|
|
|
|
if (affectedBoundary.x2 > boundary.x1) {
|
|
|
|
// Current and affected boundaries intersect. If affected boundary
|
|
|
|
// is placed on top of the current, shrinking the affected.
|
|
|
|
if (affectedBoundary.index > boundary.index) {
|
|
|
|
affectedBoundary.x2New = affectedBoundary.x2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
affectedBoundary.x2New = maxXNew;
|
|
|
|
}
|
|
|
|
} else if (affectedBoundary.x2New > maxXNew) {
|
|
|
|
// Affected boundary is touching new x, pushing it back.
|
|
|
|
affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fixing the horizon.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var changedHorizon = [],
|
|
|
|
lastBoundary = null;
|
2016-08-17 08:06:35 +09:00
|
|
|
for (q = i; q <= j; q++) {
|
|
|
|
horizonPart = horizon[q];
|
|
|
|
affectedBoundary = horizonPart.boundary;
|
|
|
|
// Checking which boundary will be visible.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
var useBoundary =
|
|
|
|
affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
|
2016-08-17 08:06:35 +09:00
|
|
|
if (lastBoundary === useBoundary) {
|
|
|
|
// Merging with previous.
|
|
|
|
changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
|
|
|
|
} else {
|
|
|
|
changedHorizon.push({
|
|
|
|
start: horizonPart.start,
|
|
|
|
end: horizonPart.end,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
boundary: useBoundary,
|
2016-08-17 08:06:35 +09:00
|
|
|
});
|
|
|
|
lastBoundary = useBoundary;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (horizon[i].start < boundary.y1) {
|
|
|
|
changedHorizon[0].start = boundary.y1;
|
|
|
|
changedHorizon.unshift({
|
|
|
|
start: horizon[i].start,
|
|
|
|
end: boundary.y1,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
boundary: horizon[i].boundary,
|
2016-08-17 08:06:35 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (boundary.y2 < horizon[j].end) {
|
|
|
|
changedHorizon[changedHorizon.length - 1].end = boundary.y2;
|
|
|
|
changedHorizon.push({
|
|
|
|
start: boundary.y2,
|
|
|
|
end: horizon[j].end,
|
Fix inconsistent spacing and trailing commas in objects in remaining `src/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 5739f6f2..4216b2d2 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -2071,7 +2071,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var map = [];
for (var i = 0, ii = positions.length; i < ii; i += 2) {
map.push({ transform: [scaleX, 0, 0, scaleY, positions[i],
- positions[i + 1]], x: 0, y: 0, w: width, h: height, });
+ positions[i + 1]], x: 0, y: 0, w: width, h: height, });
}
this.paintInlineImageXObjectGroup(imgData, map);
},
diff --git a/src/display/svg.js b/src/display/svg.js
index 9eb05dfa..2aa21482 100644
--- a/src/display/svg.js
+++ b/src/display/svg.js
@@ -458,7 +458,11 @@ SVGGraphics = (function SVGGraphicsClosure() {
for (var x = 0; x < fnArrayLen; x++) {
var fnId = fnArray[x];
- opList.push({ 'fnId': fnId, 'fn': REVOPS[fnId], 'args': argsArray[x], });
+ opList.push({
+ 'fnId': fnId,
+ 'fn': REVOPS[fnId],
+ 'args': argsArray[x],
+ });
}
return opListToTree(opList);
},
```
2017-06-02 18:26:37 +09:00
|
|
|
boundary: horizon[j].boundary,
|
2016-08-17 08:06:35 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set x2 new of boundary that is no longer visible (see overlapping case
|
|
|
|
// above).
|
|
|
|
// TODO more efficient, e.g. via reference counting.
|
|
|
|
for (q = i; q <= j; q++) {
|
|
|
|
horizonPart = horizon[q];
|
|
|
|
affectedBoundary = horizonPart.boundary;
|
|
|
|
if (affectedBoundary.x2New !== undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var used = false;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
for (
|
|
|
|
k = i - 1;
|
|
|
|
!used && k >= 0 && horizon[k].start >= affectedBoundary.y1;
|
|
|
|
k--
|
|
|
|
) {
|
2016-08-17 08:06:35 +09:00
|
|
|
used = horizon[k].boundary === affectedBoundary;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
for (
|
|
|
|
k = j + 1;
|
|
|
|
!used && k < horizon.length && horizon[k].end <= affectedBoundary.y2;
|
|
|
|
k++
|
|
|
|
) {
|
2016-08-17 08:06:35 +09:00
|
|
|
used = horizon[k].boundary === affectedBoundary;
|
|
|
|
}
|
|
|
|
for (k = 0; !used && k < changedHorizon.length; k++) {
|
|
|
|
used = changedHorizon[k].boundary === affectedBoundary;
|
|
|
|
}
|
|
|
|
if (!used) {
|
|
|
|
affectedBoundary.x2New = maxXNew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
Array.prototype.splice.apply(
|
|
|
|
horizon,
|
|
|
|
[i, j - i + 1].concat(changedHorizon)
|
|
|
|
);
|
2016-08-17 08:06:35 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// Set new x2 for all unset boundaries.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
horizon.forEach(function(horizonPart) {
|
2016-08-17 08:06:35 +09:00
|
|
|
var affectedBoundary = horizonPart.boundary;
|
|
|
|
if (affectedBoundary.x2New === undefined) {
|
|
|
|
affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
|
|
|
|
}
|
|
|
|
});
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text layer rendering task.
|
|
|
|
*
|
|
|
|
* @param {TextContent} textContent
|
|
|
|
* @param {HTMLElement} container
|
2016-03-29 04:49:22 +09:00
|
|
|
* @param {PageViewport} viewport
|
2015-11-11 00:45:03 +09:00
|
|
|
* @param {Array} textDivs
|
2016-08-17 08:06:35 +09:00
|
|
|
* @param {boolean} enhanceTextSelection
|
2015-11-11 00:45:03 +09:00
|
|
|
* @private
|
|
|
|
*/
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
function TextLayerRenderTask({
|
|
|
|
textContent,
|
|
|
|
textContentStream,
|
|
|
|
container,
|
|
|
|
viewport,
|
|
|
|
textDivs,
|
|
|
|
textContentItemsStr,
|
|
|
|
enhanceTextSelection,
|
|
|
|
}) {
|
2015-11-11 00:45:03 +09:00
|
|
|
this._textContent = textContent;
|
2017-04-17 21:46:53 +09:00
|
|
|
this._textContentStream = textContentStream;
|
2015-11-11 00:45:03 +09:00
|
|
|
this._container = container;
|
|
|
|
this._viewport = viewport;
|
2016-09-03 00:51:13 +09:00
|
|
|
this._textDivs = textDivs || [];
|
2017-04-17 21:46:53 +09:00
|
|
|
this._textContentItemsStr = textContentItemsStr || [];
|
|
|
|
this._enhanceTextSelection = !!enhanceTextSelection;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._fontInspectorEnabled = !!(
|
|
|
|
globalThis.FontInspector && globalThis.FontInspector.enabled
|
|
|
|
);
|
2017-04-17 21:46:53 +09:00
|
|
|
|
|
|
|
this._reader = null;
|
|
|
|
this._layoutTextLastFontSize = null;
|
|
|
|
this._layoutTextLastFontFamily = null;
|
|
|
|
this._layoutTextCtx = null;
|
2016-09-03 01:10:37 +09:00
|
|
|
this._textDivProperties = new WeakMap();
|
2016-08-17 08:06:35 +09:00
|
|
|
this._renderingDone = false;
|
2015-11-11 00:45:03 +09:00
|
|
|
this._canceled = false;
|
|
|
|
this._capability = createPromiseCapability();
|
|
|
|
this._renderTimer = null;
|
2016-08-17 08:06:35 +09:00
|
|
|
this._bounds = [];
|
2019-03-01 11:32:40 +09:00
|
|
|
|
|
|
|
// Always clean-up the temporary canvas once rendering is no longer pending.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._capability.promise
|
|
|
|
.finally(() => {
|
|
|
|
if (this._layoutTextCtx) {
|
|
|
|
// Zeroing the width and height cause Firefox to release graphics
|
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
this._layoutTextCtx.canvas.width = 0;
|
|
|
|
this._layoutTextCtx.canvas.height = 0;
|
|
|
|
this._layoutTextCtx = null;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
/* Avoid "Uncaught promise" messages in the console. */
|
|
|
|
});
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
|
|
|
TextLayerRenderTask.prototype = {
|
|
|
|
get promise() {
|
|
|
|
return this._capability.promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel: function TextLayer_cancel() {
|
2019-03-01 11:32:40 +09:00
|
|
|
this._canceled = true;
|
2017-04-17 21:46:53 +09:00
|
|
|
if (this._reader) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._reader.cancel(new AbortException("TextLayer task cancelled."));
|
2017-04-17 21:46:53 +09:00
|
|
|
this._reader = null;
|
|
|
|
}
|
2015-11-11 00:45:03 +09:00
|
|
|
if (this._renderTimer !== null) {
|
|
|
|
clearTimeout(this._renderTimer);
|
|
|
|
this._renderTimer = null;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._capability.reject(new Error("TextLayer task cancelled."));
|
2015-11-11 00:45:03 +09:00
|
|
|
},
|
|
|
|
|
2017-04-17 21:46:53 +09:00
|
|
|
_processItems(items, styleCache) {
|
|
|
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
|
|
this._textContentItemsStr.push(items[i].str);
|
|
|
|
appendText(this, items[i], styleCache);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_layoutText(textDiv) {
|
2019-08-28 23:08:06 +09:00
|
|
|
const textDivProperties = this._textDivProperties.get(textDiv);
|
2017-04-17 21:46:53 +09:00
|
|
|
if (textDivProperties.isWhitespace) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let transform = "";
|
2019-08-25 19:32:49 +09:00
|
|
|
if (textDivProperties.canvasWidth !== 0) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const { fontSize, fontFamily } = textDiv.style;
|
2019-08-28 23:08:06 +09:00
|
|
|
|
|
|
|
// Only build font string and set to context if different from last.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
fontSize !== this._layoutTextLastFontSize ||
|
|
|
|
fontFamily !== this._layoutTextLastFontFamily
|
|
|
|
) {
|
2019-08-28 23:08:06 +09:00
|
|
|
this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
|
|
|
|
this._layoutTextLastFontSize = fontSize;
|
|
|
|
this._layoutTextLastFontFamily = fontFamily;
|
|
|
|
}
|
2019-08-25 19:32:49 +09:00
|
|
|
// Only measure the width for multi-char text divs, see `appendText`.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const { width } = this._layoutTextCtx.measureText(textDiv.textContent);
|
2019-08-28 23:08:06 +09:00
|
|
|
|
2019-08-25 19:32:49 +09:00
|
|
|
if (width > 0) {
|
|
|
|
textDivProperties.scale = textDivProperties.canvasWidth / width;
|
|
|
|
transform = `scaleX(${textDivProperties.scale})`;
|
|
|
|
}
|
2017-04-17 21:46:53 +09:00
|
|
|
}
|
|
|
|
if (textDivProperties.angle !== 0) {
|
2018-12-30 22:34:43 +09:00
|
|
|
transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
|
2017-04-17 21:46:53 +09:00
|
|
|
}
|
2018-12-30 22:34:43 +09:00
|
|
|
if (transform.length > 0) {
|
2019-08-22 20:26:28 +09:00
|
|
|
if (this._enhanceTextSelection) {
|
|
|
|
textDivProperties.originalTransform = transform;
|
|
|
|
}
|
2017-12-31 21:51:51 +09:00
|
|
|
textDiv.style.transform = transform;
|
2017-04-17 21:46:53 +09:00
|
|
|
}
|
|
|
|
this._textDivProperties.set(textDiv, textDivProperties);
|
2019-08-28 23:08:06 +09:00
|
|
|
this._container.appendChild(textDiv);
|
2017-04-17 21:46:53 +09:00
|
|
|
},
|
|
|
|
|
2015-11-11 00:45:03 +09:00
|
|
|
_render: function TextLayer_render(timeout) {
|
2017-04-17 21:46:53 +09:00
|
|
|
let capability = createPromiseCapability();
|
|
|
|
let styleCache = Object.create(null);
|
|
|
|
|
|
|
|
// The temporary canvas is used to measure text length in the DOM.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
let canvas = document.createElement("canvas");
|
|
|
|
if (
|
|
|
|
typeof PDFJSDev === "undefined" ||
|
|
|
|
PDFJSDev.test("FIREFOX || MOZCENTRAL || GENERIC")
|
|
|
|
) {
|
|
|
|
canvas.mozOpaque = true;
|
2017-04-17 21:46:53 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._layoutTextCtx = canvas.getContext("2d", { alpha: false });
|
2017-04-17 21:46:53 +09:00
|
|
|
|
|
|
|
if (this._textContent) {
|
|
|
|
let textItems = this._textContent.items;
|
|
|
|
let textStyles = this._textContent.styles;
|
|
|
|
this._processItems(textItems, textStyles);
|
|
|
|
capability.resolve();
|
|
|
|
} else if (this._textContentStream) {
|
|
|
|
let pump = () => {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
this._reader.read().then(({ value, done }) => {
|
2017-04-17 21:46:53 +09:00
|
|
|
if (done) {
|
|
|
|
capability.resolve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-11 02:59:03 +09:00
|
|
|
Object.assign(styleCache, value.styles);
|
2017-04-17 21:46:53 +09:00
|
|
|
this._processItems(value.items, styleCache);
|
|
|
|
pump();
|
|
|
|
}, capability.reject);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._reader = this._textContentStream.getReader();
|
|
|
|
pump();
|
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
throw new Error(
|
|
|
|
'Neither "textContent" nor "textContentStream"' +
|
|
|
|
" parameters specified."
|
|
|
|
);
|
2015-11-11 00:45:03 +09:00
|
|
|
}
|
|
|
|
|
2017-04-17 21:46:53 +09:00
|
|
|
capability.promise.then(() => {
|
|
|
|
styleCache = null;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (!timeout) {
|
|
|
|
// Render right away
|
2017-05-03 23:39:54 +09:00
|
|
|
render(this);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
} else {
|
|
|
|
// Schedule
|
2017-04-17 21:46:53 +09:00
|
|
|
this._renderTimer = setTimeout(() => {
|
|
|
|
render(this);
|
|
|
|
this._renderTimer = null;
|
|
|
|
}, timeout);
|
|
|
|
}
|
|
|
|
}, this._capability.reject);
|
2016-08-17 08:06:35 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
|
|
|
|
if (!this._enhanceTextSelection || !this._renderingDone) {
|
|
|
|
return;
|
|
|
|
}
|
[EnhanceTextSelection] Make `expandTextDivs` more efficient by updating all styles at once instead of piecewise
I intended to provide proper benchmarking results here, as outlined in https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes, but after wasting a couple of hours over the weekend getting weird results I gave up.
It appears that there's a lot of, i.e. way too much, variance between subsequent runs of `text` tests for the results to be meaningful.
(Previously I've only benchmarked `eq` tests, so I don't know if the `text` tests has never worked well or if it's a newer problem. For reference, please see the results of back-to-back benchmark runs on the current `master` with a *very* simple manifest file: [link here].)
Instead I used `console.time/timeEnd` in `appendText` and `expandTextDivs` to be able to compare the performance with/without the patch. The entire viewer was (skip-cache) reloaded between measurements, and the result are available here: [link here].
Given the troubles I've had with benchmarking, I've not yet computed any statistics on the results (e.g. mean, variance, confidence intervals, and so on).
However, just by looking at the data I think it's safe to say that this patch first of all doesn't seem to regress the current performance. Secondly it certainly looks *very* likely that this patch actually improves the performance, especially for the one-glyph-per-text-div case (cf. issue 7224).
Re: issue 7584.
2016-09-14 00:04:57 +09:00
|
|
|
if (this._bounds !== null) {
|
2016-09-03 00:51:13 +09:00
|
|
|
expand(this);
|
[EnhanceTextSelection] Make `expandTextDivs` more efficient by updating all styles at once instead of piecewise
I intended to provide proper benchmarking results here, as outlined in https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes, but after wasting a couple of hours over the weekend getting weird results I gave up.
It appears that there's a lot of, i.e. way too much, variance between subsequent runs of `text` tests for the results to be meaningful.
(Previously I've only benchmarked `eq` tests, so I don't know if the `text` tests has never worked well or if it's a newer problem. For reference, please see the results of back-to-back benchmark runs on the current `master` with a *very* simple manifest file: [link here].)
Instead I used `console.time/timeEnd` in `appendText` and `expandTextDivs` to be able to compare the performance with/without the patch. The entire viewer was (skip-cache) reloaded between measurements, and the result are available here: [link here].
Given the troubles I've had with benchmarking, I've not yet computed any statistics on the results (e.g. mean, variance, confidence intervals, and so on).
However, just by looking at the data I think it's safe to say that this patch first of all doesn't seem to regress the current performance. Secondly it certainly looks *very* likely that this patch actually improves the performance, especially for the one-glyph-per-text-div case (cf. issue 7224).
Re: issue 7584.
2016-09-14 00:04:57 +09:00
|
|
|
this._bounds = null;
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const NO_PADDING = "0 0 0 0";
|
|
|
|
const transformBuf = [],
|
|
|
|
paddingBuf = [];
|
2016-09-03 01:10:37 +09:00
|
|
|
|
|
|
|
for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
|
2019-08-19 19:09:18 +09:00
|
|
|
const div = this._textDivs[i];
|
|
|
|
const divProps = this._textDivProperties.get(div);
|
2016-09-03 01:10:37 +09:00
|
|
|
|
2019-08-19 19:09:18 +09:00
|
|
|
if (divProps.isWhitespace) {
|
[EnhanceTextSelection] Make `expandTextDivs` more efficient by updating all styles at once instead of piecewise
I intended to provide proper benchmarking results here, as outlined in https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes, but after wasting a couple of hours over the weekend getting weird results I gave up.
It appears that there's a lot of, i.e. way too much, variance between subsequent runs of `text` tests for the results to be meaningful.
(Previously I've only benchmarked `eq` tests, so I don't know if the `text` tests has never worked well or if it's a newer problem. For reference, please see the results of back-to-back benchmark runs on the current `master` with a *very* simple manifest file: [link here].)
Instead I used `console.time/timeEnd` in `appendText` and `expandTextDivs` to be able to compare the performance with/without the patch. The entire viewer was (skip-cache) reloaded between measurements, and the result are available here: [link here].
Given the troubles I've had with benchmarking, I've not yet computed any statistics on the results (e.g. mean, variance, confidence intervals, and so on).
However, just by looking at the data I think it's safe to say that this patch first of all doesn't seem to regress the current performance. Secondly it certainly looks *very* likely that this patch actually improves the performance, especially for the one-glyph-per-text-div case (cf. issue 7224).
Re: issue 7584.
2016-09-14 00:04:57 +09:00
|
|
|
continue;
|
|
|
|
}
|
2016-09-03 01:10:37 +09:00
|
|
|
if (expandDivs) {
|
2019-08-23 01:40:15 +09:00
|
|
|
transformBuf.length = 0;
|
2019-08-24 06:24:57 +09:00
|
|
|
paddingBuf.length = 0;
|
2016-09-03 01:10:37 +09:00
|
|
|
|
2019-08-25 19:39:46 +09:00
|
|
|
if (divProps.originalTransform) {
|
|
|
|
transformBuf.push(divProps.originalTransform);
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
2019-08-23 00:35:48 +09:00
|
|
|
if (divProps.paddingTop > 0) {
|
2019-08-24 06:24:57 +09:00
|
|
|
paddingBuf.push(`${divProps.paddingTop}px`);
|
2019-08-23 01:40:15 +09:00
|
|
|
transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
|
2019-08-24 06:24:57 +09:00
|
|
|
} else {
|
|
|
|
paddingBuf.push(0);
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
2019-08-23 00:35:48 +09:00
|
|
|
if (divProps.paddingRight > 0) {
|
2019-08-24 06:24:57 +09:00
|
|
|
paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
|
|
|
|
} else {
|
|
|
|
paddingBuf.push(0);
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
2019-08-23 00:35:48 +09:00
|
|
|
if (divProps.paddingBottom > 0) {
|
2019-08-24 06:24:57 +09:00
|
|
|
paddingBuf.push(`${divProps.paddingBottom}px`);
|
|
|
|
} else {
|
|
|
|
paddingBuf.push(0);
|
|
|
|
}
|
|
|
|
if (divProps.paddingLeft > 0) {
|
|
|
|
paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
|
|
|
|
transformBuf.push(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
`translateX(${-divProps.paddingLeft / divProps.scale}px)`
|
|
|
|
);
|
2019-08-24 06:24:57 +09:00
|
|
|
} else {
|
|
|
|
paddingBuf.push(0);
|
[EnhanceTextSelection] Make `expandTextDivs` more efficient by updating all styles at once instead of piecewise
I intended to provide proper benchmarking results here, as outlined in https://github.com/mozilla/pdf.js/wiki/Benchmarking-your-changes, but after wasting a couple of hours over the weekend getting weird results I gave up.
It appears that there's a lot of, i.e. way too much, variance between subsequent runs of `text` tests for the results to be meaningful.
(Previously I've only benchmarked `eq` tests, so I don't know if the `text` tests has never worked well or if it's a newer problem. For reference, please see the results of back-to-back benchmark runs on the current `master` with a *very* simple manifest file: [link here].)
Instead I used `console.time/timeEnd` in `appendText` and `expandTextDivs` to be able to compare the performance with/without the patch. The entire viewer was (skip-cache) reloaded between measurements, and the result are available here: [link here].
Given the troubles I've had with benchmarking, I've not yet computed any statistics on the results (e.g. mean, variance, confidence intervals, and so on).
However, just by looking at the data I think it's safe to say that this patch first of all doesn't seem to regress the current performance. Secondly it certainly looks *very* likely that this patch actually improves the performance, especially for the one-glyph-per-text-div case (cf. issue 7224).
Re: issue 7584.
2016-09-14 00:04:57 +09:00
|
|
|
}
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
const padding = paddingBuf.join(" ");
|
2019-08-24 06:24:57 +09:00
|
|
|
if (padding !== NO_PADDING) {
|
|
|
|
div.style.padding = padding;
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
2019-08-23 01:40:15 +09:00
|
|
|
if (transformBuf.length) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
div.style.transform = transformBuf.join(" ");
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
2016-09-03 01:10:37 +09:00
|
|
|
} else {
|
2019-08-22 20:26:28 +09:00
|
|
|
div.style.padding = null;
|
|
|
|
div.style.transform = divProps.originalTransform;
|
2016-08-17 08:06:35 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-11-11 00:45:03 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts rendering of the text layer.
|
|
|
|
*
|
|
|
|
* @param {TextLayerRenderParameters} renderParameters
|
|
|
|
* @returns {TextLayerRenderTask}
|
|
|
|
*/
|
|
|
|
function renderTextLayer(renderParameters) {
|
2017-04-17 21:46:53 +09:00
|
|
|
var task = new TextLayerRenderTask({
|
|
|
|
textContent: renderParameters.textContent,
|
|
|
|
textContentStream: renderParameters.textContentStream,
|
|
|
|
container: renderParameters.container,
|
|
|
|
viewport: renderParameters.viewport,
|
|
|
|
textDivs: renderParameters.textDivs,
|
|
|
|
textContentItemsStr: renderParameters.textContentItemsStr,
|
|
|
|
enhanceTextSelection: renderParameters.enhanceTextSelection,
|
|
|
|
});
|
2015-11-11 00:45:03 +09:00
|
|
|
task._render(renderParameters.timeout);
|
|
|
|
return task;
|
|
|
|
}
|
|
|
|
|
|
|
|
return renderTextLayer;
|
|
|
|
})();
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
export { renderTextLayer };
|