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

Unified Diff: tools/render_pdfs_main.cpp

Issue 24811002: Update the SkDocument interface to allow for 1) abort won't emit pdf, 2) close can report success/f… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix typo Created 7 years, 2 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 | « tools/PdfRenderer.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/render_pdfs_main.cpp
diff --git a/tools/render_pdfs_main.cpp b/tools/render_pdfs_main.cpp
index a7100645281045ace38a2d6745baaa1985a40473..e07664c304aab8e692fe517527889c1a1c969601 100644
--- a/tools/render_pdfs_main.cpp
+++ b/tools/render_pdfs_main.cpp
@@ -131,28 +131,24 @@ static bool make_output_filepath(SkString* path, const SkString& dir,
* @param inputFilename The skp file that was read.
* @param renderer The object responsible to write the pdf file.
*/
-static bool write_output(const SkString& outputDir,
- const SkString& inputFilename,
- const sk_tools::PdfRenderer& renderer) {
+static SkWStream* open_stream(const SkString& outputDir,
+ const SkString& inputFilename) {
if (outputDir.isEmpty()) {
- SkDynamicMemoryWStream stream;
- renderer.write(&stream);
- return true;
+ return SkNEW(SkDynamicMemoryWStream);
}
SkString outputPath;
if (!make_output_filepath(&outputPath, outputDir, inputFilename)) {
- return false;
+ return NULL;
}
- SkFILEWStream stream(outputPath.c_str());
- if (!stream.isValid()) {
+ SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (outputPath.c_str()));
+ if (!stream->isValid()) {
SkDebugf("Could not write to file %s\n", outputPath.c_str());
- return false;
+ return NULL;
}
- renderer.write(&stream);
- return true;
+ return stream;
}
/** Reads an skp file, renders it to pdf and writes the output to a pdf file
@@ -182,13 +178,19 @@ static bool render_pdf(const SkString& inputPath, const SkString& outputDir,
SkDebugf("exporting... [%i %i] %s\n", picture->width(), picture->height(),
inputPath.c_str());
- renderer.init(picture);
+ SkWStream* stream(open_stream(outputDir, inputFilename));
- renderer.render();
+ if (!stream) {
+ return false;
+ }
- bool success = write_output(outputDir, inputFilename, renderer);
+ renderer.init(picture, stream);
+
+ bool success = renderer.render();
+ SkDELETE(stream);
renderer.end();
+
return success;
}
« no previous file with comments | « tools/PdfRenderer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698