summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/include/fpdfdoc/fpdf_doc.h19
-rw-r--r--core/src/fpdfdoc/doc_metadata.cpp137
-rw-r--r--fpdfsdk/src/fpdf_ext.cpp7
3 files changed, 24 insertions, 139 deletions
diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h
index 18dc7aa064..13c52433cd 100644
--- a/core/include/fpdfdoc/fpdf_doc.h
+++ b/core/include/fpdfdoc/fpdf_doc.h
@@ -9,6 +9,7 @@
#include <map>
+#include "../../../third_party/base/nonstd_unique_ptr.h"
#include "../fpdfapi/fpdf_parser.h"
#include "../fpdfapi/fpdf_render.h"
@@ -1151,23 +1152,19 @@ class CPDF_PageLabel {
protected:
CPDF_Document* m_pDocument;
};
+
class CPDF_Metadata {
public:
- CPDF_Metadata();
-
+ explicit CPDF_Metadata(CPDF_Document* pDoc);
~CPDF_Metadata();
- void LoadDoc(CPDF_Document* pDoc);
-
- int32_t GetString(const CFX_ByteStringC& bsItem, CFX_WideString& wsStr);
-
- CXML_Element* GetRoot() const;
+ const CXML_Element* GetRoot() const;
- CXML_Element* GetRDF() const;
-
- protected:
- void* m_pData;
+ private:
+ CPDF_Document* const m_pDoc; // Not owned.
+ nonstd::unique_ptr<CXML_Element> m_pXmlElement;
};
+
class CPDF_ViewerPreferences {
public:
CPDF_ViewerPreferences(CPDF_Document* pDoc);
diff --git a/core/src/fpdfdoc/doc_metadata.cpp b/core/src/fpdfdoc/doc_metadata.cpp
index b617eecf87..c779f68354 100644
--- a/core/src/fpdfdoc/doc_metadata.cpp
+++ b/core/src/fpdfdoc/doc_metadata.cpp
@@ -6,134 +6,23 @@
#include "../../include/fpdfdoc/fpdf_doc.h"
#include "../../include/fxcrt/fx_xml.h"
-typedef struct _PDFDOC_METADATA {
- CPDF_Document* m_pDoc;
- CXML_Element* m_pXmlElmnt;
- CXML_Element* m_pElmntRdf;
- CFX_CMapByteStringToPtr* m_pStringMap;
-} PDFDOC_METADATA, *PDFDOC_LPMETADATA;
-typedef PDFDOC_METADATA const* PDFDOC_LPCMETADATA;
-const FX_CHAR* const gs_FPDFDOC_Metadata_Titles[] = {
- "Title", "title", "Subject", "description", "Author",
- "creator", "Keywords", "Keywords", "Producer", "Producer",
- "Creator", "CreatorTool", "CreationDate", "CreateDate", "ModDate",
- "ModifyDate", "MetadataDate", "MetadataDate"};
-CPDF_Metadata::CPDF_Metadata() {
- m_pData = FX_Alloc(PDFDOC_METADATA, 1);
- CFX_CMapByteStringToPtr*& pStringMap =
- ((PDFDOC_LPMETADATA)m_pData)->m_pStringMap;
- pStringMap = new CFX_CMapByteStringToPtr;
- CFX_ByteString bstr;
- for (int i = 0; i < 18; i += 2) {
- bstr = gs_FPDFDOC_Metadata_Titles[i];
- pStringMap->AddValue(bstr, (void*)gs_FPDFDOC_Metadata_Titles[i + 1]);
- }
-}
-CPDF_Metadata::~CPDF_Metadata() {
- FXSYS_assert(m_pData != NULL);
- CXML_Element*& p = ((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt;
- delete p;
- CFX_CMapByteStringToPtr* pStringMap =
- ((PDFDOC_LPMETADATA)m_pData)->m_pStringMap;
- if (pStringMap) {
- pStringMap->RemoveAll();
- delete pStringMap;
- }
- FX_Free(m_pData);
-}
-void CPDF_Metadata::LoadDoc(CPDF_Document* pDoc) {
- FXSYS_assert(pDoc != NULL);
- ((PDFDOC_LPMETADATA)m_pData)->m_pDoc = pDoc;
+
+CPDF_Metadata::CPDF_Metadata(CPDF_Document* pDoc) : m_pDoc(pDoc) {
CPDF_Dictionary* pRoot = pDoc->GetRoot();
+ if (!pRoot)
+ return;
+
CPDF_Stream* pStream = pRoot->GetStream(FX_BSTRC("Metadata"));
- if (!pStream) {
+ if (!pStream)
return;
- }
+
CPDF_StreamAcc acc;
acc.LoadAllData(pStream, FALSE);
- int size = acc.GetSize();
- const uint8_t* pBuf = acc.GetData();
- CXML_Element*& pXmlElmnt = ((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt;
- pXmlElmnt = CXML_Element::Parse(pBuf, size);
- if (!pXmlElmnt) {
- return;
- }
- CXML_Element*& pElmntRdf = ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf;
- if (pXmlElmnt->GetTagName() == FX_BSTRC("RDF")) {
- pElmntRdf = pXmlElmnt;
- } else {
- pElmntRdf = pXmlElmnt->GetElement(NULL, FX_BSTRC("RDF"));
- }
-}
-int32_t CPDF_Metadata::GetString(const CFX_ByteStringC& bsItem,
- CFX_WideString& wsStr) {
- if (!((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt) {
- return -1;
- }
- if (!((PDFDOC_LPMETADATA)m_pData)->m_pStringMap) {
- return -1;
- }
- void* szTag;
- if (!((PDFDOC_LPMETADATA)m_pData)->m_pStringMap->Lookup(bsItem, szTag)) {
- return -1;
- }
- CFX_ByteString bsTag = (const FX_CHAR*)szTag;
- wsStr = L"";
- CXML_Element* pElmntRdf = ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf;
- if (!pElmntRdf) {
- return -1;
- }
- int nChild = pElmntRdf->CountChildren();
- for (int i = 0; i < nChild; i++) {
- CXML_Element* pTag =
- pElmntRdf->GetElement(NULL, FX_BSTRC("Description"), i);
- if (!pTag) {
- continue;
- }
- if (bsItem == FX_BSTRC("Title") || bsItem == FX_BSTRC("Subject")) {
- CXML_Element* pElmnt = pTag->GetElement(NULL, bsTag);
- if (!pElmnt) {
- continue;
- }
- pElmnt = pElmnt->GetElement(NULL, FX_BSTRC("Alt"));
- if (!pElmnt) {
- continue;
- }
- pElmnt = pElmnt->GetElement(NULL, FX_BSTRC("li"));
- if (!pElmnt) {
- continue;
- }
- wsStr = pElmnt->GetContent(0);
- return wsStr.GetLength();
- }
- if (bsItem == FX_BSTRC("Author")) {
- CXML_Element* pElmnt = pTag->GetElement(NULL, bsTag);
- if (!pElmnt) {
- continue;
- }
- pElmnt = pElmnt->GetElement(NULL, FX_BSTRC("Seq"));
- if (!pElmnt) {
- continue;
- }
- pElmnt = pElmnt->GetElement(NULL, FX_BSTRC("li"));
- if (!pElmnt) {
- continue;
- }
- wsStr = pElmnt->GetContent(0);
- return wsStr.GetLength();
- }
- CXML_Element* pElmnt = pTag->GetElement(NULL, bsTag);
- if (!pElmnt) {
- continue;
- }
- wsStr = pElmnt->GetContent(0);
- return wsStr.GetLength();
- }
- return -1;
-}
-CXML_Element* CPDF_Metadata::GetRoot() const {
- return ((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt;
+ m_pXmlElement.reset(CXML_Element::Parse(acc.GetData(), acc.GetSize()));
}
-CXML_Element* CPDF_Metadata::GetRDF() const {
- return ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf;
+
+CPDF_Metadata::~CPDF_Metadata() {}
+
+const CXML_Element* CPDF_Metadata::GetRoot() const {
+ return m_pXmlElement.get();
}
diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp
index e95a2f0094..2d84ff2a50 100644
--- a/fpdfsdk/src/fpdf_ext.cpp
+++ b/fpdfsdk/src/fpdf_ext.cpp
@@ -88,7 +88,7 @@ void CheckUnSupportAnnot(CPDF_Document* pDoc, CPDF_Annot* pPDFAnnot) {
}
}
-FX_BOOL CheckSharedForm(CXML_Element* pElement, CFX_ByteString cbName) {
+FX_BOOL CheckSharedForm(const CXML_Element* pElement, CFX_ByteString cbName) {
int count = pElement->CountAttrs();
int i = 0;
for (i = 0; i < count; i++) {
@@ -169,9 +169,8 @@ void CheckUnSupportError(CPDF_Document* pDoc, FX_DWORD err_code) {
}
// SharedForm
- CPDF_Metadata metaData;
- metaData.LoadDoc(pDoc);
- CXML_Element* pElement = metaData.GetRoot();
+ CPDF_Metadata metaData(pDoc);
+ const CXML_Element* pElement = metaData.GetRoot();
if (pElement)
CheckSharedForm(pElement, "workflowType");