mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-26 00:47:21 +02:00
Simplify positioning of elements inside markedContent
By setting `display: contents` on `.markedContent` containers, they stop affecting the layout of their children. This means that we can always position text layer `<span>` elements using percentages relative to the page dimensions, rather than having two separate code paths. For some reason this breaks the workaround for text selection flickering in Chrome/Safari, which can be fixed by setting `user-select: text` on the `.endOfContent` div (only in Chrome/Safari, as it would break selection in Firefox).
This commit is contained in:
parent
4af193bbfc
commit
7e0c9395fb
@ -346,14 +346,8 @@ class TextLayer {
|
|||||||
const divStyle = textDiv.style;
|
const divStyle = textDiv.style;
|
||||||
// Setting the style properties individually, rather than all at once,
|
// Setting the style properties individually, rather than all at once,
|
||||||
// should be OK since the `textDiv` isn't appended to the document yet.
|
// should be OK since the `textDiv` isn't appended to the document yet.
|
||||||
if (this.#container === this.#rootContainer) {
|
divStyle.left = `${((100 * left) / this.#pageWidth).toFixed(2)}%`;
|
||||||
divStyle.left = `${((100 * left) / this.#pageWidth).toFixed(2)}%`;
|
divStyle.top = `${((100 * top) / this.#pageHeight).toFixed(2)}%`;
|
||||||
divStyle.top = `${((100 * top) / this.#pageHeight).toFixed(2)}%`;
|
|
||||||
} else {
|
|
||||||
// We're in a marked content span, hence we can't use percents.
|
|
||||||
divStyle.left = `calc(var(--total-scale-factor) * ${left.toFixed(2)}px)`;
|
|
||||||
divStyle.top = `calc(var(--total-scale-factor) * ${top.toFixed(2)}px)`;
|
|
||||||
}
|
|
||||||
divStyle.setProperty("--font-height", `${fontHeight.toFixed(2)}px`);
|
divStyle.setProperty("--font-height", `${fontHeight.toFixed(2)}px`);
|
||||||
divStyle.fontFamily = fontFamily;
|
divStyle.fontFamily = fontFamily;
|
||||||
|
|
||||||
|
|||||||
@ -59,14 +59,9 @@
|
|||||||
scale(var(--min-font-size-inv));
|
scale(var(--min-font-size-inv));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only necessary in Google Chrome, see issue 14205, and most unfortunately
|
.markedContent {
|
||||||
* the problem doesn't show up in "text" reference tests. */
|
display: contents;
|
||||||
/*#if !MOZCENTRAL*/
|
|
||||||
span.markedContent {
|
|
||||||
top: 0;
|
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
/*#endif*/
|
|
||||||
|
|
||||||
span[role="img"] {
|
span[role="img"] {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|||||||
@ -321,6 +321,7 @@ class TextLayerBuilder {
|
|||||||
if (endDiv) {
|
if (endDiv) {
|
||||||
endDiv.style.width = parentTextLayer.style.width;
|
endDiv.style.width = parentTextLayer.style.width;
|
||||||
endDiv.style.height = parentTextLayer.style.height;
|
endDiv.style.height = parentTextLayer.style.height;
|
||||||
|
endDiv.style.userSelect = "text";
|
||||||
anchor.parentElement.insertBefore(
|
anchor.parentElement.insertBefore(
|
||||||
endDiv,
|
endDiv,
|
||||||
modifyStart ? anchor : anchor.nextSibling
|
modifyStart ? anchor : anchor.nextSibling
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user