mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15: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:
parent
580bfad628
commit
3e550f392a
7 changed files with 38 additions and 22 deletions
|
@ -13,9 +13,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AnnotationMode, createPromiseCapability, version } from "pdfjs-lib";
|
||||
import {
|
||||
CSS_UNITS,
|
||||
AnnotationMode,
|
||||
createPromiseCapability,
|
||||
PixelsPerInch,
|
||||
version,
|
||||
} from "pdfjs-lib";
|
||||
import {
|
||||
DEFAULT_SCALE,
|
||||
DEFAULT_SCALE_DELTA,
|
||||
DEFAULT_SCALE_VALUE,
|
||||
|
@ -535,7 +539,9 @@ class BaseViewer {
|
|||
this._optionalContentConfigPromise = optionalContentConfigPromise;
|
||||
|
||||
const scale = this.currentScale;
|
||||
const viewport = firstPdfPage.getViewport({ scale: scale * CSS_UNITS });
|
||||
const viewport = firstPdfPage.getViewport({
|
||||
scale: scale * PixelsPerInch.PDF_TO_CSS_UNITS,
|
||||
});
|
||||
const textLayerFactory =
|
||||
this.textLayerMode !== TextLayerMode.DISABLE && !isPureXfa
|
||||
? this
|
||||
|
@ -904,11 +910,11 @@ class BaseViewer {
|
|||
const pageWidth =
|
||||
(changeOrientation ? pageView.height : pageView.width) /
|
||||
pageView.scale /
|
||||
CSS_UNITS;
|
||||
PixelsPerInch.PDF_TO_CSS_UNITS;
|
||||
const pageHeight =
|
||||
(changeOrientation ? pageView.width : pageView.height) /
|
||||
pageView.scale /
|
||||
CSS_UNITS;
|
||||
PixelsPerInch.PDF_TO_CSS_UNITS;
|
||||
let scale = 0;
|
||||
switch (destArray[1].name) {
|
||||
case "XYZ":
|
||||
|
@ -957,9 +963,13 @@ class BaseViewer {
|
|||
const vPadding = this.removePageBorders ? 0 : VERTICAL_PADDING;
|
||||
|
||||
widthScale =
|
||||
(this.container.clientWidth - hPadding) / width / CSS_UNITS;
|
||||
(this.container.clientWidth - hPadding) /
|
||||
width /
|
||||
PixelsPerInch.PDF_TO_CSS_UNITS;
|
||||
heightScale =
|
||||
(this.container.clientHeight - vPadding) / height / CSS_UNITS;
|
||||
(this.container.clientHeight - vPadding) /
|
||||
height /
|
||||
PixelsPerInch.PDF_TO_CSS_UNITS;
|
||||
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
import {
|
||||
AnnotationMode,
|
||||
createPromiseCapability,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
SVGGraphics,
|
||||
} from "pdfjs-lib";
|
||||
import {
|
||||
approximateFraction,
|
||||
CSS_UNITS,
|
||||
DEFAULT_SCALE,
|
||||
getOutputScale,
|
||||
RendererType,
|
||||
|
@ -149,7 +149,7 @@ class PDFPageView {
|
|||
|
||||
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
||||
this.viewport = pdfPage.getViewport({
|
||||
scale: this.scale * CSS_UNITS,
|
||||
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
|
||||
rotation: totalRotation,
|
||||
});
|
||||
this.reset();
|
||||
|
@ -329,7 +329,7 @@ class PDFPageView {
|
|||
|
||||
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
||||
this.viewport = this.viewport.clone({
|
||||
scale: this.scale * CSS_UNITS,
|
||||
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS,
|
||||
rotation: totalRotation,
|
||||
});
|
||||
|
||||
|
@ -774,7 +774,9 @@ class PDFPageView {
|
|||
this.outputScale = outputScale;
|
||||
|
||||
if (this.useOnlyCssZoom) {
|
||||
const actualSizeViewport = viewport.clone({ scale: CSS_UNITS });
|
||||
const actualSizeViewport = viewport.clone({
|
||||
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
||||
});
|
||||
// Use a scale that makes the canvas have the originally intended size
|
||||
// of the page.
|
||||
outputScale.sx *= actualSizeViewport.width / viewport.width;
|
||||
|
@ -863,7 +865,9 @@ class PDFPageView {
|
|||
};
|
||||
|
||||
const pdfPage = this.pdfPage;
|
||||
const actualSizeViewport = this.viewport.clone({ scale: CSS_UNITS });
|
||||
const actualSizeViewport = this.viewport.clone({
|
||||
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
||||
});
|
||||
const promise = pdfPage
|
||||
.getOperatorList({
|
||||
annotationMode: this._annotatationMode,
|
||||
|
|
|
@ -13,14 +13,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CSS_UNITS } from "./ui_utils.js";
|
||||
import { getXfaPageViewport, PixelsPerInch } from "pdfjs-lib";
|
||||
import { DefaultXfaLayerFactory } from "./xfa_layer_builder.js";
|
||||
import { getXfaPageViewport } from "pdfjs-lib";
|
||||
|
||||
function getXfaHtmlForPrinting(printContainer, pdfDocument) {
|
||||
const xfaHtml = pdfDocument.allXfaHtml;
|
||||
const factory = new DefaultXfaLayerFactory();
|
||||
const scale = Math.round(CSS_UNITS * 100) / 100;
|
||||
const scale = Math.round(PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
|
||||
|
||||
for (const xfaPage of xfaHtml.children) {
|
||||
const page = document.createElement("div");
|
||||
|
|
|
@ -13,9 +13,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PixelsPerInch } from "pdfjs-lib";
|
||||
|
||||
const CSS_UNITS = PixelsPerInch.CSS / PixelsPerInch.PDF;
|
||||
const DEFAULT_SCALE_VALUE = "auto";
|
||||
const DEFAULT_SCALE = 1.0;
|
||||
const DEFAULT_SCALE_DELTA = 1.1;
|
||||
|
@ -1004,7 +1001,6 @@ export {
|
|||
AutoPrintRegExp,
|
||||
backtrackBeforeAllVisibleElements, // only exported for testing
|
||||
binarySearchFirstItem,
|
||||
CSS_UNITS,
|
||||
DEFAULT_SCALE,
|
||||
DEFAULT_SCALE_DELTA,
|
||||
DEFAULT_SCALE_VALUE,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue