Skip to content

Commit

Permalink
Merge pull request #16798 from calixteman/issue16797
Browse files Browse the repository at this point in the history
[Editor] Fix the dimensions of the annotation editor layer (follow-up of #16794)
  • Loading branch information
calixteman authored Aug 8, 2023
2 parents 19c712c + 4006996 commit 15c21d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "./base_factory.js";
import {
BaseException,
FeatureTest,
shadow,
stringToBytes,
Util,
Expand Down Expand Up @@ -967,8 +968,6 @@ function getCurrentTransformInverse(ctx) {
return [a, b, c, d, e, f];
}

const useRound = globalThis.CSS?.supports?.("width: round(1.5px, 1px)");

/**
* @param {HTMLDivElement} div
* @param {PageViewport} viewport
Expand All @@ -984,6 +983,7 @@ function setLayerDimensions(
if (viewport instanceof PageViewport) {
const { pageWidth, pageHeight } = viewport.rawDims;
const { style } = div;
const useRound = FeatureTest.isCSSRoundSupported;

const w = `var(--scale-factor) * ${pageWidth}px`,
h = `var(--scale-factor) * ${pageHeight}px`;
Expand Down
12 changes: 9 additions & 3 deletions src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,15 @@ class AnnotationEditor {
}

get parentDimensions() {
const { realScale } = this._uiManager.viewParameters;
const [pageWidth, pageHeight] = this.pageDimensions;
return [pageWidth * realScale, pageHeight * realScale];
const {
parentScale,
pageDimensions: [pageWidth, pageHeight],
} = this;
const scaledWidth = pageWidth * parentScale;
const scaledHeight = pageHeight * parentScale;
return FeatureTest.isCSSRoundSupported
? [Math.round(scaledWidth), Math.round(scaledHeight)]
: [scaledWidth, scaledHeight];
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,14 @@ class FeatureTest {
isMac: navigator.platform.includes("Mac"),
});
}

static get isCSSRoundSupported() {
return shadow(
this,
"isCSSRoundSupported",
globalThis.CSS?.supports?.("width: round(1.5px, 1px)")
);
}
}

const hexNumbers = [...Array(256).keys()].map(n =>
Expand Down

0 comments on commit 15c21d7

Please sign in to comment.