OLD | NEW |
1 #include "DMSrcSink.h" | 1 #include "DMSrcSink.h" |
2 #include "SamplePipeControllers.h" | 2 #include "SamplePipeControllers.h" |
3 #include "SkCommonFlags.h" | 3 #include "SkCommonFlags.h" |
4 #include "SkDocument.h" | 4 #include "SkDocument.h" |
5 #include "SkError.h" | 5 #include "SkError.h" |
6 #include "SkMultiPictureDraw.h" | 6 #include "SkMultiPictureDraw.h" |
7 #include "SkNullCanvas.h" | 7 #include "SkNullCanvas.h" |
8 #include "SkOSFile.h" | 8 #include "SkOSFile.h" |
9 #include "SkPictureRecorder.h" | 9 #include "SkPictureRecorder.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 dst->allocPixels(info); | 187 dst->allocPixels(info); |
188 canvas->readPixels(dst, 0, 0); | 188 canvas->readPixels(dst, 0, 0); |
189 if (FLAGS_abandonGpuContext) { | 189 if (FLAGS_abandonGpuContext) { |
190 factory.abandonContexts(); | 190 factory.abandonContexts(); |
191 } | 191 } |
192 return ""; | 192 return ""; |
193 } | 193 } |
194 | 194 |
195 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 195 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
196 | 196 |
197 static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) { | 197 PDFSink::PDFSink() {} |
198 // Print the given DM:Src to a document, breaking on 8.5x11 pages. | 198 |
199 SkASSERT(doc); | 199 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
{ |
| 200 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages. |
| 201 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); |
| 202 |
200 int width = src.size().width(), | 203 int width = src.size().width(), |
201 height = src.size().height(); | 204 height = src.size().height(); |
202 | 205 |
203 const int kLetterWidth = 612, // 8.5 * 72 | 206 const int kLetterWidth = 612, // 8.5 * 72 |
204 kLetterHeight = 792; // 11 * 72 | 207 kLetterHeight = 792; // 11 * 72 |
205 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), | 208 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), |
206 SkIntToScalar(kLetterHeight)); | 209 SkIntToScalar(kLetterHeight)); |
207 | 210 |
208 int xPages = ((width - 1) / kLetterWidth) + 1; | 211 int xPages = ((width - 1) / kLetterWidth) + 1; |
209 int yPages = ((height - 1) / kLetterHeight) + 1; | 212 int yPages = ((height - 1) / kLetterHeight) + 1; |
(...skipping 11 matching lines...) Expand all Loading... |
221 return err; | 224 return err; |
222 } | 225 } |
223 doc->endPage(); | 226 doc->endPage(); |
224 } | 227 } |
225 } | 228 } |
226 doc->close(); | 229 doc->close(); |
227 dst->flush(); | 230 dst->flush(); |
228 return ""; | 231 return ""; |
229 } | 232 } |
230 | 233 |
231 PDFSink::PDFSink() {} | |
232 | |
233 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
{ | |
234 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); | |
235 if (!doc) { | |
236 return "SkDocument::CreatePDF() returned NULL"; | |
237 } | |
238 return draw_skdocument(src, doc.get(), dst); | |
239 } | |
240 | |
241 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
242 | 235 |
243 XPSSink::XPSSink() {} | |
244 | |
245 Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
{ | |
246 SkAutoTUnref<SkDocument> doc(SkDocument::CreateXPS(dst)); | |
247 if (!doc) { | |
248 return "SkDocument::CreateXPS() returned NULL"; | |
249 } | |
250 return draw_skdocument(src, doc.get(), dst); | |
251 } | |
252 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | |
253 | |
254 SKPSink::SKPSink() {} | 236 SKPSink::SKPSink() {} |
255 | 237 |
256 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
{ | 238 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
{ |
257 SkSize size; | 239 SkSize size; |
258 size = src.size(); | 240 size = src.size(); |
259 SkPictureRecorder recorder; | 241 SkPictureRecorder recorder; |
260 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); | 242 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); |
261 if (!err.isEmpty()) { | 243 if (!err.isEmpty()) { |
262 return err; | 244 return err; |
263 } | 245 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 surfaces.unrefAll(); | 464 surfaces.unrefAll(); |
483 return ""; | 465 return ""; |
484 } | 466 } |
485 SkISize size() const SK_OVERRIDE { return fSize; } | 467 SkISize size() const SK_OVERRIDE { return fSize; } |
486 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 468 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
487 } proxy(fW, fH, pic, src.size()); | 469 } proxy(fW, fH, pic, src.size()); |
488 return fSink->draw(proxy, bitmap, stream, log); | 470 return fSink->draw(proxy, bitmap, stream, log); |
489 } | 471 } |
490 | 472 |
491 } // namespace DM | 473 } // namespace DM |
OLD | NEW |