use --scale-factor variable to set text layer font size

Newer pdf.js versions requires this variable to be set equal to the
actual scale (zoom ratio), to properly set font size in text layer div.
This commit is contained in:
octocorvus 2023-03-17 21:53:36 +00:00 committed by Daniel Micay
parent f5a1452a2d
commit 2dea11799c
2 changed files with 5 additions and 0 deletions

View File

@ -12,6 +12,8 @@ body {
} }
#container { #container {
--scale-factor: 1;
width: 100%; width: 100%;
height: 100%; height: 100%;
display: grid; display: grid;

View File

@ -7,6 +7,7 @@ let pageRendering = false;
let renderPending = false; let renderPending = false;
let renderPendingZoom = 0; let renderPendingZoom = 0;
const canvas = document.getElementById('content'); const canvas = document.getElementById('content');
const container = document.getElementById("container");
let orientationDegrees = 0; let orientationDegrees = 0;
let zoomRatio = 1; let zoomRatio = 1;
let textLayerDiv = document.getElementById("text"); let textLayerDiv = document.getElementById("text");
@ -82,6 +83,7 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
textLayerDiv.replaceWith(cached.textLayerDiv); textLayerDiv.replaceWith(cached.textLayerDiv);
textLayerDiv = cached.textLayerDiv; textLayerDiv = cached.textLayerDiv;
container.style.setProperty("--scale-factor", newZoomRatio.toString());
} }
pageRendering = false; pageRendering = false;
@ -153,6 +155,7 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
if (useRender) { if (useRender) {
textLayerDiv.replaceWith(newTextLayerDiv); textLayerDiv.replaceWith(newTextLayerDiv);
textLayerDiv = newTextLayerDiv; textLayerDiv = newTextLayerDiv;
container.style.setProperty("--scale-factor", newZoomRatio.toString());
} }
if (cache.length === maxCached) { if (cache.length === maxCached) {