Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: experimental/PdfViewer/inc/SkPdfRenderer.h

Issue 59493011: Pdfviewer refactoring. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Move include/ to inc/ Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « experimental/PdfViewer/SkPdfRenderer.cpp ('k') | experimental/PdfViewer/pdf_viewer_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 8
9 #ifndef SkPdfRenderer_DEFINED 9 #ifndef SkPdfRenderer_DEFINED
10 #define SkPdfRenderer_DEFINED 10 #define SkPdfRenderer_DEFINED
11 11
12 // TODO(edisonn): remove this dependency, and load only from a stream! 12 #include "SkTypes.h"
13 #include "SkString.h"
14 13
15 class SkBitmap; 14 class SkBitmap;
16 class SkCanvas; 15 class SkCanvas;
17 class SkPdfNativeDoc; 16 class SkPdfNativeDoc;
18 struct SkRect; 17 struct SkRect;
19 class SkStream; 18 class SkStream;
20 class SkString;
21 19
22 // What kind of content to render. 20 // What kind of content to render.
21 // FIXME: Currently unused.
23 enum SkPdfContent { 22 enum SkPdfContent {
24 kNoForms_SkPdfContent, 23 kNoForms_SkPdfContent,
25 kAll_SkPdfContent, 24 kAll_SkPdfContent,
26 }; 25 };
27 26
28 /** \class SkPdfRenderer 27 /** \class SkPdfRenderer
29 * 28 *
30 * The SkPdfRenderer class is used to render a PDF into canvas. 29 * The SkPdfRenderer class is used to render a PDF into canvas.
31 * 30 *
32 */ 31 */
33 class SkPdfRenderer { 32 class SkPdfRenderer : public SkNoncopyable {
34 public: 33 public:
35 SkPdfRenderer() : fPdfDoc(NULL) {} 34 // Create a new renderer from a stream.
36 virtual ~SkPdfRenderer() {unload();} 35 // TODO(edisonn): replace it with a SkSmartStream which would know to to eff iciently
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();
37 43
38 // Render a specific page into the canvas, in a specific rectangle. 44 // Render a specific page into the canvas, in a specific rectangle.
39 bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const; 45 bool renderPage(int page, SkCanvas* canvas, const SkRect& dst) const;
40 46
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 eff iciently
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. 47 // Returns the number of pages in the loaded pdf.
55 int pages() const; 48 int pages() const;
56 49
57 // Returns the MediaBox of a page. Can be used by client to crate a canvas. 50 // Returns the MediaBox of a page. Can be used by client to crate a canvas.
58 SkRect MediaBox(int page) const; 51 SkRect MediaBox(int page) const;
59 52
60 // TODO(edisonn): for testing only, probably it should be removed, unless so me client wants to 53 // TODO(edisonn): for testing only, probably it should be removed, unless so me client wants to
61 // let users know how much memory the PDF needs. 54 // let users know how much memory the PDF needs.
62 size_t bytesUsed() const; 55 size_t bytesUsed() const;
63 56
64 private: 57 private:
58 // Takes ownership of SkPdfNativeDoc.
59 SkPdfRenderer(SkPdfNativeDoc*);
65 SkPdfNativeDoc* fPdfDoc; 60 SkPdfNativeDoc* fPdfDoc;
66 }; 61 };
67 62
68 // For testing only, reports stats about rendering, like how many operations fai led, or are NYI, ... 63 // For testing only, reports stats about rendering, like how many operations fai led, or are NYI, ...
69 void reportPdfRenderStats(); 64 void reportPdfRenderStats();
70 65
71 // Renders a page of a pdf in a bitmap. 66 // Renders a page of a pdf in a bitmap.
72 bool SkPDFNativeRenderToBitmap(SkStream* stream, 67 bool SkPDFNativeRenderToBitmap(SkStream* stream,
73 SkBitmap* output, 68 SkBitmap* output,
74 int page = 0, 69 int page = 0,
75 SkPdfContent content = kAll_SkPdfContent, 70 SkPdfContent content = kAll_SkPdfContent,
76 double dpi = 72.0); 71 double dpi = 72.0);
77 72
78 // TODO(edisonn): add options to render forms, checkboxes, ... 73 // TODO(edisonn): add options to render forms, checkboxes, ...
79 // TODO(edisonn): Add API for Forms viewing and editing 74 // TODO(edisonn): Add API for Forms viewing and editing
80 // e.g. SkBitmap getPage(int page); 75 // e.g. SkBitmap getPage(int page);
81 // int formsCount(); 76 // int formsCount();
82 // SkForm getForm(int formID); // SkForm(SkRect, .. other data) 77 // SkForm getForm(int formID); // SkForm(SkRect, .. other data)
83 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, for pa rsing content, ... 78 // TODO (edisonn): Add intend when loading pdf, for example: for viewing, for pa rsing content, ...
84 79
85 #endif // SkPdfRenderer_DEFINED 80 #endif // SkPdfRenderer_DEFINED
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfRenderer.cpp ('k') | experimental/PdfViewer/pdf_viewer_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698