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 #include "public/fpdf_structtree.h" |
| 6 |
| 7 #include "core/fpdfapi/page/cpdf_page.h" |
| 8 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 9 #include "core/fpdfdoc/fpdf_tagged.h" |
| 10 #include "fpdfsdk/fsdk_define.h" |
| 11 |
| 12 DLLEXPORT FPDF_STRUCTTREE STDCALL FPDF_StructTree_GetForPage(FPDF_PAGE page) { |
| 13 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 14 if (!pPage) |
| 15 return nullptr; |
| 16 return IPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict); |
| 17 } |
| 18 |
| 19 DLLEXPORT void STDCALL FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree) { |
| 20 delete reinterpret_cast<IPDF_StructTree*>(struct_tree); |
| 21 } |
| 22 |
| 23 DLLEXPORT int STDCALL |
| 24 FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) { |
| 25 IPDF_StructTree* tree = reinterpret_cast<IPDF_StructTree*>(struct_tree); |
| 26 return tree ? tree->CountTopElements() : -1; |
| 27 } |
| 28 |
| 29 DLLEXPORT FPDF_STRUCTELEMENT STDCALL |
| 30 FPDF_StructTree_GetChildAtIndex(FPDF_STRUCTTREE struct_tree, int index) { |
| 31 IPDF_StructTree* tree = reinterpret_cast<IPDF_StructTree*>(struct_tree); |
| 32 if (!tree || index < 0 || index >= tree->CountTopElements()) |
| 33 return nullptr; |
| 34 return tree->GetTopElement(index); |
| 35 } |
| 36 |
| 37 DLLEXPORT unsigned long STDCALL |
| 38 FPDF_StructElement_GetAltText(FPDF_STRUCTELEMENT struct_element, |
| 39 void* buffer, |
| 40 unsigned long buflen) { |
| 41 IPDF_StructElement* elem = |
| 42 reinterpret_cast<IPDF_StructElement*>(struct_element); |
| 43 if (!elem) |
| 44 return 0; |
| 45 |
| 46 CPDF_Dictionary* dict = elem->GetDict(); |
| 47 if (!dict) |
| 48 return 0; |
| 49 |
| 50 CFX_ByteString str = elem->GetDict()->GetStringFor("Alt", ""); |
| 51 if (str.IsEmpty()) |
| 52 return 0; |
| 53 |
| 54 unsigned long len = str.GetLength() + 1; |
| 55 if (buffer || buflen >= len) |
| 56 FXSYS_memcpy(buffer, str.c_str(), len); |
| 57 return len; |
| 58 } |
| 59 |
| 60 DLLEXPORT int STDCALL |
| 61 FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element) { |
| 62 IPDF_StructElement* elem = |
| 63 reinterpret_cast<IPDF_StructElement*>(struct_element); |
| 64 return elem ? elem->CountKids() : -1; |
| 65 } |
| 66 |
| 67 DLLEXPORT FPDF_STRUCTELEMENT STDCALL |
| 68 FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element, |
| 69 int index) { |
| 70 IPDF_StructElement* elem = |
| 71 reinterpret_cast<IPDF_StructElement*>(struct_element); |
| 72 if (!elem || index < 0 || index >= elem->CountKids()) |
| 73 return nullptr; |
| 74 |
| 75 CPDF_StructKid kid = elem->GetKid(index); |
| 76 return kid.m_Type == CPDF_StructKid::Element ? kid.m_Element.m_pElement |
| 77 : nullptr; |
| 78 } |
OLD | NEW |