Simplify PDFium by removing code that's not used in the open source repo.
[pdfium.git] / samples / pdfium_test.cc
index 72c8c5d..9cdc4a7 100644 (file)
@@ -16,6 +16,7 @@
 #include "../fpdfsdk/include/fpdfformfill.h"
 #include "../fpdfsdk/include/fpdftext.h"
 #include "../fpdfsdk/include/fpdfview.h"
+#include "../core/include/fxcrt/fx_system.h"
 #include "v8/include/v8.h"
 
 #ifdef _WIN32
@@ -289,7 +290,7 @@ void RenderPdf(const char* name, const char* pBuf, size_t len,
   (void) FPDF_GetDocPermissions(doc);
   (void) FPDFAvail_IsFormAvail(pdf_avail, &hints);
 
-  FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnviroument(doc, &form_callbacks);
+  FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks);
   FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD);
   FPDF_SetFormFieldHighlightAlpha(form, 100);
 
@@ -304,8 +305,14 @@ void RenderPdf(const char* name, const char* pBuf, size_t len,
   FORM_DoDocumentJSAction(form);
   FORM_DoDocumentOpenAction(form);
 
+  size_t rendered_pages = 0;
+  size_t bad_pages = 0;
   for (int i = 0; i < page_count; ++i) {
     FPDF_PAGE page = FPDF_LoadPage(doc, i);
+    if (!page) {
+        bad_pages ++;
+        continue;
+    }
     FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
     FORM_OnAfterLoadPage(page, form);
     FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN);
@@ -316,6 +323,8 @@ void RenderPdf(const char* name, const char* pBuf, size_t len,
     FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
 
     FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
+    rendered_pages ++;
+
     FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0);
     int stride = FPDFBitmap_GetStride(bitmap);
     const char* buffer =
@@ -347,11 +356,12 @@ void RenderPdf(const char* name, const char* pBuf, size_t len,
   }
 
   FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC);
-  FPDFDOC_ExitFormFillEnviroument(form);
+  FPDFDOC_ExitFormFillEnvironment(form);
   FPDF_CloseDocument(doc);
   FPDFAvail_Destroy(pdf_avail);
 
-  printf("Loaded, parsed and rendered %d pages.\n", page_count);
+  printf("Loaded, parsed and rendered %" PRIuS " pages.\n", rendered_pages);
+  printf("Skipped %" PRIuS " bad pages.\n", bad_pages);
 }
 
 int main(int argc, const char* argv[]) {
@@ -368,7 +378,7 @@ int main(int argc, const char* argv[]) {
     return 1;
   }
 
-  FPDF_InitLibrary(NULL);
+  FPDF_InitLibrary();
 
   UNSUPPORT_INFO unsuppored_info;
   memset(&unsuppored_info, '\0', sizeof(unsuppored_info));