[Editor] Take into account the crop box when saving/printing some highlighted text (bug 1872721)
This commit is contained in:
parent
231c79800b
commit
35863cd54b
@ -361,14 +361,15 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
this.parent?.drawLayer.removeClass(this.#outlineId, "selected");
|
this.parent?.drawLayer.removeClass(this.#outlineId, "selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
#serializeBoxes() {
|
#serializeBoxes(rect) {
|
||||||
const [pageWidth, pageHeight] = this.pageDimensions;
|
const [pageWidth, pageHeight] = this.pageDimensions;
|
||||||
const boxes = this.#boxes;
|
const boxes = this.#boxes;
|
||||||
const quadPoints = new Array(boxes.length * 8);
|
const quadPoints = new Array(boxes.length * 8);
|
||||||
|
const [tx, ty] = rect;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const { x, y, width, height } of boxes) {
|
for (const { x, y, width, height } of boxes) {
|
||||||
const sx = x * pageWidth;
|
const sx = tx + x * pageWidth;
|
||||||
const sy = (1 - y - height) * pageHeight;
|
const sy = ty + (1 - y - height) * pageHeight;
|
||||||
// The specifications say that the rectangle should start from the bottom
|
// The specifications say that the rectangle should start from the bottom
|
||||||
// left corner and go counter-clockwise.
|
// left corner and go counter-clockwise.
|
||||||
// But when opening the file in Adobe Acrobat it appears that this isn't
|
// But when opening the file in Adobe Acrobat it appears that this isn't
|
||||||
@ -382,12 +383,11 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
return quadPoints;
|
return quadPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
#serializeOutlines() {
|
#serializeOutlines(rect) {
|
||||||
const [pageWidth, pageHeight] = this.pageDimensions;
|
const [pageWidth, pageHeight] = this.pageDimensions;
|
||||||
const width = this.width * pageWidth;
|
const width = this.width * pageWidth;
|
||||||
const height = this.height * pageHeight;
|
const height = this.height * pageHeight;
|
||||||
const tx = this.x * pageWidth;
|
const [tx, ty] = rect;
|
||||||
const ty = (1 - this.y - this.height) * pageHeight;
|
|
||||||
const outlines = [];
|
const outlines = [];
|
||||||
for (const outline of this.#highlightOutlines.outlines) {
|
for (const outline of this.#highlightOutlines.outlines) {
|
||||||
const points = new Array(outline.length);
|
const points = new Array(outline.length);
|
||||||
@ -404,18 +404,22 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
static deserialize(data, parent, uiManager) {
|
static deserialize(data, parent, uiManager) {
|
||||||
const editor = super.deserialize(data, parent, uiManager);
|
const editor = super.deserialize(data, parent, uiManager);
|
||||||
|
|
||||||
const { rect, color, quadPoints } = data;
|
const {
|
||||||
|
rect: [blX, blY, trX, trY],
|
||||||
|
color,
|
||||||
|
quadPoints,
|
||||||
|
} = data;
|
||||||
editor.color = Util.makeHexColor(...color);
|
editor.color = Util.makeHexColor(...color);
|
||||||
editor.#opacity = data.opacity;
|
editor.#opacity = data.opacity;
|
||||||
|
|
||||||
const [pageWidth, pageHeight] = editor.pageDimensions;
|
const [pageWidth, pageHeight] = editor.pageDimensions;
|
||||||
editor.width = (rect[2] - rect[0]) / pageWidth;
|
editor.width = (trX - blX) / pageWidth;
|
||||||
editor.height = (rect[3] - rect[1]) / pageHeight;
|
editor.height = (trY - blY) / pageHeight;
|
||||||
const boxes = (editor.#boxes = []);
|
const boxes = (editor.#boxes = []);
|
||||||
for (let i = 0; i < quadPoints.length; i += 8) {
|
for (let i = 0; i < quadPoints.length; i += 8) {
|
||||||
boxes.push({
|
boxes.push({
|
||||||
x: quadPoints[4] / pageWidth,
|
x: (quadPoints[4] - trX) / pageWidth,
|
||||||
y: 1 - quadPoints[i + 5] / pageHeight,
|
y: (trY - (1 - quadPoints[i + 5])) / pageHeight,
|
||||||
width: (quadPoints[i + 2] - quadPoints[i]) / pageWidth,
|
width: (quadPoints[i + 2] - quadPoints[i]) / pageWidth,
|
||||||
height: (quadPoints[i + 5] - quadPoints[i + 1]) / pageHeight,
|
height: (quadPoints[i + 5] - quadPoints[i + 1]) / pageHeight,
|
||||||
});
|
});
|
||||||
@ -439,8 +443,8 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
annotationType: AnnotationEditorType.HIGHLIGHT,
|
annotationType: AnnotationEditorType.HIGHLIGHT,
|
||||||
color,
|
color,
|
||||||
opacity: this.#opacity,
|
opacity: this.#opacity,
|
||||||
quadPoints: this.#serializeBoxes(),
|
quadPoints: this.#serializeBoxes(rect),
|
||||||
outlines: this.#serializeOutlines(),
|
outlines: this.#serializeOutlines(rect),
|
||||||
pageIndex: this.pageIndex,
|
pageIndex: this.pageIndex,
|
||||||
rect,
|
rect,
|
||||||
rotation: 0,
|
rotation: 0,
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -620,3 +620,4 @@
|
|||||||
!issue17215.pdf
|
!issue17215.pdf
|
||||||
!bug1863910.pdf
|
!bug1863910.pdf
|
||||||
!bug1865341.pdf
|
!bug1865341.pdf
|
||||||
|
!bug1872721.pdf
|
||||||
|
BIN
test/pdfs/bug1872721.pdf
Executable file
BIN
test/pdfs/bug1872721.pdf
Executable file
Binary file not shown.
@ -8411,5 +8411,52 @@
|
|||||||
"rotation": 0
|
"rotation": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "bug1872721-highlight-editor-save-print",
|
||||||
|
"file": "pdfs/bug1872721.pdf",
|
||||||
|
"md5": "8318654cda60dc71df9e62a3c78cf193",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq",
|
||||||
|
"save": true,
|
||||||
|
"print": true,
|
||||||
|
"annotationStorage": {
|
||||||
|
"pdfjs_internal_editor_0": {
|
||||||
|
"annotationType": 9,
|
||||||
|
"color": [ 83, 255, 188 ],
|
||||||
|
"opacity": 1,
|
||||||
|
"quadPoints": [
|
||||||
|
209.0454157057542,
|
||||||
|
718.4044878560951,
|
||||||
|
270.0049972773625,
|
||||||
|
718.4044878560951,
|
||||||
|
209.0454157057542,
|
||||||
|
731.7427487256604,
|
||||||
|
270.0049972773625,
|
||||||
|
731.7427487256604
|
||||||
|
],
|
||||||
|
"outlines": [
|
||||||
|
[
|
||||||
|
197.85841250000001,
|
||||||
|
709.458959,
|
||||||
|
197.85841250000001,
|
||||||
|
722.8621772,
|
||||||
|
259.003853,
|
||||||
|
722.8621772,
|
||||||
|
259.003853,
|
||||||
|
709.458959
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"pageIndex": 0,
|
||||||
|
"rect": [
|
||||||
|
197.85841250000001,
|
||||||
|
709.458959,
|
||||||
|
259.003853,
|
||||||
|
722.8621772
|
||||||
|
],
|
||||||
|
"rotation": 0,
|
||||||
|
"structTreeParentId": null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user