OLD | NEW |
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/image.h" | 5 #include "printing/image.h" |
6 | 6 |
7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
8 | 8 |
9 #include "base/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
10 #include "printing/metafile.h" | 10 #include "printing/metafile.h" |
11 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
12 | 12 |
13 namespace printing { | 13 namespace printing { |
14 | 14 |
15 bool Image::LoadMetafile(const Metafile& metafile) { | 15 bool Image::LoadMetafile(const Metafile& metafile) { |
16 // The printing system uses single-page metafiles (page indexes are 1-based). | 16 // The printing system uses single-page metafiles (page indexes are 1-based). |
17 const unsigned int page_number = 1; | 17 const unsigned int page_number = 1; |
18 gfx::Rect rect(metafile.GetPageBounds(page_number)); | 18 gfx::Rect rect(metafile.GetPageBounds(page_number)); |
19 if (rect.width() < 1 || rect.height() < 1) | 19 if (rect.width() < 1 || rect.height() < 1) |
20 return false; | 20 return false; |
21 | 21 |
22 size_ = rect.size(); | 22 size_ = rect.size(); |
23 row_length_ = size_.width() * sizeof(uint32); | 23 row_length_ = size_.width() * sizeof(uint32); |
24 size_t bytes = row_length_ * size_.height(); | 24 size_t bytes = row_length_ * size_.height(); |
25 DCHECK(bytes); | 25 DCHECK(bytes); |
26 | 26 |
27 data_.resize(bytes); | 27 data_.resize(bytes); |
28 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 28 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
29 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 29 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
30 base::mac::ScopedCFTypeRef<CGContextRef> bitmap_context( | 30 base::ScopedCFTypeRef<CGContextRef> bitmap_context( |
31 CGBitmapContextCreate(&*data_.begin(), size_.width(), size_.height(), | 31 CGBitmapContextCreate(&*data_.begin(), |
32 8, row_length_, color_space, | 32 size_.width(), |
| 33 size_.height(), |
| 34 8, |
| 35 row_length_, |
| 36 color_space, |
33 kCGImageAlphaPremultipliedLast)); | 37 kCGImageAlphaPremultipliedLast)); |
34 DCHECK(bitmap_context.get()); | 38 DCHECK(bitmap_context.get()); |
35 | 39 |
36 struct Metafile::MacRenderPageParams params; | 40 struct Metafile::MacRenderPageParams params; |
37 params.shrink_to_fit = true; | 41 params.shrink_to_fit = true; |
38 metafile.RenderPage(page_number, bitmap_context, | 42 metafile.RenderPage(page_number, bitmap_context, |
39 CGRectMake(0, 0, size_.width(), size_.height()), params); | 43 CGRectMake(0, 0, size_.width(), size_.height()), params); |
40 | 44 |
41 return true; | 45 return true; |
42 } | 46 } |
43 | 47 |
44 } // namespace printing | 48 } // namespace printing |
OLD | NEW |