diff --git a/src/display/text_layer.js b/src/display/text_layer.js index 92fa54801..3a86b21e1 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -467,6 +467,19 @@ function renderTextLayer(params) { ); params.textContentSource = params.textContent || params.textContentStream; } + if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC && !TESTING")) { + const { container, viewport } = params; + const style = getComputedStyle(container); + const scaleFactor = parseFloat(style.getPropertyValue("--scale-factor")); + + if (!scaleFactor || Math.abs(scaleFactor - viewport.scale) > 1e-15) { + console.error( + "The `--scale-factor` CSS-variable must be set, " + + "to the same value as `viewport.scale`, " + + "either on the `container`-element itself or higher up in the DOM." + ); + } + } const task = new TextLayerRenderTask(params); task._render(); return task; diff --git a/test/unit/text_layer_spec.js b/test/unit/text_layer_spec.js index 0600dfe22..0cc06ae0e 100644 --- a/test/unit/text_layer_spec.js +++ b/test/unit/text_layer_spec.js @@ -35,7 +35,7 @@ describe("textLayer", function () { const textLayerRenderTask = renderTextLayer({ textContentSource: page.streamTextContent(), container: document.createElement("div"), - viewport: page.getViewport(), + viewport: page.getViewport({ scale: 1 }), textContentItemsStr, }); expect(textLayerRenderTask instanceof TextLayerRenderTask).toEqual(true);