Files
pdf.js/web/text_layer_builder.css
Calixte Denizet 34246a0b6f Zoom the text layer with CSS and only set a transform on the spans which need one
The span font sizes are in page units and the transform is only set when the
span is rotated, skewed or scaled, which makes the layout cheaper.
The free highlight box comes from the editor layer: with the pre-standard CSS
zoom (Chrome < 128, Safari 18), the zoomed text layer client rect is scaled.
2026-11-30 13:45:33 +01:00

178 lines
4.2 KiB
CSS

/* Copyright 2014 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.
*/
.textLayer {
--layer-zoom: var(--total-scale-factor, 1);
/* Keep highlight decorations and debug borders independent of PDF zoom. */
--text-layer-screen-px: calc(1px / var(--layer-zoom));
color-scheme: only light;
zoom: var(--layer-zoom);
position: absolute;
text-align: initial;
inset: 0;
overflow: clip;
opacity: 1;
line-height: 1;
letter-spacing: normal;
word-spacing: normal;
text-size-adjust: none;
forced-color-adjust: none;
transform-origin: 0 0;
caret-color: CanvasText;
z-index: 0;
&.highlighting {
touch-action: none;
}
:is(span, br) {
color: transparent;
position: absolute;
white-space: pre;
cursor: text;
transform-origin: 0% 0%;
user-select: text;
}
/* Show the glyph boxes of the text layer fonts, see `#textLayer=visible`. */
&.debugFonts :is(span, br) {
color: red;
}
&.textLayerFonts {
font-kerning: normal;
font-variant-ligatures: none;
}
> :not(.markedContent),
.markedContent span:not(.markedContent) {
z-index: 1;
}
.markedContent {
display: contents;
}
span[role="img"] {
user-select: none;
cursor: default;
}
.highlight {
--highlight-bg-color: rgb(180 0 170 / 0.25);
--highlight-selected-bg-color: rgb(0 100 0 / 0.25);
--highlight-color: var(--highlight-bg-color);
--highlight-backdrop-filter: none;
--highlight-selected-backdrop-filter: none;
@media screen and (forced-colors: active) {
--highlight-bg-color: transparent;
--highlight-selected-bg-color: transparent;
--highlight-backdrop-filter: var(--hcm-highlight-filter);
--highlight-selected-backdrop-filter: var(
--hcm-highlight-selected-filter
);
}
--highlight-radius: calc(4 * var(--text-layer-screen-px));
margin: calc(-1 * var(--text-layer-screen-px));
padding: var(--text-layer-screen-px);
background-color: var(--highlight-color);
backdrop-filter: var(--highlight-backdrop-filter);
border-radius: var(--highlight-radius);
&.appended {
position: initial;
}
&.begin {
border-radius: var(--highlight-radius) 0 0 var(--highlight-radius);
}
&.end {
border-radius: 0 var(--highlight-radius) var(--highlight-radius) 0;
}
&.middle {
border-radius: 0;
}
&.selected {
--highlight-color: var(--highlight-selected-bg-color);
backdrop-filter: var(--highlight-selected-backdrop-filter);
scroll-margin-top: calc(50 * var(--text-layer-screen-px));
}
}
/* Paint the outline without breaking kerning across an inline highlight. */
&.textLayerFonts .highlight {
margin: 0;
padding: 0;
box-shadow: 0 0 0 var(--text-layer-screen-px) var(--highlight-color);
}
::selection {
/* stylelint-disable declaration-block-no-duplicate-properties */
/*#if !MOZCENTRAL*/
background: rgba(0 0 255 / 0.25);
/*#endif*/
/* stylelint-enable declaration-block-no-duplicate-properties */
background: color-mix(in srgb, AccentColor, transparent 50%);
color: transparent;
}
&.selectionRendering {
::selection {
background: transparent;
color: transparent;
}
}
/* Avoids https://github.com/mozilla/pdf.js/issues/13840 in Chrome */
/*#if !MOZCENTRAL*/
br::selection {
background: transparent;
}
/*#endif*/
.endOfContent {
display: block;
position: absolute;
inset: 100% 0 0;
z-index: 0;
cursor: default;
user-select: none;
}
&.selecting .endOfContent {
top: 0;
}
}
.textLayerImages {
position: absolute;
inset: 0;
user-select: none;
canvas {
position: absolute;
transform-origin: 0% 0%;
}
}