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

Add PDF_TO_CSS_UNITS to the PixelsPerInch-structure

Rather than re-computing this value in a number of different places throughout the code-base[1], we can expose this in the API via the existing `PixelsPerInch`-structure instead.
There's also been feature requests asking for the old `CSS_UNITS` viewer constant to be made accessible, such that it could be used in third-party implementations.

I suppose that it could be argued that it's somewhat confusing to place a unitless property in `PixelsPerInch`, however given that the `PDF_TO_CSS_UNITS`-property is defined strictly in terms of the existing properties this is hopefully deemed reasonable.

---
[1] These include:
 - The viewer, with the `CSS_UNITS` name.
 - The reference-tests.
 - The display-layer, when rendering images; see PR 13991.
This commit is contained in:
Jonas Jenwald 2021-09-20 10:10:57 +02:00
parent 580bfad628
commit 3e550f392a
7 changed files with 38 additions and 22 deletions

View file

@ -879,7 +879,7 @@ function getImageSmoothingEnabled(transform, interpolate) {
scale[0] = Math.fround(scale[0]);
scale[1] = Math.fround(scale[1]);
const actualScale = Math.fround(
((globalThis.devicePixelRatio || 1) * PixelsPerInch.CSS) / PixelsPerInch.PDF
(globalThis.devicePixelRatio || 1) * PixelsPerInch.PDF_TO_CSS_UNITS
);
if (interpolate !== undefined) {
// If the value is explicitly set use it.

View file

@ -18,6 +18,7 @@ import {
BaseException,
isString,
removeNullCharacters,
shadow,
stringToBytes,
Util,
warn,
@ -35,6 +36,11 @@ const SVG_NS = "http://www.w3.org/2000/svg";
const PixelsPerInch = {
CSS: 96.0,
PDF: 72.0,
/** @type {number} */
get PDF_TO_CSS_UNITS() {
return shadow(this, "PDF_TO_CSS_UNITS", this.CSS / this.PDF);
},
};
class DOMCanvasFactory extends BaseCanvasFactory {