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 PDFSink::PDFSink() {} | 197 static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) { |
198 | 198 // Print the given DM:Src to a document, breaking on 8.5x11 pages. |
199 Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
{ | 199 SkASSERT(doc); |
200 // Print the given DM:Src to a PDF, breaking on 8.5x11 pages. | |
201 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst)); | |
202 | |
203 int width = src.size().width(), | 200 int width = src.size().width(), |
204 height = src.size().height(); | 201 height = src.size().height(); |
205 | 202 |
206 const int kLetterWidth = 612, // 8.5 * 72 | 203 const int kLetterWidth = 612, // 8.5 * 72 |
207 kLetterHeight = 792; // 11 * 72 | 204 kLetterHeight = 792; // 11 * 72 |
208 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), | 205 const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth), |
209 SkIntToScalar(kLetterHeight)); | 206 SkIntToScalar(kLetterHeight)); |
210 | 207 |
211 int xPages = ((width - 1) / kLetterWidth) + 1; | 208 int xPages = ((width - 1) / kLetterWidth) + 1; |
212 int yPages = ((height - 1) / kLetterHeight) + 1; | 209 int yPages = ((height - 1) / kLetterHeight) + 1; |
(...skipping 11 matching lines...) Expand all Loading... |
224 return err; | 221 return err; |
225 } | 222 } |
226 doc->endPage(); | 223 doc->endPage(); |
227 } | 224 } |
228 } | 225 } |
229 doc->close(); | 226 doc->close(); |
230 dst->flush(); | 227 dst->flush(); |
231 return ""; | 228 return ""; |
232 } | 229 } |
233 | 230 |
| 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 |
234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 241 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
235 | 242 |
| 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 |
236 SKPSink::SKPSink() {} | 254 SKPSink::SKPSink() {} |
237 | 255 |
238 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
{ | 256 Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const
{ |
239 SkSize size; | 257 SkSize size; |
240 size = src.size(); | 258 size = src.size(); |
241 SkPictureRecorder recorder; | 259 SkPictureRecorder recorder; |
242 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); | 260 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); |
243 if (!err.isEmpty()) { | 261 if (!err.isEmpty()) { |
244 return err; | 262 return err; |
245 } | 263 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 surfaces.unrefAll(); | 482 surfaces.unrefAll(); |
465 return ""; | 483 return ""; |
466 } | 484 } |
467 SkISize size() const SK_OVERRIDE { return fSize; } | 485 SkISize size() const SK_OVERRIDE { return fSize; } |
468 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 486 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
469 } proxy(fW, fH, pic, src.size()); | 487 } proxy(fW, fH, pic, src.size()); |
470 return fSink->draw(proxy, bitmap, stream, log); | 488 return fSink->draw(proxy, bitmap, stream, log); |
471 } | 489 } |
472 | 490 |
473 } // namespace DM | 491 } // namespace DM |
OLD | NEW |