aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode/SamplePdfFileViewer.cpp
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-14 19:09:27 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-14 19:09:27 +0000
commit909228992c1671ea7451d1c6bc588a8ec991841e (patch)
tree5ddd2c2f4f1fc2f94f51512a49cfccbae83a4cd4 /samplecode/SamplePdfFileViewer.cpp
parentbe65a4c9d6ce40e7fc27e5a830196bcaa7be97c9 (diff)
Pdfviewer refactoring.
Mostly superficial changes, to help me make sure I understand the code while making modifications. SkPdfRenderer: First class I'm modifying. Move it into include/ and src/ directories. Inherit from SkNoncopyable. Replace load() with factory function which returns NULL if the load fails. Remove unload() and loaded(), which no longer make sense, since the factory will return NULL on a failure to load, and unload() happens on destruction. Use a const char* for loading a PDF, following the convention of SkStream::NewFromFile. Remove unnecessary call to sqrt in SkPDFNativeRenderToBitmap. Also in SkPDFNativeRenderToBitmap, use an appropriate SkScalar macro to convert to an integer. Use this-> when calling member functions. pdf_viewer_main.cpp: Call the new interface for SkPdfRenderer. gyp files: Refer to the new location of SkPdfRenderer. R=edisonn@google.com Review URL: https://codereview.chromium.org/59493011 git-svn-id: http://skia.googlecode.com/svn/trunk@12296 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode/SamplePdfFileViewer.cpp')
-rw-r--r--samplecode/SamplePdfFileViewer.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/samplecode/SamplePdfFileViewer.cpp b/samplecode/SamplePdfFileViewer.cpp
index fc8b0f0acd..55c7002fa8 100644
--- a/samplecode/SamplePdfFileViewer.cpp
+++ b/samplecode/SamplePdfFileViewer.cpp
@@ -37,18 +37,16 @@ private:
SkPicture* fPicture; // TODO(edisonn): multiple pages, one page / picture, make it an array
static SkPicture* LoadPdf(const char path[]) {
- SkPicture* pic = NULL;
-
- SkPdfRenderer renderer;
- SkString skpath;
- skpath.append(path);
- renderer.load(skpath);
- if (renderer.loaded()) {
- pic = SkNEW(SkPicture);
- SkCanvas* canvas = pic->beginRecording((int)renderer.MediaBox(0).width(), (int)renderer.MediaBox(0).height());
- renderer.renderPage(0, canvas, renderer.MediaBox(0));
- pic->endRecording();
+ SkAutoTDelete<SkPdfRenderer> renderer(SkPdfRenderer::CreateFromFile(path));
+ if (NULL == renderer.get()) {
+ return NULL;
}
+
+ SkPicture* pic = SkNEW(SkPicture);
+ SkCanvas* canvas = pic->beginRecording((int) renderer->MediaBox(0).width(),
+ (int) renderer->MediaBox(0).height());
+ renderer->renderPage(0, canvas, renderer->MediaBox(0));
+ pic->endRecording();
return pic;
}