Add support for line ending in FreeTextAnnotation callouts.

This commit is contained in:
Edoardo Cavazza 2025-01-24 14:47:54 +01:00
parent 4f1078dc63
commit fe2680fa9b

View File

@ -969,6 +969,37 @@ class Annotation {
this.color = getRgbColor(color);
}
/**
* Set the line ending; should only be used with FreeText annotations.
* @param {Name} lineEnding - The line ending name.
*/
setLineEnding(lineEnding) {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
throw new Error("Not implemented: setLineEnding");
}
this.lineEnding = "None"; // The default value.
if (lineEnding instanceof Name) {
switch (lineEnding.name) {
case "None":
return;
case "Square":
case "Circle":
case "Diamond":
case "OpenArrow":
case "ClosedArrow":
case "Butt":
case "ROpenArrow":
case "RClosedArrow":
case "Slash":
this.lineEnding = lineEnding.name;
return;
}
}
warn(`Ignoring invalid lineEnding: ${lineEnding}`);
}
/**
* Set the line endings; should only be used with specific annotation types.
* @param {Array} lineEndings - The line endings array.
@ -3882,11 +3913,16 @@ class FreeTextAnnotation extends MarkupAnnotation {
// We want to be able to add mouse listeners to the annotation.
this.data.noHTML = false;
const { evaluatorOptions, xref } = params;
const { evaluatorOptions, xref, dict } = params;
this.data.annotationType = AnnotationType.FREETEXT;
this.setDefaultAppearance(params);
this._hasAppearance = !!this.appearance;
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
this.setLineEnding(dict.getArray("LE"));
this.data.lineEnding = this.lineEnding;
}
if (this._hasAppearance) {
const { fontColor, fontSize } = parseAppearanceStream(
this.appearance,