edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 1 | #include "SkCanvas.h" |
edisonn@google.com | a5aaa79 | 2013-07-11 12:27:21 +0000 | [diff] [blame] | 2 | #include "SkCommandLineFlags.h" |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 3 | #include "SkDevice.h" |
| 4 | #include "SkGraphics.h" |
| 5 | #include "SkImageDecoder.h" |
| 6 | #include "SkImageEncoder.h" |
| 7 | #include "SkOSFile.h" |
| 8 | #include "SkPicture.h" |
| 9 | #include "SkStream.h" |
| 10 | #include "SkTypeface.h" |
| 11 | #include "SkTArray.h" |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 12 | #include "SkNulCanvas.h" |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 13 | |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 14 | #include "SkPdfRenderer.h" |
edisonn@google.com | b857a0c | 2013-06-25 20:45:40 +0000 | [diff] [blame] | 15 | |
edisonn@google.com | a5aaa79 | 2013-07-11 12:27:21 +0000 | [diff] [blame] | 16 | DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to process."); |
| 17 | DEFINE_string2(writePath, w, "", "Directory to write the rendered pages."); |
| 18 | DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one page."); |
| 19 | DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage."); |
edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 20 | DEFINE_string2(pages, p, "all", "What pages to render and how:\n" |
| 21 | "\tall - all pages\n" |
| 22 | "\treverse - all pages, in reverse order\n" |
| 23 | "\tfirst - first page\n" |
| 24 | "\tlast - last page\n" |
| 25 | "\tnumber - a specific page number\n" |
| 26 | ); |
edisonn@google.com | 15b1118 | 2013-07-11 14:43:15 +0000 | [diff] [blame] | 27 | DEFINE_double(DPI, 72, "DPI to be used for rendering (scale)."); |
edisonn@google.com | 6a9d436 | 2013-07-11 16:25:51 +0000 | [diff] [blame] | 28 | DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any rendering and \n" |
| 29 | "\tminimal parsing to ensure correctness. Default 0 (disabled)."); |
| 30 | DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disabled)"); |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 31 | DEFINE_string2(config, c, "8888", "Canvas to render:\n" |
| 32 | "\t8888 - all pages\n" |
| 33 | "\tnul - all pages, in reverse order\n" |
| 34 | ); |
edisonn@google.com | 6a9d436 | 2013-07-11 16:25:51 +0000 | [diff] [blame] | 35 | |
| 36 | |
edisonn@google.com | 15b1118 | 2013-07-11 14:43:15 +0000 | [diff] [blame] | 37 | // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all |
edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 38 | |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 39 | /** |
| 40 | * Given list of directories and files to use as input, expects to find .pdf |
| 41 | * files and it will convert them to .png files writing them in the same directory |
| 42 | * one file for each page. |
| 43 | * |
| 44 | * Returns zero exit code if all .pdf files were converted successfully, |
| 45 | * otherwise returns error code 1. |
| 46 | */ |
| 47 | |
| 48 | static const char PDF_FILE_EXTENSION[] = "pdf"; |
| 49 | static const char PNG_FILE_EXTENSION[] = "png"; |
| 50 | |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 51 | /** Replaces the extension of a file. |
| 52 | * @param path File name whose extension will be changed. |
| 53 | * @param old_extension The old extension. |
| 54 | * @param new_extension The new extension. |
| 55 | * @returns false if the file did not has the expected extension. |
| 56 | * if false is returned, contents of path are undefined. |
| 57 | */ |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 58 | static bool add_page_and_replace_filename_extension(SkString* path, int page, |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 59 | const char old_extension[], |
| 60 | const char new_extension[]) { |
| 61 | if (path->endsWith(old_extension)) { |
| 62 | path->remove(path->size() - strlen(old_extension), |
| 63 | strlen(old_extension)); |
| 64 | if (!path->endsWith(".")) { |
| 65 | return false; |
| 66 | } |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 67 | if (page >= 0) { |
| 68 | path->appendf("%i.", page); |
| 69 | } |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 70 | path->append(new_extension); |
| 71 | return true; |
| 72 | } |
| 73 | return false; |
| 74 | } |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 75 | |
edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame^] | 76 | void make_filepath(SkString* path, const SkString& dir, const SkString& name) { |
| 77 | size_t len = dir.size(); |
| 78 | path->set(dir); |
| 79 | if (0 < len && '/' != dir[len - 1]) { |
| 80 | path->append("/"); |
| 81 | } |
| 82 | path->append(name); |
| 83 | } |
| 84 | |
| 85 | bool is_path_seperator(const char chr) { |
| 86 | #if defined(SK_BUILD_FOR_WIN) |
| 87 | return chr == '\\' || chr == '/'; |
| 88 | #else |
| 89 | return chr == '/'; |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | void get_basename(SkString* basename, const SkString& path) { |
| 94 | if (path.size() == 0) { |
| 95 | basename->reset(); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | size_t end = path.size() - 1; |
| 100 | |
| 101 | // Paths pointing to directories often have a trailing slash, |
| 102 | // we remove it so the name is not empty |
| 103 | if (is_path_seperator(path[end])) { |
| 104 | if (end == 0) { |
| 105 | basename->reset(); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | end -= 1; |
| 110 | } |
| 111 | |
| 112 | size_t i = end; |
| 113 | do { |
| 114 | --i; |
| 115 | if (is_path_seperator(path[i])) { |
| 116 | const char* basenameStart = path.c_str() + i + 1; |
| 117 | size_t basenameLength = end - i; |
| 118 | basename->set(basenameStart, basenameLength); |
| 119 | return; |
| 120 | } |
| 121 | } while (i > 0); |
| 122 | |
| 123 | basename->set(path.c_str(), end + 1); |
| 124 | } |
| 125 | |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 126 | /** Builds the output filename. path = dir/name, and it replaces expected |
| 127 | * .skp extension with .pdf extention. |
| 128 | * @param path Output filename. |
| 129 | * @param name The name of the file. |
| 130 | * @returns false if the file did not has the expected extension. |
| 131 | * if false is returned, contents of path are undefined. |
| 132 | */ |
| 133 | static bool make_output_filepath(SkString* path, const SkString& dir, |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 134 | const SkString& name, |
| 135 | int page) { |
edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame^] | 136 | make_filepath(path, dir, name); |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 137 | return add_page_and_replace_filename_extension(path, page, |
| 138 | PDF_FILE_EXTENSION, |
| 139 | PNG_FILE_EXTENSION); |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 140 | } |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 141 | |
| 142 | static void setup_bitmap(SkBitmap* bitmap, int width, int height, SkColor color = SK_ColorWHITE) { |
| 143 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 144 | |
| 145 | bitmap->allocPixels(); |
| 146 | bitmap->eraseColor(color); |
| 147 | } |
| 148 | |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 149 | /** Write the output of pdf renderer to a file. |
| 150 | * @param outputDir Output dir. |
| 151 | * @param inputFilename The skp file that was read. |
| 152 | * @param renderer The object responsible to write the pdf file. |
edisonn@google.com | cdad30b | 2013-07-10 22:37:38 +0000 | [diff] [blame] | 153 | * @param page -1 means there is only one page (0), and render in a file without page extension |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 154 | */ |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 155 | |
edisonn@google.com | 1310238 | 2013-07-11 14:50:12 +0000 | [diff] [blame] | 156 | extern "C" SkBitmap* gDumpBitmap; |
| 157 | extern "C" SkCanvas* gDumpCanvas; |
| 158 | |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 159 | static bool render_page(const SkString& outputDir, |
edisonn@google.com | 444e25a | 2013-07-11 15:20:50 +0000 | [diff] [blame] | 160 | const SkString& inputFilename, |
| 161 | const SkPdfRenderer& renderer, |
| 162 | int page) { |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 163 | SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); |
| 164 | |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 165 | // Exercise all pdf codepaths as in normal rendering, but no actual bits are changed. |
| 166 | if (!FLAGS_config.isEmpty() && strcmp(FLAGS_config[0], "nul") == 0) { |
| 167 | SkBitmap bitmap; |
| 168 | SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); |
| 169 | SkNulCanvas canvas(device); |
| 170 | renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); |
| 171 | } else { |
| 172 | // 8888 |
| 173 | SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); |
edisonn@google.com | 444e25a | 2013-07-11 15:20:50 +0000 | [diff] [blame] | 174 | |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 175 | SkBitmap bitmap; |
| 176 | SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(FLAGS_DPI / 72.0))); |
| 177 | SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(FLAGS_DPI / 72.0))); |
| 178 | |
| 179 | rect = SkRect::MakeWH(width, height); |
edisonn@google.com | 444e25a | 2013-07-11 15:20:50 +0000 | [diff] [blame] | 180 | |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 181 | #ifdef PDF_DEBUG_3X |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 182 | setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScalarToDouble(height)); |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 183 | #else |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 184 | setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height)); |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 185 | #endif |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 186 | SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); |
| 187 | SkCanvas canvas(device); |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 188 | |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 189 | gDumpBitmap = &bitmap; |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 190 | |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 191 | gDumpCanvas = &canvas; |
| 192 | renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 193 | |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 194 | SkString outputPath; |
| 195 | if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) { |
| 196 | return false; |
| 197 | } |
| 198 | SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100); |
| 199 | |
| 200 | if (FLAGS_showMemoryUsage) { |
| 201 | SkDebugf("Memory usage after page %i rendered: %u\n", page < 0 ? 0 : page, (unsigned int)renderer.bytesUsed()); |
| 202 | } |
edisonn@google.com | 1310238 | 2013-07-11 14:50:12 +0000 | [diff] [blame] | 203 | } |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 204 | return true; |
| 205 | } |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 206 | |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 207 | /** Reads an skp file, renders it to pdf and writes the output to a pdf file |
| 208 | * @param inputPath The skp file to be read. |
| 209 | * @param outputDir Output dir. |
| 210 | * @param renderer The object responsible to render the skp object into pdf. |
| 211 | */ |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 212 | static bool process_pdf(const SkString& inputPath, const SkString& outputDir, |
edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 213 | SkPdfRenderer& renderer) { |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 214 | SkDebugf("Loading PDF: %s\n", inputPath.c_str()); |
| 215 | |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 216 | SkString inputFilename; |
edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame^] | 217 | get_basename(&inputFilename, inputPath); |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 218 | |
| 219 | SkFILEStream inputStream; |
| 220 | inputStream.setPath(inputPath.c_str()); |
| 221 | if (!inputStream.isValid()) { |
| 222 | SkDebugf("Could not open file %s\n", inputPath.c_str()); |
| 223 | return false; |
| 224 | } |
| 225 | |
| 226 | bool success = false; |
| 227 | |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 228 | success = renderer.load(inputPath); |
edisonn@google.com | 6a9d436 | 2013-07-11 16:25:51 +0000 | [diff] [blame] | 229 | if (FLAGS_showMemoryUsage) { |
| 230 | SkDebugf("Memory usage after load: %u\n", (unsigned int)renderer.bytesUsed()); |
| 231 | } |
| 232 | |
| 233 | // TODO(edisonn): bench timers |
| 234 | if (FLAGS_benchLoad > 0) { |
| 235 | for (int i = 0 ; i < FLAGS_benchLoad; i++) { |
| 236 | success = renderer.load(inputPath); |
| 237 | if (FLAGS_showMemoryUsage) { |
| 238 | SkDebugf("Memory usage after load %i number : %u\n", i, (unsigned int)renderer.bytesUsed()); |
| 239 | } |
| 240 | } |
| 241 | } |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 242 | |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 243 | if (success) { |
| 244 | if (!renderer.pages()) |
| 245 | { |
| 246 | SkDebugf("ERROR: Empty PDF Document %s\n", inputPath.c_str()); |
| 247 | return false; |
| 248 | } else { |
edisonn@google.com | 2ccc3af | 2013-07-23 17:43:18 +0000 | [diff] [blame] | 249 | printf("renders = %i\n", FLAGS_benchRender); |
edisonn@google.com | 6a9d436 | 2013-07-11 16:25:51 +0000 | [diff] [blame] | 250 | for (int i = 0; i < FLAGS_benchRender + 1; i++) { |
| 251 | // TODO(edisonn) if (i == 1) start timer |
| 252 | if (strcmp(FLAGS_pages[0], "all") == 0) { |
| 253 | for (int pn = 0; pn < renderer.pages(); ++pn) { |
| 254 | success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; |
| 255 | } |
| 256 | } else if (strcmp(FLAGS_pages[0], "reverse") == 0) { |
| 257 | for (int pn = renderer.pages() - 1; pn >= 0; --pn) { |
| 258 | success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; |
| 259 | } |
| 260 | } else if (strcmp(FLAGS_pages[0], "first") == 0) { |
| 261 | success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) && success; |
| 262 | } else if (strcmp(FLAGS_pages[0], "last") == 0) { |
| 263 | success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && success; |
| 264 | } else { |
| 265 | int pn = atoi(FLAGS_pages[0]); |
| 266 | success = render_page(outputDir, inputFilename, renderer, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) && pn; |
edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 267 | } |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | } |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 271 | |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 272 | return success; |
| 273 | } |
| 274 | |
| 275 | /** For each file in the directory or for the file passed in input, call |
| 276 | * parse_pdf. |
| 277 | * @param input A directory or an pdf file. |
| 278 | * @param outputDir Output dir. |
| 279 | * @param renderer The object responsible to render the skp object into pdf. |
| 280 | */ |
edisonn@google.com | a5aaa79 | 2013-07-11 12:27:21 +0000 | [diff] [blame] | 281 | static int process_input(const char* input, const SkString& outputDir, |
edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 282 | SkPdfRenderer& renderer) { |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 283 | int failures = 0; |
edisonn@google.com | a5aaa79 | 2013-07-11 12:27:21 +0000 | [diff] [blame] | 284 | if (sk_isdir(input)) { |
| 285 | SkOSFile::Iter iter(input, PDF_FILE_EXTENSION); |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 286 | SkString inputFilename; |
| 287 | while (iter.next(&inputFilename)) { |
| 288 | SkString inputPath; |
edisonn@google.com | a5aaa79 | 2013-07-11 12:27:21 +0000 | [diff] [blame] | 289 | SkString _input; |
| 290 | _input.append(input); |
edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame^] | 291 | make_filepath(&inputPath, _input, inputFilename); |
edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 292 | if (!process_pdf(inputPath, outputDir, renderer)) { |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 293 | ++failures; |
| 294 | } |
| 295 | } |
| 296 | } else { |
| 297 | SkString inputPath(input); |
edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 298 | if (!process_pdf(inputPath, outputDir, renderer)) { |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 299 | ++failures; |
| 300 | } |
| 301 | } |
| 302 | return failures; |
| 303 | } |
| 304 | |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 305 | int tool_main(int argc, char** argv); |
| 306 | int tool_main(int argc, char** argv) { |
edisonn@google.com | a5aaa79 | 2013-07-11 12:27:21 +0000 | [diff] [blame] | 307 | SkCommandLineFlags::SetUsage("Parse and Render .pdf files (pdf viewer)."); |
| 308 | SkCommandLineFlags::Parse(argc, argv); |
| 309 | |
| 310 | if (FLAGS_readPath.isEmpty()) { |
| 311 | SkDebugf(".pdf files or directories are required.\n"); |
| 312 | exit(-1); |
| 313 | } |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 314 | |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 315 | SkPdfRenderer renderer; |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 316 | |
| 317 | SkString outputDir; |
edisonn@google.com | a5aaa79 | 2013-07-11 12:27:21 +0000 | [diff] [blame] | 318 | if (FLAGS_writePath.count() == 1) { |
| 319 | outputDir.set(FLAGS_writePath[0]); |
| 320 | } |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 321 | |
| 322 | int failures = 0; |
edisonn@google.com | a5aaa79 | 2013-07-11 12:27:21 +0000 | [diff] [blame] | 323 | for (int i = 0; i < FLAGS_readPath.count(); i ++) { |
edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 324 | failures += process_input(FLAGS_readPath[i], outputDir, renderer); |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 325 | renderer.unload(); |
edisonn@google.com | 01cd4d5 | 2013-06-10 20:44:45 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | reportPdfRenderStats(); |
| 329 | |
| 330 | if (failures != 0) { |
| 331 | SkDebugf("Failed to render %i PDFs.\n", failures); |
| 332 | return 1; |
| 333 | } |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | #if !defined SK_BUILD_FOR_IOS |
| 339 | int main(int argc, char * const argv[]) { |
| 340 | return tool_main(argc, (char**) argv); |
| 341 | } |
| 342 | #endif |