From e5d982d40c7d6a0e03da2c6772265bbf7455773f Mon Sep 17 00:00:00 2001 From: "kmadhusu@chromium.org" Date: Tue, 27 Sep 2011 22:10:32 +0000 Subject: Revert 103021 - PrintPreview: Printing preview of a PDF on Mac with Skia only previews the last page of the PDF BUG=93145 TEST=Please refer to bug report. Review URL: http://codereview.chromium.org/7719014 TBR=kmadhusu@chromium.org Review URL: http://codereview.chromium.org/8052020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103026 0039d316-1c4b-4281-b951-d872f2087c98 --- printing/metafile_skia_wrapper.cc | 34 +++++++++++++++++++++++++++++----- printing/metafile_skia_wrapper.h | 8 ++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'printing') diff --git a/printing/metafile_skia_wrapper.cc b/printing/metafile_skia_wrapper.cc index ee24a66..cc7fa08 100644 --- a/printing/metafile_skia_wrapper.cc +++ b/printing/metafile_skia_wrapper.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/logging.h" #include "printing/metafile_skia_wrapper.h" -#include "skia/ext/platform_device.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkDevice.h" #include "third_party/skia/include/core/SkMetaData.h" @@ -12,25 +12,34 @@ namespace printing { namespace { +const char* kDraftModeKey = "CrDraftMode"; const char* kMetafileKey = "CrMetafile"; +SkMetaData& getMetaData(SkCanvas* canvas) { + DCHECK(canvas != NULL); + + SkDevice* device = canvas->getDevice(); + DCHECK(device != NULL); + return device->getMetaData(); +} + } // namespace // static -void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, +void MetafileSkiaWrapper::SetMetafileOnCanvas(SkCanvas* canvas, Metafile* metafile) { MetafileSkiaWrapper* wrapper = NULL; if (metafile) wrapper = new MetafileSkiaWrapper(metafile); - SkMetaData& meta = skia::getMetaData(canvas); + SkMetaData& meta = getMetaData(canvas); meta.setRefCnt(kMetafileKey, wrapper); SkSafeUnref(wrapper); } // static -Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { - SkMetaData& meta = skia::getMetaData(canvas); +Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(SkCanvas* canvas) { + SkMetaData& meta = getMetaData(canvas); SkRefCnt* value; if (!meta.findRefCnt(kMetafileKey, &value) || !value) return NULL; @@ -38,6 +47,21 @@ Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { return static_cast(value)->metafile_; } +// static +void MetafileSkiaWrapper::SetDraftMode(SkCanvas* canvas, bool draft_mode) { + SkMetaData& meta = getMetaData(canvas); + meta.setBool(kDraftModeKey, draft_mode); +} + +// static +bool MetafileSkiaWrapper::GetDraftMode(SkCanvas* canvas) { + SkMetaData& meta = getMetaData(canvas); + bool draft_mode; + if (!meta.findBool(kDraftModeKey, &draft_mode)) + draft_mode = false; + return draft_mode; +} + MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) : metafile_(metafile) { } diff --git a/printing/metafile_skia_wrapper.h b/printing/metafile_skia_wrapper.h index 9010449..40e26e8 100644 --- a/printing/metafile_skia_wrapper.h +++ b/printing/metafile_skia_wrapper.h @@ -20,9 +20,13 @@ class Metafile; // as long as the canvas. class PRINTING_EXPORT MetafileSkiaWrapper : public SkRefCnt { public: - static void SetMetafileOnCanvas(const SkCanvas& canvas, Metafile* metafile); + static void SetMetafileOnCanvas(SkCanvas* canvas, Metafile* metafile); - static Metafile* GetMetafileFromCanvas(const SkCanvas& canvas); + static Metafile* GetMetafileFromCanvas(SkCanvas* canvas); + + static void SetDraftMode(SkCanvas* canvas, bool draft_mode); + + static bool GetDraftMode(SkCanvas* canvas); private: explicit MetafileSkiaWrapper(Metafile* metafile); -- cgit v1.1