OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
8 #include "../../include/fxcrt/fx_xml.h" | 8 #include "../../include/fxcrt/fx_xml.h" |
9 typedef struct _PDFDOC_METADATA { | 9 typedef struct _PDFDOC_METADATA { |
10 CPDF_Document *m_pDoc; | 10 CPDF_Document *m_pDoc; |
11 CXML_Element *m_pXmlElmnt; | 11 CXML_Element *m_pXmlElmnt; |
12 CXML_Element *m_pElmntRdf; | 12 CXML_Element *m_pElmntRdf; |
13 CFX_CMapByteStringToPtr *m_pStringMap; | 13 CFX_CMapByteStringToPtr *m_pStringMap; |
14 } PDFDOC_METADATA, * PDFDOC_LPMETADATA; | 14 } PDFDOC_METADATA, * PDFDOC_LPMETADATA; |
15 typedef PDFDOC_METADATA const * PDFDOC_LPCMETADATA; | 15 typedef PDFDOC_METADATA const * PDFDOC_LPCMETADATA; |
16 const FX_LPCSTR gs_FPDFDOC_Metadata_Titles[] = { | 16 const FX_CHAR* const gs_FPDFDOC_Metadata_Titles[] = { |
17 "Title", "title", | 17 "Title", "title", |
18 "Subject", "description", | 18 "Subject", "description", |
19 "Author", "creator", | 19 "Author", "creator", |
20 "Keywords", "Keywords", | 20 "Keywords", "Keywords", |
21 "Producer", "Producer", | 21 "Producer", "Producer", |
22 "Creator", "CreatorTool", | 22 "Creator", "CreatorTool", |
23 "CreationDate", "CreateDate", | 23 "CreationDate", "CreateDate", |
24 "ModDate", "ModifyDate", | 24 "ModDate", "ModifyDate", |
25 "MetadataDate", "MetadataDate" | 25 "MetadataDate", "MetadataDate" |
26 }; | 26 }; |
(...skipping 26 matching lines...) Expand all Loading... |
53 FXSYS_assert(pDoc != NULL); | 53 FXSYS_assert(pDoc != NULL); |
54 ((PDFDOC_LPMETADATA)m_pData)->m_pDoc = pDoc; | 54 ((PDFDOC_LPMETADATA)m_pData)->m_pDoc = pDoc; |
55 CPDF_Dictionary *pRoot = pDoc->GetRoot(); | 55 CPDF_Dictionary *pRoot = pDoc->GetRoot(); |
56 CPDF_Stream *pStream = pRoot->GetStream(FX_BSTRC("Metadata")); | 56 CPDF_Stream *pStream = pRoot->GetStream(FX_BSTRC("Metadata")); |
57 if (!pStream) { | 57 if (!pStream) { |
58 return; | 58 return; |
59 } | 59 } |
60 CPDF_StreamAcc acc; | 60 CPDF_StreamAcc acc; |
61 acc.LoadAllData(pStream, FALSE); | 61 acc.LoadAllData(pStream, FALSE); |
62 int size = acc.GetSize(); | 62 int size = acc.GetSize(); |
63 FX_LPCBYTE pBuf = acc.GetData(); | 63 const uint8_t* pBuf = acc.GetData(); |
64 CXML_Element *&pXmlElmnt = ((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt; | 64 CXML_Element *&pXmlElmnt = ((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt; |
65 pXmlElmnt = CXML_Element::Parse(pBuf, size); | 65 pXmlElmnt = CXML_Element::Parse(pBuf, size); |
66 if (!pXmlElmnt) { | 66 if (!pXmlElmnt) { |
67 return; | 67 return; |
68 } | 68 } |
69 CXML_Element *&pElmntRdf = ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf; | 69 CXML_Element *&pElmntRdf = ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf; |
70 if (pXmlElmnt->GetTagName() == FX_BSTRC("RDF")) { | 70 if (pXmlElmnt->GetTagName() == FX_BSTRC("RDF")) { |
71 pElmntRdf = pXmlElmnt; | 71 pElmntRdf = pXmlElmnt; |
72 } else { | 72 } else { |
73 pElmntRdf = pXmlElmnt->GetElement(NULL, FX_BSTRC("RDF")); | 73 pElmntRdf = pXmlElmnt->GetElement(NULL, FX_BSTRC("RDF")); |
74 } | 74 } |
75 } | 75 } |
76 int32_t CPDF_Metadata::GetString(FX_BSTR bsItem, CFX_WideString &wsStr) | 76 int32_t CPDF_Metadata::GetString(FX_BSTR bsItem, CFX_WideString &wsStr) |
77 { | 77 { |
78 if (!((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt) { | 78 if (!((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt) { |
79 return -1; | 79 return -1; |
80 } | 80 } |
81 if (!((PDFDOC_LPMETADATA)m_pData)->m_pStringMap) { | 81 if (!((PDFDOC_LPMETADATA)m_pData)->m_pStringMap) { |
82 return -1; | 82 return -1; |
83 } | 83 } |
84 void *szTag; | 84 void *szTag; |
85 if (!((PDFDOC_LPMETADATA)m_pData)->m_pStringMap->Lookup(bsItem, szTag)) { | 85 if (!((PDFDOC_LPMETADATA)m_pData)->m_pStringMap->Lookup(bsItem, szTag)) { |
86 return -1; | 86 return -1; |
87 } | 87 } |
88 CFX_ByteString bsTag = (FX_LPCSTR)szTag; | 88 CFX_ByteString bsTag = (const FX_CHAR*)szTag; |
89 wsStr = L""; | 89 wsStr = L""; |
90 CXML_Element *pElmntRdf = ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf; | 90 CXML_Element *pElmntRdf = ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf; |
91 if (!pElmntRdf) { | 91 if (!pElmntRdf) { |
92 return -1; | 92 return -1; |
93 } | 93 } |
94 int nChild = pElmntRdf->CountChildren(); | 94 int nChild = pElmntRdf->CountChildren(); |
95 for (int i = 0; i < nChild; i++) { | 95 for (int i = 0; i < nChild; i++) { |
96 CXML_Element *pTag = pElmntRdf->GetElement(NULL, FX_BSTRC("Description")
, i); | 96 CXML_Element *pTag = pElmntRdf->GetElement(NULL, FX_BSTRC("Description")
, i); |
97 if (!pTag) { | 97 if (!pTag) { |
98 continue; | 98 continue; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return -1; | 139 return -1; |
140 } | 140 } |
141 CXML_Element* CPDF_Metadata::GetRoot() const | 141 CXML_Element* CPDF_Metadata::GetRoot() const |
142 { | 142 { |
143 return ((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt; | 143 return ((PDFDOC_LPMETADATA)m_pData)->m_pXmlElmnt; |
144 } | 144 } |
145 CXML_Element* CPDF_Metadata::GetRDF() const | 145 CXML_Element* CPDF_Metadata::GetRDF() const |
146 { | 146 { |
147 return ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf; | 147 return ((PDFDOC_LPMETADATA)m_pData)->m_pElmntRdf; |
148 } | 148 } |
OLD | NEW |