mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-28 02:55:49 +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,
|
getParentToUpdate,
|
||||||
getRotationMatrix,
|
getRotationMatrix,
|
||||||
isNumberArray,
|
isNumberArray,
|
||||||
|
lookupLineEnding,
|
||||||
lookupMatrix,
|
lookupMatrix,
|
||||||
lookupNormalRect,
|
lookupNormalRect,
|
||||||
lookupRect,
|
lookupRect,
|
||||||
@ -978,26 +979,7 @@ class Annotation {
|
|||||||
throw new Error("Not implemented: setLineEnding");
|
throw new Error("Not implemented: setLineEnding");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lineEnding = "None"; // The default value.
|
this.lineEnding = lookupLineEnding(lineEnding, "None");
|
||||||
|
|
||||||
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}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1012,26 +994,7 @@ class Annotation {
|
|||||||
|
|
||||||
if (Array.isArray(lineEndings) && lineEndings.length === 2) {
|
if (Array.isArray(lineEndings) && lineEndings.length === 2) {
|
||||||
for (let i = 0; i < 2; i++) {
|
for (let i = 0; i < 2; i++) {
|
||||||
const obj = lineEndings[i];
|
this.lineEndings[i] = lookupLineEnding(lineEndings[i], "None");
|
||||||
|
|
||||||
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}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3922,7 +3885,6 @@ class FreeTextAnnotation extends MarkupAnnotation {
|
|||||||
if (dict.has("CL")) {
|
if (dict.has("CL")) {
|
||||||
this.setLineEnding(dict.getArray("LE"));
|
this.setLineEnding(dict.getArray("LE"));
|
||||||
this.data.calloutLine = dict.getArray("CL");
|
this.data.calloutLine = dict.getArray("CL");
|
||||||
this.data.rectDifference = dict.getArray("RD");
|
|
||||||
this.data.lineEnding = this.lineEnding;
|
this.data.lineEnding = this.lineEnding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import {
|
|||||||
Util,
|
Util,
|
||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} 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";
|
import { BaseStream } from "./base_stream.js";
|
||||||
|
|
||||||
const PDF_VERSION_REGEXP = /^[1-9]\.\d$/;
|
const PDF_VERSION_REGEXP = /^[1-9]\.\d$/;
|
||||||
@ -300,6 +300,27 @@ function lookupNormalRect(arr, fallback) {
|
|||||||
return isNumberArray(arr, 4) ? Util.normalizeRect(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
|
* AcroForm field names use an array like notation to refer to
|
||||||
* repeated XFA elements e.g. foo.bar[nnn].
|
* repeated XFA elements e.g. foo.bar[nnn].
|
||||||
@ -723,6 +744,7 @@ export {
|
|||||||
isNumberArray,
|
isNumberArray,
|
||||||
isWhiteSpace,
|
isWhiteSpace,
|
||||||
log2,
|
log2,
|
||||||
|
lookupLineEnding,
|
||||||
lookupMatrix,
|
lookupMatrix,
|
||||||
lookupNormalRect,
|
lookupNormalRect,
|
||||||
lookupRect,
|
lookupRect,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user