Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
|
Tom Sepez
2016/11/22 23:45:36
I'm not sure if we need this line since we cooked
Lei Zhang
2016/11/23 00:03:26
Done.
| |
| 6 | |
| 7 #include "public/fpdf_structtree.h" | |
| 8 | |
| 9 #include "core/fpdfapi/page/cpdf_page.h" | |
| 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" | |
| 11 #include "core/fpdfdoc/fpdf_tagged.h" | |
| 12 #include "fpdfsdk/fsdk_define.h" | |
| 13 | |
| 14 DLLEXPORT FPDF_STRUCTTREE STDCALL FPDF_StructTree_GetForPage(FPDF_PAGE page) { | |
| 15 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | |
| 16 if (!pPage) | |
| 17 return nullptr; | |
| 18 return IPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict); | |
| 19 } | |
| 20 | |
| 21 DLLEXPORT void STDCALL FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree) { | |
| 22 delete reinterpret_cast<IPDF_StructTree*>(struct_tree); | |
| 23 } | |
| 24 | |
| 25 DLLEXPORT int STDCALL | |
| 26 FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) { | |
| 27 IPDF_StructTree* tree = reinterpret_cast<IPDF_StructTree*>(struct_tree); | |
| 28 return tree ? tree->CountTopElements() : -1; | |
| 29 } | |
| 30 | |
| 31 DLLEXPORT FPDF_STRUCTELEMENT STDCALL | |
| 32 FPDF_StructTree_GetChildAtIndex(FPDF_STRUCTTREE struct_tree, int index) { | |
| 33 IPDF_StructTree* tree = reinterpret_cast<IPDF_StructTree*>(struct_tree); | |
| 34 if (!tree || index < 0 || index >= tree->CountTopElements()) | |
| 35 return nullptr; | |
| 36 return tree->GetTopElement(index); | |
| 37 } | |
| 38 | |
| 39 DLLEXPORT unsigned long STDCALL | |
| 40 FPDF_StructElement_GetAltText(FPDF_STRUCTELEMENT struct_element, | |
| 41 void* buffer, | |
| 42 unsigned long buflen) { | |
| 43 IPDF_StructElement* elem = | |
| 44 reinterpret_cast<IPDF_StructElement*>(struct_element); | |
| 45 if (!elem) | |
| 46 return 0; | |
| 47 | |
| 48 CPDF_Dictionary* dict = elem->GetDict(); | |
| 49 if (!dict) | |
| 50 return 0; | |
| 51 | |
| 52 CFX_ByteString str = elem->GetDict()->GetStringFor("Alt", ""); | |
| 53 if (str.IsEmpty()) | |
| 54 return 0; | |
| 55 | |
| 56 unsigned long len = str.GetLength() + 1; | |
| 57 if (buffer || buflen >= len) | |
| 58 FXSYS_memcpy(buffer, str.c_str(), len); | |
| 59 return len; | |
| 60 } | |
| 61 | |
| 62 DLLEXPORT int STDCALL | |
| 63 FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element) { | |
| 64 IPDF_StructElement* elem = | |
| 65 reinterpret_cast<IPDF_StructElement*>(struct_element); | |
| 66 return elem ? elem->CountKids() : -1; | |
| 67 } | |
| 68 | |
| 69 DLLEXPORT FPDF_STRUCTELEMENT STDCALL | |
| 70 FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element, | |
| 71 int index) { | |
| 72 IPDF_StructElement* elem = | |
| 73 reinterpret_cast<IPDF_StructElement*>(struct_element); | |
| 74 if (!elem || index < 0 || index >= elem->CountKids()) | |
| 75 return nullptr; | |
| 76 | |
| 77 CPDF_StructKid kid = elem->GetKid(index); | |
| 78 return kid.m_Type == CPDF_StructKid::Element ? kid.m_Element.m_pElement | |
| 79 : nullptr; | |
| 80 } | |
| OLD | NEW |