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 <map> | 10 #include <map> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 struct AvailDeleter { | 80 struct AvailDeleter { |
81 inline void operator()(FPDF_AVAIL avail) const { FPDFAvail_Destroy(avail); } | 81 inline void operator()(FPDF_AVAIL avail) const { FPDFAvail_Destroy(avail); } |
82 }; | 82 }; |
83 | 83 |
84 static FPDF_FORMFILLINFO_PDFiumTest* ToPDFiumTestFormFillInfo( | 84 static FPDF_FORMFILLINFO_PDFiumTest* ToPDFiumTestFormFillInfo( |
85 FPDF_FORMFILLINFO* formFillInfo) { | 85 FPDF_FORMFILLINFO* formFillInfo) { |
86 return static_cast<FPDF_FORMFILLINFO_PDFiumTest*>(formFillInfo); | 86 return static_cast<FPDF_FORMFILLINFO_PDFiumTest*>(formFillInfo); |
87 } | 87 } |
88 | 88 |
89 static void CloseDocAndForm(FPDF_DOCUMENT doc, FPDF_FORMHANDLE form) { | |
90 #ifdef PDF_ENABLE_XFA | |
91 // Note: The shut down order here is the reverse of the non-XFA branch order. | |
92 // Need to work out if this is required, and if it is, the lifetimes of | |
93 // objects owned by |doc| that |form| reference. | |
94 FPDF_CloseDocument(doc); | |
95 FPDFDOC_ExitFormFillEnvironment(form); | |
96 #else // PDF_ENABLE_XFA | |
97 FPDFDOC_ExitFormFillEnvironment(form); | |
98 FPDF_CloseDocument(doc); | |
99 #endif // PDF_ENABLE_XFA | |
100 } | |
101 | |
102 static bool CheckDimensions(int stride, int width, int height) { | 89 static bool CheckDimensions(int stride, int width, int height) { |
103 if (stride < 0 || width < 0 || height < 0) | 90 if (stride < 0 || width < 0 || height < 0) |
104 return false; | 91 return false; |
105 if (height > 0 && width > INT_MAX / height) | 92 if (height > 0 && width > INT_MAX / height) |
106 return false; | 93 return false; |
107 return true; | 94 return true; |
108 } | 95 } |
109 | 96 |
110 static void WritePpm(const char* pdf_name, int num, const void* buffer_void, | 97 static void WritePpm(const char* pdf_name, int num, const void* buffer_void, |
111 int stride, int width, int height) { | 98 int stride, int width, int height) { |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 int bad_pages = 0; | 771 int bad_pages = 0; |
785 for (int i = 0; i < page_count; ++i) { | 772 for (int i = 0; i < page_count; ++i) { |
786 if (bIsLinearized) { | 773 if (bIsLinearized) { |
787 nRet = PDF_DATA_NOTAVAIL; | 774 nRet = PDF_DATA_NOTAVAIL; |
788 while (nRet == PDF_DATA_NOTAVAIL) | 775 while (nRet == PDF_DATA_NOTAVAIL) |
789 nRet = FPDFAvail_IsPageAvail(pdf_avail, i, &hints); | 776 nRet = FPDFAvail_IsPageAvail(pdf_avail, i, &hints); |
790 | 777 |
791 if (nRet == PDF_DATA_ERROR) { | 778 if (nRet == PDF_DATA_ERROR) { |
792 fprintf(stderr, "Unknown error in checking if page %d is available.\n", | 779 fprintf(stderr, "Unknown error in checking if page %d is available.\n", |
793 i); | 780 i); |
794 CloseDocAndForm(doc, form); | 781 FPDFDOC_ExitFormFillEnvironment(form); |
| 782 FPDF_CloseDocument(doc); |
795 return; | 783 return; |
796 } | 784 } |
797 } | 785 } |
798 if (RenderPage(name, doc, form, form_callbacks, i, options, events)) | 786 if (RenderPage(name, doc, form, form_callbacks, i, options, events)) |
799 ++rendered_pages; | 787 ++rendered_pages; |
800 else | 788 else |
801 ++bad_pages; | 789 ++bad_pages; |
802 } | 790 } |
803 | 791 |
804 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); | 792 FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC); |
805 | 793 |
806 CloseDocAndForm(doc, form); | 794 FPDFDOC_ExitFormFillEnvironment(form); |
| 795 FPDF_CloseDocument(doc); |
807 | 796 |
808 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); | 797 fprintf(stderr, "Rendered %d pages.\n", rendered_pages); |
809 if (bad_pages) | 798 if (bad_pages) |
810 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); | 799 fprintf(stderr, "Skipped %d bad pages.\n", bad_pages); |
811 } | 800 } |
812 | 801 |
813 static void ShowConfig() { | 802 static void ShowConfig() { |
814 std::string config; | 803 std::string config; |
815 std::string maybe_comma; | 804 std::string maybe_comma; |
816 #if PDF_ENABLE_V8 | 805 #if PDF_ENABLE_V8 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 delete platform; | 922 delete platform; |
934 | 923 |
935 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 924 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
936 free(const_cast<char*>(natives.data)); | 925 free(const_cast<char*>(natives.data)); |
937 free(const_cast<char*>(snapshot.data)); | 926 free(const_cast<char*>(snapshot.data)); |
938 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 927 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
939 #endif // PDF_ENABLE_V8 | 928 #endif // PDF_ENABLE_V8 |
940 | 929 |
941 return 0; | 930 return 0; |
942 } | 931 } |
OLD | NEW |