From 8dcfaf32bdd34c01c0b3e90281d979faf6038e22 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 14 Feb 2021 16:24:01 +0100 Subject: [PATCH] [api-minor] Change the `dc:subject` Metadata field to an Array This patch simply extends the existing handling of the `dc:creator` field, which should hopefully suffice here; please refer to https://wwwimages2.adobe.com/content/dam/acom/en/devnet/xmp/pdfs/XMP%20SDK%20Release%20cc-2016-08/XMPSpecificationPart1.pdf#page=34 --- src/display/metadata.js | 36 +++++++++++++++++++++--------------- test/unit/metadata_spec.js | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/display/metadata.js b/src/display/metadata.js index 54ff9f7c2af1fb..9c363205c9e72e 100644 --- a/src/display/metadata.js +++ b/src/display/metadata.js @@ -89,22 +89,24 @@ class Metadata { return entry.childNodes.filter(node => node.nodeName === "rdf:li"); } - _getCreators(entry) { - if (entry.nodeName !== "dc:creator") { - return false; - } + _getArray(entry) { + const name = entry.nodeName; + assert( + name === "dc:creator" || name === "dc:subject", + `_getArray - unexpected type: "${name}".` + ); + if (!entry.hasChildNodes()) { return true; } - // Child must be a Bag (unordered array) or a Seq. - const seqNode = entry.childNodes[0]; - const authors = this._getSequence(seqNode) || []; + const [seqNode] = entry.childNodes; + const sequence = this._getSequence(seqNode) || []; + this._metadataMap.set( - entry.nodeName, - authors.map(node => node.textContent.trim()) + name, + sequence.map(node => node.textContent.trim()) ); - return true; } @@ -130,11 +132,15 @@ class Metadata { for (const entry of desc.childNodes) { const name = entry.nodeName; - if (name === "#text") { - continue; - } - if (this._getCreators(entry)) { - continue; + switch (name) { + case "#text": + continue; + case "dc:creator": + case "dc:subject": + if (this._getArray(entry)) { + continue; + } + break; } this._metadataMap.set(name, entry.textContent.trim()); } diff --git a/test/unit/metadata_spec.js b/test/unit/metadata_spec.js index 7d6b0d3246bdd1..557e957bbb6aad 100644 --- a/test/unit/metadata_spec.js +++ b/test/unit/metadata_spec.js @@ -171,7 +171,7 @@ describe("metadata", function () { "dc:creator": [""], "dc:description": "", "dc:format": "application/pdf", - "dc:subject": "", + "dc:subject": [], "dc:title": "", "pdf:keywords": "", "pdf:pdfversion": "1.7",