| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #ifndef SkPdfRenderer_DEFINED | 9 #ifndef SkPdfRenderer_DEFINED |
| 10 #define SkPdfRenderer_DEFINED | 10 #define SkPdfRenderer_DEFINED |
| 11 | 11 |
| 12 // TODO(edisonn): remove this dependency, and load only from a stream! | 12 // TODO(edisonn): remove this dependency, and load only from a stream! |
| 13 #include "SkString.h" | 13 #include "SkString.h" |
| 14 | 14 |
| 15 class SkBitmap; | 15 class SkBitmap; |
| 16 class SkCanvas; | 16 class SkCanvas; |
| 17 class SkPdfNativeDoc; | 17 class SkPdfNativeDoc; |
| 18 struct SkRect; | 18 struct SkRect; |
| 19 class SkStream; | 19 class SkStream; |
| 20 class SkString; | 20 class SkString; |
| 21 | 21 |
| 22 // What kind of content to render. |
| 22 enum SkPdfContent { | 23 enum SkPdfContent { |
| 23 kNoForms_SkPdfContent, | 24 kNoForms_SkPdfContent, |
| 24 kAll_SkPdfContent, | 25 kAll_SkPdfContent, |
| 25 }; | 26 }; |
| 26 | 27 |
| 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 eff
iciently |
| 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 so
me 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 fai
led, 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 |
| 27 // TODO(edisonn): add options to render forms, checkboxes, ... | 78 // TODO(edisonn): add options to render forms, checkboxes, ... |
| 28 // TODO(edisonn): Add API for Forms viewing and editing | 79 // TODO(edisonn): Add API for Forms viewing and editing |
| 29 // e.g. SkBitmap getPage(int page); | 80 // e.g. SkBitmap getPage(int page); |
| 30 // int formsCount(); | 81 // int formsCount(); |
| 31 // SkForm getForm(int formID); // SkForm(SkRect, .. other data) | 82 // SkForm getForm(int formID); // SkForm(SkRect, .. other data) |
| 32 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, for pa
rsing content, ... | 83 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, for pa
rsing content, ... |
| 33 | 84 |
| 34 class SkPdfRenderer { | |
| 35 SkPdfNativeDoc* fPdfDoc; | |
| 36 public: | |
| 37 SkPdfRenderer() : fPdfDoc(NULL) {} | |
| 38 virtual ~SkPdfRenderer() {unload();} | |
| 39 | |
| 40 bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const; | |
| 41 | |
| 42 // TODO(edisonn): deprecated, should be removed! | |
| 43 bool load(const SkString inputFileName); | |
| 44 | |
| 45 bool load(SkStream* stream); | |
| 46 | |
| 47 void unload(); | |
| 48 | |
| 49 bool loaded() const {return fPdfDoc != NULL;} | |
| 50 | |
| 51 int pages() const; | |
| 52 | |
| 53 SkRect MediaBox(int page) const; | |
| 54 | |
| 55 // TODO(edisonn): for testing only, probably it should be removed, unless so
me client wants to | |
| 56 // let users know how much memory the PDF needs. | |
| 57 size_t bytesUsed() const; | |
| 58 }; | |
| 59 | |
| 60 void reportPdfRenderStats(); | |
| 61 | |
| 62 bool SkPDFNativeRenderToBitmap(SkStream* stream, | |
| 63 SkBitmap* output, | |
| 64 int page = 0, | |
| 65 SkPdfContent content = kAll_SkPdfContent, | |
| 66 double dpi = 72.0); | |
| 67 | |
| 68 #endif // SkPdfRenderer_DEFINED | 85 #endif // SkPdfRenderer_DEFINED |
| OLD | NEW |