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

Unified Diff: experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.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/pdfparser/native/SkNativeParsedPDF.h ('k') | gyp/pdfviewer.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp
===================================================================
--- experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp (revision 10294)
+++ experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.cpp (working copy)
@@ -14,6 +14,7 @@
#include "SkPdfPageTreeNodeDictionary_autogen.h"
#include "SkPdfMapper_autogen.h"
+#include "SkStream.h"
static long getFileSize(const char* filename)
@@ -67,25 +68,48 @@
// 1) run on a lot of file
// 2) recoverable corupt file: remove endobj, endsteam, remove other keywords, use other white spaces, insert comments randomly, ...
// 3) irrecoverable corrupt file
+
+SkNativeParsedPDF::SkNativeParsedPDF(SkStream* stream)
+ : fAllocator(new SkPdfAllocator())
+ , fFileContent(NULL)
+ , fContentLength(0)
+ , fRootCatalogRef(NULL)
+ , fRootCatalog(NULL) {
+ size_t size = stream->getLength();
+ void* ptr = sk_malloc_throw(size);
+ stream->read(ptr, size);
+
+ init(ptr, size);
+}
+
SkNativeParsedPDF::SkNativeParsedPDF(const char* path)
: fAllocator(new SkPdfAllocator())
+ , fFileContent(NULL)
+ , fContentLength(0)
, fRootCatalogRef(NULL)
, fRootCatalog(NULL) {
gDoc = this;
FILE* file = fopen(path, "r");
- fContentLength = getFileSize(path);
- unsigned char* content = new unsigned char[fContentLength + 1];
- bool ok = (0 != fread(content, fContentLength, 1, file));
- content[fContentLength] = '\0';
- fFileContent = content;
+ size_t size = getFileSize(path);
+ void* content = sk_malloc_throw(size);
+ bool ok = (0 != fread(content, size, 1, file));
fclose(file);
file = NULL;
if (!ok) {
+ sk_free(content);
// TODO(edisonn): report read error
+ // TODO(edisonn): not nice to return like this from constructor, create a static
+ // function that can report NULL for failures.
return; // Doc will have 0 pages
}
+ init(content, size);
+}
+
+void SkNativeParsedPDF::init(const void* bytes, size_t length) {
+ fFileContent = (const unsigned char*)bytes;
+ fContentLength = length;
const unsigned char* eofLine = lineHome(fFileContent, fFileContent + fContentLength - 1);
const unsigned char* xrefByteOffsetLine = previousLineHome(fFileContent, eofLine);
const unsigned char* xrefstartKeywordLine = previousLineHome(fFileContent, xrefByteOffsetLine);
@@ -126,7 +150,7 @@
// TODO(edisonn): NYI
SkNativeParsedPDF::~SkNativeParsedPDF() {
- delete[] fFileContent;
+ sk_free((void*)fFileContent);
delete fAllocator;
}
« no previous file with comments | « experimental/PdfViewer/pdfparser/native/SkNativeParsedPDF.h ('k') | gyp/pdfviewer.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698