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

Side by Side Diff: experimental/PdfViewer/SkPdfRenderer.cpp

Issue 20087003: pdfviewer: remove dependency on picture_utils. add utility function to render SkStream into bitmap. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 5 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
« no previous file with comments | « experimental/PdfViewer/SkPdfRenderer.h ('k') | experimental/PdfViewer/pdf_viewer_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkForceLinking.h" 10 #include "SkForceLinking.h"
(...skipping 2012 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 // TODO(edisonn): create static function that could return NULL if there are errors 2023 // TODO(edisonn): create static function that could return NULL if there are errors
2024 fPdfDoc = new SkNativeParsedPDF(inputFileName.c_str()); 2024 fPdfDoc = new SkNativeParsedPDF(inputFileName.c_str());
2025 if (fPdfDoc->pages() == 0) { 2025 if (fPdfDoc->pages() == 0) {
2026 delete fPdfDoc; 2026 delete fPdfDoc;
2027 fPdfDoc = NULL; 2027 fPdfDoc = NULL;
2028 } 2028 }
2029 2029
2030 return fPdfDoc != NULL; 2030 return fPdfDoc != NULL;
2031 } 2031 }
2032 2032
2033 bool SkPdfRenderer::load(SkStream* stream) {
2034 unload();
2035
2036 // TODO(edisonn): create static function that could return NULL if there are errors
2037 fPdfDoc = new SkNativeParsedPDF(stream);
2038 if (fPdfDoc->pages() == 0) {
2039 delete fPdfDoc;
2040 fPdfDoc = NULL;
2041 }
2042
2043 return fPdfDoc != NULL;
2044 }
2045
2046
2033 int SkPdfRenderer::pages() const { 2047 int SkPdfRenderer::pages() const {
2034 return fPdfDoc != NULL ? fPdfDoc->pages() : 0; 2048 return fPdfDoc != NULL ? fPdfDoc->pages() : 0;
2035 } 2049 }
2036 2050
2037 void SkPdfRenderer::unload() { 2051 void SkPdfRenderer::unload() {
2038 delete fPdfDoc; 2052 delete fPdfDoc;
2039 fPdfDoc = NULL; 2053 fPdfDoc = NULL;
2040 } 2054 }
2041 2055
2042 SkRect SkPdfRenderer::MediaBox(int page) const { 2056 SkRect SkPdfRenderer::MediaBox(int page) const {
2043 SkASSERT(fPdfDoc); 2057 SkASSERT(fPdfDoc);
2044 return fPdfDoc->MediaBox(page); 2058 return fPdfDoc->MediaBox(page);
2045 } 2059 }
2046 2060
2047 size_t SkPdfRenderer::bytesUsed() const { 2061 size_t SkPdfRenderer::bytesUsed() const {
2048 return fPdfDoc ? fPdfDoc->bytesUsed() : 0; 2062 return fPdfDoc ? fPdfDoc->bytesUsed() : 0;
2049 } 2063 }
2064
2065 bool SkPDFNativeRenderToBitmap(SkStream* stream,
2066 SkBitmap* output,
2067 int page,
2068 SkPdfContent content,
2069 double dpi) {
2070 SkASSERT(page >= 0);
2071 SkPdfRenderer renderer;
2072 renderer.load(stream);
2073 if (!renderer.loaded() || page >= renderer.pages() || page < 0) {
2074 return false;
2075 }
2076
2077 SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
2078
2079 SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(dpi / 72.0 )));
2080 SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(dpi / 72 .0)));
2081
2082 rect = SkRect::MakeWH(width, height);
2083
2084 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght));
2085
2086 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output)));
2087 SkCanvas canvas(device);
2088
2089 return renderer.renderPage(page, &canvas, rect);
2090 }
OLDNEW
« no previous file with comments | « experimental/PdfViewer/SkPdfRenderer.h ('k') | experimental/PdfViewer/pdf_viewer_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698