Chromium Code Reviews| Index: samples/pdfium_test.cc |
| diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc |
| index 656e041e36d4a404c44064032e6ac48bff7f7529..21f7e8303f527fc68c155b3ab820dc7a41422a08 100644 |
| --- a/samples/pdfium_test.cc |
| +++ b/samples/pdfium_test.cc |
| @@ -31,6 +31,13 @@ |
| #define snprintf _snprintf |
| #endif |
| +#define _SKP_SUPPORT_ |
| + |
| +#ifdef _SKP_SUPPORT_ |
| +#include "third_party/skia/include/core/SkPictureRecorder.h" |
| +#include "third_party/skia/include/core/SkStream.h" |
| +#endif |
| + |
| enum OutputFormat { |
| OUTPUT_NONE, |
| OUTPUT_PPM, |
| @@ -39,6 +46,9 @@ enum OutputFormat { |
| OUTPUT_BMP, |
| OUTPUT_EMF, |
| #endif |
| +#ifdef _SKP_SUPPORT_ |
| + OUTPUT_SKP, |
| +#endif |
| }; |
| struct Options { |
| @@ -195,6 +205,25 @@ void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) { |
| } |
| #endif |
| +#ifdef _SKP_SUPPORT_ |
| +void WriteSkp(const char* pdf_name, int num, const void* recorder) { |
| + char filename[256]; |
| + int chars_formatted = snprintf( |
| + filename, sizeof(filename), "%s.%d.skp", pdf_name, num); |
| + |
| + if (chars_formatted < 0 || |
| + static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
| + fprintf(stderr, "Filname %s is too long\n", filename); |
|
dsinclair
2016/03/10 14:38:54
nit: filename
caryclark
2016/03/10 20:44:55
Done.
|
| + return; |
| + } |
| + |
| + SkPictureRecorder* r = (SkPictureRecorder*) recorder; |
| + SkPicture* picture = r->endRecordingAsPicture(); |
| + SkFILEWStream wStream(filename); |
| + picture->serialize(&wStream); |
| +} |
| +#endif |
| + |
| // These example JS platform callback handlers are entirely optional, |
| // and exist here to show the flow of information from a document back |
| // to the embedder. |
| @@ -319,6 +348,14 @@ bool ParseCommandLine(const std::vector<std::string>& args, |
| return false; |
| } |
| options->output_format = OUTPUT_PNG; |
| +#ifdef _SKP_SUPPORT_ |
| + } else if (cur_arg == "--skp") { |
| + if (options->output_format != OUTPUT_NONE) { |
| + fprintf(stderr, "Duplicate or conflicting --skp argument\n"); |
| + return false; |
| + } |
| + options->output_format = OUTPUT_SKP; |
| +#endif |
| } else if (cur_arg.size() > 11 && |
| cur_arg.compare(0, 11, "--font-dir=") == 0) { |
| if (!options->font_directory.empty()) { |
| @@ -408,7 +445,7 @@ bool RenderPage(const std::string& name, |
| FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); |
| FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); |
| - FPDF_FFLDraw(form, bitmap, page, 0, 0, width, height, 0, 0); |
| + FPDF_FFLDraw(form, bitmap, nullptr, page, 0, 0, width, height, 0, 0); |
| int stride = FPDFBitmap_GetStride(bitmap); |
| const char* buffer = |
| reinterpret_cast<const char*>(FPDFBitmap_GetBuffer(bitmap)); |
| @@ -431,6 +468,14 @@ bool RenderPage(const std::string& name, |
| WritePpm(name.c_str(), page_index, buffer, stride, width, height); |
| break; |
| +#ifdef _SKP_SUPPORT_ |
| + case OUTPUT_SKP: { |
| + void* recorder = FPDF_RenderPageSkp(page, width, height); |
|
dsinclair
2016/03/10 14:38:54
unique_ptr
caryclark
2016/03/10 20:44:55
Done.
|
| + FPDF_FFLDraw(form, nullptr, recorder, page, 0, 0, width, height, 0, 0); |
| + WriteSkp(name.c_str(), page_index, recorder); |
| + delete recorder; |
| + } break; |
| +#endif |
| default: |
| break; |
| } |