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

Side by Side Diff: samplecode/SamplePdfFileViewer.cpp

Issue 17904006: Add an option to have a PdfViewer in SampleApp. Add a parameter --pdfDir to pass the dir with pdfs.… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 months 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
« samplecode/SampleApp.cpp ('K') | « samplecode/SampleApp.cpp ('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
(Empty)
1
2 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #ifdef SAMPLE_PDF_FILE_VIEWER
10
11 #include "SampleCode.h"
12 #include "SkDumpCanvas.h"
13 #include "SkView.h"
14 #include "SkCanvas.h"
15 #include "Sk64.h"
16 #include "SkGradientShader.h"
17 #include "SkGraphics.h"
18 #include "SkImageDecoder.h"
19 #include "SkOSFile.h"
20 #include "SkPath.h"
21 #include "SkPicture.h"
22 #include "SkRandom.h"
23 #include "SkRegion.h"
24 #include "SkShader.h"
25 #include "SkUtils.h"
26 #include "SkColorPriv.h"
27 #include "SkColorFilter.h"
28 #include "SkTime.h"
29 #include "SkTypeface.h"
30 #include "SkXfermode.h"
31
32 #include "SkPdfParser.h"
33
34 class PdfFileViewer : public SampleView {
35 SkString fFilename;
36 SkPicture* fPicture; // TODO(edisonn): multiple pages, one page / picture, make it an array
37
38 static SkPicture* LoadPdf(const char path[]) {
39 SkPicture* pic = NULL;
40
41 SkPdfDoc doc(path);
vandebo (ex-Chrome) 2013/06/26 21:58:36 We now have SkPDFDocument and SkPdfDoc? That's no
edisonn 2013/07/02 23:20:33 Renamed to SkPodofoParsedPDF There will be a SkNa
42 if (doc.pages()) {
43 pic = SkNEW(SkPicture);
44 SkCanvas* canvas = pic->beginRecording((int)doc.width(0), (int)doc.h eight(0));
45 doc.drawPage(0, canvas);
46 pic->endRecording();
47 }
48 return pic;
49 }
50
51 public:
52 PdfFileViewer(const char name[] = NULL) : fFilename(name) {
53 fPicture = NULL;
54 }
55
56 virtual ~PdfFileViewer() {
57 SkSafeUnref(fPicture);
58 }
59
60 protected:
61 // overrides from SkEventSink
62 virtual bool onQuery(SkEvent* evt) {
63 if (SampleCode::TitleQ(*evt)) {
64 SkString name("P:");
65 const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR);
66 name.append(basename ? basename+1: fFilename.c_str());
67 SampleCode::TitleR(evt, name.c_str());
68 return true;
69 }
70 return this->INHERITED::onQuery(evt);
71 }
72
73 virtual bool onEvent(const SkEvent& evt) {
74 // TODO(edisonn): add here event handlers to disable clipping, or to sho w helpful info
75 // like pdf object from click, ...
76 // TODO(edisonn): first, next, prev, last page navigation + slideshow
77 return this->INHERITED::onEvent(evt);
78 }
79
80 virtual void onDrawContent(SkCanvas* canvas) {
81 if (!fPicture) {
82 fPicture = LoadPdf(fFilename.c_str());
83 }
84 if (fPicture) {
85 canvas->drawPicture(*fPicture);
86 }
87 }
88
89 private:
90 typedef SampleView INHERITED;
91 };
92
93 SampleView* CreateSamplePdfFileViewer(const char filename[]);
94 SampleView* CreateSamplePdfFileViewer(const char filename[]) {
95 return new PdfFileViewer(filename);
96 }
97
98 //////////////////////////////////////////////////////////////////////////////
99
100 #if 0
101 static SkView* MyFactory() { return new PdfFileViewer; }
102 static SkViewRegister reg(MyFactory);
103 #endif
104
105 #endif // SAMPLE_PDF_FILE_VIEWER
OLDNEW
« samplecode/SampleApp.cpp ('K') | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698