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

Unified Diff: printing/pdf_metafile_skia.cc

Issue 2064843002: PdfMetafileSkia: start supporting more document types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« printing/pdf_metafile_skia.h ('K') | « printing/pdf_metafile_skia.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/pdf_metafile_skia.cc
diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc
index aebd263025f66a4ce302d9b8a5fa327595eabacd..9efc17a7e3cc2027e6274a8a09bdf8c17b1c417f 100644
--- a/printing/pdf_metafile_skia.cc
+++ b/printing/pdf_metafile_skia.cc
@@ -10,6 +10,7 @@
#include "third_party/skia/include/core/SkDocument.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkStream.h"
+#include "third_party/skia/src/utils/SkMultiPictureDocument.h"
Lei Zhang 2016/06/13 21:01:34 The printing/DEPS rule just says "+third_party/ski
hal.canary 2016/06/14 16:34:49 Acknowledged. I have noted the situation.
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/skia_util.h"
@@ -92,6 +93,7 @@ struct PdfMetafileSkiaData {
// meaningful for a vector canvas as for a raster canvas.
float scale_factor_;
SkSize size_;
+ printing::SkiaDocumentType type_;
Lei Zhang 2016/06/13 21:01:34 Generally no need for $foo:: in namespace $foo.
hal.canary 2016/06/14 16:34:49 Done.
#if defined(OS_MACOSX)
PdfMetafileCg pdf_cg_;
@@ -157,9 +159,8 @@ bool PdfMetafileSkia::FinishPage() {
sk_sp<SkPicture> pic = data_->recorder_.finishRecordingAsPicture();
if (data_->scale_factor_ != 1.0f) {
- SkCanvas* canvas =
- data_->recorder_.beginRecording(data_->size_.width(),
- data_->size_.height());
+ SkCanvas* canvas = data_->recorder_.beginRecording(data_->size_.width(),
+ data_->size_.height());
canvas->scale(data_->scale_factor_, data_->scale_factor_);
canvas->drawPicture(pic);
pic = data_->recorder_.finishRecordingAsPicture();
@@ -177,9 +178,18 @@ bool PdfMetafileSkia::FinishDocument() {
FinishPage();
SkDynamicMemoryWStream stream;
- // TODO(halcanary): support more document types (XPS, a sequence of display
- // lists).
- sk_sp<SkDocument> doc = MakePdfDocument(&stream);
+ sk_sp<SkDocument> doc;
+ switch (data_->type_) {
+ case PDF_SKIA_DOCUMENT_TYPE:
+ doc = MakePdfDocument(&stream);
+ break;
+ case MSKP_SKIA_DOCUMENT_TYPE:
+ doc = SkMakeMultiPictureDocument(&stream);
+ break;
+ default:
Lei Zhang 2016/06/13 21:01:34 No need. I believe if you add a new enum value and
hal.canary 2016/06/14 16:34:49 Done.
+ NOTREACHED();
+ return false;
+ }
for (const Page& page : data_->pages_) {
SkCanvas* canvas = doc->beginPage(page.size_.width(), page.size_.height());
@@ -287,13 +297,16 @@ bool PdfMetafileSkia::SaveTo(base::File* file) const {
return true;
}
-PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) {
+PdfMetafileSkia::PdfMetafileSkia(printing::SkiaDocumentType type)
+ : data_(new PdfMetafileSkiaData) {
+ data_->type_ = type;
}
-std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage() {
+std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage(
+ printing::SkiaDocumentType type) {
// If we only ever need the metafile for the last page, should we
// only keep a handle on one SkPicture?
- std::unique_ptr<PdfMetafileSkia> metafile(new PdfMetafileSkia);
+ std::unique_ptr<PdfMetafileSkia> metafile(new PdfMetafileSkia(type));
if (data_->pages_.size() == 0)
return metafile;
« printing/pdf_metafile_skia.h ('K') | « printing/pdf_metafile_skia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698