OLD | NEW |
1 #include "SkCanvas.h" | 1 #include "SkCanvas.h" |
2 #include "SkCommandLineFlags.h" | 2 #include "SkCommandLineFlags.h" |
3 #include "SkDevice.h" | 3 #include "SkDevice.h" |
4 #include "SkGraphics.h" | 4 #include "SkGraphics.h" |
5 #include "SkImageDecoder.h" | 5 #include "SkImageDecoder.h" |
6 #include "SkImageEncoder.h" | 6 #include "SkImageEncoder.h" |
7 #include "SkOSFile.h" | 7 #include "SkOSFile.h" |
8 #include "SkPicture.h" | 8 #include "SkPicture.h" |
9 #include "SkStream.h" | 9 #include "SkStream.h" |
10 #include "SkTypeface.h" | 10 #include "SkTypeface.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 * @param outputDir Output dir. | 209 * @param outputDir Output dir. |
210 * @param renderer The object responsible to render the skp object into pdf. | 210 * @param renderer The object responsible to render the skp object into pdf. |
211 */ | 211 */ |
212 static bool process_pdf(const SkString& inputPath, const SkString& outputDir, | 212 static bool process_pdf(const SkString& inputPath, const SkString& outputDir, |
213 SkPdfRenderer& renderer) { | 213 SkPdfRenderer& renderer) { |
214 SkDebugf("Loading PDF: %s\n", inputPath.c_str()); | 214 SkDebugf("Loading PDF: %s\n", inputPath.c_str()); |
215 | 215 |
216 SkString inputFilename; | 216 SkString inputFilename; |
217 get_basename(&inputFilename, inputPath); | 217 get_basename(&inputFilename, inputPath); |
218 | 218 |
219 SkFILEStream inputStream; | 219 bool success = true; |
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 | 220 |
228 success = renderer.load(inputPath); | 221 success = renderer.load(inputPath); |
229 if (FLAGS_showMemoryUsage) { | 222 if (FLAGS_showMemoryUsage) { |
230 SkDebugf("Memory usage after load: %u\n", (unsigned int)renderer.bytesUs
ed()); | 223 SkDebugf("Memory usage after load: %u\n", (unsigned int)renderer.bytesUs
ed()); |
231 } | 224 } |
232 | 225 |
233 // TODO(edisonn): bench timers | 226 // TODO(edisonn): bench timers |
234 if (FLAGS_benchLoad > 0) { | 227 if (FLAGS_benchLoad > 0) { |
235 for (int i = 0 ; i < FLAGS_benchLoad; i++) { | 228 for (int i = 0 ; i < FLAGS_benchLoad; i++) { |
236 success = renderer.load(inputPath); | 229 success = renderer.load(inputPath) && success; |
237 if (FLAGS_showMemoryUsage) { | 230 if (FLAGS_showMemoryUsage) { |
238 SkDebugf("Memory usage after load %i number : %u\n", i, (unsigne
d int)renderer.bytesUsed()); | 231 SkDebugf("Memory usage after load %i number : %u\n", i, (unsigne
d int)renderer.bytesUsed()); |
239 } | 232 } |
240 } | 233 } |
241 } | 234 } |
242 | 235 |
243 if (success) { | 236 if (success) { |
244 if (!renderer.pages()) | 237 if (!renderer.pages()) |
245 { | 238 { |
246 SkDebugf("ERROR: Empty PDF Document %s\n", inputPath.c_str()); | 239 SkDebugf("ERROR: Empty PDF Document %s\n", inputPath.c_str()); |
247 return false; | 240 return false; |
248 } else { | 241 } else { |
249 for (int i = 0; i < FLAGS_benchRender + 1; i++) { | 242 for (int i = 0; i < FLAGS_benchRender + 1; i++) { |
250 // TODO(edisonn) if (i == 1) start timer | 243 // TODO(edisonn) if (i == 1) start timer |
251 if (strcmp(FLAGS_pages[0], "all") == 0) { | 244 if (strcmp(FLAGS_pages[0], "all") == 0) { |
252 for (int pn = 0; pn < renderer.pages(); ++pn) { | 245 for (int pn = 0; pn < renderer.pages(); ++pn) { |
253 success = render_page(outputDir, inputFilename, renderer
, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; | 246 success = render_page(outputDir, inputFilename, renderer
, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; |
254 } | 247 } |
255 } else if (strcmp(FLAGS_pages[0], "reverse") == 0) { | 248 } else if (strcmp(FLAGS_pages[0], "reverse") == 0) { |
256 for (int pn = renderer.pages() - 1; pn >= 0; --pn) { | 249 for (int pn = renderer.pages() - 1; pn >= 0; --pn) { |
257 success = render_page(outputDir, inputFilename, renderer
, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; | 250 success = render_page(outputDir, inputFilename, renderer
, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; |
258 } | 251 } |
259 } else if (strcmp(FLAGS_pages[0], "first") == 0) { | 252 } else if (strcmp(FLAGS_pages[0], "first") == 0) { |
260 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) && success; | 253 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) && success; |
261 } else if (strcmp(FLAGS_pages[0], "last") == 0) { | 254 } else if (strcmp(FLAGS_pages[0], "last") == 0) { |
262 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() -
1) && success; | 255 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() -
1) && success; |
263 } else { | 256 } else { |
264 int pn = atoi(FLAGS_pages[0]); | 257 int pn = atoi(FLAGS_pages[0]); |
265 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() -
1) && pn; | 258 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; |
266 } | 259 } |
267 } | 260 } |
268 } | 261 } |
269 } | 262 } |
270 | 263 |
| 264 if (!success) { |
| 265 SkDebugf("Failures for file %s\n", inputPath.c_str()); |
| 266 } |
| 267 |
271 return success; | 268 return success; |
272 } | 269 } |
273 | 270 |
274 /** For each file in the directory or for the file passed in input, call | 271 /** For each file in the directory or for the file passed in input, call |
275 * parse_pdf. | 272 * parse_pdf. |
276 * @param input A directory or an pdf file. | 273 * @param input A directory or an pdf file. |
277 * @param outputDir Output dir. | 274 * @param outputDir Output dir. |
278 * @param renderer The object responsible to render the skp object into pdf. | 275 * @param renderer The object responsible to render the skp object into pdf. |
279 */ | 276 */ |
280 static int process_input(const char* input, const SkString& outputDir, | 277 static int process_input(const char* input, const SkString& outputDir, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 329 } |
333 | 330 |
334 return 0; | 331 return 0; |
335 } | 332 } |
336 | 333 |
337 #if !defined SK_BUILD_FOR_IOS | 334 #if !defined SK_BUILD_FOR_IOS |
338 int main(int argc, char * const argv[]) { | 335 int main(int argc, char * const argv[]) { |
339 return tool_main(argc, (char**) argv); | 336 return tool_main(argc, (char**) argv); |
340 } | 337 } |
341 #endif | 338 #endif |
OLD | NEW |