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 | |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 22 | // What kind of content to render. |
edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 23 | enum SkPdfContent { |
| 24 | kNoForms_SkPdfContent, |
| 25 | kAll_SkPdfContent, |
| 26 | }; |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 27 | |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 28 | /** \class SkPdfRenderer |
| 29 | * |
| 30 | * The SkPdfRenderer class is used to render a PDF into canvas. |
| 31 | * |
| 32 | */ |
| 33 | class SkPdfRenderer { |
| 34 | public: |
| 35 | SkPdfRenderer() : fPdfDoc(NULL) {} |
| 36 | virtual ~SkPdfRenderer() {unload();} |
| 37 | |
| 38 | // Render a specific page into the canvas, in a specific rectangle. |
| 39 | bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const; |
| 40 | |
| 41 | // TODO(edisonn): deprecated, should be removed! |
| 42 | bool load(const SkString inputFileName); |
| 43 | |
| 44 | // TODO(edisonn): replace it with a SkSmartStream which would know to to efficiently |
| 45 | // deal with a HTTP stream. |
| 46 | bool load(SkStream* stream); |
| 47 | |
| 48 | // Unloads the pdf document. |
| 49 | void unload(); |
| 50 | |
| 51 | // Returns true if we succesfully loaded a document. |
| 52 | bool loaded() const {return fPdfDoc != NULL && pages() > 0;} |
| 53 | |
| 54 | // Returns the number of pages in the loaded pdf. |
| 55 | int pages() const; |
| 56 | |
| 57 | // Returns the MediaBox of a page. Can be used by client to crate a canvas. |
| 58 | SkRect MediaBox(int page) const; |
| 59 | |
| 60 | // TODO(edisonn): for testing only, probably it should be removed, unless some client wants to |
| 61 | // let users know how much memory the PDF needs. |
| 62 | size_t bytesUsed() const; |
| 63 | |
| 64 | private: |
| 65 | SkPdfNativeDoc* fPdfDoc; |
| 66 | }; |
| 67 | |
| 68 | // For testing only, reports stats about rendering, like how many operations failed, or are NYI, ... |
| 69 | void reportPdfRenderStats(); |
| 70 | |
| 71 | // Renders a page of a pdf in a bitmap. |
| 72 | bool SkPDFNativeRenderToBitmap(SkStream* stream, |
| 73 | SkBitmap* output, |
| 74 | int page = 0, |
| 75 | SkPdfContent content = kAll_SkPdfContent, |
| 76 | double dpi = 72.0); |
| 77 | |
edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame] | 78 | // TODO(edisonn): add options to render forms, checkboxes, ... |
| 79 | // TODO(edisonn): Add API for Forms viewing and editing |
| 80 | // e.g. SkBitmap getPage(int page); |
| 81 | // int formsCount(); |
| 82 | // SkForm getForm(int formID); // SkForm(SkRect, .. other data) |
| 83 | // TODO (edisonn): Add intend when loading pdf, for example: for viewing, for parsing content, ... |
| 84 | |
edisonn@google.com | 15b1118 | 2013-07-11 14:43:15 +0000 | [diff] [blame] | 85 | #endif // SkPdfRenderer_DEFINED |