Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: experimental/PdfViewer/pdf_viewer_main.cpp

Issue 18503013: pdfviewer: render in the same way regadless if we write the result to a file or not. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 "\tall - all pages\n" 21 "\tall - all pages\n"
22 "\treverse - all pages, in reverse order\n" 22 "\treverse - all pages, in reverse order\n"
23 "\tfirst - first page\n" 23 "\tfirst - first page\n"
24 "\tlast - last page\n" 24 "\tlast - last page\n"
25 "\tnumber - a specific page number\n" 25 "\tnumber - a specific page number\n"
26 ); 26 );
27 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale)."); 27 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale).");
28 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all 28 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not to render at all
29 // TODO(edisonn): add ability to do the op N times, bench (either load N times, render n times or load + render n times) 29 // TODO(edisonn): add ability to do the op N times, bench (either load N times, render n times or load + render n times)
30 30
31
32 /** 31 /**
33 * Given list of directories and files to use as input, expects to find .pdf 32 * Given list of directories and files to use as input, expects to find .pdf
34 * files and it will convert them to .png files writing them in the same directo ry 33 * files and it will convert them to .png files writing them in the same directo ry
35 * one file for each page. 34 * one file for each page.
36 * 35 *
37 * Returns zero exit code if all .pdf files were converted successfully, 36 * Returns zero exit code if all .pdf files were converted successfully,
38 * otherwise returns error code 1. 37 * otherwise returns error code 1.
39 */ 38 */
40 39
41 static const char PDF_FILE_EXTENSION[] = "pdf"; 40 static const char PDF_FILE_EXTENSION[] = "pdf";
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 bitmap->eraseColor(color); 90 bitmap->eraseColor(color);
92 } 91 }
93 92
94 /** Write the output of pdf renderer to a file. 93 /** Write the output of pdf renderer to a file.
95 * @param outputDir Output dir. 94 * @param outputDir Output dir.
96 * @param inputFilename The skp file that was read. 95 * @param inputFilename The skp file that was read.
97 * @param renderer The object responsible to write the pdf file. 96 * @param renderer The object responsible to write the pdf file.
98 * @param page -1 means there is only one page (0), and render in a file without page extension 97 * @param page -1 means there is only one page (0), and render in a file without page extension
99 */ 98 */
100 99
100 extern "C" SkBitmap* gDumpBitmap;
101 extern "C" SkCanvas* gDumpCanvas;
102
101 static bool render_page(const SkString& outputDir, 103 static bool render_page(const SkString& outputDir,
102 const SkString& inputFilename, 104 const SkString& inputFilename,
103 const SkPdfRenderer& renderer, 105 const SkPdfRenderer& renderer,
104 int page) { 106 int page) {
105 if (outputDir.isEmpty()) {
106 SkBitmap bitmap;
107 setup_bitmap(&bitmap, 1, 1);
108 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap)));
109 SkCanvas canvas(device);
110 return renderer.renderPage(page < 0 ? 0 : page, &canvas);
111 }
112
113 SkString outputPath;
114 if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) {
115 return false;
116 }
117
118 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); 107 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
119 108
120 SkBitmap bitmap; 109 SkBitmap bitmap;
121 #ifdef PDF_DEBUG_3X 110 #ifdef PDF_DEBUG_3X
122 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(rect.width()), 3 * (int)SkSc alarToDouble(rect.height())); 111 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(rect.width()), 3 * (int)SkSc alarToDouble(rect.height()));
123 #else 112 #else
124 setup_bitmap(&bitmap, (int)SkScalarToDouble(rect.width()), (int)SkScalarToDo uble(rect.height())); 113 setup_bitmap(&bitmap, (int)SkScalarToDouble(rect.width()), (int)SkScalarToDo uble(rect.height()));
125 #endif 114 #endif
126 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); 115 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap)));
127 SkCanvas canvas(device); 116 SkCanvas canvas(device);
128 117
129 gDumpBitmap = &bitmap; 118 gDumpBitmap = &bitmap;
130 119
131 gDumpCanvas = &canvas; 120 gDumpCanvas = &canvas;
132 renderer.renderPage(page < 0 ? 0 : page, &canvas); 121 renderer.renderPage(page < 0 ? 0 : page, &canvas);
133 122
123 SkString outputPath;
124 if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) {
125 return false;
126 }
134 SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::kPNG_ Type, 100); 127 SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::kPNG_ Type, 100);
135 128
136 if (FLAGS_showMemoryUsage) { 129 if (FLAGS_showMemoryUsage) {
137 SkDebugf("Memory usage after page %i rendered: %u\n", page < 0 ? 0 : pag e, (unsigned int)renderer.bytesUsed()); 130 SkDebugf("Memory usage after page %i rendered: %u\n", page < 0 ? 0 : pag e, (unsigned int)renderer.bytesUsed());
138 } 131 }
139 132
140 return true; 133 return true;
141 } 134 }
142 135
143 /** Reads an skp file, renders it to pdf and writes the output to a pdf file 136 /** Reads an skp file, renders it to pdf and writes the output to a pdf file
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 248 }
256 249
257 return 0; 250 return 0;
258 } 251 }
259 252
260 #if !defined SK_BUILD_FOR_IOS 253 #if !defined SK_BUILD_FOR_IOS
261 int main(int argc, char * const argv[]) { 254 int main(int argc, char * const argv[]) {
262 return tool_main(argc, (char**) argv); 255 return tool_main(argc, (char**) argv);
263 } 256 }
264 #endif 257 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698