diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-04 10:48:19 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-04 15:00:53 +0000 |
commit | 29479f6380942515b06240c4933bf3b4cf502013 (patch) | |
tree | 17c63412945c264cf3087a2f959d157f2ad1b19b /fpdfsdk/fpdf_structtree.cpp | |
parent | f02c8bf51c992057376e0acdd262c18540bd8e13 (diff) | |
download | pdfium-29479f6380942515b06240c4933bf3b4cf502013.tar.xz |
Add method to get tagged type
This CL adds a FPDF_StructElement_GetType method to get the type of a given
tagged struct. This corresponds to the /S key in the structure element
dictionary. See PDF1.7 Table 10.10.
Bug: pdfium:672
Change-Id: I313eb886dc9623715995d73a76bce01ba9985e4b
Reviewed-on: https://pdfium-review.googlesource.com/3623
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_structtree.cpp')
-rw-r--r-- | fpdfsdk/fpdf_structtree.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp index 06713fba1d..8a93d2299d 100644 --- a/fpdfsdk/fpdf_structtree.cpp +++ b/fpdfsdk/fpdf_structtree.cpp @@ -21,6 +21,19 @@ IPDF_StructElement* ToStructTreeElement(FPDF_STRUCTELEMENT struct_element) { return reinterpret_cast<IPDF_StructElement*>(struct_element); } +unsigned long WideStringToBuffer(const CFX_WideString& str, + void* buffer, + unsigned long buflen) { + if (str.IsEmpty()) + return 0; + + CFX_ByteString encodedStr = str.UTF16LE_Encode(); + const unsigned long len = encodedStr.GetLength(); + if (buffer && len <= buflen) + memcpy(buffer, encodedStr.c_str(), len); + return len; +} + } // namespace DLLEXPORT FPDF_STRUCTTREE STDCALL FPDF_StructTree_GetForPage(FPDF_PAGE page) { @@ -54,22 +67,19 @@ FPDF_StructElement_GetAltText(FPDF_STRUCTELEMENT struct_element, void* buffer, unsigned long buflen) { IPDF_StructElement* elem = ToStructTreeElement(struct_element); - if (!elem) - return 0; - - CPDF_Dictionary* dict = elem->GetDict(); - if (!dict) - return 0; - - CFX_WideString str = elem->GetDict()->GetUnicodeTextFor("Alt"); - if (str.IsEmpty()) - return 0; + return (elem && elem->GetDict()) + ? WideStringToBuffer(elem->GetDict()->GetUnicodeTextFor("Alt"), + buffer, buflen) + : 0; +} - CFX_ByteString encodedStr = str.UTF16LE_Encode(); - const unsigned long len = encodedStr.GetLength(); - if (buffer && len <= buflen) - memcpy(buffer, encodedStr.c_str(), len); - return len; +DLLEXPORT unsigned long STDCALL +FPDF_StructElement_GetType(FPDF_STRUCTELEMENT struct_element, + void* buffer, + unsigned long buflen) { + IPDF_StructElement* elem = ToStructTreeElement(struct_element); + return elem ? WideStringToBuffer(elem->GetType().UTF8Decode(), buffer, buflen) + : 0; } DLLEXPORT int STDCALL |