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 | |
scroggo@google.com | 9092289 | 2013-11-14 19:09:27 +0000 | [diff] [blame] | 12 | #include "SkTypes.h" |
edisonn@google.com | af54a51 | 2013-09-13 19:33:42 +0000 | [diff] [blame] | 13 | |
edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 14 | class SkBitmap; |
edisonn@google.com | 222382b | 2013-07-10 22:33:10 +0000 | [diff] [blame] | 15 | class SkCanvas; |
edisonn@google.com | 3aa3555 | 2013-08-14 18:26:20 +0000 | [diff] [blame] | 16 | class SkPdfNativeDoc; |
edisonn@google.com | 96ba3aa | 2013-07-28 20:04:35 +0000 | [diff] [blame] | 17 | struct SkRect; |
edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 18 | class SkStream; |
| 19 | |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 20 | // What kind of content to render. |
scroggo@google.com | 9092289 | 2013-11-14 19:09:27 +0000 | [diff] [blame] | 21 | // FIXME: Currently unused. |
edisonn@google.com | 147adb1 | 2013-07-24 15:56:19 +0000 | [diff] [blame] | 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 | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 27 | /** \class SkPdfRenderer |
| 28 | * |
| 29 | * The SkPdfRenderer class is used to render a PDF into canvas. |
| 30 | * |
| 31 | */ |
commit-bot@chromium.org | e3beb6b | 2014-04-07 19:34:38 +0000 | [diff] [blame] | 32 | class SkPdfRenderer : SkNoncopyable { |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 33 | public: |
scroggo@google.com | 9092289 | 2013-11-14 19:09:27 +0000 | [diff] [blame] | 34 | // Create a new renderer from a stream. |
| 35 | // TODO(edisonn): replace it with a SkSmartStream which would know to to efficiently |
| 36 | // deal with a HTTP stream. |
| 37 | // FIXME: Untested. |
| 38 | static SkPdfRenderer* CreateFromStream(SkStream*); |
| 39 | // Create a new renderer from a file. |
| 40 | static SkPdfRenderer* CreateFromFile(const char* filename); |
| 41 | |
| 42 | ~SkPdfRenderer(); |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 43 | |
| 44 | // Render a specific page into the canvas, in a specific rectangle. |
| 45 | bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const; |
| 46 | |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 47 | // Returns the number of pages in the loaded pdf. |
| 48 | int pages() const; |
| 49 | |
| 50 | // Returns the MediaBox of a page. Can be used by client to crate a canvas. |
| 51 | SkRect MediaBox(int page) const; |
| 52 | |
| 53 | // TODO(edisonn): for testing only, probably it should be removed, unless some client wants to |
| 54 | // let users know how much memory the PDF needs. |
| 55 | size_t bytesUsed() const; |
| 56 | |
| 57 | private: |
scroggo@google.com | 9092289 | 2013-11-14 19:09:27 +0000 | [diff] [blame] | 58 | // Takes ownership of SkPdfNativeDoc. |
| 59 | SkPdfRenderer(SkPdfNativeDoc*); |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 60 | SkPdfNativeDoc* fPdfDoc; |
| 61 | }; |
| 62 | |
| 63 | // For testing only, reports stats about rendering, like how many operations failed, or are NYI, ... |
| 64 | void reportPdfRenderStats(); |
| 65 | |
| 66 | // Renders a page of a pdf in a bitmap. |
| 67 | bool SkPDFNativeRenderToBitmap(SkStream* stream, |
| 68 | SkBitmap* output, |
| 69 | int page = 0, |
| 70 | SkPdfContent content = kAll_SkPdfContent, |
| 71 | double dpi = 72.0); |
| 72 | |
edisonn@google.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame] | 73 | // TODO(edisonn): add options to render forms, checkboxes, ... |
| 74 | // TODO(edisonn): Add API for Forms viewing and editing |
| 75 | // e.g. SkBitmap getPage(int page); |
| 76 | // int formsCount(); |
| 77 | // SkForm getForm(int formID); // SkForm(SkRect, .. other data) |
| 78 | // TODO (edisonn): Add intend when loading pdf, for example: for viewing, for parsing content, ... |
| 79 | |
edisonn@google.com | 15b1118 | 2013-07-11 14:43:15 +0000 | [diff] [blame] | 80 | #endif // SkPdfRenderer_DEFINED |