Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1228)

Unified Diff: samples/pdfium_test.cc

Issue 1960193003: pdfium_test: print out some annotations Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 2016-05-20 (Friday) 20:39:39 EDT Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« public/fpdf_doc.h ('K') | « public/fpdf_doc.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/pdfium_test.cc
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 9ba11e12e4b506fad5f60747620bb891cf5a2a8b..f0b6b7174c984c93b14ccf46032362c13f067561 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -18,6 +18,7 @@
#endif
#include "public/fpdf_dataavail.h"
+#include "public/fpdf_doc.h"
#include "public/fpdf_edit.h"
#include "public/fpdf_ext.h"
#include "public/fpdf_formfill.h"
@@ -55,10 +56,14 @@ enum OutputFormat {
struct Options {
Options()
- : show_config(false), send_events(false), output_format(OUTPUT_NONE) {}
+ : show_config(false),
+ send_events(false),
+ show_annotations(false),
+ output_format(OUTPUT_NONE) {}
bool show_config;
bool send_events;
+ bool show_annotations;
OutputFormat output_format;
std::string scale_factor_as_string;
std::string exe_path;
@@ -342,6 +347,8 @@ bool ParseCommandLine(const std::vector<std::string>& args,
options->show_config = true;
} else if (cur_arg == "--send-events") {
options->send_events = true;
+ } else if (cur_arg == "--show-annotations") {
+ options->show_annotations = true;
} else if (cur_arg == "--ppm") {
if (options->output_format != OUTPUT_NONE) {
fprintf(stderr, "Duplicate or conflicting --ppm argument\n");
@@ -483,6 +490,39 @@ void SendPageEvents(const FPDF_FORMHANDLE& form,
}
}
+void ShowAnnotations(const FPDF_DOCUMENT& doc, const int page_index) {
+ FPDF_PAGE page = FPDF_LoadPage(doc, page_index);
Lei Zhang 2016/05/23 16:47:33 Why not put the ShowAnnotations() call inside Rend
+ if (!page) {
+ fprintf(stderr, "bad page %d\n", page_index);
+ return;
+ }
+ printf("page %d [%g,%g]:\n", page_index, FPDF_GetPageWidth(page),
+ FPDF_GetPageHeight(page));
+ int startPos = 0;
+ FPDF_LINK linkAnnot;
+ while (FPDFLink_Enumerate(page, &startPos, &linkAnnot)) {
+ FS_RECTF rect = {0.0f, 0.0f, 0.0f, 0.0f};
+ (void)FPDFLink_GetAnnotRect(linkAnnot, &rect);
+ FPDF_ACTION action = FPDFLink_GetAction(linkAnnot);
+ if (action && PDFACTION_URI == FPDFAction_GetType(action)) {
+ auto len = FPDFAction_GetURIPath(doc, action, nullptr, 0);
Lei Zhang 2016/05/23 16:47:33 write out unsigned int instead of using auto?
+ std::vector<char> buffer(len);
+ (void)FPDFAction_GetURIPath(doc, action, &buffer[0], buffer.size());
+ printf(" <%g,%g,%g,%g> uri: \"%.*s\"\n", rect.left, rect.top,
Lei Zhang 2016/05/23 16:47:32 I see 5 conversion specifiers and 6 variables.
+ rect.right, rect.bottom, (int)buffer.size(), &buffer[0]);
Lei Zhang 2016/05/23 16:47:33 Borrow PRIuS from base/format_macros.h for size_t
+ } else if (FPDF_DEST dest = FPDFLink_GetDest(doc, linkAnnot)) {
+ unsigned long dest_page = FPDFDest_GetPageIndex(doc, dest);
+ FS_FLOAT x = 0.0f;
+ FS_FLOAT y = 0.0f;
+ (void)FPDFDest_GetLocationInPage(dest, &x, &y);
+ printf(" <%g,%g,%g,%g> page: %lu; point: (%g,%g)\n", rect.left,
+ rect.top, rect.right, rect.bottom, dest_page, x, y);
+ }
+ }
+ FPDF_ClosePage(page);
+ printf("\n");
+}
+
bool RenderPage(const std::string& name,
const FPDF_DOCUMENT& doc,
const FPDF_FORMHANDLE& form,
@@ -696,6 +736,9 @@ void RenderPdf(const std::string& name,
} else {
++bad_pages;
}
+ if (options.show_annotations) {
+ ShowAnnotations(doc, i);
+ }
}
FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC);
@@ -741,11 +784,13 @@ static void ShowConfig() {
static const char usage_string[] =
"Usage: pdfium_test [OPTION] [FILE]...\n"
- " --show-config - print build options and exit\n"
- " --send-events - send input described by .evt file\n"
- " --bin-dir=<path> - override path to v8 external data\n"
- " --font-dir=<path> - override path to external fonts\n"
- " --scale=<number> - scale output size by number (e.g. 0.5)\n"
+ " --show-config - print build options and exit\n"
+ " --send-events - send input described by .evt file\n"
+ " --bin-dir=<path> - override path to v8 external data\n"
+ " --font-dir=<path> - override path to external fonts\n"
+ " --show-annotations - print information about URL and internal\n"
+ " link annotations in the document.\n"
+ " --scale=<number> - scale output size by number (e.g. 0.5)\n"
#ifdef _WIN32
" --bmp - write page images <pdf-name>.<page-number>.bmp\n"
" --emf - write page meta files <pdf-name>.<page-number>.emf\n"
« public/fpdf_doc.h ('K') | « public/fpdf_doc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698