mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
[Editor] Take into account the device pixel ratio when drawing an added image
Fixes #18626.
This commit is contained in:
parent
c72fb9b733
commit
46fac8b2c1
9 changed files with 164 additions and 100 deletions
|
@ -371,14 +371,21 @@ class NewAltTextManager {
|
|||
// TODO: get this value from Firefox
|
||||
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1908184)
|
||||
const AI_MAX_IMAGE_DIMENSION = 224;
|
||||
const MAX_PREVIEW_DIMENSION = 180;
|
||||
|
||||
// The max dimension of the preview in the dialog is 180px, so we keep 224px
|
||||
// and rescale it thanks to css.
|
||||
|
||||
let canvas;
|
||||
let canvas, width, height;
|
||||
if (mlManager) {
|
||||
({ canvas, imageData: this.#imageData } = editor.copyCanvas(
|
||||
({
|
||||
canvas,
|
||||
width,
|
||||
height,
|
||||
imageData: this.#imageData,
|
||||
} = editor.copyCanvas(
|
||||
AI_MAX_IMAGE_DIMENSION,
|
||||
MAX_PREVIEW_DIMENSION,
|
||||
/* createImageData = */ true
|
||||
));
|
||||
if (hasAI) {
|
||||
|
@ -388,13 +395,17 @@ class NewAltTextManager {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
({ canvas } = editor.copyCanvas(
|
||||
({ canvas, width, height } = editor.copyCanvas(
|
||||
AI_MAX_IMAGE_DIMENSION,
|
||||
MAX_PREVIEW_DIMENSION,
|
||||
/* createImageData = */ false
|
||||
));
|
||||
}
|
||||
|
||||
canvas.setAttribute("role", "presentation");
|
||||
const { style } = canvas;
|
||||
style.width = `${width}px`;
|
||||
style.height = `${height}px`;
|
||||
this.#imagePreview.append(canvas);
|
||||
|
||||
this.#toggleNotNow();
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
import {
|
||||
AbortException,
|
||||
AnnotationMode,
|
||||
OutputScale,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
setLayerDimensions,
|
||||
|
@ -36,7 +37,6 @@ import {
|
|||
calcRound,
|
||||
DEFAULT_SCALE,
|
||||
floorToDivide,
|
||||
OutputScale,
|
||||
RenderingStates,
|
||||
TextLayerMode,
|
||||
} from "./ui_utils.js";
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
// eslint-disable-next-line max-len
|
||||
/** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */
|
||||
|
||||
import { OutputScale, RenderingStates } from "./ui_utils.js";
|
||||
import { RenderingCancelledException } from "pdfjs-lib";
|
||||
import { OutputScale, RenderingCancelledException } from "pdfjs-lib";
|
||||
import { RenderingStates } from "./ui_utils.js";
|
||||
|
||||
const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below.
|
||||
const MAX_NUM_SCALING_STEPS = 3;
|
||||
|
|
|
@ -42,6 +42,7 @@ const {
|
|||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
OutputScale,
|
||||
PasswordResponses,
|
||||
PDFDataRangeTransport,
|
||||
PDFDateString,
|
||||
|
@ -88,6 +89,7 @@ export {
|
|||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
OutputScale,
|
||||
PasswordResponses,
|
||||
PDFDataRangeTransport,
|
||||
PDFDateString,
|
||||
|
|
|
@ -76,32 +76,6 @@ const CursorTool = {
|
|||
// Used by `PDFViewerApplication`, and by the API unit-tests.
|
||||
const AutoPrintRegExp = /\bprint\s*\(/;
|
||||
|
||||
/**
|
||||
* Scale factors for the canvas, necessary with HiDPI displays.
|
||||
*/
|
||||
class OutputScale {
|
||||
constructor() {
|
||||
const pixelRatio = window.devicePixelRatio || 1;
|
||||
|
||||
/**
|
||||
* @type {number} Horizontal scale.
|
||||
*/
|
||||
this.sx = pixelRatio;
|
||||
|
||||
/**
|
||||
* @type {number} Vertical scale.
|
||||
*/
|
||||
this.sy = pixelRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {boolean} Returns `true` when scaling is required, `false` otherwise.
|
||||
*/
|
||||
get scaled() {
|
||||
return this.sx !== 1 || this.sy !== 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls specified element into view of its parent.
|
||||
* @param {HTMLElement} element - The element to be visible.
|
||||
|
@ -908,7 +882,6 @@ export {
|
|||
MIN_SCALE,
|
||||
normalizeWheelEventDelta,
|
||||
normalizeWheelEventDirection,
|
||||
OutputScale,
|
||||
parseQueryString,
|
||||
PresentationModeState,
|
||||
ProgressBar,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue