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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 FX_DOWNLOADHINTS hints; | 462 FX_DOWNLOADHINTS hints; |
463 memset(&hints, '\0', sizeof(hints)); | 463 memset(&hints, '\0', sizeof(hints)); |
464 hints.version = 1; | 464 hints.version = 1; |
465 hints.AddSegment = Add_Segment; | 465 hints.AddSegment = Add_Segment; |
466 | 466 |
467 FPDF_DOCUMENT doc; | 467 FPDF_DOCUMENT doc; |
468 FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); | 468 FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access); |
469 | 469 |
470 (void)FPDFAvail_IsDocAvail(pdf_avail, &hints); | 470 (void)FPDFAvail_IsDocAvail(pdf_avail, &hints); |
471 | 471 |
472 if (!FPDFAvail_IsLinearized(pdf_avail)) { | 472 if (FPDFAvail_IsLinearized(pdf_avail)) { |
| 473 fprintf(stderr, "Linearized path...\n"); |
| 474 doc = FPDFAvail_GetDocument(pdf_avail, nullptr); |
| 475 } else { |
473 fprintf(stderr, "Non-linearized path...\n"); | 476 fprintf(stderr, "Non-linearized path...\n"); |
474 doc = FPDF_LoadCustomDocument(&file_access, nullptr); | 477 doc = FPDF_LoadCustomDocument(&file_access, nullptr); |
475 } else { | 478 } |
476 fprintf(stderr, "Linearized path...\n"); | 479 |
477 doc = FPDFAvail_GetDocument(pdf_avail, nullptr); | 480 if (!doc) { |
| 481 fprintf(stderr, "Load pdf docs unsuccessful.\n"); |
| 482 return; |
478 } | 483 } |
479 | 484 |
480 (void)FPDF_GetDocPermissions(doc); | 485 (void)FPDF_GetDocPermissions(doc); |
481 (void)FPDFAvail_IsFormAvail(pdf_avail, &hints); | 486 (void)FPDFAvail_IsFormAvail(pdf_avail, &hints); |
482 | 487 |
483 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); | 488 FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks); |
484 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); | 489 FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD); |
485 FPDF_SetFormFieldHighlightAlpha(form, 100); | 490 FPDF_SetFormFieldHighlightAlpha(form, 100); |
486 | 491 |
487 int first_page = FPDFAvail_GetFirstPageNum(doc); | 492 int first_page = FPDFAvail_GetFirstPageNum(doc); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 v8::StartupData natives; | 609 v8::StartupData natives; |
605 v8::StartupData snapshot; | 610 v8::StartupData snapshot; |
606 if (!GetExternalData(options, "natives_blob.bin", &natives) || | 611 if (!GetExternalData(options, "natives_blob.bin", &natives) || |
607 !GetExternalData(options, "snapshot_blob.bin", &snapshot)) { | 612 !GetExternalData(options, "snapshot_blob.bin", &snapshot)) { |
608 return 1; | 613 return 1; |
609 } | 614 } |
610 v8::V8::SetNativesDataBlob(&natives); | 615 v8::V8::SetNativesDataBlob(&natives); |
611 v8::V8::SetSnapshotDataBlob(&snapshot); | 616 v8::V8::SetSnapshotDataBlob(&snapshot); |
612 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 617 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
613 | 618 |
614 if (!options.font_directory.empty()) { | 619 if (options.font_directory.empty()) { |
| 620 FPDF_InitLibrary(); |
| 621 } else { |
615 const char* path_array[2]; | 622 const char* path_array[2]; |
616 path_array[0] = options.font_directory.c_str(); | 623 path_array[0] = options.font_directory.c_str(); |
617 path_array[1] = nullptr; | 624 path_array[1] = nullptr; |
618 FPDF_LIBRARY_CONFIG config; | 625 FPDF_LIBRARY_CONFIG config; |
619 config.version = 1; | 626 config.version = 1; |
620 config.m_pUserFontPaths = path_array; | 627 config.m_pUserFontPaths = path_array; |
621 FPDF_InitLibraryWithConfig(&config); | 628 FPDF_InitLibraryWithConfig(&config); |
622 } else { | |
623 FPDF_InitLibrary(); | |
624 } | 629 } |
625 | 630 |
626 UNSUPPORT_INFO unsuppored_info; | 631 UNSUPPORT_INFO unsuppored_info; |
627 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); | 632 memset(&unsuppored_info, '\0', sizeof(unsuppored_info)); |
628 unsuppored_info.version = 1; | 633 unsuppored_info.version = 1; |
629 unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; | 634 unsuppored_info.FSDK_UnSupport_Handler = ExampleUnsupportedHandler; |
630 | 635 |
631 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); | 636 FSDK_SetUnSpObjProcessHandler(&unsuppored_info); |
632 | 637 |
633 while (!files.empty()) { | 638 while (!files.empty()) { |
634 std::string filename = files.front(); | 639 std::string filename = files.front(); |
635 files.pop_front(); | 640 files.pop_front(); |
636 size_t file_length = 0; | 641 size_t file_length = 0; |
637 char* file_contents = GetFileContents(filename.c_str(), &file_length); | 642 char* file_contents = GetFileContents(filename.c_str(), &file_length); |
638 if (!file_contents) | 643 if (!file_contents) |
639 continue; | 644 continue; |
640 RenderPdf(filename, file_contents, file_length, options); | 645 RenderPdf(filename, file_contents, file_length, options); |
641 free(file_contents); | 646 free(file_contents); |
642 } | 647 } |
643 | 648 |
644 FPDF_DestroyLibrary(); | 649 FPDF_DestroyLibrary(); |
645 v8::V8::ShutdownPlatform(); | 650 v8::V8::ShutdownPlatform(); |
646 delete platform; | 651 delete platform; |
647 | 652 |
648 return 0; | 653 return 0; |
649 } | 654 } |
OLD | NEW |