OLD | NEW |
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 |
OLD | NEW |