Convert all files on the master branch to unix line endings.
[pdfium.git] / samples / pdfium_test.cc
index 068dbaa..0d76b63 100644 (file)
 #include <utility>
 #include <vector>
 
-#include "../fpdfsdk/include/fpdf_dataavail.h"
-#include "../fpdfsdk/include/fpdf_ext.h"
-#include "../fpdfsdk/include/fpdfformfill.h"
-#include "../fpdfsdk/include/fpdftext.h"
-#include "../fpdfsdk/include/fpdfview.h"
-#include "../core/include/fxcrt/fx_system.h"
+#include "../public/fpdf_dataavail.h"
+#include "../public/fpdf_ext.h"
+#include "../public/fpdf_formfill.h"
+#include "../public/fpdf_text.h"
+#include "../public/fpdfview.h"
 #include "image_diff_png.h"
-#include "v8/include/v8.h"
 #include "v8/include/libplatform/libplatform.h"
+#include "v8/include/v8.h"
 
 #ifdef _WIN32
 #define snprintf _snprintf
@@ -216,7 +215,7 @@ static void WriteBmp(const char* pdf_name, int num, const void* buffer,
   if (!fp)
     return;
 
-  BITMAPINFO bmi = {0};
+  BITMAPINFO bmi = {};
   bmi.bmiHeader.biSize = sizeof(bmi) - sizeof(RGBQUAD);
   bmi.bmiHeader.biWidth = width;
   bmi.bmiHeader.biHeight = -height;  // top-down image
@@ -225,7 +224,7 @@ static void WriteBmp(const char* pdf_name, int num, const void* buffer,
   bmi.bmiHeader.biCompression = BI_RGB;
   bmi.bmiHeader.biSizeImage = 0;
 
-  BITMAPFILEHEADER file_header = {0};
+  BITMAPFILEHEADER file_header = {};
   file_header.bfType = 0x4d42;
   file_header.bfSize = sizeof(file_header) + bmi.bmiHeader.biSize + out_len;
   file_header.bfOffBits = file_header.bfSize - out_len;
@@ -414,7 +413,7 @@ int Get_Block(void* param, unsigned long pos, unsigned char* pBuf,
   return 1;
 }
 
-bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) {
+FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) {
   return true;
 }
 
@@ -427,7 +426,7 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len,
 
   IPDF_JSPLATFORM platform_callbacks;
   memset(&platform_callbacks, '\0', sizeof(platform_callbacks));
-  platform_callbacks.version = 1;
+  platform_callbacks.version = 2;
   platform_callbacks.app_alert = ExampleAppAlert;
   platform_callbacks.Doc_gotoPage = ExampleDocGotoPage;
 
@@ -485,8 +484,8 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len,
   FORM_DoDocumentJSAction(form);
   FORM_DoDocumentOpenAction(form);
 
-  size_t rendered_pages = 0;
-  size_t bad_pages = 0;
+  int rendered_pages = 0;
+  int bad_pages = 0;
   for (int i = 0; i < page_count; ++i) {
     FPDF_PAGE page = FPDF_LoadPage(doc, i);
     if (!page) {
@@ -505,6 +504,12 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len,
     int height = static_cast<int>(FPDF_GetPageHeight(page) * scale);
 
     FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0);
+    if (!bitmap) {
+      fprintf(stderr, "Page was too large to be rendered.\n");
+      bad_pages++;
+      continue;
+    }
+
     FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
     FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);
     rendered_pages ++;
@@ -549,8 +554,8 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len,
   FPDF_CloseDocument(doc);
   FPDFAvail_Destroy(pdf_avail);
 
-  fprintf(stderr, "Rendered %" PRIuS " pages.\n", rendered_pages);
-  fprintf(stderr, "Skipped %" PRIuS " bad pages.\n", bad_pages);
+  fprintf(stderr, "Rendered %d pages.\n", rendered_pages);
+  fprintf(stderr, "Skipped %d bad pages.\n", bad_pages);
 }
 
 static const char usage_string[] =
@@ -578,6 +583,11 @@ int main(int argc, const char* argv[]) {
   v8::V8::InitializePlatform(platform);
   v8::V8::Initialize();
 
+  // By enabling predictable mode, V8 won't post any background tasks.
+  static const char predictable_flag[] = "--predictable";
+  v8::V8::SetFlagsFromString(predictable_flag,
+                             static_cast<int>(strlen(predictable_flag)));
+
 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
   v8::StartupData natives;
   v8::StartupData snapshot;