Merge pull request #19397 from Snuffleupagus/Annotation-width-height-getters
Add width/height getters in the `Annotation` class
This commit is contained in:
commit
b48717a99e
@ -1153,7 +1153,7 @@ class Annotation {
|
|||||||
const isUsingOwnCanvas = !!(
|
const isUsingOwnCanvas = !!(
|
||||||
hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY
|
hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY
|
||||||
);
|
);
|
||||||
if (isUsingOwnCanvas && (rect[0] === rect[2] || rect[1] === rect[3])) {
|
if (isUsingOwnCanvas && (this.width === 0 || this.height === 0)) {
|
||||||
// Empty annotation, don't draw anything.
|
// Empty annotation, don't draw anything.
|
||||||
this.data.hasOwnCanvas = false;
|
this.data.hasOwnCanvas = false;
|
||||||
return {
|
return {
|
||||||
@ -1411,6 +1411,14 @@ class Annotation {
|
|||||||
}
|
}
|
||||||
return fieldName.join(".");
|
return fieldName.join(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get width() {
|
||||||
|
return this.data.rect[2] - this.data.rect[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
get height() {
|
||||||
|
return this.data.rect[3] - this.data.rect[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1960,14 +1968,9 @@ class WidgetAnnotation extends Annotation {
|
|||||||
rotation = this.rotation;
|
rotation = this.rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rotation === 0) {
|
return rotation === 0
|
||||||
return IDENTITY_MATRIX;
|
? IDENTITY_MATRIX
|
||||||
}
|
: getRotationMatrix(rotation, this.width, this.height);
|
||||||
|
|
||||||
const width = this.data.rect[2] - this.data.rect[0];
|
|
||||||
const height = this.data.rect[3] - this.data.rect[1];
|
|
||||||
|
|
||||||
return getRotationMatrix(rotation, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getBorderAndBackgroundAppearances(annotationStorage) {
|
getBorderAndBackgroundAppearances(annotationStorage) {
|
||||||
@ -1979,12 +1982,10 @@ class WidgetAnnotation extends Annotation {
|
|||||||
if (!this.backgroundColor && !this.borderColor) {
|
if (!this.backgroundColor && !this.borderColor) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
const width = this.data.rect[2] - this.data.rect[0];
|
|
||||||
const height = this.data.rect[3] - this.data.rect[1];
|
|
||||||
const rect =
|
const rect =
|
||||||
rotation === 0 || rotation === 180
|
rotation === 0 || rotation === 180
|
||||||
? `0 0 ${width} ${height} re`
|
? `0 0 ${this.width} ${this.height} re`
|
||||||
: `0 0 ${height} ${width} re`;
|
: `0 0 ${this.height} ${this.width} re`;
|
||||||
|
|
||||||
let str = "";
|
let str = "";
|
||||||
if (this.backgroundColor) {
|
if (this.backgroundColor) {
|
||||||
@ -2048,12 +2049,7 @@ class WidgetAnnotation extends Annotation {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const matrix = [1, 0, 0, 1, 0, 0];
|
const matrix = [1, 0, 0, 1, 0, 0];
|
||||||
const bbox = [
|
const bbox = [0, 0, this.width, this.height];
|
||||||
0,
|
|
||||||
0,
|
|
||||||
this.data.rect[2] - this.data.rect[0],
|
|
||||||
this.data.rect[3] - this.data.rect[1],
|
|
||||||
];
|
|
||||||
const transform = getTransformMatrix(this.data.rect, bbox, matrix);
|
const transform = getTransformMatrix(this.data.rect, bbox, matrix);
|
||||||
|
|
||||||
let optionalContent;
|
let optionalContent;
|
||||||
@ -2238,12 +2234,7 @@ class WidgetAnnotation extends Annotation {
|
|||||||
const appearanceDict = (appearanceStream.dict = new Dict(xref));
|
const appearanceDict = (appearanceStream.dict = new Dict(xref));
|
||||||
appearanceDict.set("Subtype", Name.get("Form"));
|
appearanceDict.set("Subtype", Name.get("Form"));
|
||||||
appearanceDict.set("Resources", resources);
|
appearanceDict.set("Resources", resources);
|
||||||
appearanceDict.set("BBox", [
|
appearanceDict.set("BBox", [0, 0, this.width, this.height]);
|
||||||
0,
|
|
||||||
0,
|
|
||||||
this.data.rect[2] - this.data.rect[0],
|
|
||||||
this.data.rect[3] - this.data.rect[1],
|
|
||||||
]);
|
|
||||||
|
|
||||||
const rotationMatrix = this.getRotationMatrix(annotationStorage);
|
const rotationMatrix = this.getRotationMatrix(annotationStorage);
|
||||||
if (rotationMatrix !== IDENTITY_MATRIX) {
|
if (rotationMatrix !== IDENTITY_MATRIX) {
|
||||||
@ -2343,8 +2334,7 @@ class WidgetAnnotation extends Annotation {
|
|||||||
|
|
||||||
const defaultPadding = 1;
|
const defaultPadding = 1;
|
||||||
const defaultHPadding = 2;
|
const defaultHPadding = 2;
|
||||||
let totalHeight = this.data.rect[3] - this.data.rect[1];
|
let { width: totalWidth, height: totalHeight } = this;
|
||||||
let totalWidth = this.data.rect[2] - this.data.rect[0];
|
|
||||||
|
|
||||||
if (rotation === 90 || rotation === 270) {
|
if (rotation === 90 || rotation === 270) {
|
||||||
[totalWidth, totalHeight] = [totalHeight, totalWidth];
|
[totalWidth, totalHeight] = [totalHeight, totalWidth];
|
||||||
@ -3210,8 +3200,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getDefaultCheckedAppearance(params, type) {
|
_getDefaultCheckedAppearance(params, type) {
|
||||||
const width = this.data.rect[2] - this.data.rect[0];
|
const { width, height } = this;
|
||||||
const height = this.data.rect[3] - this.data.rect[1];
|
|
||||||
const bbox = [0, 0, width, height];
|
const bbox = [0, 0, width, height];
|
||||||
|
|
||||||
// Ratio used to have a mark slightly smaller than the bbox.
|
// Ratio used to have a mark slightly smaller than the bbox.
|
||||||
@ -3596,8 +3585,7 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
|||||||
|
|
||||||
const defaultPadding = 1;
|
const defaultPadding = 1;
|
||||||
const defaultHPadding = 2;
|
const defaultHPadding = 2;
|
||||||
let totalHeight = this.data.rect[3] - this.data.rect[1];
|
let { width: totalWidth, height: totalHeight } = this;
|
||||||
let totalWidth = this.data.rect[2] - this.data.rect[0];
|
|
||||||
|
|
||||||
if (rotation === 90 || rotation === 270) {
|
if (rotation === 90 || rotation === 270) {
|
||||||
[totalWidth, totalHeight] = [totalHeight, totalWidth];
|
[totalWidth, totalHeight] = [totalHeight, totalWidth];
|
||||||
@ -3809,10 +3797,7 @@ class PopupAnnotation extends Annotation {
|
|||||||
// version.
|
// version.
|
||||||
this.data.noHTML = false;
|
this.data.noHTML = false;
|
||||||
|
|
||||||
if (
|
if (this.width === 0 || this.height === 0) {
|
||||||
this.data.rect[0] === this.data.rect[2] ||
|
|
||||||
this.data.rect[1] === this.data.rect[3]
|
|
||||||
) {
|
|
||||||
this.data.rect = null;
|
this.data.rect = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user