mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #12349 from calixteman/followup_12344
Follow-up of pr #12344
This commit is contained in:
commit
f9d56320f5
9 changed files with 69 additions and 56 deletions
|
@ -165,6 +165,26 @@ function isWhiteSpace(ch) {
|
|||
return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
|
||||
}
|
||||
|
||||
/**
|
||||
* AcroForm field names use an array like notation to refer to
|
||||
* repeated XFA elements e.g. foo.bar[nnn].
|
||||
* see: XFA Spec Chapter 3 - Repeated Elements
|
||||
*
|
||||
* @param {string} path - XFA path name.
|
||||
* @returns {Array} - Array of Objects with the name and pos of
|
||||
* each part of the path.
|
||||
*/
|
||||
function parseXFAPath(path) {
|
||||
const positionPattern = /(.+)\[([0-9]+)\]$/;
|
||||
return path.split(".").map(component => {
|
||||
const m = component.match(positionPattern);
|
||||
if (m) {
|
||||
return { name: m[1], pos: parseInt(m[2], 10) };
|
||||
}
|
||||
return { name: component, pos: 0 };
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
getLookupTableFactory,
|
||||
MissingDataException,
|
||||
|
@ -173,6 +193,7 @@ export {
|
|||
getInheritableProperty,
|
||||
toRomanNumerals,
|
||||
log2,
|
||||
parseXFAPath,
|
||||
readInt8,
|
||||
readUint16,
|
||||
readUint32,
|
||||
|
|
|
@ -589,13 +589,13 @@ class WorkerMessageHandler {
|
|||
}
|
||||
xref.resetNewRef();
|
||||
|
||||
return incrementalUpdate(
|
||||
stream.bytes,
|
||||
newXrefInfo,
|
||||
return incrementalUpdate({
|
||||
originalData: stream.bytes,
|
||||
xrefInfo: newXrefInfo,
|
||||
newRefs,
|
||||
xref,
|
||||
xfaDatasets
|
||||
);
|
||||
datasetsRef: xfaDatasets,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -14,15 +14,11 @@
|
|||
*/
|
||||
/* eslint no-var: error */
|
||||
|
||||
import {
|
||||
bytesToString,
|
||||
escapeString,
|
||||
parseXFAPath,
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
import { bytesToString, escapeString, warn } from "../shared/util.js";
|
||||
import { Dict, isDict, isName, isRef, isStream, Name } from "./primitives.js";
|
||||
import { SimpleDOMNode, SimpleXMLParser } from "../shared/xml_parser.js";
|
||||
import { calculateMD5 } from "./crypto.js";
|
||||
import { parseXFAPath } from "./core_utils.js";
|
||||
|
||||
function writeDict(dict, buffer, transform) {
|
||||
buffer.push("<<");
|
||||
|
@ -175,7 +171,13 @@ function updateXFA(datasetsRef, newRefs, xref) {
|
|||
newRefs.push({ ref: datasetsRef, data });
|
||||
}
|
||||
|
||||
function incrementalUpdate(originalData, xrefInfo, newRefs, xref, datasetsRef) {
|
||||
function incrementalUpdate({
|
||||
originalData,
|
||||
xrefInfo,
|
||||
newRefs,
|
||||
xref = null,
|
||||
datasetsRef = null,
|
||||
}) {
|
||||
updateXFA(datasetsRef, newRefs, xref);
|
||||
|
||||
const newXref = new Dict(null);
|
||||
|
|
|
@ -910,26 +910,6 @@ const createObjectURL = (function createObjectURLClosure() {
|
|||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* AcroForm field names use an array like notation to refer to
|
||||
* repeated XFA elements e.g. foo.bar[nnn].
|
||||
* see: XFA Spec Chapter 3 - Repeated Elements
|
||||
*
|
||||
* @param {string} path - XFA path name.
|
||||
* @returns {Array} - Array of Objects with the name and pos of
|
||||
* each part of the path.
|
||||
*/
|
||||
function parseXFAPath(path) {
|
||||
const positionPattern = /(.+)\[([0-9]+)\]$/;
|
||||
return path.split(".").map(component => {
|
||||
const m = component.match(positionPattern);
|
||||
if (m) {
|
||||
return { name: m[1], pos: parseInt(m[2], 10) };
|
||||
}
|
||||
return { name: component, pos: 0 };
|
||||
});
|
||||
}
|
||||
|
||||
const XMLEntities = {
|
||||
/* < */ 0x3c: "<",
|
||||
/* > */ 0x3e: ">",
|
||||
|
@ -1027,7 +1007,6 @@ export {
|
|||
createValidAbsoluteUrl,
|
||||
IsLittleEndianCached,
|
||||
IsEvalSupportedCached,
|
||||
parseXFAPath,
|
||||
removeNullCharacters,
|
||||
setVerbosityLevel,
|
||||
shadow,
|
||||
|
|
|
@ -329,6 +329,18 @@ class SimpleDOMNode {
|
|||
return this.childNodes && this.childNodes.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search a node in the tree with the given path
|
||||
* foo.bar[nnn], i.e. find the nnn-th node named
|
||||
* bar under a node named foo.
|
||||
*
|
||||
* @param {Array} paths - an array of objects as
|
||||
* returned by {parseXFAPath}.
|
||||
* @param {number} pos - the current position in
|
||||
* the paths array.
|
||||
* @returns {SimpleDOMNode} The node corresponding
|
||||
* to the path or null if not found.
|
||||
*/
|
||||
searchNode(paths, pos) {
|
||||
if (pos >= paths.length) {
|
||||
return this;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue