OLD | NEW |
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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 fprintf(stderr, "Rendering PDF file %s.\n", name.c_str()); | 400 fprintf(stderr, "Rendering PDF file %s.\n", name.c_str()); |
401 | 401 |
402 IPDF_JSPLATFORM platform_callbacks; | 402 IPDF_JSPLATFORM platform_callbacks; |
403 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); | 403 memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); |
404 platform_callbacks.version = 3; | 404 platform_callbacks.version = 3; |
405 platform_callbacks.app_alert = ExampleAppAlert; | 405 platform_callbacks.app_alert = ExampleAppAlert; |
406 platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; | 406 platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; |
407 | 407 |
408 FPDF_FORMFILLINFO form_callbacks; | 408 FPDF_FORMFILLINFO form_callbacks; |
409 memset(&form_callbacks, '\0', sizeof(form_callbacks)); | 409 memset(&form_callbacks, '\0', sizeof(form_callbacks)); |
| 410 #ifdef PDF_ENABLE_XFA |
410 form_callbacks.version = 2; | 411 form_callbacks.version = 2; |
| 412 #else // PDF_ENABLE_XFA |
| 413 form_callbacks.version = 1; |
| 414 #endif // PDF_ENABLE_XFA |
411 form_callbacks.m_pJsPlatform = &platform_callbacks; | 415 form_callbacks.m_pJsPlatform = &platform_callbacks; |
412 | 416 |
413 TestLoader loader(pBuf, len); | 417 TestLoader loader(pBuf, len); |
414 FPDF_FILEACCESS file_access; | 418 FPDF_FILEACCESS file_access; |
415 memset(&file_access, '\0', sizeof(file_access)); | 419 memset(&file_access, '\0', sizeof(file_access)); |
416 file_access.m_FileLen = static_cast<unsigned long>(len); | 420 file_access.m_FileLen = static_cast<unsigned long>(len); |
417 file_access.m_GetBlock = TestLoader::GetBlock; | 421 file_access.m_GetBlock = TestLoader::GetBlock; |
418 file_access.m_Param = &loader; | 422 file_access.m_Param = &loader; |
419 | 423 |
420 FX_FILEAVAIL file_avail; | 424 FX_FILEAVAIL file_avail; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 } | 491 } |
488 fprintf(stderr, ".\n"); | 492 fprintf(stderr, ".\n"); |
489 | 493 |
490 FPDFAvail_Destroy(pdf_avail); | 494 FPDFAvail_Destroy(pdf_avail); |
491 return; | 495 return; |
492 } | 496 } |
493 | 497 |
494 (void)FPDF_GetDocPermissions(doc); | 498 (void)FPDF_GetDocPermissions(doc); |
495 | 499 |
496 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); | 500 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); |
| 501 #ifdef PDF_ENABLE_XFA |
497 int docType = DOCTYPE_PDF; | 502 int docType = DOCTYPE_PDF; |
498 if (FPDF_HasXFAField(doc, &docType) && docType != DOCTYPE_PDF && | 503 if (FPDF_HasXFAField(doc, &docType) && docType != DOCTYPE_PDF && |
499 !FPDF_LoadXFA(doc)) { | 504 !FPDF_LoadXFA(doc)) { |
500 fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n"); | 505 fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n"); |
501 } | 506 } |
| 507 #endif // PDF_ENABLE_XFA |
502 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); | 508 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); |
503 FPDF_SetFormFieldHighlightAlpha(form, 100); | 509 FPDF_SetFormFieldHighlightAlpha(form, 100); |
504 | 510 |
505 FORM_DoDocumentJSAction(form); | 511 FORM_DoDocumentJSAction(form); |
506 FORM_DoDocumentOpenAction(form); | 512 FORM_DoDocumentOpenAction(form); |
507 | 513 |
508 int page_count = FPDF_GetPageCount(doc); | 514 int page_count = FPDF_GetPageCount(doc); |
509 int rendered_pages = 0; | 515 int rendered_pages = 0; |
510 int bad_pages = 0; | 516 int bad_pages = 0; |
511 for (int i = 0; i < page_count; ++i) { | 517 for (int i = 0; i < page_count; ++i) { |
(...skipping 10 matching lines...) Expand all Loading... |
522 } | 528 } |
523 if (RenderPage(name, doc, form, i, options)) { | 529 if (RenderPage(name, doc, form, i, options)) { |
524 ++rendered_pages; | 530 ++rendered_pages; |
525 } else { | 531 } else { |
526 ++bad_pages; | 532 ++bad_pages; |
527 } | 533 } |
528 } | 534 } |
529 | 535 |
530 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); | 536 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); |
531 | 537 |
| 538 #ifdef PDF_ENABLE_XFA |
532 // Note: The shut down order here is the reverse of the non-XFA branch order. | 539 // Note: The shut down order here is the reverse of the non-XFA branch order. |
533 // Need to work out if this is required, and if it is, the lifetimes of | 540 // Need to work out if this is required, and if it is, the lifetimes of |
534 // objects owned by |doc| that |form| reference. | 541 // objects owned by |doc| that |form| reference. |
535 FPDF_CloseDocument(doc); | 542 FPDF_CloseDocument(doc); |
536 FPDFDOC_ExitFormFillEnvironment(form); | 543 FPDFDOC_ExitFormFillEnvironment(form); |
| 544 #else // PDF_ENABLE_XFA |
| 545 FPDFDOC_ExitFormFillEnvironment(form); |
| 546 FPDF_CloseDocument(doc); |
| 547 #endif // PDF_ENABLE_XFA |
537 | 548 |
538 FPDFAvail_Destroy(pdf_avail); | 549 FPDFAvail_Destroy(pdf_avail); |
539 | 550 |
540 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); | 551 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); |
541 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); | 552 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); |
542 } | 553 } |
543 | 554 |
544 static const char usage_string[] = | 555 static const char usage_string[] = |
545 "Usage: pdfium_test [OPTION] [FILE]...\n" | 556 "Usage: pdfium_test [OPTION] [FILE]...\n" |
546 " --bin-dir=<path> - override path to v8 external data\n" | 557 " --bin-dir=<path> - override path to v8 external data\n" |
547 " --font-dir=<path> - override path to external fonts\n" | 558 " --font-dir=<path> - override path to external fonts\n" |
548 " --scale=<number> - scale output size by number (e.g. 0.5)\n" | 559 " --scale=<number> - scale output size by number (e.g. 0.5)\n" |
549 #ifdef _WIN32 | 560 #ifdef _WIN32 |
550 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" | 561 " --bmp - write page images <pdf-name>.<page-number>.bmp\n" |
551 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" | 562 " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
552 #endif | 563 #endif // _WIN32 |
553 " --png - write page images <pdf-name>.<page-number>.png\n" | 564 " --png - write page images <pdf-name>.<page-number>.png\n" |
554 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; | 565 " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; |
555 | 566 |
556 int main(int argc, const char* argv[]) { | 567 int main(int argc, const char* argv[]) { |
557 std::vector<std::string> args(argv, argv + argc); | 568 std::vector<std::string> args(argv, argv + argc); |
558 Options options; | 569 Options options; |
559 std::list<std::string> files; | 570 std::list<std::string> files; |
560 if (!ParseCommandLine(args, &options, &files)) { | 571 if (!ParseCommandLine(args, &options, &files)) { |
561 fprintf(stderr, "%s", usage_string); | 572 fprintf(stderr, "%s", usage_string); |
562 return 1; | 573 return 1; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 } | 618 } |
608 | 619 |
609 FPDF_DestroyLibrary(); | 620 FPDF_DestroyLibrary(); |
610 #ifdef PDF_ENABLE_V8 | 621 #ifdef PDF_ENABLE_V8 |
611 v8::V8::ShutdownPlatform(); | 622 v8::V8::ShutdownPlatform(); |
612 delete platform; | 623 delete platform; |
613 #endif // PDF_ENABLE_V8 | 624 #endif // PDF_ENABLE_V8 |
614 | 625 |
615 return 0; | 626 return 0; |
616 } | 627 } |
OLD | NEW |