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

Side by Side Diff: samples/pdfium_test.cc

Issue 1946873004: Fix event sending in pdfium_test. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Same thing in test_runner.py 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
« no previous file with comments | « no previous file | testing/tools/run_corpus_tests.py » ('j') | 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>
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 const std::string& events) { 491 const std::string& events) {
492 FPDF_PAGE page = FPDF_LoadPage(doc, page_index); 492 FPDF_PAGE page = FPDF_LoadPage(doc, page_index);
493 if (!page) { 493 if (!page) {
494 return false; 494 return false;
495 } 495 }
496 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page); 496 FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
497 FORM_OnAfterLoadPage(page, form); 497 FORM_OnAfterLoadPage(page, form);
498 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN); 498 FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN);
499 499
500 if (options.send_events) 500 if (options.send_events)
501 SendPageEvents(doc, form, events); 501 SendPageEvents(form, page, events);
502 502
503 double scale = 1.0; 503 double scale = 1.0;
504 if (!options.scale_factor_as_string.empty()) { 504 if (!options.scale_factor_as_string.empty()) {
505 std::stringstream(options.scale_factor_as_string) >> scale; 505 std::stringstream(options.scale_factor_as_string) >> scale;
506 } 506 }
507 int width = static_cast<int>(FPDF_GetPageWidth(page) * scale); 507 int width = static_cast<int>(FPDF_GetPageWidth(page) * scale);
508 int height = static_cast<int>(FPDF_GetPageHeight(page) * scale); 508 int height = static_cast<int>(FPDF_GetPageHeight(page) * scale);
509 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; 509 int alpha = FPDFPage_HasTransparency(page) ? 1 : 0;
510 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); 510 FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha);
511 if (!bitmap) { 511 if (!bitmap) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 FPDFText_ClosePage(text_page); 557 FPDFText_ClosePage(text_page);
558 FPDF_ClosePage(page); 558 FPDF_ClosePage(page);
559 return true; 559 return true;
560 } 560 }
561 561
562 void RenderPdf(const std::string& name, 562 void RenderPdf(const std::string& name,
563 const char* pBuf, 563 const char* pBuf,
564 size_t len, 564 size_t len,
565 const Options& options, 565 const Options& options,
566 const std::string& events) { 566 const std::string& events) {
567 fprintf(stderr, "Rendering PDF file %s.\n", name.c_str());
568
569 IPDF_JSPLATFORM platform_callbacks; 567 IPDF_JSPLATFORM platform_callbacks;
570 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); 568 memset(&platform_callbacks, '\0', sizeof(platform_callbacks));
571 platform_callbacks.version = 3; 569 platform_callbacks.version = 3;
572 platform_callbacks.app_alert = ExampleAppAlert; 570 platform_callbacks.app_alert = ExampleAppAlert;
573 platform_callbacks.app_response = ExampleAppResponse; 571 platform_callbacks.app_response = ExampleAppResponse;
574 platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; 572 platform_callbacks.Doc_gotoPage = ExampleDocGotoPage;
575 platform_callbacks.Doc_mail = ExampleDocMail; 573 platform_callbacks.Doc_mail = ExampleDocMail;
576 574
577 FPDF_FORMFILLINFO form_callbacks; 575 FPDF_FORMFILLINFO form_callbacks;
578 memset(&form_callbacks, '\0', sizeof(form_callbacks)); 576 memset(&form_callbacks, '\0', sizeof(form_callbacks));
(...skipping 20 matching lines...) Expand all
599 memset(&hints, '\0', sizeof(hints)); 597 memset(&hints, '\0', sizeof(hints));
600 hints.version = 1; 598 hints.version = 1;
601 hints.AddSegment = Add_Segment; 599 hints.AddSegment = Add_Segment;
602 600
603 FPDF_DOCUMENT doc; 601 FPDF_DOCUMENT doc;
604 int nRet = PDF_DATA_NOTAVAIL; 602 int nRet = PDF_DATA_NOTAVAIL;
605 bool bIsLinearized = false; 603 bool bIsLinearized = false;
606 FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); 604 FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access);
607 605
608 if (FPDFAvail_IsLinearized(pdf_avail) == PDF_LINEARIZED) { 606 if (FPDFAvail_IsLinearized(pdf_avail) == PDF_LINEARIZED) {
609 fprintf(stderr, "Linearized path...\n");
610 doc = FPDFAvail_GetDocument(pdf_avail, nullptr); 607 doc = FPDFAvail_GetDocument(pdf_avail, nullptr);
611 if (doc) { 608 if (doc) {
612 while (nRet == PDF_DATA_NOTAVAIL) { 609 while (nRet == PDF_DATA_NOTAVAIL) {
613 nRet = FPDFAvail_IsDocAvail(pdf_avail, &hints); 610 nRet = FPDFAvail_IsDocAvail(pdf_avail, &hints);
614 } 611 }
615 if (nRet == PDF_DATA_ERROR) { 612 if (nRet == PDF_DATA_ERROR) {
616 fprintf(stderr, "Unknown error in checking if doc was available.\n"); 613 fprintf(stderr, "Unknown error in checking if doc was available.\n");
617 return; 614 return;
618 } 615 }
619 nRet = FPDFAvail_IsFormAvail(pdf_avail, &hints); 616 nRet = FPDFAvail_IsFormAvail(pdf_avail, &hints);
620 if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) { 617 if (nRet == PDF_FORM_ERROR || nRet == PDF_FORM_NOTAVAIL) {
621 fprintf(stderr, 618 fprintf(stderr,
622 "Error %d was returned in checking if form was available.\n", 619 "Error %d was returned in checking if form was available.\n",
623 nRet); 620 nRet);
624 return; 621 return;
625 } 622 }
626 bIsLinearized = true; 623 bIsLinearized = true;
627 } 624 }
628 } else { 625 } else {
629 fprintf(stderr, "Non-linearized path...\n");
630 doc = FPDF_LoadCustomDocument(&file_access, nullptr); 626 doc = FPDF_LoadCustomDocument(&file_access, nullptr);
631 } 627 }
632 628
633 if (!doc) { 629 if (!doc) {
634 unsigned long err = FPDF_GetLastError(); 630 unsigned long err = FPDF_GetLastError();
635 fprintf(stderr, "Load pdf docs unsuccessful: "); 631 fprintf(stderr, "Load pdf docs unsuccessful: ");
636 switch (err) { 632 switch (err) {
637 case FPDF_ERR_SUCCESS: 633 case FPDF_ERR_SUCCESS:
638 fprintf(stderr, "Success"); 634 fprintf(stderr, "Success");
639 break; 635 break;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 FPDF_CloseDocument(doc); 707 FPDF_CloseDocument(doc);
712 FPDFDOC_ExitFormFillEnvironment(form); 708 FPDFDOC_ExitFormFillEnvironment(form);
713 #else // PDF_ENABLE_XFA 709 #else // PDF_ENABLE_XFA
714 FPDFDOC_ExitFormFillEnvironment(form); 710 FPDFDOC_ExitFormFillEnvironment(form);
715 FPDF_CloseDocument(doc); 711 FPDF_CloseDocument(doc);
716 #endif // PDF_ENABLE_XFA 712 #endif // PDF_ENABLE_XFA
717 713
718 FPDFAvail_Destroy(pdf_avail); 714 FPDFAvail_Destroy(pdf_avail);
719 715
720 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); 716 fprintf(stderr, "Rendered %d pages.\n", rendered_pages);
721 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); 717 if (bad_pages)
718 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages);
722 } 719 }
723 720
724 static void ShowConfig() { 721 static void ShowConfig() {
725 std::string config; 722 std::string config;
726 std::string maybe_comma; 723 std::string maybe_comma;
727 #if PDF_ENABLE_V8 724 #if PDF_ENABLE_V8
728 config.append(maybe_comma); 725 config.append(maybe_comma);
729 config.append("V8"); 726 config.append("V8");
730 maybe_comma = ","; 727 maybe_comma = ",";
731 #endif // PDF_ENABLE_V8 728 #endif // PDF_ENABLE_V8
732 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 729 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
733 config.append(maybe_comma); 730 config.append(maybe_comma);
734 config.append("V8_EXTERNAL"); 731 config.append("V8_EXTERNAL");
735 maybe_comma = ","; 732 maybe_comma = ",";
736 #endif // V8_USE_EXTERNAL_STARTUP_DATA 733 #endif // V8_USE_EXTERNAL_STARTUP_DATA
737 #ifdef PDF_ENABLE_XFA 734 #ifdef PDF_ENABLE_XFA
738 config.append(maybe_comma); 735 config.append(maybe_comma);
739 config.append("XFA"); 736 config.append("XFA");
740 maybe_comma = ","; 737 maybe_comma = ",";
741 #endif // PDF_ENABLE_XFA 738 #endif // PDF_ENABLE_XFA
742 printf("%s\n", config.c_str()); 739 printf("%s\n", config.c_str());
743 } 740 }
744 741
745 static const char usage_string[] = 742 static const char usage_string[] =
746 "Usage: pdfium_test [OPTION] [FILE]...\n" 743 "Usage: pdfium_test [OPTION] [FILE]...\n"
747 " --show-config - print build options and exit\n" 744 " --show-config - print build options and exit\n"
745 " --send-events - send input described by .evt file\n"
748 " --bin-dir=<path> - override path to v8 external data\n" 746 " --bin-dir=<path> - override path to v8 external data\n"
749 " --font-dir=<path> - override path to external fonts\n" 747 " --font-dir=<path> - override path to external fonts\n"
750 " --scale=<number> - scale output size by number (e.g. 0.5)\n" 748 " --scale=<number> - scale output size by number (e.g. 0.5)\n"
751 #ifdef _WIN32 749 #ifdef _WIN32
752 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" 750 " --bmp - write page images <pdf-name>.<page-number>.bmp\n"
753 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" 751 " --emf - write page meta files <pdf-name>.<page-number>.emf\n"
754 #endif // _WIN32 752 #endif // _WIN32
755 " --png - write page images <pdf-name>.<page-number>.png\n" 753 " --png - write page images <pdf-name>.<page-number>.png\n"
756 #ifdef PDF_ENABLE_SKIA 754 #ifdef PDF_ENABLE_SKIA
757 " --skp - write page images <pdf-name>.<page-number>.skp\n" 755 " --skp - write page images <pdf-name>.<page-number>.skp\n"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); 809 FSDK_SetUnSpObjProcessHandler(&unsuppored_info);
812 810
813 while (!files.empty()) { 811 while (!files.empty()) {
814 std::string filename = files.front(); 812 std::string filename = files.front();
815 files.pop_front(); 813 files.pop_front();
816 size_t file_length = 0; 814 size_t file_length = 0;
817 std::unique_ptr<char, pdfium::FreeDeleter> file_contents = 815 std::unique_ptr<char, pdfium::FreeDeleter> file_contents =
818 GetFileContents(filename.c_str(), &file_length); 816 GetFileContents(filename.c_str(), &file_length);
819 if (!file_contents) 817 if (!file_contents)
820 continue; 818 continue;
819 fprintf(stderr, "Rendering PDF file %s.\n", filename.c_str());
821 std::string events; 820 std::string events;
822 if (options.send_events) { 821 if (options.send_events) {
823 std::string event_filename = filename; 822 std::string event_filename = filename;
824 size_t event_length = 0; 823 size_t event_length = 0;
825 size_t extension_pos = event_filename.find(".pdf"); 824 size_t extension_pos = event_filename.find(".pdf");
826 if (extension_pos != std::string::npos) { 825 if (extension_pos != std::string::npos) {
827 event_filename.replace(extension_pos, 4, ".evt"); 826 event_filename.replace(extension_pos, 4, ".evt");
828 std::unique_ptr<char, pdfium::FreeDeleter> event_contents = 827 std::unique_ptr<char, pdfium::FreeDeleter> event_contents =
829 GetFileContents(event_filename.c_str(), &event_length); 828 GetFileContents(event_filename.c_str(), &event_length);
830 if (event_contents) { 829 if (event_contents) {
830 fprintf(stderr, "Sending events from: %s\n", event_filename.c_str());
831 events = std::string(event_contents.get(), event_length); 831 events = std::string(event_contents.get(), event_length);
832 } else {
833 fprintf(stderr, "Warning: no event file: %s\n",
834 event_filename.c_str());
835 } 832 }
836 } 833 }
837 } 834 }
838 RenderPdf(filename, file_contents.get(), file_length, options, events); 835 RenderPdf(filename, file_contents.get(), file_length, options, events);
839 } 836 }
840 837
841 FPDF_DestroyLibrary(); 838 FPDF_DestroyLibrary();
842 #ifdef PDF_ENABLE_V8 839 #ifdef PDF_ENABLE_V8
843 v8::V8::ShutdownPlatform(); 840 v8::V8::ShutdownPlatform();
844 delete platform; 841 delete platform;
845 #endif // PDF_ENABLE_V8 842 #endif // PDF_ENABLE_V8
846 843
847 return 0; 844 return 0;
848 } 845 }
OLDNEW
« no previous file with comments | « no previous file | testing/tools/run_corpus_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698