diff --git a/src/core/annotation.js b/src/core/annotation.js index 79fd83fe7..fec27fdd6 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -45,6 +45,7 @@ import { getParentToUpdate, getRotationMatrix, isNumberArray, + lookupLineEnding, lookupMatrix, lookupNormalRect, lookupRect, @@ -978,26 +979,7 @@ class Annotation { 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}`); + this.lineEnding = lookupLineEnding(lineEnding, "None"); } /** @@ -1012,26 +994,7 @@ class Annotation { if (Array.isArray(lineEndings) && lineEndings.length === 2) { for (let i = 0; i < 2; i++) { - const obj = lineEndings[i]; - - if (obj instanceof Name) { - switch (obj.name) { - case "None": - continue; - case "Square": - case "Circle": - case "Diamond": - case "OpenArrow": - case "ClosedArrow": - case "Butt": - case "ROpenArrow": - case "RClosedArrow": - case "Slash": - this.lineEndings[i] = obj.name; - continue; - } - } - warn(`Ignoring invalid lineEnding: ${obj}`); + this.lineEndings[i] = lookupLineEnding(lineEndings[i], "None"); } } } @@ -3922,7 +3885,6 @@ class FreeTextAnnotation extends MarkupAnnotation { if (dict.has("CL")) { this.setLineEnding(dict.getArray("LE")); this.data.calloutLine = dict.getArray("CL"); - this.data.rectDifference = dict.getArray("RD"); this.data.lineEnding = this.lineEnding; } } diff --git a/src/core/core_utils.js b/src/core/core_utils.js index c92a0374d..5900580ae 100644 --- a/src/core/core_utils.js +++ b/src/core/core_utils.js @@ -23,7 +23,7 @@ import { Util, warn, } from "../shared/util.js"; -import { Dict, isName, Ref, RefSet } from "./primitives.js"; +import { Dict, isName, Name, Ref, RefSet } from "./primitives.js"; import { BaseStream } from "./base_stream.js"; const PDF_VERSION_REGEXP = /^[1-9]\.\d$/; @@ -300,6 +300,27 @@ function lookupNormalRect(arr, fallback) { return isNumberArray(arr, 4) ? Util.normalizeRect(arr) : fallback; } +// Returns the line ending style, or the fallback value if it's invalid. +function lookupLineEnding(value, fallback) { + if (value instanceof Name) { + switch (value.name) { + case "None": + case "Square": + case "Circle": + case "Diamond": + case "OpenArrow": + case "ClosedArrow": + case "Butt": + case "ROpenArrow": + case "RClosedArrow": + case "Slash": + return value.name; + } + } + + return fallback; +} + /** * AcroForm field names use an array like notation to refer to * repeated XFA elements e.g. foo.bar[nnn]. @@ -723,6 +744,7 @@ export { isNumberArray, isWhiteSpace, log2, + lookupLineEnding, lookupMatrix, lookupNormalRect, lookupRect,