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

Side by Side Diff: printing/metafile_skia_wrapper.cc

Issue 641923002: Change PDF scaling factor from double to float. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 6 years, 2 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
« no previous file with comments | « printing/metafile_skia_wrapper.h ('k') | printing/printed_document.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "skia/ext/refptr.h" 7 #include "skia/ext/refptr.h"
8 #include "third_party/skia/include/core/SkCanvas.h" 8 #include "third_party/skia/include/core/SkCanvas.h"
9 #include "third_party/skia/include/core/SkDevice.h" 9 #include "third_party/skia/include/core/SkDevice.h"
10 #include "third_party/skia/include/core/SkMetaData.h" 10 #include "third_party/skia/include/core/SkMetaData.h"
11 11
12 namespace printing { 12 namespace printing {
13 13
14 namespace { 14 namespace {
15 15
16 const char* kMetafileKey = "CrMetafile"; 16 const char* kMetafileKey = "CrMetafile";
17 const char* kCustomScaleKey = "CrCustomScale";
18 17
19 } // namespace 18 } // namespace
20 19
21 // static 20 // static
22 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas, 21 void MetafileSkiaWrapper::SetMetafileOnCanvas(const SkCanvas& canvas,
23 PdfMetafileSkia* metafile) { 22 PdfMetafileSkia* metafile) {
24 skia::RefPtr<MetafileSkiaWrapper> wrapper; 23 skia::RefPtr<MetafileSkiaWrapper> wrapper;
25 if (metafile) 24 if (metafile)
26 wrapper = skia::AdoptRef(new MetafileSkiaWrapper(metafile)); 25 wrapper = skia::AdoptRef(new MetafileSkiaWrapper(metafile));
27 26
28 SkMetaData& meta = skia::getMetaData(canvas); 27 SkMetaData& meta = skia::getMetaData(canvas);
29 meta.setRefCnt(kMetafileKey, wrapper.get()); 28 meta.setRefCnt(kMetafileKey, wrapper.get());
30 } 29 }
31 30
32 // static 31 // static
33 PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas( 32 PdfMetafileSkia* MetafileSkiaWrapper::GetMetafileFromCanvas(
34 const SkCanvas& canvas) { 33 const SkCanvas& canvas) {
35 SkMetaData& meta = skia::getMetaData(canvas); 34 SkMetaData& meta = skia::getMetaData(canvas);
36 SkRefCnt* value; 35 SkRefCnt* value;
37 if (!meta.findRefCnt(kMetafileKey, &value) || !value) 36 if (!meta.findRefCnt(kMetafileKey, &value) || !value)
38 return NULL; 37 return NULL;
39 38
40 return static_cast<MetafileSkiaWrapper*>(value)->metafile_; 39 return static_cast<MetafileSkiaWrapper*>(value)->metafile_;
41 } 40 }
42 41
43 // static
44 void MetafileSkiaWrapper::SetCustomScaleOnCanvas(const SkCanvas& canvas,
45 double scale) {
46 SkMetaData& meta = skia::getMetaData(canvas);
47 meta.setScalar(kCustomScaleKey, SkFloatToScalar(scale));
48 }
49
50 // static
51 bool MetafileSkiaWrapper::GetCustomScaleOnCanvas(const SkCanvas& canvas,
52 double* scale) {
53 SkMetaData& meta = skia::getMetaData(canvas);
54 SkScalar value;
55 if (!meta.findScalar(kCustomScaleKey, &value))
56 return false;
57
58 *scale = SkScalarToFloat(value);
59 return true;
60 }
61
62 MetafileSkiaWrapper::MetafileSkiaWrapper(PdfMetafileSkia* metafile) 42 MetafileSkiaWrapper::MetafileSkiaWrapper(PdfMetafileSkia* metafile)
63 : metafile_(metafile) { 43 : metafile_(metafile) {
64 } 44 }
65 45
66 } // namespace printing 46 } // namespace printing
OLDNEW
« no previous file with comments | « printing/metafile_skia_wrapper.h ('k') | printing/printed_document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698