5#include "testing/helpers/dump.h"
16#include "public/cpp/fpdf_scopers.h"
17#include "public/fpdf_doc.h"
18#include "public/fpdf_transformpage.h"
19#include "testing/fx_string_testhelpers.h"
22 std::function<
bool(FPDF_PAGE,
float*,
float*,
float*,
float*)>;
26std::wstring ConvertToWString(
const unsigned short* buf,
27 unsigned long buf_size) {
29 result.reserve(buf_size);
30 std::copy(buf, buf + buf_size,
std::back_inserter(result));
39 bool ret = func(page, &rect.left, &rect.bottom, &rect.right, &rect.top);
41 printf(
"Page %d: No %s.\n", page_idx, box_type);
44 printf(
"Page %d: %s: %0.2f %0.2f %0.2f %0.2f\n", page_idx, box_type,
45 rect.left, rect.bottom, rect.right, rect.top);
48void DumpStructureElementAttributeValues(
49 FPDF_STRUCTELEMENT_ATTR_VALUE attr_value,
53 printf(
"%*s FPDF_StructElement_Attr_GetValue failed for %s\n", indent,
"",
63 printf(
"%*s %s: %d\n", indent,
"", name, value);
65 printf(
"%*s %s: Failed FPDF_StructElement_Attr_GetBooleanValue\n",
73 printf(
"%*s %s: %f\n", indent,
"", name, value);
75 printf(
"%*s %s: Failed FPDF_StructElement_Attr_GetNumberValue\n",
82 static const size_t kBufSize = 1024;
83 unsigned short buffer[kBufSize];
85 if (FPDF_StructElement_Attr_GetStringValue(attr_value, buffer,
86 sizeof(buffer), &len)) {
87 printf(
"%*s %s: %ls\n", indent,
"", name,
88 ConvertToWString(buffer, len).c_str());
90 printf(
"%*s %s: Failed FPDF_StructElement_Attr_GetStringValue\n",
96 printf(
"%*s %s:\n", indent,
"", name);
98 for (
int i = 0; i < count; ++i) {
99 DumpStructureElementAttributeValues(
106 printf(
"%*s %s: FPDF_OBJECT_UNKNOWN\n", indent,
"", name);
110 printf(
"%*s %s: NOT_YET_IMPLEMENTED: %d\n", indent,
"", name, type);
116void DumpStructureElementAttributes(FPDF_STRUCTELEMENT_ATTR attr,
int indent) {
117 static const size_t kBufSize = 1024;
119 for (
int i = 0; i < count; ++i) {
122 if (!FPDF_StructElement_Attr_GetName(attr, i, name,
sizeof(name), &len)) {
123 printf(
"%*s FPDF_StructElement_Attr_GetName failed for %d\n", indent,
"",
128 DumpStructureElementAttributeValues(
129 FPDF_StructElement_Attr_GetValue(attr, name), name, indent);
136 static const size_t kBufSize = 1024;
137 unsigned short buf[kBufSize];
138 unsigned long len = FPDF_StructElement_GetType(child, buf, kBufSize);
140 printf(
"%*s S: %ls\n", indent * 2,
"", ConvertToWString(buf, len).c_str());
144 for (
int i = 0; i < attr_count; i++) {
145 FPDF_STRUCTELEMENT_ATTR child_attr =
150 printf(
"%*s A[%d]:\n", indent * 2,
"", i);
151 DumpStructureElementAttributes(child_attr, indent * 2 + 2);
154 memset(buf, 0,
sizeof(buf));
155 len = FPDF_StructElement_GetActualText(child, buf, kBufSize);
157 printf(
"%*s ActualText: %ls\n", indent * 2,
"",
158 ConvertToWString(buf, len).c_str());
161 memset(buf, 0,
sizeof(buf));
162 len = FPDF_StructElement_GetAltText(child, buf, kBufSize);
164 printf(
"%*s AltText: %ls\n", indent * 2,
"",
165 ConvertToWString(buf, len).c_str());
168 memset(buf, 0,
sizeof(buf));
169 len = FPDF_StructElement_GetID(child, buf, kBufSize);
171 printf(
"%*s ID: %ls\n", indent * 2,
"", ConvertToWString(buf, len).c_str());
174 memset(buf, 0,
sizeof(buf));
175 len = FPDF_StructElement_GetLang(child, buf, kBufSize);
177 printf(
"%*s Lang: %ls\n", indent * 2,
"",
178 ConvertToWString(buf, len).c_str());
182 for (
int i = 0; i < mcid_count; ++i) {
185 printf(
"%*s MCID%d: %d\n", indent * 2,
"", i, mcid);
191 memset(buf, 0,
sizeof(buf));
192 len = FPDF_StructElement_GetID(parent, buf, kBufSize);
194 printf(
"%*s Parent ID: %ls\n", indent * 2,
"",
195 ConvertToWString(buf, len).c_str());
199 memset(buf, 0,
sizeof(buf));
200 len = FPDF_StructElement_GetTitle(child, buf, kBufSize);
202 printf(
"%*s Title: %ls\n", indent * 2,
"",
203 ConvertToWString(buf, len).c_str());
206 memset(buf, 0,
sizeof(buf));
207 len = FPDF_StructElement_GetObjType(child, buf, kBufSize);
209 printf(
"%*s Type: %ls\n", indent * 2,
"",
210 ConvertToWString(buf, len).c_str());
236 fprintf(stderr,
"Failed to load struct tree for page %d\n", page_idx);
240 printf(
"Structure Tree for Page %d\n", page_idx);
241 for (
int i = 0; i < FPDF_StructTree_CountChildren(tree.get()); ++i) {
242 FPDF_STRUCTELEMENT child = FPDF_StructTree_GetChildAtIndex(tree.get(), i);
244 fprintf(stderr,
"Failed to load child %d for page %d\n", i, page_idx);
253 static constexpr const char* kMetaTags[] = {
254 "Title",
"Author",
"Subject",
"Keywords",
255 "Creator",
"Producer",
"CreationDate",
"ModDate"};
256 for (
const char* meta_tag : kMetaTags) {
257 char meta_buffer[4096];
264 auto* meta_string =
reinterpret_cast<
unsigned short*>(meta_buffer);
265 printf(
"%-12s = %ls (%lu bytes)\n", meta_tag,
void DumpPageStructure(FPDF_PAGE page, int page_idx)
void DumpMetaData(FPDF_DOCUMENT doc)
void DumpPageInfo(FPDF_PAGE page, int page_idx)
std::function< bool(FPDF_PAGE, float *, float *, float *, float *)> GetBoxInfoFunc
void DumpChildStructure(FPDF_STRUCTELEMENT child, int indent)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetMetaText(FPDF_DOCUMENT document, FPDF_BYTESTRING tag, void *buffer, unsigned long buflen)
FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV FPDF_StructElement_GetParent(FPDF_STRUCTELEMENT struct_element)
FPDF_EXPORT int FPDF_CALLCONV FPDF_StructElement_GetAttributeCount(FPDF_STRUCTELEMENT struct_element)
FPDF_EXPORT FPDF_STRUCTTREE FPDF_CALLCONV FPDF_StructTree_GetForPage(FPDF_PAGE page)
FPDF_EXPORT FPDF_STRUCTELEMENT_ATTR_VALUE FPDF_CALLCONV FPDF_StructElement_Attr_GetChildAtIndex(FPDF_STRUCTELEMENT_ATTR_VALUE value, int index)
FPDF_EXPORT int FPDF_CALLCONV FPDF_StructElement_GetMarkedContentIdAtIndex(FPDF_STRUCTELEMENT struct_element, int index)
FPDF_EXPORT int FPDF_CALLCONV FPDF_StructElement_Attr_GetCount(FPDF_STRUCTELEMENT_ATTR struct_attribute)
FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV FPDF_StructElement_Attr_GetType(FPDF_STRUCTELEMENT_ATTR_VALUE value)
FPDF_EXPORT FPDF_STRUCTELEMENT FPDF_CALLCONV FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element, int index)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_StructElement_Attr_GetNumberValue(FPDF_STRUCTELEMENT_ATTR_VALUE value, float *out_value)
FPDF_EXPORT FPDF_STRUCTELEMENT_ATTR FPDF_CALLCONV FPDF_StructElement_GetAttributeAtIndex(FPDF_STRUCTELEMENT struct_element, int index)
FPDF_EXPORT int FPDF_CALLCONV FPDF_StructElement_Attr_CountChildren(FPDF_STRUCTELEMENT_ATTR_VALUE value)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_StructElement_Attr_GetBooleanValue(FPDF_STRUCTELEMENT_ATTR_VALUE value, FPDF_BOOL *out_value)
FPDF_EXPORT int FPDF_CALLCONV FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element)
FPDF_EXPORT int FPDF_CALLCONV FPDF_StructElement_GetMarkedContentIdCount(FPDF_STRUCTELEMENT struct_element)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetArtBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetTrimBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetMediaBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetCropBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetBleedBox(FPDF_PAGE page, float *left, float *bottom, float *right, float *top)
#define FPDF_OBJECT_NUMBER
#define FPDF_OBJECT_BOOLEAN
#define FPDF_OBJECT_UNKNOWN
#define FPDF_OBJECT_STRING
#define FPDF_OBJECT_ARRAY
std::wstring GetPlatformWString(FPDF_WIDESTRING wstr)