Skip to content

Commit

Permalink
drill enhanceTextLayer arg
Browse files Browse the repository at this point in the history
  • Loading branch information
seanaye committed Dec 22, 2022
1 parent 3ed296e commit 877cdd0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import { deprecated, setLayerDimensions } from "./display_utils.js";
* @property {boolean} [mustRotate] true if the text layer must be rotated.
* @property {boolean} [mustRescale] true if the text layer contents must be
* rescaled.
* @property {boolean} [enhanceTextSelection] - Whether to turn on the text
* selection enhancement.
*/

const MAX_TEXT_DIVS_TO_RENDER = 100000;
Expand Down Expand Up @@ -294,8 +296,15 @@ function appendText(task, geom, styles) {
}

function layout(params) {
const { div, scale, properties, ctx, prevFontSize, prevFontFamily } = params;
const textDivProperties = this._textDivProperties.get(div);
const {
div,
scale,
properties,
ctx,
prevFontSize,
prevFontFamily,
enhanceTextSelection,
} = params;
const { style } = div;
let transform = "";
if (properties.canvasWidth !== 0 && properties.hasText) {
Expand All @@ -315,18 +324,22 @@ function layout(params) {
// const scale =
// (this._devicePixelRatio * textDivProperties.canvasWidth) / width;
// transform = `scaleX(${scale})`;
transform = `scaleX(${(this._devicePixelRatio * canvasWidth) / width})`;
if (this._enhanceTextSelection) {
textDivProperties.scale = scale;
// this function was originally part of a class which had access to
// this._devicePixelRatio since it was refactored upstream and
// we no longer have access to `this` I am assuming
// it is safe to use window.devicePixelRatio instead
transform = `scaleX(${(window.devicePixelRatio * canvasWidth) / width})`;
if (enhanceTextSelection) {
properties.scale = scale;
}
}
}
if (properties.angle !== 0) {
transform = `rotate(${properties.angle}deg) ${transform}`;
}
if (transform.length > 0) {
if (this._enhanceTextSelection) {
textDivProperties.originalTransform = transform;
if (enhanceTextSelection) {
properties.originalTransform = transform;
}
style.transform = transform;
}
Expand Down Expand Up @@ -674,6 +687,7 @@ class TextLayerRenderTask {
scale: viewport.scale * (globalThis.devicePixelRatio || 1),
properties: null,
ctx: getCtx(0, isOffscreenCanvasSupported),
enhanceTextSelection: this._enhanceTextSelection,
};
const { pageWidth, pageHeight, pageX, pageY } = viewport.rawDims;
this._transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
Expand Down Expand Up @@ -900,6 +914,7 @@ function updateTextLayer({
isOffscreenCanvasSupported,
mustRotate = true,
mustRescale = true,
enhanceTextSelection = false,
}) {
if (mustRotate) {
setLayerDimensions(container, { rotation: viewport.rotation });
Expand All @@ -914,6 +929,7 @@ function updateTextLayer({
div: null,
scale,
properties: null,
enhanceTextSelection,
ctx,
};
for (const div of textDivs) {
Expand Down
1 change: 1 addition & 0 deletions web/text_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TextLayerBuilder {
isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
mustRescale,
mustRotate,
enhanceTextSelection: this.enhanceTextSelection,
});
this.show();
this.#scale = scale;
Expand Down

0 comments on commit 877cdd0

Please sign in to comment.