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
9#ifndef SkPdfRenderer_DEFINED
10#define SkPdfRenderer_DEFINED
11
12#include "SkTypes.h"
13
14class SkBitmap;
15class SkCanvas;
16class SkPdfNativeDoc;
17struct SkRect;
18class SkStream;
19
20// What kind of content to render.
21// FIXME: Currently unused.
22enum SkPdfContent {
23    kNoForms_SkPdfContent,
24    kAll_SkPdfContent,
25};
26
27/** \class SkPdfRenderer
28 *
29 *  The SkPdfRenderer class is used to render a PDF into canvas.
30 *
31 */
32class SkPdfRenderer : SkNoncopyable {
33public:
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();
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
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
57private:
58    // Takes ownership of SkPdfNativeDoc.
59    SkPdfRenderer(SkPdfNativeDoc*);
60    SkPdfNativeDoc* fPdfDoc;
61};
62
63// For testing only, reports stats about rendering, like how many operations failed, or are NYI, ...
64void reportPdfRenderStats();
65
66// Renders a page of a pdf in a bitmap.
67bool SkPDFNativeRenderToBitmap(SkStream* stream,
68                               SkBitmap* output,
69                               int page = 0,
70                               SkPdfContent content = kAll_SkPdfContent,
71                               double dpi = 72.0);
72
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
80#endif  // SkPdfRenderer_DEFINED
81