Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: fpdfsdk/fpdf_structtree.cpp

Issue 2585873002: Return unique_ptr<> from IPDF_StructTree (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« core/fpdfdoc/doc_tagged.cpp ('K') | « core/fpdfdoc/tagged_int.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 #include "public/fpdf_structtree.h" 5 #include "public/fpdf_structtree.h"
6 6
7 #include "core/fpdfapi/page/cpdf_page.h" 7 #include "core/fpdfapi/page/cpdf_page.h"
8 #include "core/fpdfapi/parser/cpdf_dictionary.h" 8 #include "core/fpdfapi/parser/cpdf_dictionary.h"
9 #include "core/fpdfdoc/fpdf_tagged.h" 9 #include "core/fpdfdoc/fpdf_tagged.h"
10 #include "fpdfsdk/fsdk_define.h" 10 #include "fpdfsdk/fsdk_define.h"
11 11
12 namespace { 12 namespace {
13 13
14 IPDF_StructTree* ToStructTree(FPDF_STRUCTTREE struct_tree) { 14 IPDF_StructTree* ToStructTree(FPDF_STRUCTTREE struct_tree) {
15 return reinterpret_cast<IPDF_StructTree*>(struct_tree); 15 return reinterpret_cast<IPDF_StructTree*>(struct_tree);
16 } 16 }
17 17
18 IPDF_StructElement* ToStructTreeElement(FPDF_STRUCTELEMENT struct_element) { 18 IPDF_StructElement* ToStructTreeElement(FPDF_STRUCTELEMENT struct_element) {
19 return reinterpret_cast<IPDF_StructElement*>(struct_element); 19 return reinterpret_cast<IPDF_StructElement*>(struct_element);
20 } 20 }
21 21
22 } // namespace 22 } // namespace
23 23
24 DLLEXPORT FPDF_STRUCTTREE STDCALL FPDF_StructTree_GetForPage(FPDF_PAGE page) { 24 DLLEXPORT FPDF_STRUCTTREE STDCALL FPDF_StructTree_GetForPage(FPDF_PAGE page) {
25 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); 25 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
26 if (!pPage) 26 if (!pPage)
27 return nullptr; 27 return nullptr;
28 return IPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict); 28 return IPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict)
29 .release();
29 } 30 }
30 31
31 DLLEXPORT void STDCALL FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree) { 32 DLLEXPORT void STDCALL FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree) {
32 delete ToStructTree(struct_tree); 33 delete ToStructTree(struct_tree);
33 } 34 }
34 35
35 DLLEXPORT int STDCALL 36 DLLEXPORT int STDCALL
36 FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) { 37 FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) {
37 IPDF_StructTree* tree = ToStructTree(struct_tree); 38 IPDF_StructTree* tree = ToStructTree(struct_tree);
38 return tree ? tree->CountTopElements() : -1; 39 return tree ? tree->CountTopElements() : -1;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element, 80 FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element,
80 int index) { 81 int index) {
81 IPDF_StructElement* elem = ToStructTreeElement(struct_element); 82 IPDF_StructElement* elem = ToStructTreeElement(struct_element);
82 if (!elem || index < 0 || index >= elem->CountKids()) 83 if (!elem || index < 0 || index >= elem->CountKids())
83 return nullptr; 84 return nullptr;
84 85
85 CPDF_StructKid kid = elem->GetKid(index); 86 CPDF_StructKid kid = elem->GetKid(index);
86 return kid.m_Type == CPDF_StructKid::Element ? kid.m_Element.m_pElement 87 return kid.m_Type == CPDF_StructKid::Element ? kid.m_Element.m_pElement
87 : nullptr; 88 : nullptr;
88 } 89 }
OLDNEW
« core/fpdfdoc/doc_tagged.cpp ('K') | « core/fpdfdoc/tagged_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698