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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 * @param outputDir Output dir. | 94 * @param outputDir Output dir. |
95 * @param inputFilename The skp file that was read. | 95 * @param inputFilename The skp file that was read. |
96 * @param renderer The object responsible to write the pdf file. | 96 * @param renderer The object responsible to write the pdf file. |
97 * @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 |
98 */ | 98 */ |
99 | 99 |
100 extern "C" SkBitmap* gDumpBitmap; | 100 extern "C" SkBitmap* gDumpBitmap; |
101 extern "C" SkCanvas* gDumpCanvas; | 101 extern "C" SkCanvas* gDumpCanvas; |
102 | 102 |
103 static bool render_page(const SkString& outputDir, | 103 static bool render_page(const SkString& outputDir, |
104 const SkString& inputFilename, | 104 const SkString& inputFilename, |
105 const SkPdfRenderer& renderer, | 105 const SkPdfRenderer& renderer, |
106 int page) { | 106 int page) { |
107 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); | 107 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page); |
108 | 108 |
109 SkBitmap bitmap; | 109 SkBitmap bitmap; |
| 110 SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(FLAGS_DPI
/ 72.0))); |
| 111 SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(FLAGS_DP
I / 72.0))); |
| 112 |
| 113 rect = SkRect::MakeWH(width, height); |
| 114 |
110 #ifdef PDF_DEBUG_3X | 115 #ifdef PDF_DEBUG_3X |
111 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(rect.width()), 3 * (int)SkSc
alarToDouble(rect.height())); | 116 setup_bitmap(&bitmap, 3 * (int)SkScalarToDouble(width), 3 * (int)SkScalarToD
ouble(height)); |
112 #else | 117 #else |
113 setup_bitmap(&bitmap, (int)SkScalarToDouble(rect.width()), (int)SkScalarToDo
uble(rect.height())); | 118 setup_bitmap(&bitmap, (int)SkScalarToDouble(width), (int)SkScalarToDouble(he
ight)); |
114 #endif | 119 #endif |
115 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); | 120 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (bitmap))); |
116 SkCanvas canvas(device); | 121 SkCanvas canvas(device); |
117 | 122 |
118 gDumpBitmap = &bitmap; | 123 gDumpBitmap = &bitmap; |
119 | 124 |
120 gDumpCanvas = &canvas; | 125 gDumpCanvas = &canvas; |
121 renderer.renderPage(page < 0 ? 0 : page, &canvas); | 126 renderer.renderPage(page < 0 ? 0 : page, &canvas, rect); |
122 | 127 |
123 SkString outputPath; | 128 SkString outputPath; |
124 if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) { | 129 if (!make_output_filepath(&outputPath, outputDir, inputFilename, page)) { |
125 return false; | 130 return false; |
126 } | 131 } |
127 SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::kPNG_
Type, 100); | 132 SkImageEncoder::EncodeFile(outputPath.c_str(), bitmap, SkImageEncoder::kPNG_
Type, 100); |
128 | 133 |
129 if (FLAGS_showMemoryUsage) { | 134 if (FLAGS_showMemoryUsage) { |
130 SkDebugf("Memory usage after page %i rendered: %u\n", page < 0 ? 0 : pag
e, (unsigned int)renderer.bytesUsed()); | 135 SkDebugf("Memory usage after page %i rendered: %u\n", page < 0 ? 0 : pag
e, (unsigned int)renderer.bytesUsed()); |
131 } | 136 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 253 } |
249 | 254 |
250 return 0; | 255 return 0; |
251 } | 256 } |
252 | 257 |
253 #if !defined SK_BUILD_FOR_IOS | 258 #if !defined SK_BUILD_FOR_IOS |
254 int main(int argc, char * const argv[]) { | 259 int main(int argc, char * const argv[]) { |
255 return tool_main(argc, (char**) argv); | 260 return tool_main(argc, (char**) argv); |
256 } | 261 } |
257 #endif | 262 #endif |
OLD | NEW |