Create a standalone pdfium build.
authorJohn Abd-El-Malek <jam@chromium.org>
Thu, 22 May 2014 23:14:52 +0000 (16:14 -0700)
committerJohn Abd-El-Malek <jam@chromium.org>
Fri, 23 May 2014 23:55:40 +0000 (16:55 -0700)
I moved pdfium_test from chromium's repo to pdfium's. It's now buildable as a sample following the instructions on the wiki.

.gitignore [new file with mode: 0644]
README.txt [new file with mode: 0644]
build/all.gyp [new file with mode: 0644]
build/gyp_pdfium [new file with mode: 0644]
build/gyp_pdfium.py [new file with mode: 0644]
build/standalone.gypi [new file with mode: 0644]
samples/pdfium_test.cc [new file with mode: 0644]
samples/samples.gyp [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..06184bd
--- /dev/null
@@ -0,0 +1,18 @@
+/build/Debug
+/build/Release
+/build/gyp
+/out
+/v8
+/xcodebuild
+Makefile
+.DS_Store
+*.filters
+*.mk
+*.opensdf
+*.pyc
+*.sdf
+*.sln
+*.suo
+*.user
+*.vcxproj
+*.xcodeproj
\ No newline at end of file
diff --git a/README.txt b/README.txt
new file mode 100644 (file)
index 0000000..3a2cbde
--- /dev/null
@@ -0,0 +1 @@
+For build instructions visit https://code.google.com/p/pdfium/wiki/Build
\ No newline at end of file
diff --git a/build/all.gyp b/build/all.gyp
new file mode 100644 (file)
index 0000000..e9229dd
--- /dev/null
@@ -0,0 +1,15 @@
+# Copyright 2014 PDFium Authors. All rights reserved.\r
+# Use of this source code is governed by a BSD-style license that can be\r
+# found in the LICENSE file.\r
+\r
+{\r
+  'targets': [\r
+    {\r
+      'target_name': 'All',\r
+      'type': 'none',\r
+      'dependencies': [\r
+        '../samples/samples.gyp:*',\r
+      ],\r
+    }\r
+  ]\r
+}
\ No newline at end of file
diff --git a/build/gyp_pdfium b/build/gyp_pdfium
new file mode 100644 (file)
index 0000000..0458b96
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env python\r
+#\r
+# Copyright 2014 PDFium Authors. All rights reserved.\r
+# Use of this source code is governed by a BSD-style license that can be\r
+# found in the LICENSE file.\r
+\r
+# This script is wrapper for PDFium that adds some support for how GYP\r
+# is invoked by PDFium beyond what can be done in the gclient hooks.\r
+\r
+import os\r
+import platform\r
+import sys\r
+\r
+script_dir = os.path.dirname(os.path.realpath(__file__))\r
+pdfium_root = os.path.abspath(os.path.join(script_dir, os.pardir))\r
+\r
+sys.path.insert(0, os.path.join(pdfium_root, 'build', 'gyp', 'pylib'))\r
+import gyp\r
+\r
+\r
+def run_gyp(args):\r
+  rc = gyp.main(args)\r
+  if rc != 0:\r
+    print 'Error running GYP'\r
+    sys.exit(rc)\r
+\r
+\r
+def main():\r
+  args = sys.argv[1:]\r
+  args.append(os.path.join(script_dir, 'all.gyp'))\r
+  \r
+  args.append('-I')\r
+  args.append(os.path.join(pdfium_root, 'build', 'standalone.gypi'))\r
+  \r
+  args.extend(['-D', 'gyp_output_dir=out'])\r
+\r
+  # Set the GYP DEPTH variable to the root of the PDFium project.\r
+  args.append('--depth=' + os.path.relpath(pdfium_root))\r
+\r
+  print 'Updating projects from gyp files...'\r
+  sys.stdout.flush()\r
+\r
+  run_gyp(args)\r
+\r
+if __name__ == '__main__':\r
+  sys.exit(main())
\ No newline at end of file
diff --git a/build/gyp_pdfium.py b/build/gyp_pdfium.py
new file mode 100644 (file)
index 0000000..9776c30
--- /dev/null
@@ -0,0 +1,8 @@
+# Copyright 2014 PDFium Authors. All rights reserved.\r
+# Use of this source code is governed by a BSD-style license that can be\r
+# found in the LICENSE file.\r
+\r
+import os\r
+\r
+path = os.path.abspath(os.path.split(__file__)[0])\r
+execfile(os.path.join(path, 'gyp_pdfium'))\r
diff --git a/build/standalone.gypi b/build/standalone.gypi
new file mode 100644 (file)
index 0000000..970c059
--- /dev/null
@@ -0,0 +1,259 @@
+# Copyright 2014 PDFium Authors. All rights reserved.\r
+# Use of this source code is governed by a BSD-style license that can be\r
+# found in the LICENSE file.\r
+\r
+# Definitions to be used when building stand-alone PDFium binaries.\r
+\r
+{\r
+  'variables': {\r
+    'component%': 'static_library',\r
+    'clang%': 0,\r
+    'msvs_multi_core_compile%': '1',\r
+    'variables': {\r
+      'variables': {\r
+        'variables': {\r
+          'conditions': [\r
+            ['OS=="linux" or OS=="mac"', {\r
+              # This handles the Unix platforms we generally deal with.\r
+              # Anything else gets passed through, which probably won't work\r
+              # very well; such hosts should pass an explicit target_arch\r
+              # to gyp.\r
+              'host_arch%':\r
+                '<!(uname -m | sed -e "s/i.86/ia32/;\\r
+                                       s/x86_64/x64/;\\r
+                                       s/amd64/x64/;\\r
+                                       s/arm.*/arm/;\\r
+                                       s/aarch64/arm64/;\\r
+                                       s/mips.*/mipsel/")',\r
+            }, {\r
+              # OS!="linux" and OS!="mac"\r
+              'host_arch%': 'ia32',\r
+            }],\r
+          ],\r
+        },\r
+        'host_arch%': '<(host_arch)',\r
+        'target_arch%': '<(host_arch)',\r
+      },\r
+      'host_arch%': '<(host_arch)',\r
+      'target_arch%': '<(target_arch)',\r
+    },\r
+    'host_arch%': '<(host_arch)',\r
+    'target_arch%': '<(target_arch)',\r
+    'werror%': '-Werror',\r
+    'v8_optimized_debug%': 0,\r
+    'icu_gyp_path': '../v8/third_party/icu/icu.gyp',\r
+    'conditions': [\r
+      ['OS == "win"', {\r
+        'os_posix%': 0,\r
+      }, {\r
+        'os_posix%': 1,\r
+      }],\r
+    ],\r
+  },\r
+  'target_defaults': {\r
+    'default_configuration': 'Debug',\r
+    'configurations': {\r
+      'Debug': {\r
+        'cflags': [\r
+          '-g',\r
+          '-O0',          \r
+          '-fdata-sections',\r
+          '-ffunction-sections',\r
+        ],\r
+        'msvs_settings': {\r
+          'VCCLCompilerTool': {\r
+            'Optimization': '0',\r
+            'conditions': [\r
+              ['component=="shared_library"', {\r
+                'RuntimeLibrary': '3',  # /MDd\r
+              }, {\r
+                'RuntimeLibrary': '1',  # /MTd\r
+              }],\r
+            ],\r
+          },\r
+          'VCLinkerTool': {\r
+            'LinkIncremental': '2',\r
+          },\r
+        },\r
+        'xcode_settings': {\r
+          'GCC_OPTIMIZATION_LEVEL': '0',  # -O0\r
+        },\r
+      },\r
+      'Release': {\r
+        'cflags': [\r
+          '-fno-strict-aliasing',\r
+        ],\r
+        'xcode_settings': {\r
+          'GCC_OPTIMIZATION_LEVEL': '3',  # -O3\r
+          'GCC_STRICT_ALIASING': 'NO',\r
+        },\r
+        'msvs_settings': {\r
+          'VCCLCompilerTool': {\r
+            'Optimization': '2',\r
+            'InlineFunctionExpansion': '2',\r
+            'EnableIntrinsicFunctions': 'true',\r
+            'FavorSizeOrSpeed': '0',\r
+            'StringPooling': 'true',\r
+            'conditions': [\r
+              ['component=="shared_library"', {\r
+                'RuntimeLibrary': '2',  #/MD\r
+              }, {\r
+                'RuntimeLibrary': '0',  #/MT\r
+              }],\r
+            ],\r
+          },\r
+          'VCLinkerTool': {\r
+            'LinkIncremental': '1',\r
+            'OptimizeReferences': '2',\r
+            'EnableCOMDATFolding': '2',\r
+          },\r
+        },\r
+        'conditions': [\r
+          ['OS=="linux"', {\r
+            'cflags': [\r
+              '-fdata-sections',\r
+              '-ffunction-sections',\r
+              '-O3',\r
+              '-O2',\r
+            ],\r
+          }],\r
+          ['OS=="android"', {\r
+            'cflags!': [\r
+              '-O3',\r
+              '-Os',\r
+            ],\r
+            'cflags': [\r
+              '-fdata-sections',\r
+              '-ffunction-sections',\r
+              '-O2',\r
+            ],\r
+          }],\r
+        ],  # conditions\r
+      },\r
+    },\r
+    'defines!': [\r
+      'DEBUG',\r
+    ],\r
+    'cflags!': [\r
+      '-Wall',\r
+      '-W',\r
+      '-Wno-unused-parameter',\r
+      '-pthread', '-fno-exceptions',\r
+      '-fvisibility=hidden',\r
+    ],\r
+    'cflags_cc': [\r
+      '-Wnon-virtual-dtor',\r
+      '-fno-rtti',\r
+    ],\r
+    'ldflags': [\r
+      '-pthread',\r
+    ],\r
+    'msvs_cygwin_dirs': ['<(DEPTH)/v8/third_party/cygwin'],\r
+    'msvs_configuration_attributes': {\r
+      'OutputDirectory': '<(DEPTH)\\out\\$(ConfigurationName)',\r
+      'IntermediateDirectory': '$(OutDir)\\obj\\$(ProjectName)',\r
+      'CharacterSet': '1',\r
+    },\r
+    'msvs_settings': {\r
+      'VCCLCompilerTool': {\r
+        'MinimalRebuild': 'false',\r
+        'BufferSecurityCheck': 'true',\r
+        'EnableFunctionLevelLinking': 'true',\r
+        'RuntimeTypeInfo': 'false',\r
+        'WarningLevel': '3',\r
+        'WarnAsError': 'false',\r
+        'DebugInformationFormat': '3',\r
+        'Detect64BitPortabilityProblems': 'false',\r
+        'conditions': [\r
+          [ 'msvs_multi_core_compile', {\r
+            'AdditionalOptions': ['/MP'],\r
+          }],\r
+          ['component=="shared_library"', {\r
+            'ExceptionHandling': '1',  # /EHsc\r
+          }, {\r
+            'ExceptionHandling': '0',\r
+          }],\r
+        ],\r
+      },\r
+      'VCLibrarianTool': {\r
+        'AdditionalOptions': ['/ignore:4221'],\r
+      },\r
+      'VCLinkerTool': {\r
+        'GenerateDebugInformation': 'true',\r
+        'LinkIncremental': '1',\r
+        # SubSystem values:\r
+        #   0 == not set\r
+        #   1 == /SUBSYSTEM:CONSOLE\r
+        #   2 == /SUBSYSTEM:WINDOWS\r
+        'SubSystem': '1',\r
+        'AdditionalDependencies': [\r
+          'advapi32.lib',\r
+          'gdi32.lib',\r
+          'user32.lib',\r
+        ],\r
+      },\r
+    },\r
+    'xcode_settings': {\r
+      'ALWAYS_SEARCH_USER_PATHS': 'NO',\r
+      'GCC_CW_ASM_SYNTAX': 'NO',                # No -fasm-blocks\r
+      'GCC_DYNAMIC_NO_PIC': 'NO',               # No -mdynamic-no-pic\r
+                                                # (Equivalent to -fPIC)\r
+      'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',        # -fno-exceptions\r
+      'GCC_ENABLE_CPP_RTTI': 'NO',              # -fno-rtti\r
+      'GCC_ENABLE_PASCAL_STRINGS': 'NO',        # No -mpascal-strings\r
+      # GCC_INLINES_ARE_PRIVATE_EXTERN maps to -fvisibility-inlines-hidden\r
+      'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES',\r
+      'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES',      # -fvisibility=hidden\r
+      'GCC_TREAT_WARNINGS_AS_ERRORS': 'NO',     # -Werror\r
+      'GCC_WARN_NON_VIRTUAL_DESTRUCTOR': 'YES', # -Wnon-virtual-dtor\r
+      'SYMROOT': '<(DEPTH)/xcodebuild',\r
+      'USE_HEADERMAP': 'NO',\r
+      'OTHER_CFLAGS': [\r
+        '-fno-strict-aliasing',\r
+      ],\r
+      'WARNING_CFLAGS': [\r
+        '-Wall',\r
+        '-Wendif-labels',\r
+        '-W',\r
+        '-Wno-unused-parameter',\r
+      ],\r
+    },\r
+  },\r
+  'conditions': [\r
+    ['component=="shared_library"', {\r
+      'cflags': [\r
+        '-fPIC',\r
+      ],\r
+    }],\r
+    ['OS=="win"', {\r
+      'target_defaults': {\r
+        'defines': [\r
+          '_CRT_SECURE_NO_DEPRECATE',\r
+          '_CRT_NONSTDC_NO_DEPRECATE',\r
+        ],\r
+        'conditions': [\r
+          ['component=="static_library"', {\r
+            'defines': [\r
+              '_HAS_EXCEPTIONS=0',\r
+            ],\r
+          }],\r
+        ],\r
+      },\r
+    }],  # OS=="win"\r
+    ['OS=="mac"', {\r
+      'target_defaults': {\r
+        'link_settings': {\r
+          'libraries': [\r
+            '$(SDKROOT)/System/Library/Frameworks/AppKit.framework',\r
+            '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework',\r
+          ],\r
+        },\r
+        'target_conditions': [\r
+          ['_type!="static_library"', {\r
+            'xcode_settings': {'OTHER_LDFLAGS': ['-Wl,-search_paths_first']},\r
+          }],\r
+        ],  # target_conditions\r
+      },  # target_defaults\r
+    }],  # OS=="mac"\r
+  ],\r
+}
\ No newline at end of file
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
new file mode 100644 (file)
index 0000000..67c15e0
--- /dev/null
@@ -0,0 +1,309 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.\r
+// Use of this source code is governed by a BSD-style license that can be\r
+// found in the LICENSE file.\r
+\r
+#include <limits.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include <list>\r
+#include <string>\r
+#include <utility>\r
+\r
+#include "fpdfsdk/include/fpdf_dataavail.h"\r
+#include "fpdfsdk/include/fpdf_ext.h"\r
+#include "fpdfsdk/include/fpdfformfill.h"\r
+#include "fpdfsdk/include/fpdftext.h"\r
+#include "fpdfsdk/include/fpdfview.h"\r
+#include "v8/include/v8.h"\r
+\r
+#ifdef _WIN32\r
+  #define snprintf _snprintf\r
+  /* in Windows, rb for open and read binary file */\r
+  #define FOPEN_READ "rb"\r
+#else\r
+  #define FOPEN_READ "r"\r
+#endif\r
+\r
+static void WritePpm(const char* pdf_name, int num,\r
+                     const char* buffer, int stride, int width, int height) {\r
+  if (stride < 0 || width < 0 || height < 0)\r
+    return;\r
+  if (height > 0 && width > INT_MAX / height)\r
+    return;\r
+  int out_len = width * height;\r
+  if (out_len > INT_MAX / 3)\r
+    return;\r
+  out_len *= 3;\r
+\r
+  char filename[256];\r
+  snprintf(filename, sizeof(filename), "%s.%d.ppm", pdf_name, num);\r
+  FILE* fp = fopen(filename, "w");\r
+  if (!fp)\r
+    return;\r
+  fprintf(fp, "P6\n# PDF test render\n%d %d\n255\n", width, height);\r
+  // Source data is B, G, R, unused.\r
+  // Dest data is R, G, B.\r
+  char* result = new char[out_len];\r
+  if (result) {\r
+    for (int h = 0; h < height; ++h) {\r
+      const char* src_line = buffer + (stride * h);\r
+      char* dest_line = result + (width * h * 3);\r
+      for (int w = 0; w < width; ++w) {\r
+        // R\r
+        dest_line[w * 3] = src_line[(w * 4) + 2];\r
+        // G\r
+        dest_line[(w * 3) + 1] = src_line[(w * 4) + 1];\r
+        // B\r
+        dest_line[(w * 3) + 2] = src_line[w * 4];\r
+      }\r
+    }\r
+    fwrite(result, out_len, 1, fp);\r
+    delete [] result;\r
+  }\r
+  fclose(fp);\r
+}\r
+\r
+int Form_Alert(IPDF_JSPLATFORM*, FPDF_WIDESTRING, FPDF_WIDESTRING, int, int) {\r
+  printf("Form_Alert called.\n");\r
+  return 0;\r
+}\r
+\r
+void Unsupported_Handler(UNSUPPORT_INFO*, int type) {\r
+  std::string feature = "Unknown";\r
+  switch (type) {\r
+    case FPDF_UNSP_DOC_XFAFORM:\r
+      feature = "XFA";\r
+      break;\r
+    case FPDF_UNSP_DOC_PORTABLECOLLECTION:\r
+      feature = "Portfolios_Packages";\r
+      break;\r
+    case FPDF_UNSP_DOC_ATTACHMENT:\r
+    case FPDF_UNSP_ANNOT_ATTACHMENT:\r
+      feature = "Attachment";\r
+      break;\r
+    case FPDF_UNSP_DOC_SECURITY:\r
+      feature = "Rights_Management";\r
+      break;\r
+    case FPDF_UNSP_DOC_SHAREDREVIEW:\r
+      feature = "Shared_Review";\r
+      break;\r
+    case FPDF_UNSP_DOC_SHAREDFORM_ACROBAT:\r
+    case FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM:\r
+    case FPDF_UNSP_DOC_SHAREDFORM_EMAIL:\r
+      feature = "Shared_Form";\r
+      break;\r
+    case FPDF_UNSP_ANNOT_3DANNOT:\r
+      feature = "3D";\r
+      break;\r
+    case FPDF_UNSP_ANNOT_MOVIE:\r
+      feature = "Movie";\r
+      break;\r
+    case FPDF_UNSP_ANNOT_SOUND:\r
+      feature = "Sound";\r
+      break;\r
+    case FPDF_UNSP_ANNOT_SCREEN_MEDIA:\r
+    case FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA:\r
+      feature = "Screen";\r
+      break;\r
+    case FPDF_UNSP_ANNOT_SIG:\r
+      feature = "Digital_Signature";\r
+      break;\r
+  }\r
+  printf("Unsupported feature: %s.\n", feature.c_str());\r
+}\r
+\r
+bool ParseCommandLine(int argc, const char* argv[], bool* write_images,\r
+                      std::list<const char*>* files) {\r
+  *write_images = false;\r
+  files->clear();\r
+\r
+  int cur_arg = 1;\r
+  if (cur_arg < argc &&\r
+      strcmp(argv[cur_arg], "--write_images") == 0) {\r
+    *write_images = true;\r
+    cur_arg++;\r
+  }\r
+\r
+  if (cur_arg >= argc)\r
+    return false;\r
+\r
+  for (int i = cur_arg; i < argc; i++)\r
+    files->push_back(argv[i]);\r
+\r
+  return true;\r
+}\r
+\r
+class TestLoader {\r
+ public:\r
+  TestLoader(const char* pBuf, size_t len);\r
+\r
+  const char* m_pBuf;\r
+  size_t m_Len;\r
+};\r
+\r
+TestLoader::TestLoader(const char* pBuf, size_t len)\r
+    : m_pBuf(pBuf), m_Len(len) {\r
+}\r
+\r
+int Get_Block(void* param, unsigned long pos, unsigned char* pBuf,\r
+              unsigned long size) {\r
+  TestLoader* pLoader = (TestLoader*) param;\r
+  if (pos + size < pos || pos + size > pLoader->m_Len) return 0;\r
+  memcpy(pBuf, pLoader->m_pBuf + pos, size);\r
+  return 1;\r
+}\r
+\r
+bool Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) {\r
+  return true;\r
+}\r
+\r
+void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {\r
+}\r
+\r
+void RenderPdf(const char* name, const char* pBuf, size_t len,\r
+               bool write_images) {\r
+  printf("Rendering PDF file %s.\n", name);\r
+\r
+  IPDF_JSPLATFORM platform_callbacks;\r
+  memset(&platform_callbacks, '\0', sizeof(platform_callbacks));\r
+  platform_callbacks.version = 1;\r
+  platform_callbacks.app_alert = Form_Alert;\r
+\r
+  FPDF_FORMFILLINFO form_callbacks;\r
+  memset(&form_callbacks, '\0', sizeof(form_callbacks));\r
+  form_callbacks.version = 1;\r
+  form_callbacks.m_pJsPlatform = &platform_callbacks;\r
+\r
+  TestLoader loader(pBuf, len);\r
+\r
+  FPDF_FILEACCESS file_access;\r
+  memset(&file_access, '\0', sizeof(file_access));\r
+  file_access.m_FileLen = len;\r
+  file_access.m_GetBlock = Get_Block;\r
+  file_access.m_Param = &loader;\r
+\r
+  FX_FILEAVAIL file_avail;\r
+  memset(&file_avail, '\0', sizeof(file_avail));\r
+  file_avail.version = 1;\r
+  file_avail.IsDataAvail = Is_Data_Avail;\r
+\r
+  FX_DOWNLOADHINTS hints;\r
+  memset(&hints, '\0', sizeof(hints));\r
+  hints.version = 1;\r
+  hints.AddSegment = Add_Segment;\r
+\r
+  FPDF_DOCUMENT doc;\r
+  FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access);\r
+\r
+  (void) FPDFAvail_IsDocAvail(pdf_avail, &hints);\r
+\r
+  if (!FPDFAvail_IsLinearized(pdf_avail)) {\r
+    printf("Non-linearized path...\n");\r
+    doc = FPDF_LoadCustomDocument(&file_access, NULL);\r
+  } else {\r
+    printf("Linearized path...\n");\r
+    doc = FPDFAvail_GetDocument(pdf_avail, NULL);\r
+  }\r
+\r
+  (void) FPDF_GetDocPermissions(doc);\r
+  (void) FPDFAvail_IsFormAvail(pdf_avail, &hints);\r
+\r
+  FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnviroument(doc, &form_callbacks);\r
+  FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD);\r
+  FPDF_SetFormFieldHighlightAlpha(form, 100);\r
+\r
+  int first_page = FPDFAvail_GetFirstPageNum(doc);\r
+  (void) FPDFAvail_IsPageAvail(pdf_avail, first_page, &hints);\r
+\r
+  int page_count = FPDF_GetPageCount(doc);\r
+  for (int i = 0; i < page_count; ++i) {\r
+    (void) FPDFAvail_IsPageAvail(pdf_avail, i, &hints);\r
+  }\r
+\r
+  FORM_DoDocumentJSAction(form);\r
+  FORM_DoDocumentOpenAction(form);\r
+\r
+  for (int i = 0; i < page_count; ++i) {\r
+    FPDF_PAGE page = FPDF_LoadPage(doc, i);\r
+    FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);\r
+    FORM_OnAfterLoadPage(page, form);\r
+    FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN);\r
+\r
+    int width = static_cast<int>(FPDF_GetPageWidth(page));\r
+    int height = static_cast<int>(FPDF_GetPageHeight(page));\r
+    FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0);\r
+    FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 255, 255, 255, 255);\r
+\r
+    FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0);\r
+    FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0);\r
+    if (write_images) {\r
+      const char* buffer = reinterpret_cast<const char*>(\r
+          FPDFBitmap_GetBuffer(bitmap));\r
+      int stride = FPDFBitmap_GetStride(bitmap);\r
+      WritePpm(name, i, buffer, stride, width, height);\r
+    }\r
+\r
+    FPDFBitmap_Destroy(bitmap);\r
+\r
+    FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE);\r
+    FORM_OnBeforeClosePage(page, form);\r
+    FPDFText_ClosePage(text_page);\r
+    FPDF_ClosePage(page);\r
+  }\r
+\r
+  FORM_DoDocumentAAction(form, FPDFDOC_AACTION_WC);\r
+  FPDFDOC_ExitFormFillEnviroument(form);\r
+  FPDF_CloseDocument(doc);\r
+  FPDFAvail_Destroy(pdf_avail);\r
+\r
+  printf("Loaded, parsed and rendered %d pages.\n", page_count);\r
+}\r
+\r
+int main(int argc, const char* argv[]) {\r
+  v8::V8::InitializeICU();\r
+  bool write_images = false;\r
+  std::list<const char*> files;\r
+  if (!ParseCommandLine(argc, argv, &write_images, &files)) {\r
+    printf("Usage is: test [--write_images] /path/to/pdf\n");\r
+    printf("--write_images - to write page images <pdf-name>.<page-number>.ppm\n");\r
+    return 1;\r
+  }\r
+\r
+  FPDF_InitLibrary(NULL);\r
+\r
+  UNSUPPORT_INFO unsuppored_info;\r
+  memset(&unsuppored_info, '\0', sizeof(unsuppored_info));\r
+  unsuppored_info.version = 1;\r
+  unsuppored_info.FSDK_UnSupport_Handler = Unsupported_Handler;\r
+\r
+  FSDK_SetUnSpObjProcessHandler(&unsuppored_info);\r
+\r
+  while (!files.empty()) {\r
+    const char* filename = files.front();\r
+    files.pop_front();\r
+    FILE* file = fopen(filename, FOPEN_READ);\r
+    if (!file) {\r
+      fprintf(stderr, "Failed to open: %s\n", filename);\r
+      continue;\r
+    }\r
+    (void) fseek(file, 0, SEEK_END);\r
+    size_t len = ftell(file);\r
+    (void) fseek(file, 0, SEEK_SET);\r
+    char* pBuf = (char*) malloc(len);\r
+    size_t ret = fread(pBuf, 1, len, file);\r
+    (void) fclose(file);\r
+    if (ret != len) {\r
+      fprintf(stderr, "Failed to read: %s\n", filename);\r
+    } else {\r
+      RenderPdf(filename, pBuf, len, write_images);\r
+    }\r
+    free(pBuf);\r
+  }\r
+\r
+  FPDF_DestroyLibrary();\r
+\r
+  return 0;\r
+}\r
+\r
diff --git a/samples/samples.gyp b/samples/samples.gyp
new file mode 100644 (file)
index 0000000..f7b7237
--- /dev/null
@@ -0,0 +1,21 @@
+# Copyright 2014 PDFium Authors. All rights reserved.\r
+# Use of this source code is governed by a BSD-style license that can be\r
+# found in the LICENSE file.\r
+\r
+{\r
+  'target_defaults': {\r
+    'type': 'executable',\r
+    'dependencies': [\r
+      '../pdfium.gyp:fpdfsdk',\r
+    ],\r
+    'include_dirs': ['<(DEPTH)'],\r
+  },\r
+  'targets': [\r
+    {\r
+      'target_name': 'pdfium_test',\r
+      'sources': [\r
+        'pdfium_test.cc',\r
+      ],\r
+    },\r
+  ],\r
+}
\ No newline at end of file