Chromium Code Reviews| Index: samples/pdfium_test.cc |
| diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc |
| index 656e041e36d4a404c44064032e6ac48bff7f7529..ed3c5651ff962cc70c01312162e40f47d9e8f058 100644 |
| --- a/samples/pdfium_test.cc |
| +++ b/samples/pdfium_test.cc |
| @@ -31,6 +31,11 @@ |
| #define snprintf _snprintf |
| #endif |
| +#ifdef _SKIA_SUPPORT_ |
|
Tom Sepez
2016/03/10 22:55:32
Technicaly, identifiers beginning with an undersco
caryclark
2016/03/11 12:40:34
Changed the define so that it is clear what is spe
|
| +#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 +44,9 @@ enum OutputFormat { |
| OUTPUT_BMP, |
| OUTPUT_EMF, |
| #endif |
| +#ifdef _SKIA_SUPPORT_ |
| + OUTPUT_SKP, |
| +#endif |
| }; |
| struct Options { |
| @@ -116,7 +124,7 @@ static void WritePng(const char* pdf_name, int num, const void* buffer_void, |
| filename, sizeof(filename), "%s.%d.png", pdf_name, num); |
| if (chars_formatted < 0 || |
| static_cast<size_t>(chars_formatted) >= sizeof(filename)) { |
| - fprintf(stderr, "Filname %s is too long\n", filename); |
| + fprintf(stderr, "Filename %s is too long\n", filename); |
| return; |
| } |
| @@ -195,6 +203,25 @@ void WriteEmf(FPDF_PAGE page, const char* pdf_name, int num) { |
| } |
| #endif |
| +#ifdef _SKIA_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, "Filename %s is too long\n", filename); |
| + 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 +346,14 @@ bool ParseCommandLine(const std::vector<std::string>& args, |
| return false; |
| } |
| options->output_format = OUTPUT_PNG; |
| +#ifdef _SKIA_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()) { |
| @@ -431,6 +466,14 @@ bool RenderPage(const std::string& name, |
| WritePpm(name.c_str(), page_index, buffer, stride, width, height); |
| break; |
| +#ifdef _SKIA_SUPPORT_ |
| + case OUTPUT_SKP: { |
| + std::unique_ptr<SkPictureRecorder> recorder( |
| + (SkPictureRecorder*)FPDF_RenderPageSkp(page, width, height)); |
| + FPDF_FFLRecord(form, recorder.get(), page, 0, 0, width, height, 0, 0); |
| + WriteSkp(name.c_str(), page_index, recorder.get()); |
| + } break; |
| +#endif |
| default: |
| break; |
| } |
| @@ -634,7 +677,12 @@ static const char usage_string[] = |
| " --emf - write page meta files <pdf-name>.<page-number>.emf\n" |
| #endif // _WIN32 |
| " --png - write page images <pdf-name>.<page-number>.png\n" |
| +#ifdef _SKIA_SUPPORT_ |
| + " --ppm - write page images <pdf-name>.<page-number>.ppm\n" |
|
Tom Sepez
2016/03/10 22:55:32
Why duplicated ppm line in both halves of the ifde
caryclark
2016/03/11 12:40:34
The style checker complained when a single semicol
|
| + " --skp - write page images <pdf-name>.<page-number>.skp\n"; |
| +#else |
| " --ppm - write page images <pdf-name>.<page-number>.ppm\n"; |
| +#endif |
| int main(int argc, const char* argv[]) { |
| std::vector<std::string> args(argv, argv + argc); |