Merge pull request #17514 from calixteman/issue17418

[Editor] Draw a line instead of a Bezier curve when an Ink has only one point
This commit is contained in:
calixteman 2024-01-15 14:23:04 +01:00 committed by GitHub
commit 7769018316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 8 deletions

View File

@ -4397,14 +4397,20 @@ class InkAnnotation extends MarkupAnnotation {
buffer.push(
`${numberToString(bezier[0])} ${numberToString(bezier[1])} m`
);
for (let i = 2, ii = bezier.length; i < ii; i += 6) {
const curve = bezier
.slice(i, i + 6)
.map(numberToString)
.join(" ");
buffer.push(`${curve} c`);
if (bezier.length === 2) {
buffer.push(
`${numberToString(bezier[0])} ${numberToString(bezier[1])} l S`
);
} else {
for (let i = 2, ii = bezier.length; i < ii; i += 6) {
const curve = bezier
.slice(i, i + 6)
.map(numberToString)
.join(" ");
buffer.push(`${curve} c`);
}
buffer.push("S");
}
buffer.push("S");
appearanceBuffer.push(buffer.join("\n"));
}
const appearance = appearanceBuffer.join("\n");

View File

@ -628,7 +628,7 @@ class InkEditor extends AnnotationEditor {
this.parent.addInkEditorIfNeeded(/* isCommitting = */ true);
// When commiting, the position of this editor is changed, hence we must
// When committing, the position of this editor is changed, hence we must
// move it to the right position in the DOM.
this.moveInDOM();
this.div.focus({
@ -994,6 +994,14 @@ class InkEditor extends AnnotationEditor {
const points = [];
for (let j = 0, jj = bezier.length; j < jj; j++) {
const [first, control1, control2, second] = bezier[j];
if (first[0] === second[0] && first[1] === second[1] && jj === 1) {
// We have only one point.
const p0 = s * first[0] + shiftX;
const p1 = s * first[1] + shiftY;
buffer.push(p0, p1);
points.push(p0, p1);
break;
}
const p10 = s * first[0] + shiftX;
const p11 = s * first[1] + shiftY;
const p20 = s * control1[0] + shiftX;

View File

@ -8458,5 +8458,43 @@
"structTreeParentId": null
}
}
},
{
"id": "issue17418",
"file": "pdfs/empty.pdf",
"md5": "2bfd06746bd5c2e6fc3492c83c152bc5",
"rounds": 1,
"type": "eq",
"save": true,
"print": true,
"annotationStorage": {
"pdfjs_internal_editor_0": {
"annotationType": 15,
"color": [ 53, 228, 47 ],
"thickness": 20,
"opacity": 1,
"paths": [
{
"bezier": [
279.9183673469388,
477.0105263157895
],
"points": [
279.9183673469388,
477.0105263157895
]
}
],
"pageIndex": 0,
"rect": [
269.9183673469388,
443.93684210526317,
312.9387755102041,
487.0105263157895
],
"rotation": 0,
"structTreeParentId": null
}
}
}
]