2013-07-10 22:33:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-07-11 14:43:15 +00:00
|
|
|
#ifndef SkPdfRenderer_DEFINED
|
|
|
|
#define SkPdfRenderer_DEFINED
|
2013-07-10 22:33:10 +00:00
|
|
|
|
2013-11-14 19:09:27 +00:00
|
|
|
#include "SkTypes.h"
|
2013-09-13 19:33:42 +00:00
|
|
|
|
2013-07-24 15:56:19 +00:00
|
|
|
class SkBitmap;
|
2013-07-10 22:33:10 +00:00
|
|
|
class SkCanvas;
|
2013-08-14 18:26:20 +00:00
|
|
|
class SkPdfNativeDoc;
|
2013-07-28 20:04:35 +00:00
|
|
|
struct SkRect;
|
2013-07-24 15:56:19 +00:00
|
|
|
class SkStream;
|
|
|
|
|
2013-10-11 18:26:45 +00:00
|
|
|
// What kind of content to render.
|
2013-11-14 19:09:27 +00:00
|
|
|
// FIXME: Currently unused.
|
2013-07-24 15:56:19 +00:00
|
|
|
enum SkPdfContent {
|
|
|
|
kNoForms_SkPdfContent,
|
|
|
|
kAll_SkPdfContent,
|
|
|
|
};
|
2013-07-10 22:33:10 +00:00
|
|
|
|
2013-10-11 18:26:45 +00:00
|
|
|
/** \class SkPdfRenderer
|
|
|
|
*
|
|
|
|
* The SkPdfRenderer class is used to render a PDF into canvas.
|
|
|
|
*
|
|
|
|
*/
|
2014-04-07 19:34:38 +00:00
|
|
|
class SkPdfRenderer : SkNoncopyable {
|
2013-07-10 22:33:10 +00:00
|
|
|
public:
|
2013-11-14 19:09:27 +00:00
|
|
|
// Create a new renderer from a stream.
|
2013-10-11 18:26:45 +00:00
|
|
|
// TODO(edisonn): replace it with a SkSmartStream which would know to to efficiently
|
|
|
|
// deal with a HTTP stream.
|
2013-11-14 19:09:27 +00:00
|
|
|
// FIXME: Untested.
|
|
|
|
static SkPdfRenderer* CreateFromStream(SkStream*);
|
|
|
|
// Create a new renderer from a file.
|
|
|
|
static SkPdfRenderer* CreateFromFile(const char* filename);
|
2013-10-10 20:58:22 +00:00
|
|
|
|
2013-11-14 19:09:27 +00:00
|
|
|
~SkPdfRenderer();
|
2013-10-10 20:58:22 +00:00
|
|
|
|
2013-11-14 19:09:27 +00:00
|
|
|
// Render a specific page into the canvas, in a specific rectangle.
|
|
|
|
bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const;
|
2013-10-10 20:58:22 +00:00
|
|
|
|
2013-10-11 18:26:45 +00:00
|
|
|
// Returns the number of pages in the loaded pdf.
|
2013-07-10 22:33:10 +00:00
|
|
|
int pages() const;
|
2013-10-10 20:58:22 +00:00
|
|
|
|
2013-10-11 18:26:45 +00:00
|
|
|
// Returns the MediaBox of a page. Can be used by client to crate a canvas.
|
2013-07-10 22:33:10 +00:00
|
|
|
SkRect MediaBox(int page) const;
|
2013-10-10 20:58:22 +00:00
|
|
|
|
|
|
|
// TODO(edisonn): for testing only, probably it should be removed, unless some client wants to
|
|
|
|
// let users know how much memory the PDF needs.
|
2013-07-11 12:53:06 +00:00
|
|
|
size_t bytesUsed() const;
|
2013-10-11 18:26:45 +00:00
|
|
|
|
|
|
|
private:
|
2013-11-14 19:09:27 +00:00
|
|
|
// Takes ownership of SkPdfNativeDoc.
|
|
|
|
SkPdfRenderer(SkPdfNativeDoc*);
|
2013-10-11 18:26:45 +00:00
|
|
|
SkPdfNativeDoc* fPdfDoc;
|
2013-07-10 22:33:10 +00:00
|
|
|
};
|
|
|
|
|
2013-10-11 18:26:45 +00:00
|
|
|
// For testing only, reports stats about rendering, like how many operations failed, or are NYI, ...
|
2013-07-10 22:33:10 +00:00
|
|
|
void reportPdfRenderStats();
|
|
|
|
|
2013-10-11 18:26:45 +00:00
|
|
|
// Renders a page of a pdf in a bitmap.
|
2013-07-24 15:56:19 +00:00
|
|
|
bool SkPDFNativeRenderToBitmap(SkStream* stream,
|
|
|
|
SkBitmap* output,
|
|
|
|
int page = 0,
|
|
|
|
SkPdfContent content = kAll_SkPdfContent,
|
|
|
|
double dpi = 72.0);
|
|
|
|
|
2013-10-11 18:26:45 +00:00
|
|
|
// TODO(edisonn): add options to render forms, checkboxes, ...
|
|
|
|
// TODO(edisonn): Add API for Forms viewing and editing
|
|
|
|
// e.g. SkBitmap getPage(int page);
|
|
|
|
// int formsCount();
|
|
|
|
// SkForm getForm(int formID); // SkForm(SkRect, .. other data)
|
|
|
|
// TODO (edisonn): Add intend when loading pdf, for example: for viewing, for parsing content, ...
|
|
|
|
|
2013-07-11 14:43:15 +00:00
|
|
|
#endif // SkPdfRenderer_DEFINED
|