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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/PdfViewer/SkPdfRenderer.h ('k') | experimental/PdfViewer/pdf_viewer_main.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/SkPdfRenderer.cpp
===================================================================
--- experimental/PdfViewer/SkPdfRenderer.cpp (revision 10294)
+++ experimental/PdfViewer/SkPdfRenderer.cpp (working copy)
@@ -2030,6 +2030,20 @@
return fPdfDoc != NULL;
}
+bool SkPdfRenderer::load(SkStream* stream) {
+ unload();
+
+ // TODO(edisonn): create static function that could return NULL if there are errors
+ fPdfDoc = new SkNativeParsedPDF(stream);
+ if (fPdfDoc->pages() == 0) {
+ delete fPdfDoc;
+ fPdfDoc = NULL;
+ }
+
+ return fPdfDoc != NULL;
+}
+
+
int SkPdfRenderer::pages() const {
return fPdfDoc != NULL ? fPdfDoc->pages() : 0;
}
@@ -2047,3 +2061,30 @@
size_t SkPdfRenderer::bytesUsed() const {
return fPdfDoc ? fPdfDoc->bytesUsed() : 0;
}
+
+bool SkPDFNativeRenderToBitmap(SkStream* stream,
+ SkBitmap* output,
+ int page,
+ SkPdfContent content,
+ double dpi) {
+ SkASSERT(page >= 0);
+ SkPdfRenderer renderer;
+ renderer.load(stream);
+ if (!renderer.loaded() || page >= renderer.pages() || page < 0) {
+ return false;
+ }
+
+ SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
+
+ SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(sqrt(dpi / 72.0)));
+ SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(sqrt(dpi / 72.0)));
+
+ rect = SkRect::MakeWH(width, height);
+
+ setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height));
+
+ SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output)));
+ SkCanvas canvas(device);
+
+ return renderer.renderPage(page, &canvas, rect);
+}
« 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