| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | |
| edisonn@google.com | 15b1118 | 2013-07-11 14:43:15 +0000 | [diff] [blame] | 9 | #ifndef SkPdfRenderer_DEFINED |
| 10 | #define SkPdfRenderer_DEFINED |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 11 | |
| edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame^] | 12 | // TODO(edisonn): remove this dependency, and load only from a stream! |
| edisonn@google.com | af54a51 | 2013-09-13 19:33:42 +0000 | [diff] [blame] | 13 | #include "SkString.h" |
| 14 | |
| edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 15 | class SkBitmap; |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 16 | class SkCanvas; |
| edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 17 | class SkPdfNativeDoc; |
| edisonn@google.com | 96ba3aa | 2013-07-28 20:04:35 +0000 | [diff] [blame] | 18 | struct SkRect; |
| edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 19 | class SkStream; |
| edisonn@google.com | af54a51 | 2013-09-13 19:33:42 +0000 | [diff] [blame] | 20 | class SkString; |
| edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 21 | |
| 22 | enum SkPdfContent { |
| 23 | kNoForms_SkPdfContent, |
| 24 | kAll_SkPdfContent, |
| 25 | }; |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 26 | |
| edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame^] | 27 | // TODO(edisonn): add options to render forms, checkboxes, ... |
| 28 | // TODO(edisonn): Add API for Forms viewing and editing |
| 29 | // e.g. SkBitmap getPage(int page); |
| 30 | // int formsCount(); |
| 31 | // SkForm getForm(int formID); // SkForm(SkRect, .. other data) |
| 32 | // TODO (edisonn): Add intend when loading pdf, for example: for viewing, for parsing content, ... |
| 33 | |
| 34 | class SkPdfRenderer { |
| edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 35 | SkPdfNativeDoc* fPdfDoc; |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 36 | public: |
| 37 | SkPdfRenderer() : fPdfDoc(NULL) {} |
| 38 | virtual ~SkPdfRenderer() {unload();} |
| 39 | |
| edisonn@google.com | 444e25a | 2013-07-11 15:20:50 +0000 | [diff] [blame] | 40 | bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const; |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 41 | |
| edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame^] | 42 | // TODO(edisonn): deprecated, should be removed! |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 43 | bool load(const SkString inputFileName); |
| edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame^] | 44 | |
| edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 45 | bool load(SkStream* stream); |
| edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame^] | 46 | |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 47 | void unload(); |
| edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame^] | 48 | |
| 49 | bool loaded() const {return fPdfDoc != NULL;} |
| 50 | |
| 51 | int pages() const; |
| 52 | |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 53 | SkRect MediaBox(int page) const; |
| edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame^] | 54 | |
| 55 | // TODO(edisonn): for testing only, probably it should be removed, unless some client wants to |
| 56 | // let users know how much memory the PDF needs. |
| edisonn@google.com | 7b328fd | 2013-07-11 12:53:06 +0000 | [diff] [blame] | 57 | size_t bytesUsed() const; |
| edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | void reportPdfRenderStats(); |
| 61 | |
| edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 62 | bool SkPDFNativeRenderToBitmap(SkStream* stream, |
| 63 | SkBitmap* output, |
| 64 | int page = 0, |
| 65 | SkPdfContent content = kAll_SkPdfContent, |
| 66 | double dpi = 72.0); |
| 67 | |
| edisonn@google.com | 15b1118 | 2013-07-11 14:43:15 +0000 | [diff] [blame] | 68 | #endif // SkPdfRenderer_DEFINED |