Chromium Code Reviews| Index: samplecode/SamplePdfFileViewer.cpp |
| =================================================================== |
| --- samplecode/SamplePdfFileViewer.cpp (revision 0) |
| +++ samplecode/SamplePdfFileViewer.cpp (revision 0) |
| @@ -0,0 +1,105 @@ |
| + |
| +/* |
| + * Copyright 2013 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifdef SAMPLE_PDF_FILE_VIEWER |
| + |
| +#include "SampleCode.h" |
| +#include "SkDumpCanvas.h" |
| +#include "SkView.h" |
| +#include "SkCanvas.h" |
| +#include "Sk64.h" |
| +#include "SkGradientShader.h" |
| +#include "SkGraphics.h" |
| +#include "SkImageDecoder.h" |
| +#include "SkOSFile.h" |
| +#include "SkPath.h" |
| +#include "SkPicture.h" |
| +#include "SkRandom.h" |
| +#include "SkRegion.h" |
| +#include "SkShader.h" |
| +#include "SkUtils.h" |
| +#include "SkColorPriv.h" |
| +#include "SkColorFilter.h" |
| +#include "SkTime.h" |
| +#include "SkTypeface.h" |
| +#include "SkXfermode.h" |
| + |
| +#include "SkPdfParser.h" |
| + |
| +class PdfFileViewer : public SampleView { |
| + SkString fFilename; |
| + SkPicture* fPicture; // TODO(edisonn): multiple pages, one page / picture, make it an array |
| + |
| + static SkPicture* LoadPdf(const char path[]) { |
| + SkPicture* pic = NULL; |
| + |
| + 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
|
| + if (doc.pages()) { |
| + pic = SkNEW(SkPicture); |
| + SkCanvas* canvas = pic->beginRecording((int)doc.width(0), (int)doc.height(0)); |
| + doc.drawPage(0, canvas); |
| + pic->endRecording(); |
| + } |
| + return pic; |
| + } |
| + |
| +public: |
| + PdfFileViewer(const char name[] = NULL) : fFilename(name) { |
| + fPicture = NULL; |
| + } |
| + |
| + virtual ~PdfFileViewer() { |
| + SkSafeUnref(fPicture); |
| + } |
| + |
| +protected: |
| + // overrides from SkEventSink |
| + virtual bool onQuery(SkEvent* evt) { |
| + if (SampleCode::TitleQ(*evt)) { |
| + SkString name("P:"); |
| + const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR); |
| + name.append(basename ? basename+1: fFilename.c_str()); |
| + SampleCode::TitleR(evt, name.c_str()); |
| + return true; |
| + } |
| + return this->INHERITED::onQuery(evt); |
| + } |
| + |
| + virtual bool onEvent(const SkEvent& evt) { |
| + // TODO(edisonn): add here event handlers to disable clipping, or to show helpful info |
| + // like pdf object from click, ... |
| + // TODO(edisonn): first, next, prev, last page navigation + slideshow |
| + return this->INHERITED::onEvent(evt); |
| + } |
| + |
| + virtual void onDrawContent(SkCanvas* canvas) { |
| + if (!fPicture) { |
| + fPicture = LoadPdf(fFilename.c_str()); |
| + } |
| + if (fPicture) { |
| + canvas->drawPicture(*fPicture); |
| + } |
| + } |
| + |
| +private: |
| + typedef SampleView INHERITED; |
| +}; |
| + |
| +SampleView* CreateSamplePdfFileViewer(const char filename[]); |
| +SampleView* CreateSamplePdfFileViewer(const char filename[]) { |
| + return new PdfFileViewer(filename); |
| +} |
| + |
| +////////////////////////////////////////////////////////////////////////////// |
| + |
| +#if 0 |
| +static SkView* MyFactory() { return new PdfFileViewer; } |
| +static SkViewRegister reg(MyFactory); |
| +#endif |
| + |
| +#endif // SAMPLE_PDF_FILE_VIEWER |