diff options
author | 2013-11-14 19:09:27 +0000 | |
---|---|---|
committer | 2013-11-14 19:09:27 +0000 | |
commit | 909228992c1671ea7451d1c6bc588a8ec991841e (patch) | |
tree | 5ddd2c2f4f1fc2f94f51512a49cfccbae83a4cd4 /experimental/PdfViewer/inc | |
parent | be65a4c9d6ce40e7fc27e5a830196bcaa7be97c9 (diff) |
Pdfviewer refactoring.
Mostly superficial changes, to help me make sure I understand the
code while making modifications.
SkPdfRenderer:
First class I'm modifying. Move it into include/ and src/ directories.
Inherit from SkNoncopyable.
Replace load() with factory function which returns NULL if the load
fails.
Remove unload() and loaded(), which no longer make sense, since the
factory will return NULL on a failure to load, and unload() happens
on destruction.
Use a const char* for loading a PDF, following the convention of
SkStream::NewFromFile.
Remove unnecessary call to sqrt in SkPDFNativeRenderToBitmap.
Also in SkPDFNativeRenderToBitmap, use an appropriate SkScalar macro
to convert to an integer.
Use this-> when calling member functions.
pdf_viewer_main.cpp:
Call the new interface for SkPdfRenderer.
gyp files:
Refer to the new location of SkPdfRenderer.
R=edisonn@google.com
Review URL: https://codereview.chromium.org/59493011
git-svn-id: http://skia.googlecode.com/svn/trunk@12296 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/PdfViewer/inc')
-rw-r--r-- | experimental/PdfViewer/inc/SkPdfRenderer.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/experimental/PdfViewer/inc/SkPdfRenderer.h b/experimental/PdfViewer/inc/SkPdfRenderer.h new file mode 100644 index 0000000000..c978a739ec --- /dev/null +++ b/experimental/PdfViewer/inc/SkPdfRenderer.h @@ -0,0 +1,80 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + + +#ifndef SkPdfRenderer_DEFINED +#define SkPdfRenderer_DEFINED + +#include "SkTypes.h" + +class SkBitmap; +class SkCanvas; +class SkPdfNativeDoc; +struct SkRect; +class SkStream; + +// What kind of content to render. +// FIXME: Currently unused. +enum SkPdfContent { + kNoForms_SkPdfContent, + kAll_SkPdfContent, +}; + +/** \class SkPdfRenderer + * + * The SkPdfRenderer class is used to render a PDF into canvas. + * + */ +class SkPdfRenderer : public SkNoncopyable { +public: + // Create a new renderer from a stream. + // TODO(edisonn): replace it with a SkSmartStream which would know to to efficiently + // deal with a HTTP stream. + // FIXME: Untested. + static SkPdfRenderer* CreateFromStream(SkStream*); + // Create a new renderer from a file. + static SkPdfRenderer* CreateFromFile(const char* filename); + + ~SkPdfRenderer(); + + // Render a specific page into the canvas, in a specific rectangle. + bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const; + + // Returns the number of pages in the loaded pdf. + int pages() const; + + // Returns the MediaBox of a page. Can be used by client to crate a canvas. + SkRect MediaBox(int page) const; + + // TODO(edisonn): for testing only, probably it should be removed, unless some client wants to + // let users know how much memory the PDF needs. + size_t bytesUsed() const; + +private: + // Takes ownership of SkPdfNativeDoc. + SkPdfRenderer(SkPdfNativeDoc*); + SkPdfNativeDoc* fPdfDoc; +}; + +// For testing only, reports stats about rendering, like how many operations failed, or are NYI, ... +void reportPdfRenderStats(); + +// Renders a page of a pdf in a bitmap. +bool SkPDFNativeRenderToBitmap(SkStream* stream, + SkBitmap* output, + int page = 0, + SkPdfContent content = kAll_SkPdfContent, + double dpi = 72.0); + +// 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, ... + +#endif // SkPdfRenderer_DEFINED |