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

Unified Diff: experimental/PdfViewer/src/SkPdfRenderer.cpp

Issue 59493011: Pdfviewer refactoring. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Move include/ to inc/ Created 7 years, 1 month 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/pdfparser/native/SkPdfNativeDoc.cpp ('k') | gyp/SampleApp.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/src/SkPdfRenderer.cpp
diff --git a/experimental/PdfViewer/SkPdfRenderer.cpp b/experimental/PdfViewer/src/SkPdfRenderer.cpp
similarity index 98%
rename from experimental/PdfViewer/SkPdfRenderer.cpp
rename to experimental/PdfViewer/src/SkPdfRenderer.cpp
index 2d79f13077768ba5c60532455f0d318736d5449d..25fc41df88b9de330f71a66fa037cd9343c4e9fa 100644
--- a/experimental/PdfViewer/SkPdfRenderer.cpp
+++ b/experimental/PdfViewer/src/SkPdfRenderer.cpp
@@ -3087,73 +3087,73 @@ bool SkPdfRenderer::renderPage(int page, SkCanvas* canvas, const SkRect& dst) co
return true;
}
-bool SkPdfRenderer::load(const SkString inputFileName) {
- unload();
-
- fPdfDoc = new SkPdfNativeDoc(inputFileName.c_str());
- if (fPdfDoc->pages() == 0) {
- delete fPdfDoc;
- fPdfDoc = NULL;
+SkPdfRenderer* SkPdfRenderer::CreateFromFile(const char* inputFileName) {
+ // FIXME: SkPdfNativeDoc should have a similar Create function.
+ SkPdfNativeDoc* pdfDoc = SkNEW_ARGS(SkPdfNativeDoc, (inputFileName));
+ if (pdfDoc->pages() == 0) {
+ SkDELETE(pdfDoc);
+ return NULL;
}
- return fPdfDoc != NULL;
+ return SkNEW_ARGS(SkPdfRenderer, (pdfDoc));
}
-bool SkPdfRenderer::load(SkStream* stream) {
- unload();
-
+SkPdfRenderer* SkPdfRenderer::CreateFromStream(SkStream* stream) {
// TODO(edisonn): create static function that could return NULL if there are errors
- fPdfDoc = new SkPdfNativeDoc(stream);
- if (fPdfDoc->pages() == 0) {
- delete fPdfDoc;
- fPdfDoc = NULL;
+ SkPdfNativeDoc* pdfDoc = SkNEW_ARGS(SkPdfNativeDoc, (stream));
+ if (pdfDoc->pages() == 0) {
+ SkDELETE(pdfDoc);
+ return NULL;
}
- return fPdfDoc != NULL;
+ return SkNEW_ARGS(SkPdfRenderer, (pdfDoc));
}
+SkPdfRenderer::SkPdfRenderer(SkPdfNativeDoc* doc)
+ :fPdfDoc(doc) {
+}
-int SkPdfRenderer::pages() const {
- return fPdfDoc != NULL ? fPdfDoc->pages() : 0;
+SkPdfRenderer::~SkPdfRenderer() {
+ SkDELETE(fPdfDoc);
}
-void SkPdfRenderer::unload() {
- delete fPdfDoc;
- fPdfDoc = NULL;
+int SkPdfRenderer::pages() const {
+ SkASSERT(fPdfDoc != NULL);
+ return fPdfDoc->pages();
}
SkRect SkPdfRenderer::MediaBox(int page) const {
- SkASSERT(fPdfDoc);
+ SkASSERT(fPdfDoc != NULL);
return fPdfDoc->MediaBox(page);
}
size_t SkPdfRenderer::bytesUsed() const {
- return fPdfDoc ? fPdfDoc->bytesUsed() : 0;
+ SkASSERT(fPdfDoc != NULL);
+ return fPdfDoc->bytesUsed();
}
bool SkPDFNativeRenderToBitmap(SkStream* stream,
SkBitmap* output,
int page,
- SkPdfContent content,
+ SkPdfContent unused,
double dpi) {
SkASSERT(page >= 0);
- SkPdfRenderer renderer;
- renderer.load(stream);
- if (!renderer.loaded() || page >= renderer.pages() || page < 0) {
+ SkPdfRenderer* renderer = SkPdfRenderer::CreateFromStream(stream);
+ if (NULL == renderer) {
return false;
}
- SkRect rect = renderer.MediaBox(page < 0 ? 0 :page);
+ 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)));
+ SkScalar width = SkScalarMul(rect.width(), SkDoubleToScalar(dpi / 72.0));
+ SkScalar height = SkScalarMul(rect.height(), SkDoubleToScalar(dpi / 72.0));
rect = SkRect::MakeWH(width, height);
- setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(height));
+ setup_bitmap(output, SkScalarCeilToInt(width), SkScalarCeilToInt(height));
SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (*output)));
SkCanvas canvas(device);
- return renderer.renderPage(page, &canvas, rect);
+ return renderer->renderPage(page, &canvas, rect);
}
« no previous file with comments | « experimental/PdfViewer/pdfparser/native/SkPdfNativeDoc.cpp ('k') | gyp/SampleApp.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698