Index: core/fpdfdoc/doc_tagged.cpp |
diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp |
index 10c573b5cae576e1d7ab0eb6099abd48d76af3d7..39feaeef88c15168b5fdc16f1ad1226ac2bc23eb 100644 |
--- a/core/fpdfdoc/doc_tagged.cpp |
+++ b/core/fpdfdoc/doc_tagged.cpp |
@@ -5,6 +5,8 @@ |
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
#include <map> |
+#include <memory> |
+#include <utility> |
#include "core/fpdfapi/parser/cpdf_array.h" |
#include "core/fpdfapi/parser/cpdf_dictionary.h" |
@@ -16,6 +18,7 @@ |
#include "core/fpdfdoc/cpdf_numbertree.h" |
#include "core/fpdfdoc/fpdf_tagged.h" |
#include "core/fpdfdoc/tagged_int.h" |
+#include "third_party/base/ptr_util.h" |
namespace { |
@@ -30,24 +33,15 @@ bool IsTagged(const CPDF_Document* pDoc) { |
} // namespace |
// static |
-IPDF_StructTree* IPDF_StructTree::LoadPage(const CPDF_Document* pDoc, |
- const CPDF_Dictionary* pPageDict) { |
+std::unique_ptr<IPDF_StructTree> IPDF_StructTree::LoadPage( |
+ const CPDF_Document* pDoc, |
+ const CPDF_Dictionary* pPageDict) { |
if (!IsTagged(pDoc)) |
return nullptr; |
- CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc); |
+ auto pTree = pdfium::MakeUnique<CPDF_StructTreeImpl>(pDoc); |
pTree->LoadPageTree(pPageDict); |
- return pTree; |
-} |
- |
-// static. |
-IPDF_StructTree* IPDF_StructTree::LoadDoc(const CPDF_Document* pDoc) { |
- if (!IsTagged(pDoc)) |
- return nullptr; |
- |
- CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc); |
- pTree->LoadDocTree(); |
- return pTree; |
+ return std::move(pTree); |
Wei Li
2016/12/16 20:26:33
Nit: move() is not needed here
Tom Sepez
2016/12/16 22:45:17
Sadly, it is required, because the return type is
|
} |
CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc) |
@@ -65,31 +59,6 @@ IPDF_StructElement* CPDF_StructTreeImpl::GetTopElement(int i) const { |
return m_Kids[i].Get(); |
} |
-void CPDF_StructTreeImpl::LoadDocTree() { |
- m_pPage = nullptr; |
- if (!m_pTreeRoot) |
- return; |
- |
- CPDF_Object* pKids = m_pTreeRoot->GetDirectObjectFor("K"); |
- if (!pKids) |
- return; |
- |
- if (CPDF_Dictionary* pDict = pKids->AsDictionary()) { |
- m_Kids.push_back(CFX_RetainPtr<CPDF_StructElementImpl>( |
- new CPDF_StructElementImpl(this, nullptr, pDict))); |
- return; |
- } |
- |
- CPDF_Array* pArray = pKids->AsArray(); |
- if (!pArray) |
- return; |
- |
- for (size_t i = 0; i < pArray->GetCount(); i++) { |
- m_Kids.push_back(CFX_RetainPtr<CPDF_StructElementImpl>( |
- new CPDF_StructElementImpl(this, nullptr, pArray->GetDictAt(i)))); |
- } |
-} |
- |
void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { |
m_pPage = pPageDict; |
if (!m_pTreeRoot) |