blob: 51b564973ec9a023e60a48abee610370bac05a84 [file] [log] [blame]
edisonn@google.com222382b2013-07-10 22:33:10 +00001/*
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.com15b11182013-07-11 14:43:15 +00009#ifndef SkPdfRenderer_DEFINED
10#define SkPdfRenderer_DEFINED
edisonn@google.com222382b2013-07-10 22:33:10 +000011
edisonn@google.come50d9a12013-10-10 20:58:22 +000012// TODO(edisonn): remove this dependency, and load only from a stream!
edisonn@google.comaf54a512013-09-13 19:33:42 +000013#include "SkString.h"
14
edisonn@google.com147adb12013-07-24 15:56:19 +000015class SkBitmap;
edisonn@google.com222382b2013-07-10 22:33:10 +000016class SkCanvas;
edisonn@google.com3aa35552013-08-14 18:26:20 +000017class SkPdfNativeDoc;
edisonn@google.com96ba3aa2013-07-28 20:04:35 +000018struct SkRect;
edisonn@google.com147adb12013-07-24 15:56:19 +000019class SkStream;
edisonn@google.comaf54a512013-09-13 19:33:42 +000020class SkString;
edisonn@google.com147adb12013-07-24 15:56:19 +000021
edisonn@google.comd03c2c72013-10-11 18:26:45 +000022// What kind of content to render.
edisonn@google.com147adb12013-07-24 15:56:19 +000023enum SkPdfContent {
24 kNoForms_SkPdfContent,
25 kAll_SkPdfContent,
26};
edisonn@google.com222382b2013-07-10 22:33:10 +000027
edisonn@google.comd03c2c72013-10-11 18:26:45 +000028/** \class SkPdfRenderer
29 *
30 * The SkPdfRenderer class is used to render a PDF into canvas.
31 *
32 */
33class SkPdfRenderer {
34public:
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
64private:
65 SkPdfNativeDoc* fPdfDoc;
66};
67
68// For testing only, reports stats about rendering, like how many operations failed, or are NYI, ...
69void reportPdfRenderStats();
70
71// Renders a page of a pdf in a bitmap.
72bool SkPDFNativeRenderToBitmap(SkStream* stream,
73 SkBitmap* output,
74 int page = 0,
75 SkPdfContent content = kAll_SkPdfContent,
76 double dpi = 72.0);
77
edisonn@google.come50d9a12013-10-10 20:58:22 +000078// 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.com15b11182013-07-11 14:43:15 +000085#endif // SkPdfRenderer_DEFINED