Merge pull request #14000 from Snuffleupagus/PixelsPerInch
Re-factor the `CSS_PIXELS_PER_INCH`/`PDF_PIXELS_PER_INCH` exports (PR 13991 follow-up)
This commit is contained in:
commit
4ddda41383
@ -12,7 +12,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { CSS_PIXELS_PER_INCH, PDF_PIXELS_PER_INCH } from "./display_utils.js";
|
|
||||||
import {
|
import {
|
||||||
FONT_IDENTITY_MATRIX,
|
FONT_IDENTITY_MATRIX,
|
||||||
IDENTITY_MATRIX,
|
IDENTITY_MATRIX,
|
||||||
@ -28,6 +28,7 @@ import {
|
|||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import { getShadingPattern, TilingPattern } from "./pattern_helper.js";
|
import { getShadingPattern, TilingPattern } from "./pattern_helper.js";
|
||||||
|
import { PixelsPerInch } from "./display_utils.js";
|
||||||
|
|
||||||
// <canvas> contexts store most of the state we need natively.
|
// <canvas> contexts store most of the state we need natively.
|
||||||
// However, PDF needs a bit more state, which we store here.
|
// However, PDF needs a bit more state, which we store here.
|
||||||
@ -878,8 +879,7 @@ function getImageSmoothingEnabled(transform, interpolate) {
|
|||||||
scale[0] = Math.fround(scale[0]);
|
scale[0] = Math.fround(scale[0]);
|
||||||
scale[1] = Math.fround(scale[1]);
|
scale[1] = Math.fround(scale[1]);
|
||||||
const actualScale = Math.fround(
|
const actualScale = Math.fround(
|
||||||
((globalThis.devicePixelRatio || 1) * CSS_PIXELS_PER_INCH) /
|
((globalThis.devicePixelRatio || 1) * PixelsPerInch.CSS) / PixelsPerInch.PDF
|
||||||
PDF_PIXELS_PER_INCH
|
|
||||||
);
|
);
|
||||||
if (interpolate !== undefined) {
|
if (interpolate !== undefined) {
|
||||||
// If the value is explicitly set use it.
|
// If the value is explicitly set use it.
|
||||||
@ -2458,11 +2458,8 @@ class CanvasGraphics {
|
|||||||
this.ctx = this.groupStack.pop();
|
this.ctx = this.groupStack.pop();
|
||||||
// Turn off image smoothing to avoid sub pixel interpolation which can
|
// Turn off image smoothing to avoid sub pixel interpolation which can
|
||||||
// look kind of blurry for some pdfs.
|
// look kind of blurry for some pdfs.
|
||||||
if (this.ctx.imageSmoothingEnabled !== undefined) {
|
this.ctx.imageSmoothingEnabled = false;
|
||||||
this.ctx.imageSmoothingEnabled = false;
|
|
||||||
} else {
|
|
||||||
this.ctx.mozImageSmoothingEnabled = false;
|
|
||||||
}
|
|
||||||
if (group.smask) {
|
if (group.smask) {
|
||||||
this.tempSMask = this.smaskStack.pop();
|
this.tempSMask = this.smaskStack.pop();
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,8 +32,10 @@ import {
|
|||||||
const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
|
const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
|
||||||
const SVG_NS = "http://www.w3.org/2000/svg";
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||||
|
|
||||||
const CSS_PIXELS_PER_INCH = 96.0;
|
const PixelsPerInch = {
|
||||||
const PDF_PIXELS_PER_INCH = 72.0;
|
CSS: 96.0,
|
||||||
|
PDF: 72.0,
|
||||||
|
};
|
||||||
|
|
||||||
class DOMCanvasFactory extends BaseCanvasFactory {
|
class DOMCanvasFactory extends BaseCanvasFactory {
|
||||||
constructor({ ownerDocument = globalThis.document } = {}) {
|
constructor({ ownerDocument = globalThis.document } = {}) {
|
||||||
@ -625,7 +627,6 @@ function getXfaPageViewport(xfaPage, { scale = 1, rotation = 0 }) {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
addLinkAttributes,
|
addLinkAttributes,
|
||||||
CSS_PIXELS_PER_INCH,
|
|
||||||
DEFAULT_LINK_REL,
|
DEFAULT_LINK_REL,
|
||||||
deprecated,
|
deprecated,
|
||||||
DOMCanvasFactory,
|
DOMCanvasFactory,
|
||||||
@ -641,8 +642,8 @@ export {
|
|||||||
LinkTarget,
|
LinkTarget,
|
||||||
loadScript,
|
loadScript,
|
||||||
PageViewport,
|
PageViewport,
|
||||||
PDF_PIXELS_PER_INCH,
|
|
||||||
PDFDateString,
|
PDFDateString,
|
||||||
|
PixelsPerInch,
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
StatTimer,
|
StatTimer,
|
||||||
};
|
};
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
addLinkAttributes,
|
addLinkAttributes,
|
||||||
CSS_PIXELS_PER_INCH,
|
|
||||||
getFilenameFromUrl,
|
getFilenameFromUrl,
|
||||||
getPdfFilenameFromUrl,
|
getPdfFilenameFromUrl,
|
||||||
getXfaPageViewport,
|
getXfaPageViewport,
|
||||||
@ -24,8 +23,8 @@ import {
|
|||||||
isValidFetchUrl,
|
isValidFetchUrl,
|
||||||
LinkTarget,
|
LinkTarget,
|
||||||
loadScript,
|
loadScript,
|
||||||
PDF_PIXELS_PER_INCH,
|
|
||||||
PDFDateString,
|
PDFDateString,
|
||||||
|
PixelsPerInch,
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
} from "./display/display_utils.js";
|
} from "./display/display_utils.js";
|
||||||
import {
|
import {
|
||||||
@ -105,14 +104,13 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
|||||||
export {
|
export {
|
||||||
// From "./display/display_utils.js":
|
// From "./display/display_utils.js":
|
||||||
addLinkAttributes,
|
addLinkAttributes,
|
||||||
CSS_PIXELS_PER_INCH,
|
|
||||||
getFilenameFromUrl,
|
getFilenameFromUrl,
|
||||||
getPdfFilenameFromUrl,
|
getPdfFilenameFromUrl,
|
||||||
isPdfFile,
|
isPdfFile,
|
||||||
LinkTarget,
|
LinkTarget,
|
||||||
loadScript,
|
loadScript,
|
||||||
PDF_PIXELS_PER_INCH,
|
|
||||||
PDFDateString,
|
PDFDateString,
|
||||||
|
PixelsPerInch,
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
getXfaPageViewport,
|
getXfaPageViewport,
|
||||||
// From "./shared/util.js":
|
// From "./shared/util.js":
|
||||||
|
@ -20,17 +20,16 @@
|
|||||||
const {
|
const {
|
||||||
AnnotationLayer,
|
AnnotationLayer,
|
||||||
AnnotationMode,
|
AnnotationMode,
|
||||||
CSS_PIXELS_PER_INCH,
|
|
||||||
getDocument,
|
getDocument,
|
||||||
GlobalWorkerOptions,
|
GlobalWorkerOptions,
|
||||||
PDF_PIXELS_PER_INCH,
|
PixelsPerInch,
|
||||||
renderTextLayer,
|
renderTextLayer,
|
||||||
XfaLayer,
|
XfaLayer,
|
||||||
} = pdfjsLib;
|
} = pdfjsLib;
|
||||||
const { SimpleLinkService } = pdfjsViewer;
|
const { SimpleLinkService } = pdfjsViewer;
|
||||||
|
|
||||||
const WAITING_TIME = 100; // ms
|
const WAITING_TIME = 100; // ms
|
||||||
const PDF_TO_CSS_UNITS = CSS_PIXELS_PER_INCH / PDF_PIXELS_PER_INCH;
|
const PDF_TO_CSS_UNITS = PixelsPerInch.CSS / PixelsPerInch.PDF;
|
||||||
const CMAP_URL = "/build/generic/web/cmaps/";
|
const CMAP_URL = "/build/generic/web/cmaps/";
|
||||||
const CMAP_PACKED = true;
|
const CMAP_PACKED = true;
|
||||||
const STANDARD_FONT_DATA_URL = "/build/generic/web/standard_fonts/";
|
const STANDARD_FONT_DATA_URL = "/build/generic/web/standard_fonts/";
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
AnnotationMode,
|
AnnotationMode,
|
||||||
PDF_PIXELS_PER_INCH,
|
PixelsPerInch,
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
shadow,
|
shadow,
|
||||||
} from "pdfjs-lib";
|
} from "pdfjs-lib";
|
||||||
@ -34,7 +34,7 @@ function composePage(
|
|||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement("canvas");
|
||||||
|
|
||||||
// The size of the canvas in pixels for printing.
|
// The size of the canvas in pixels for printing.
|
||||||
const PRINT_UNITS = printResolution / PDF_PIXELS_PER_INCH;
|
const PRINT_UNITS = printResolution / PixelsPerInch.PDF;
|
||||||
canvas.width = Math.floor(size.width * PRINT_UNITS);
|
canvas.width = Math.floor(size.width * PRINT_UNITS);
|
||||||
canvas.height = Math.floor(size.height * PRINT_UNITS);
|
canvas.height = Math.floor(size.height * PRINT_UNITS);
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AnnotationMode, PDF_PIXELS_PER_INCH } from "pdfjs-lib";
|
import { AnnotationMode, PixelsPerInch } from "pdfjs-lib";
|
||||||
import { PDFPrintServiceFactory, PDFViewerApplication } from "./app.js";
|
import { PDFPrintServiceFactory, PDFViewerApplication } from "./app.js";
|
||||||
import { compatibilityParams } from "./app_options.js";
|
import { compatibilityParams } from "./app_options.js";
|
||||||
import { getXfaHtmlForPrinting } from "./print_utils.js";
|
import { getXfaHtmlForPrinting } from "./print_utils.js";
|
||||||
@ -34,7 +34,7 @@ function renderPage(
|
|||||||
const scratchCanvas = activeService.scratchCanvas;
|
const scratchCanvas = activeService.scratchCanvas;
|
||||||
|
|
||||||
// The size of the canvas in pixels for printing.
|
// The size of the canvas in pixels for printing.
|
||||||
const PRINT_UNITS = printResolution / PDF_PIXELS_PER_INCH;
|
const PRINT_UNITS = printResolution / PixelsPerInch.PDF;
|
||||||
scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
|
scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
|
||||||
scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
|
scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CSS_PIXELS_PER_INCH, PDF_PIXELS_PER_INCH } from "pdfjs-lib";
|
import { PixelsPerInch } from "pdfjs-lib";
|
||||||
|
|
||||||
const CSS_UNITS = CSS_PIXELS_PER_INCH / PDF_PIXELS_PER_INCH;
|
const CSS_UNITS = PixelsPerInch.CSS / PixelsPerInch.PDF;
|
||||||
const DEFAULT_SCALE_VALUE = "auto";
|
const DEFAULT_SCALE_VALUE = "auto";
|
||||||
const DEFAULT_SCALE = 1.0;
|
const DEFAULT_SCALE = 1.0;
|
||||||
const MIN_SCALE = 0.1;
|
const MIN_SCALE = 0.1;
|
||||||
|
Loading…
Reference in New Issue
Block a user