blob: c4cfe236acc98945fe0b254c5f5db4676c0bab6c [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
22enum SkPdfContent {
23 kNoForms_SkPdfContent,
24 kAll_SkPdfContent,
25};
edisonn@google.com222382b2013-07-10 22:33:10 +000026
edisonn@google.come50d9a12013-10-10 20:58:22 +000027// 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
34class SkPdfRenderer {
edisonn@google.com3aa35552013-08-14 18:26:20 +000035 SkPdfNativeDoc* fPdfDoc;
edisonn@google.com222382b2013-07-10 22:33:10 +000036public:
37 SkPdfRenderer() : fPdfDoc(NULL) {}
38 virtual ~SkPdfRenderer() {unload();}
39
edisonn@google.com444e25a2013-07-11 15:20:50 +000040 bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const;
edisonn@google.com222382b2013-07-10 22:33:10 +000041
edisonn@google.come50d9a12013-10-10 20:58:22 +000042 // TODO(edisonn): deprecated, should be removed!
edisonn@google.com222382b2013-07-10 22:33:10 +000043 bool load(const SkString inputFileName);
edisonn@google.come50d9a12013-10-10 20:58:22 +000044
edisonn@google.com147adb12013-07-24 15:56:19 +000045 bool load(SkStream* stream);
edisonn@google.come50d9a12013-10-10 20:58:22 +000046
edisonn@google.com222382b2013-07-10 22:33:10 +000047 void unload();
edisonn@google.come50d9a12013-10-10 20:58:22 +000048
49 bool loaded() const {return fPdfDoc != NULL;}
50
51 int pages() const;
52
edisonn@google.com222382b2013-07-10 22:33:10 +000053 SkRect MediaBox(int page) const;
edisonn@google.come50d9a12013-10-10 20:58:22 +000054
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.com7b328fd2013-07-11 12:53:06 +000057 size_t bytesUsed() const;
edisonn@google.com222382b2013-07-10 22:33:10 +000058};
59
60void reportPdfRenderStats();
61
edisonn@google.com147adb12013-07-24 15:56:19 +000062bool SkPDFNativeRenderToBitmap(SkStream* stream,
63 SkBitmap* output,
64 int page = 0,
65 SkPdfContent content = kAll_SkPdfContent,
66 double dpi = 72.0);
67
edisonn@google.com15b11182013-07-11 14:43:15 +000068#endif // SkPdfRenderer_DEFINED