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

Side by Side Diff: samplecode/SamplePdfFileViewer.cpp

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 | « gyp/pdfviewer_lib.gyp ('k') | no next file » | 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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #ifdef SAMPLE_PDF_FILE_VIEWER 9 #ifdef SAMPLE_PDF_FILE_VIEWER
10 10
(...skipping 19 matching lines...) Expand all
30 #include "SkXfermode.h" 30 #include "SkXfermode.h"
31 31
32 #include "SkPdfRenderer.h" 32 #include "SkPdfRenderer.h"
33 33
34 class PdfFileViewer : public SampleView { 34 class PdfFileViewer : public SampleView {
35 private: 35 private:
36 SkString fFilename; 36 SkString fFilename;
37 SkPicture* fPicture; // TODO(edisonn): multiple pages, one page / picture, make it an array 37 SkPicture* fPicture; // TODO(edisonn): multiple pages, one page / picture, make it an array
38 38
39 static SkPicture* LoadPdf(const char path[]) { 39 static SkPicture* LoadPdf(const char path[]) {
40 SkPicture* pic = NULL; 40 SkAutoTDelete<SkPdfRenderer> renderer(SkPdfRenderer::CreateFromFile(path ));
41 if (NULL == renderer.get()) {
42 return NULL;
43 }
41 44
42 SkPdfRenderer renderer; 45 SkPicture* pic = SkNEW(SkPicture);
43 SkString skpath; 46 SkCanvas* canvas = pic->beginRecording((int) renderer->MediaBox(0).width (),
44 skpath.append(path); 47 (int) renderer->MediaBox(0).heigh t());
45 renderer.load(skpath); 48 renderer->renderPage(0, canvas, renderer->MediaBox(0));
46 if (renderer.loaded()) { 49 pic->endRecording();
47 pic = SkNEW(SkPicture);
48 SkCanvas* canvas = pic->beginRecording((int)renderer.MediaBox(0).wid th(), (int)renderer.MediaBox(0).height());
49 renderer.renderPage(0, canvas, renderer.MediaBox(0));
50 pic->endRecording();
51 }
52 return pic; 50 return pic;
53 } 51 }
54 52
55 public: 53 public:
56 PdfFileViewer(const char name[] = NULL) : fFilename(name) { 54 PdfFileViewer(const char name[] = NULL) : fFilename(name) {
57 fPicture = NULL; 55 fPicture = NULL;
58 } 56 }
59 57
60 virtual ~PdfFileViewer() { 58 virtual ~PdfFileViewer() {
61 SkSafeUnref(fPicture); 59 SkSafeUnref(fPicture);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 98 }
101 99
102 ////////////////////////////////////////////////////////////////////////////// 100 //////////////////////////////////////////////////////////////////////////////
103 101
104 #if 0 102 #if 0
105 static SkView* MyFactory() { return new PdfFileViewer; } 103 static SkView* MyFactory() { return new PdfFileViewer; }
106 static SkViewRegister reg(MyFactory); 104 static SkViewRegister reg(MyFactory);
107 #endif 105 #endif
108 106
109 #endif // SAMPLE_PDF_FILE_VIEWER 107 #endif // SAMPLE_PDF_FILE_VIEWER
OLDNEW
« no previous file with comments | « gyp/pdfviewer_lib.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698