From 909228992c1671ea7451d1c6bc588a8ec991841e Mon Sep 17 00:00:00 2001 From: "scroggo@google.com" Date: Thu, 14 Nov 2013 19:09:27 +0000 Subject: 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 --- samplecode/SamplePdfFileViewer.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'samplecode/SamplePdfFileViewer.cpp') 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 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; } -- cgit v1.2.3