1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Get rid of CSS transform on each annotation in the annotation layer

- each annotation has its coordinates/dimensions expressed in percentage,
  hence it's correctly positioned whatever the scale factor is;
- the font sizes are expressed in percentage too and the main font size
  is scaled thanks a css var (--scale-factor);
- the rotation is now applied on the div annotationLayer;
- this patch improve the rendering of some strings where the glyph spacing
  was not correct (it's a Firefox bug);
- it helps to simplify the code and it should slightly improve the update of
  page (on zoom or rotation).
This commit is contained in:
Calixte Denizet 2022-06-13 11:01:55 +02:00
parent 6dc8d1f532
commit e2db9bacef
17 changed files with 154 additions and 155 deletions

View file

@ -27,13 +27,14 @@
position: absolute;
top: 0;
left: 0;
font-size: calc(100px * var(--scale-factor));
}
.annotationEditorLayer .freeTextEditor {
position: absolute;
background: transparent;
border-radius: 3px;
padding: calc(var(--freetext-padding) * var(--zoom-factor));
padding: calc(var(--freetext-padding) * var(--scale-factor));
resize: none;
width: auto;
height: auto;

View file

@ -27,9 +27,30 @@
}
}
[data-annotation-rotation="90"] {
transform: rotate(90deg) translateY(-100%);
}
[data-annotation-rotation="180"] {
transform: rotate(180deg) translate(-100%, -100%);
}
[data-annotation-rotation="270"] {
transform: rotate(270deg) translateX(-100%);
}
.annotationLayer {
position: absolute;
top: 0;
left: 0;
font-size: calc(100px * var(--scale-factor));
pointer-events: none;
transform-origin: 0 0;
}
.annotationLayer section {
position: absolute;
text-align: initial;
pointer-events: auto;
box-sizing: border-box;
}
.annotationLayer .linkAnnotation > a,
@ -43,10 +64,8 @@
}
.annotationLayer .buttonWidgetAnnotation.pushButton > canvas {
position: relative;
top: 0;
left: 0;
z-index: -1;
width: 100%;
height: 100%;
}
.annotationLayer .linkAnnotation > a:hover,
@ -59,6 +78,8 @@
.annotationLayer .textAnnotation img {
position: absolute;
cursor: pointer;
width: 100%;
height: 100%;
}
.annotationLayer .textWidgetAnnotation input,
@ -69,7 +90,7 @@
background-image: var(--annotation-unfocused-field-background);
border: 1px solid transparent;
box-sizing: border-box;
font: 9px sans-serif;
font: 9% sans-serif;
height: 100%;
margin: 0;
vertical-align: top;
@ -186,27 +207,31 @@
.annotationLayer .popupWrapper {
position: absolute;
width: 20em;
font-size: calc(9px * var(--scale-factor));
width: 100%;
min-width: calc(180px * var(--scale-factor));
pointer-events: none;
}
.annotationLayer .popup {
position: absolute;
z-index: 200;
max-width: 20em;
max-width: calc(180px * var(--scale-factor));
background-color: rgba(255, 255, 153, 1);
box-shadow: 0 2px 5px rgba(136, 136, 136, 1);
border-radius: 2px;
padding: 6px;
margin-left: 5px;
box-shadow: 0 calc(2px * var(--scale-factor)) calc(5px * var(--scale-factor))
rgba(136, 136, 136, 1);
border-radius: calc(2px * var(--scale-factor));
padding: calc(6px * var(--scale-factor));
margin-left: calc(5px * var(--scale-factor));
cursor: pointer;
font: message-box;
font-size: 9px;
white-space: normal;
word-wrap: break-word;
pointer-events: auto;
}
.annotationLayer .popup > * {
font-size: 9px;
font-size: calc(9px * var(--scale-factor));
}
.annotationLayer .popup h1 {
@ -215,17 +240,18 @@
.annotationLayer .popupDate {
display: inline-block;
margin-left: 5px;
margin-left: calc(5px * var(--scale-factor));
}
.annotationLayer .popupContent {
border-top: 1px solid rgba(51, 51, 51, 1);
margin-top: 2px;
padding-top: 2px;
margin-top: calc(2px * var(--scale-factor));
padding-top: calc(2px * var(--scale-factor));
}
.annotationLayer .richText > * {
white-space: pre-wrap;
font-size: calc(9px * var(--scale-factor));
}
.annotationLayer .highlightAnnotation,
@ -244,3 +270,9 @@
.annotationLayer .fileAttachmentAnnotation {
cursor: pointer;
}
.annotationLayer section svg {
position: absolute;
width: 100%;
height: 100%;
}

View file

@ -117,11 +117,14 @@ class AnnotationLayerBuilder {
if (this.div) {
// If an annotationLayer already exists, refresh its children's
// transformation matrices.
AnnotationLayer.setDimensions(this.div, viewport);
AnnotationLayer.update(parameters);
} else {
// Create an annotation layer div and render the annotations
// if there is at least one annotation.
this.div = document.createElement("div");
AnnotationLayer.setDimensions(this.div, viewport);
this.div.className = "annotationLayer";
this.pageDiv.append(this.div);
parameters.div = this.div;

View file

@ -1048,7 +1048,10 @@ class BaseViewer {
return;
}
docStyle.setProperty("--zoom-factor", newScale);
docStyle.setProperty(
"--scale-factor",
newScale * PixelsPerInch.PDF_TO_CSS_UNITS
);
const updateArgs = { scale: newScale };
for (const pageView of this._pages) {

View file

@ -377,7 +377,7 @@ class PDFPageView {
});
if (this._isStandalone) {
docStyle.setProperty("--zoom-factor", this.scale);
docStyle.setProperty("--scale-factor", this.viewport.scale);
}
if (this.svg) {

View file

@ -23,7 +23,7 @@
--page-margin: 1px auto -8px;
--page-border: 9px solid transparent;
--spreadHorizontalWrapped-margin-LR: -3.5px;
--zoom-factor: 1;
--scale-factor: 1;
}
@media screen and (forced-colors: active) {