mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-27 18:45:48 +02:00
Use common helper to lookup line ending value
This commit is contained in:
parent
edfad112da
commit
8e40e4e864
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user