summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-16 05:54:09 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-16 05:54:09 +0000
commitbb3f58dbcb7195e9e641fcc64e2ab537cf3fbc61 (patch)
treea4aaa3a58970fe29dea577381d83cca145ef2cad /samples
parentf1925d9429f8674b25fff8010e04f2fc132ea38a (diff)
downloadpdfium-bb3f58dbcb7195e9e641fcc64e2ab537cf3fbc61.tar.xz
Add pdfium_test --show-pageinfo to dump page bounding boxes.
The bounding boxes are LBRT coordinates. e.g. Page 0: MediaBox: 0.00 0.00 595.00 842.00 Page 0: No CropBox. Page 0: BleedBox: 0.04 0.00 842.04 594.96 Page 0: TrimBox: 0.04 0.00 842.04 594.96 Page 0: ArtBox: 0.00 0.02 594.96 594.96 Change-Id: I2809aab69f3c51bde9a443d6c92f3167ee10b3c9 Reviewed-on: https://pdfium-review.googlesource.com/c/43976 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Shirleen Lou <xlou@chromium.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/pdfium_test.cc13
-rw-r--r--samples/pdfium_test_dump_helper.cc29
-rw-r--r--samples/pdfium_test_dump_helper.h3
3 files changed, 43 insertions, 2 deletions
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 2e8487e2c2..e64382c911 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -70,6 +70,7 @@
enum OutputFormat {
OUTPUT_NONE,
+ OUTPUT_PAGEINFO,
OUTPUT_STRUCTURE,
OUTPUT_TEXT,
OUTPUT_PPM,
@@ -402,6 +403,12 @@ bool ParseCommandLine(const std::vector<std::string>& args,
return false;
}
options->scale_factor_as_string = cur_arg.substr(8);
+ } else if (cur_arg == "--show-pageinfo") {
+ if (options->output_format != OUTPUT_NONE) {
+ fprintf(stderr, "Duplicate or conflicting --show-pageinfo argument\n");
+ return false;
+ }
+ options->output_format = OUTPUT_PAGEINFO;
} else if (cur_arg == "--show-structure") {
if (options->output_format != OUTPUT_NONE) {
fprintf(stderr, "Duplicate or conflicting --show-structure argument\n");
@@ -534,6 +541,11 @@ bool RenderPage(const std::string& name,
SendPageEvents(form, page, events);
if (options.save_images)
WriteImages(page, name.c_str(), page_index);
+
+ if (options.output_format == OUTPUT_PAGEINFO) {
+ DumpPageInfo(page, page_index);
+ return true;
+ }
if (options.output_format == OUTPUT_STRUCTURE) {
DumpPageStructure(page, page_index);
return true;
@@ -814,6 +826,7 @@ constexpr char kUsageString[] =
"Usage: pdfium_test [OPTION] [FILE]...\n"
" --show-config - print build options and exit\n"
" --show-metadata - print the file metadata\n"
+ " --show-pageinfo - print information about pages\n"
" --show-structure - print the structure elements from the document\n"
" --send-events - send input described by .evt file\n"
" --render-oneshot - render image without using progressive renderer\n"
diff --git a/samples/pdfium_test_dump_helper.cc b/samples/pdfium_test_dump_helper.cc
index 2b422a93fb..93a184a691 100644
--- a/samples/pdfium_test_dump_helper.cc
+++ b/samples/pdfium_test_dump_helper.cc
@@ -7,13 +7,18 @@
#include <string.h>
#include <algorithm>
+#include <functional>
#include <memory>
#include <string>
#include <utility>
#include "public/cpp/fpdf_scopers.h"
+#include "public/fpdf_transformpage.h"
#include "testing/test_support.h"
+using GetBoxInfoFunc =
+ std::function<bool(FPDF_PAGE, float*, float*, float*, float*)>;
+
namespace {
std::wstring ConvertToWString(const unsigned short* buf,
@@ -24,6 +29,20 @@ std::wstring ConvertToWString(const unsigned short* buf,
return result;
}
+void DumpBoxInfo(GetBoxInfoFunc func,
+ const char* box_type,
+ FPDF_PAGE page,
+ int page_idx) {
+ FS_RECTF rect;
+ bool ret = func(page, &rect.left, &rect.bottom, &rect.right, &rect.top);
+ if (!ret) {
+ printf("Page %d: No %s.\n", page_idx, box_type);
+ return;
+ }
+ printf("Page %d: %s: %0.2f %0.2f %0.2f %0.2f\n", page_idx, box_type,
+ rect.left, rect.bottom, rect.right, rect.top);
+}
+
} // namespace
void DumpChildStructure(FPDF_STRUCTELEMENT child, int indent) {
@@ -54,7 +73,15 @@ void DumpChildStructure(FPDF_STRUCTELEMENT child, int indent) {
}
}
-void DumpPageStructure(FPDF_PAGE page, const int page_idx) {
+void DumpPageInfo(FPDF_PAGE page, int page_idx) {
+ DumpBoxInfo(&FPDFPage_GetMediaBox, "MediaBox", page, page_idx);
+ DumpBoxInfo(&FPDFPage_GetCropBox, "CropBox", page, page_idx);
+ DumpBoxInfo(&FPDFPage_GetBleedBox, "BleedBox", page, page_idx);
+ DumpBoxInfo(&FPDFPage_GetTrimBox, "TrimBox", page, page_idx);
+ DumpBoxInfo(&FPDFPage_GetArtBox, "ArtBox", page, page_idx);
+}
+
+void DumpPageStructure(FPDF_PAGE page, int page_idx) {
ScopedFPDFStructTree tree(FPDF_StructTree_GetForPage(page));
if (!tree) {
fprintf(stderr, "Failed to load struct tree for page %d\n", page_idx);
diff --git a/samples/pdfium_test_dump_helper.h b/samples/pdfium_test_dump_helper.h
index e2276f7b1a..17cbd8f7b2 100644
--- a/samples/pdfium_test_dump_helper.h
+++ b/samples/pdfium_test_dump_helper.h
@@ -8,7 +8,8 @@
#include "public/fpdfview.h"
void DumpChildStructure(FPDF_STRUCTELEMENT child, int indent);
-void DumpPageStructure(FPDF_PAGE page, const int page_idx);
+void DumpPageInfo(FPDF_PAGE page, int page_idx);
+void DumpPageStructure(FPDF_PAGE page, int page_idx);
void DumpMetaData(FPDF_DOCUMENT doc);
#endif // SAMPLES_PDFIUM_TEST_DUMP_HELPER_H_