OLD | NEW |
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 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 | 9 |
10 #ifdef SAMPLE_PDF_FILE_VIEWER | 10 #ifdef SAMPLE_PDF_FILE_VIEWER |
(...skipping 20 matching lines...) Expand all Loading... |
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 SkAutoTDelete<SkPdfRenderer> renderer(SkPdfRenderer::CreateFromFile(path
)); | 40 SkAutoTDelete<SkPdfRenderer> renderer(SkPdfRenderer::CreateFromFile(path
)); |
41 if (NULL == renderer.get()) { | 41 if (nullptr == renderer.get()) { |
42 return NULL; | 42 return nullptr; |
43 } | 43 } |
44 | 44 |
45 SkPicture* pic = new SkPicture; | 45 SkPicture* pic = new SkPicture; |
46 SkCanvas* canvas = pic->beginRecording((int) renderer->MediaBox(0).width
(), | 46 SkCanvas* canvas = pic->beginRecording((int) renderer->MediaBox(0).width
(), |
47 (int) renderer->MediaBox(0).heigh
t()); | 47 (int) renderer->MediaBox(0).heigh
t()); |
48 renderer->renderPage(0, canvas, renderer->MediaBox(0)); | 48 renderer->renderPage(0, canvas, renderer->MediaBox(0)); |
49 pic->endRecording(); | 49 pic->endRecording(); |
50 return pic; | 50 return pic; |
51 } | 51 } |
52 | 52 |
53 public: | 53 public: |
54 PdfFileViewer(const char name[] = NULL) : fFilename(name) { | 54 PdfFileViewer(const char name[] = nullptr) : fFilename(name) { |
55 fPicture = NULL; | 55 fPicture = nullptr; |
56 } | 56 } |
57 | 57 |
58 virtual ~PdfFileViewer() { | 58 virtual ~PdfFileViewer() { |
59 SkSafeUnref(fPicture); | 59 SkSafeUnref(fPicture); |
60 } | 60 } |
61 | 61 |
62 protected: | 62 protected: |
63 // overrides from SkEventSink | 63 // overrides from SkEventSink |
64 virtual bool onQuery(SkEvent* evt) { | 64 virtual bool onQuery(SkEvent* evt) { |
65 if (SampleCode::TitleQ(*evt)) { | 65 if (SampleCode::TitleQ(*evt)) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 | 99 |
100 ////////////////////////////////////////////////////////////////////////////// | 100 ////////////////////////////////////////////////////////////////////////////// |
101 | 101 |
102 #if 0 | 102 #if 0 |
103 static SkView* MyFactory() { return new PdfFileViewer; } | 103 static SkView* MyFactory() { return new PdfFileViewer; } |
104 static SkViewRegister reg(MyFactory); | 104 static SkViewRegister reg(MyFactory); |
105 #endif | 105 #endif |
106 | 106 |
107 #endif // SAMPLE_PDF_FILE_VIEWER | 107 #endif // SAMPLE_PDF_FILE_VIEWER |
OLD | NEW |