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

Unified Diff: dm/DMPDFTask.cpp

Issue 312873002: DM: add pdf (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: put cutils back Created 6 years, 7 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 | « dm/DMPDFTask.h ('k') | dm/DMWriteTask.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMPDFTask.cpp
diff --git a/dm/DMPDFTask.cpp b/dm/DMPDFTask.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..270f4b4fef8bbfd1863e397acfc93a3f77efec32
--- /dev/null
+++ b/dm/DMPDFTask.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "DMPDFTask.h"
+#include "DMExpectationsTask.h"
+#include "DMPDFRasterizeTask.h"
+#include "DMUtil.h"
+#include "DMWriteTask.h"
+#include "SkCommandLineFlags.h"
+#include "SkDocument.h"
+
+DEFINE_bool(pdf, true, "PDF backend master switch.");
+
+namespace DM {
+
+PDFTask::PDFTask(const char* suffix,
+ Reporter* reporter,
+ TaskRunner* taskRunner,
+ const Expectations& expectations,
+ skiagm::GMRegistry::Factory factory,
+ RasterizePdfProc rasterizePdfProc)
+ : CpuTask(reporter, taskRunner)
+ , fGM(factory(NULL))
+ , fName(UnderJoin(fGM->getName(), suffix))
+ , fExpectations(expectations)
+ , fRasterize(rasterizePdfProc) {}
+
+namespace {
+
+class SinglePagePDF {
+public:
+ SinglePagePDF(SkScalar width, SkScalar height)
+ : fDocument(SkDocument::CreatePDF(&fWriteStream))
+ , fCanvas(fDocument->beginPage(width, height)) {}
+
+ SkCanvas* canvas() { return fCanvas; }
+
+ SkData* end() {
+ fCanvas->flush();
+ fDocument->endPage();
+ fDocument->close();
+ return fWriteStream.copyToData();
+ }
+
+private:
+ SkDynamicMemoryWStream fWriteStream;
+ SkAutoTUnref<SkDocument> fDocument;
+ SkCanvas* fCanvas;
+};
+
+} // namespace
+
+void PDFTask::draw() {
+ SinglePagePDF pdf(fGM->width(), fGM->height());
+ //TODO(mtklein): GM doesn't do this. Why not?
+ //pdf.canvas()->concat(fGM->getInitialTransform());
vandebo (ex-Chrome) 2014/06/03 20:39:56 Because it passes it into the PDF device: https://
+ fGM->draw(pdf.canvas());
+
+ SkAutoTUnref<SkData> pdfData(pdf.end());
+ SkASSERT(pdfData.get());
+
+ if (!(fGM->getFlags() & skiagm::GM::kSkipPDFRasterization_Flag)) {
+ this->spawnChild(SkNEW_ARGS(PDFRasterizeTask,
+ (*this, pdfData.get(), fExpectations, fRasterize)));
+ }
+ this->spawnChild(SkNEW_ARGS(WriteTask, (*this, pdfData.get(), ".pdf")));
+}
+
+bool PDFTask::shouldSkip() const {
+ if (!FLAGS_pdf) {
+ return true;
+ }
+ if (fGM->getFlags() & skiagm::GM::kSkipPDF_Flag) {
+ return true;
+ }
+ return false;
+}
+
+} // namespace DM
« no previous file with comments | « dm/DMPDFTask.h ('k') | dm/DMWriteTask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698