mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Save form data in XFA datasets when pdf is a mix of acroforms and xfa (#12344)
* Move display/xml_parser.js in shared to use it in worker * Save form data in XFA datasets when pdf is a mix of acroforms and xfa Co-authored-by: Brendan Dahl <brendan.dahl@gmail.com>
This commit is contained in:
parent
622e2fbd3a
commit
68b99c59ee
11 changed files with 416 additions and 19 deletions
|
@ -910,6 +910,73 @@ 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: ">",
|
||||
/* & */ 0x26: "&",
|
||||
/* " */ 0x22: """,
|
||||
/* ' */ 0x27: "'",
|
||||
};
|
||||
|
||||
function encodeToXmlString(str) {
|
||||
const buffer = [];
|
||||
let start = 0;
|
||||
for (let i = 0, ii = str.length; i < ii; i++) {
|
||||
const char = str.codePointAt(i);
|
||||
if (0x20 <= char && char <= 0x7e) {
|
||||
// ascii
|
||||
const entity = XMLEntities[char];
|
||||
if (entity) {
|
||||
if (start < i) {
|
||||
buffer.push(str.substring(start, i));
|
||||
}
|
||||
buffer.push(entity);
|
||||
start = i + 1;
|
||||
}
|
||||
} else {
|
||||
if (start < i) {
|
||||
buffer.push(str.substring(start, i));
|
||||
}
|
||||
buffer.push(`&#x${char.toString(16).toUpperCase()};`);
|
||||
if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
|
||||
// char is represented by two u16
|
||||
i++;
|
||||
}
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer.length === 0) {
|
||||
return str;
|
||||
}
|
||||
|
||||
if (start < str.length) {
|
||||
buffer.push(str.substring(start, str.length));
|
||||
}
|
||||
|
||||
return buffer.join("");
|
||||
}
|
||||
|
||||
export {
|
||||
BaseException,
|
||||
FONT_IDENTITY_MATRIX,
|
||||
|
@ -947,6 +1014,7 @@ export {
|
|||
createPromiseCapability,
|
||||
createObjectURL,
|
||||
escapeString,
|
||||
encodeToXmlString,
|
||||
getModificationDate,
|
||||
getVerbosityLevel,
|
||||
info,
|
||||
|
@ -959,6 +1027,7 @@ export {
|
|||
createValidAbsoluteUrl,
|
||||
IsLittleEndianCached,
|
||||
IsEvalSupportedCached,
|
||||
parseXFAPath,
|
||||
removeNullCharacters,
|
||||
setVerbosityLevel,
|
||||
shadow,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue