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

Side by Side 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 unified diff | Download patch
« public/fpdf_doc.h ('K') | « public/fpdf_doc.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits.h> 5 #include <limits.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <list> 10 #include <list>
11 #include <sstream> 11 #include <sstream>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #if defined PDF_ENABLE_SKIA && !defined _SKIA_SUPPORT_ 16 #if defined PDF_ENABLE_SKIA && !defined _SKIA_SUPPORT_
17 #define _SKIA_SUPPORT_ 17 #define _SKIA_SUPPORT_
18 #endif 18 #endif
19 19
20 #include "public/fpdf_dataavail.h" 20 #include "public/fpdf_dataavail.h"
21 #include "public/fpdf_doc.h"
21 #include "public/fpdf_edit.h" 22 #include "public/fpdf_edit.h"
22 #include "public/fpdf_ext.h" 23 #include "public/fpdf_ext.h"
23 #include "public/fpdf_formfill.h" 24 #include "public/fpdf_formfill.h"
24 #include "public/fpdf_text.h" 25 #include "public/fpdf_text.h"
25 #include "public/fpdfview.h" 26 #include "public/fpdfview.h"
26 #include "samples/image_diff_png.h" 27 #include "samples/image_diff_png.h"
27 #include "testing/test_support.h" 28 #include "testing/test_support.h"
28 29
29 #ifdef PDF_ENABLE_V8 30 #ifdef PDF_ENABLE_V8
30 #include "v8/include/libplatform/libplatform.h" 31 #include "v8/include/libplatform/libplatform.h"
(...skipping 17 matching lines...) Expand all
48 OUTPUT_BMP, 49 OUTPUT_BMP,
49 OUTPUT_EMF, 50 OUTPUT_EMF,
50 #endif 51 #endif
51 #ifdef PDF_ENABLE_SKIA 52 #ifdef PDF_ENABLE_SKIA
52 OUTPUT_SKP, 53 OUTPUT_SKP,
53 #endif 54 #endif
54 }; 55 };
55 56
56 struct Options { 57 struct Options {
57 Options() 58 Options()
58 : show_config(false), send_events(false), output_format(OUTPUT_NONE) {} 59 : show_config(false),
60 send_events(false),
61 show_annotations(false),
62 output_format(OUTPUT_NONE) {}
59 63
60 bool show_config; 64 bool show_config;
61 bool send_events; 65 bool send_events;
66 bool show_annotations;
62 OutputFormat output_format; 67 OutputFormat output_format;
63 std::string scale_factor_as_string; 68 std::string scale_factor_as_string;
64 std::string exe_path; 69 std::string exe_path;
65 std::string bin_directory; 70 std::string bin_directory;
66 std::string font_directory; 71 std::string font_directory;
67 }; 72 };
68 73
69 static bool CheckDimensions(int stride, int width, int height) { 74 static bool CheckDimensions(int stride, int width, int height) {
70 if (stride < 0 || width < 0 || height < 0) 75 if (stride < 0 || width < 0 || height < 0)
71 return false; 76 return false;
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 return false; 340 return false;
336 } 341 }
337 options->exe_path = args[0]; 342 options->exe_path = args[0];
338 size_t cur_idx = 1; 343 size_t cur_idx = 1;
339 for (; cur_idx < args.size(); ++cur_idx) { 344 for (; cur_idx < args.size(); ++cur_idx) {
340 const std::string& cur_arg = args[cur_idx]; 345 const std::string& cur_arg = args[cur_idx];
341 if (cur_arg == "--show-config") { 346 if (cur_arg == "--show-config") {
342 options->show_config = true; 347 options->show_config = true;
343 } else if (cur_arg == "--send-events") { 348 } else if (cur_arg == "--send-events") {
344 options->send_events = true; 349 options->send_events = true;
350 } else if (cur_arg == "--show-annotations") {
351 options->show_annotations = true;
345 } else if (cur_arg == "--ppm") { 352 } else if (cur_arg == "--ppm") {
346 if (options->output_format != OUTPUT_NONE) { 353 if (options->output_format != OUTPUT_NONE) {
347 fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); 354 fprintf(stderr, "Duplicate or conflicting --ppm argument\n");
348 return false; 355 return false;
349 } 356 }
350 options->output_format = OUTPUT_PPM; 357 options->output_format = OUTPUT_PPM;
351 } else if (cur_arg == "--png") { 358 } else if (cur_arg == "--png") {
352 if (options->output_format != OUTPUT_NONE) { 359 if (options->output_format != OUTPUT_NONE) {
353 fprintf(stderr, "Duplicate or conflicting --png argument\n"); 360 fprintf(stderr, "Duplicate or conflicting --png argument\n");
354 return false; 361 return false;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 FORM_OnMouseMove(form, page, 0, x, y); 483 FORM_OnMouseMove(form, page, 0, x, y);
477 } else { 484 } else {
478 fprintf(stderr, "mousemove: bad args\n"); 485 fprintf(stderr, "mousemove: bad args\n");
479 } 486 }
480 } else { 487 } else {
481 fprintf(stderr, "Unrecognized event: %s\n", tokens[0].c_str()); 488 fprintf(stderr, "Unrecognized event: %s\n", tokens[0].c_str());
482 } 489 }
483 } 490 }
484 } 491 }
485 492
493 void ShowAnnotations(const FPDF_DOCUMENT& doc, const int page_index) {
494 FPDF_PAGE page = FPDF_LoadPage(doc, page_index);
Lei Zhang 2016/05/23 16:47:33 Why not put the ShowAnnotations() call inside Rend
495 if (!page) {
496 fprintf(stderr, "bad page %d\n", page_index);
497 return;
498 }
499 printf("page %d [%g,%g]:\n", page_index, FPDF_GetPageWidth(page),
500 FPDF_GetPageHeight(page));
501 int startPos = 0;
502 FPDF_LINK linkAnnot;
503 while (FPDFLink_Enumerate(page, &startPos, &linkAnnot)) {
504 FS_RECTF rect = {0.0f, 0.0f, 0.0f, 0.0f};
505 (void)FPDFLink_GetAnnotRect(linkAnnot, &rect);
506 FPDF_ACTION action = FPDFLink_GetAction(linkAnnot);
507 if (action && PDFACTION_URI == FPDFAction_GetType(action)) {
508 auto len = FPDFAction_GetURIPath(doc, action, nullptr, 0);
Lei Zhang 2016/05/23 16:47:33 write out unsigned int instead of using auto?
509 std::vector<char> buffer(len);
510 (void)FPDFAction_GetURIPath(doc, action, &buffer[0], buffer.size());
511 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.
512 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
513 } else if (FPDF_DEST dest = FPDFLink_GetDest(doc, linkAnnot)) {
514 unsigned long dest_page = FPDFDest_GetPageIndex(doc, dest);
515 FS_FLOAT x = 0.0f;
516 FS_FLOAT y = 0.0f;
517 (void)FPDFDest_GetLocationInPage(dest, &x, &y);
518 printf(" <%g,%g,%g,%g> page: %lu; point: (%g,%g)\n", rect.left,
519 rect.top, rect.right, rect.bottom, dest_page, x, y);
520 }
521 }
522 FPDF_ClosePage(page);
523 printf("\n");
524 }
525
486 bool RenderPage(const std::string& name, 526 bool RenderPage(const std::string& name,
487 const FPDF_DOCUMENT& doc, 527 const FPDF_DOCUMENT& doc,
488 const FPDF_FORMHANDLE& form, 528 const FPDF_FORMHANDLE& form,
489 const int page_index, 529 const int page_index,
490 const Options& options, 530 const Options& options,
491 const std::string& events) { 531 const std::string& events) {
492 FPDF_PAGE page = FPDF_LoadPage(doc, page_index); 532 FPDF_PAGE page = FPDF_LoadPage(doc, page_index);
493 if (!page) { 533 if (!page) {
494 return false; 534 return false;
495 } 535 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 fprintf(stderr, "Unknown error in checking if page %d is available.\n", 729 fprintf(stderr, "Unknown error in checking if page %d is available.\n",
690 i); 730 i);
691 return; 731 return;
692 } 732 }
693 } 733 }
694 if (RenderPage(name, doc, form, i, options, events)) { 734 if (RenderPage(name, doc, form, i, options, events)) {
695 ++rendered_pages; 735 ++rendered_pages;
696 } else { 736 } else {
697 ++bad_pages; 737 ++bad_pages;
698 } 738 }
739 if (options.show_annotations) {
740 ShowAnnotations(doc, i);
741 }
699 } 742 }
700 743
701 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); 744 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC);
702 745
703 #ifdef PDF_ENABLE_XFA 746 #ifdef PDF_ENABLE_XFA
704 // Note: The shut down order here is the reverse of the non-XFA branch order. 747 // Note: The shut down order here is the reverse of the non-XFA branch order.
705 // Need to work out if this is required, and if it is, the lifetimes of 748 // Need to work out if this is required, and if it is, the lifetimes of
706 // objects owned by |doc| that |form| reference. 749 // objects owned by |doc| that |form| reference.
707 FPDF_CloseDocument(doc); 750 FPDF_CloseDocument(doc);
708 FPDFDOC_ExitFormFillEnvironment(form); 751 FPDFDOC_ExitFormFillEnvironment(form);
(...skipping 25 matching lines...) Expand all
734 #ifdef PDF_ENABLE_XFA 777 #ifdef PDF_ENABLE_XFA
735 config.append(maybe_comma); 778 config.append(maybe_comma);
736 config.append("XFA"); 779 config.append("XFA");
737 maybe_comma = ","; 780 maybe_comma = ",";
738 #endif // PDF_ENABLE_XFA 781 #endif // PDF_ENABLE_XFA
739 printf("%s\n", config.c_str()); 782 printf("%s\n", config.c_str());
740 } 783 }
741 784
742 static const char usage_string[] = 785 static const char usage_string[] =
743 "Usage: pdfium_test [OPTION] [FILE]...\n" 786 "Usage: pdfium_test [OPTION] [FILE]...\n"
744 " --show-config - print build options and exit\n" 787 " --show-config - print build options and exit\n"
745 " --send-events - send input described by .evt file\n" 788 " --send-events - send input described by .evt file\n"
746 " --bin-dir=<path> - override path to v8 external data\n" 789 " --bin-dir=<path> - override path to v8 external data\n"
747 " --font-dir=<path> - override path to external fonts\n" 790 " --font-dir=<path> - override path to external fonts\n"
748 " --scale=<number> - scale output size by number (e.g. 0.5)\n" 791 " --show-annotations - print information about URL and internal\n"
792 " link annotations in the document.\n"
793 " --scale=<number> - scale output size by number (e.g. 0.5)\n"
749 #ifdef _WIN32 794 #ifdef _WIN32
750 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" 795 " --bmp - write page images <pdf-name>.<page-number>.bmp\n"
751 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" 796 " --emf - write page meta files <pdf-name>.<page-number>.emf\n"
752 #endif // _WIN32 797 #endif // _WIN32
753 " --png - write page images <pdf-name>.<page-number>.png\n" 798 " --png - write page images <pdf-name>.<page-number>.png\n"
754 #ifdef PDF_ENABLE_SKIA 799 #ifdef PDF_ENABLE_SKIA
755 " --skp - write page images <pdf-name>.<page-number>.skp\n" 800 " --skp - write page images <pdf-name>.<page-number>.skp\n"
756 #endif 801 #endif
757 ""; 802 "";
758 803
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 } 881 }
837 882
838 FPDF_DestroyLibrary(); 883 FPDF_DestroyLibrary();
839 #ifdef PDF_ENABLE_V8 884 #ifdef PDF_ENABLE_V8
840 v8::V8::ShutdownPlatform(); 885 v8::V8::ShutdownPlatform();
841 delete platform; 886 delete platform;
842 #endif // PDF_ENABLE_V8 887 #endif // PDF_ENABLE_V8
843 888
844 return 0; 889 return 0;
845 } 890 }
OLDNEW
« 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