1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-28 23:28:16 +02:00

XFA - Create Form DOM in merging template and data trees

- Spec: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.364.2157&rep=rep1&type=pdf#page=171;
  - support for the 2 ways of merging: consumeData and matchTemplate;
  - create additional nodes in template DOM when occur node allows it;
  - support for global values in data DOM.
This commit is contained in:
Calixte Denizet 2021-02-24 19:05:04 +01:00
parent 5e3af62d58
commit 3243672727
9 changed files with 1584 additions and 109 deletions

View file

@ -13,7 +13,14 @@
* limitations under the License.
*/
import { $clean, $finalize, $onChild, $onText, $setId } from "./xfa_object.js";
import {
$clean,
$finalize,
$nsAttributes,
$onChild,
$onText,
$setId,
} from "./xfa_object.js";
import { XMLParserBase, XMLParserErrorCode } from "../xml_parser.js";
import { Builder } from "./builder.js";
import { warn } from "../../shared/util.js";
@ -57,7 +64,7 @@ class XFAParser extends XMLParserBase {
// namespaces information.
let namespace = null;
let prefixes = null;
const attributeObj = Object.create(null);
const attributeObj = Object.create({});
for (const { name, value } of attributes) {
if (name === "xmlns") {
if (!namespace) {
@ -72,7 +79,23 @@ class XFAParser extends XMLParserBase {
}
prefixes.push({ prefix, value });
} else {
attributeObj[name] = value;
const i = name.indexOf(":");
if (i === -1) {
attributeObj[name] = value;
} else {
// Attributes can have their own namespace.
// For example in data, we can have <foo xfa:dataNode="dataGroup"/>
let nsAttrs = attributeObj[$nsAttributes];
if (!nsAttrs) {
nsAttrs = attributeObj[$nsAttributes] = Object.create(null);
}
const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)];
let attrs = nsAttrs[ns];
if (!attrs) {
attrs = nsAttrs[ns] = Object.create(null);
}
attrs[attrName] = value;
}
}
}