diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-01-29 15:48:15 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-01-29 15:48:15 -0800 |
commit | cedc562477cbca7496bd88999b773b72912c40f8 (patch) | |
tree | 4ad3ab2e7bc933065f9481cb83df3310451c93e8 /samples/pdfium_test.cc | |
parent | 90f9e6180384672db231e52c417c55c6f8a5872a (diff) | |
download | pdfium-cedc562477cbca7496bd88999b773b72912c40f8.tar.xz |
Merge to Master: Add output scale factor command line parameter to pdfium_test.
Original Review URL: https://codereview.chromium.org/861203003
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/889733002
Diffstat (limited to 'samples/pdfium_test.cc')
-rw-r--r-- | samples/pdfium_test.cc | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index 9e1527d98d..debe033369 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -8,6 +8,7 @@ #include <string.h> #include <list> +#include <sstream> #include <string> #include <utility> #include <vector> @@ -40,6 +41,7 @@ struct Options { Options() : output_format(OUTPUT_NONE) { } OutputFormat output_format; + std::string scale_factor_as_string; std::string exe_path; std::string bin_directory; }; @@ -303,6 +305,13 @@ bool ParseCommandLine(const std::vector<std::string>& args, options->bin_directory = cur_arg.substr(10); } #endif // V8_USE_EXTERNAL_STARTUP_DATA + else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { + if (!options->scale_factor_as_string.empty()) { + fprintf(stderr, "Duplicate --scale argument\n"); + return false; + } + options->scale_factor_as_string = cur_arg.substr(8); + } else break; } @@ -344,7 +353,7 @@ void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) { } void RenderPdf(const std::string& name, const char* pBuf, size_t len, - OutputFormat format) { + const Options& options) { printf("Rendering PDF file %s.\n", name.c_str()); IPDF_JSPLATFORM platform_callbacks; @@ -420,9 +429,15 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len, int width = static_cast<int>(FPDF_GetPageWidth(page)); int height = static_cast<int>(FPDF_GetPageHeight(page)); + if (!options.scale_factor_as_string.empty()) { + double scale = 1.0; + std::stringstream(options.scale_factor_as_string) >> scale; + width *= scale; + height *= scale; + } + FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); - FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); rendered_pages ++; @@ -431,7 +446,7 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len, const char* buffer = reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); - switch (format) { + switch (options.output_format) { #ifdef _WIN32 case OUTPUT_BMP: WriteBmp(name.c_str(), i, buffer, stride, width, height); @@ -472,6 +487,7 @@ int main(int argc, const char* argv[]) { if (!ParseCommandLine(args, &options, &files)) { printf("Usage: pdfium_test [OPTION] [FILE]...\n"); printf("--bin-dir=<path> - override path to v8 external data\n"); + printf("--scale=<number> - scale output size by number (e.g. 0.5)\n"); printf("--ppm - write page images <pdf-name>.<page-number>.ppm\n"); #ifdef _WIN32 printf("--bmp - write page images <pdf-name>.<page-number>.bmp\n"); @@ -509,7 +525,7 @@ int main(int argc, const char* argv[]) { char* file_contents = GetFileContents(filename.c_str(), &file_length); if (!file_contents) continue; - RenderPdf(filename, file_contents, file_length, options.output_format); + RenderPdf(filename, file_contents, file_length, options); free(file_contents); } |