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

Side by Side Diff: printing/metafile_skia_wrapper.cc

Issue 10387022: A better fix for scaling issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/metafile_skia_wrapper.h ('k') | printing/printing.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "printing/metafile_skia_wrapper.h" 5 #include "printing/metafile_skia_wrapper.h"
6 #include "skia/ext/platform_device.h" 6 #include "skia/ext/platform_device.h"
7 #include "third_party/skia/include/core/SkCanvas.h" 7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkDevice.h" 8 #include "third_party/skia/include/core/SkDevice.h"
9 #include "third_party/skia/include/core/SkMetaData.h" 9 #include "third_party/skia/include/core/SkMetaData.h"
10 10
11 namespace printing { 11 namespace printing {
12 12
13 namespace { 13 namespace {
14 14
15 const char* kMetafileKey = "CrMetafile"; 15 const char* kMetafileKey = "CrMetafile";
16 const char* kCustomScaleKey = "CrCustomScale";
16 17
17 } // namespace 18 } // namespace
18 19
19 // static 20 // static
20 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, 21 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas,
21 Metafile* metafile) { 22 Metafile* metafile) {
22 MetafileSkiaWrapper* wrapper = NULL; 23 MetafileSkiaWrapper* wrapper = NULL;
23 if (metafile) 24 if (metafile)
24 wrapper = new MetafileSkiaWrapper(metafile); 25 wrapper = new MetafileSkiaWrapper(metafile);
25 26
26 SkMetaData& meta = skia::getMetaData(canvas); 27 SkMetaData& meta = skia::getMetaData(canvas);
27 meta.setRefCnt(kMetafileKey, wrapper); 28 meta.setRefCnt(kMetafileKey, wrapper);
28 SkSafeUnref(wrapper); 29 SkSafeUnref(wrapper);
29 } 30 }
30 31
31 // static 32 // static
32 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) { 33 Metafile* MetafileSkiaWrapper::GetMetafileFromCanvas(const SkCanvas& canvas) {
33 SkMetaData& meta = skia::getMetaData(canvas); 34 SkMetaData& meta = skia::getMetaData(canvas);
34 SkRefCnt* value; 35 SkRefCnt* value;
35 if (!meta.findRefCnt(kMetafileKey, &value) || !value) 36 if (!meta.findRefCnt(kMetafileKey, &value) || !value)
36 return NULL; 37 return NULL;
37 38
38 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; 39 return static_cast<MetafileSkiaWrapper*>(value)->metafile_;
39 } 40 }
40 41
42 // static
43 void MetafileSkiaWrapper::SetCustomScaleOnCanvas(const SkCanvas& canvas,
44 double scale) {
45 SkMetaData& meta = skia::getMetaData(canvas);
46 meta.setScalar(kCustomScaleKey, SkFloatToScalar(scale));
47 }
48
49 // static
50 bool MetafileSkiaWrapper::GetCustomScaleOnCanvas(const SkCanvas& canvas,
51 double* scale) {
52 SkMetaData& meta = skia::getMetaData(canvas);
53 SkScalar value;
54 if (!meta.findScalar(kCustomScaleKey, &value))
55 return false;
56
57 *scale = SkScalarToFloat(value);
58 return true;
59 }
60
41 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile) 61 MetafileSkiaWrapper::MetafileSkiaWrapper(Metafile* metafile)
42 : metafile_(metafile) { 62 : metafile_(metafile) {
43 } 63 }
44 64
45 } // namespace printing 65 } // namespace printing
OLDNEW
« no previous file with comments | « printing/metafile_skia_wrapper.h ('k') | printing/printing.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698