OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/md5.h" | 8 #include "base/md5.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "gfx/codec/png_codec.h" | 10 #include "gfx/codec/png_codec.h" |
11 #include "gfx/rect.h" | 11 #include "gfx/rect.h" |
12 #include "skia/ext/platform_device.h" | 12 #include "skia/ext/platform_device.h" |
13 | 13 |
14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
15 #include "gfx/gdi_util.h" // EMF support | 15 #include "gfx/gdi_util.h" // EMF support |
16 #elif defined(OS_MACOSX) | 16 #elif defined(OS_MACOSX) |
17 #include <ApplicationServices/ApplicationServices.h> | 17 #include <ApplicationServices/ApplicationServices.h> |
18 #include "base/scoped_cftyperef.h" | 18 #include "base/mac/scoped_cftyperef.h" |
19 #endif | 19 #endif |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // A simple class which temporarily overrides system settings. | 23 // A simple class which temporarily overrides system settings. |
24 // The bitmap image rendered via the PlayEnhMetaFile() function depends on | 24 // The bitmap image rendered via the PlayEnhMetaFile() function depends on |
25 // some system settings. | 25 // some system settings. |
26 // As a workaround for such dependency, this class saves the system settings | 26 // As a workaround for such dependency, this class saves the system settings |
27 // and changes them. This class also restore the saved settings in its | 27 // and changes them. This class also restore the saved settings in its |
28 // destructor. | 28 // destructor. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 #elif defined(OS_MACOSX) | 236 #elif defined(OS_MACOSX) |
237 // The printing system uses single-page metafiles (page indexes are 1-based). | 237 // The printing system uses single-page metafiles (page indexes are 1-based). |
238 const unsigned int page_number = 1; | 238 const unsigned int page_number = 1; |
239 gfx::Rect rect(metafile.GetPageBounds(page_number)); | 239 gfx::Rect rect(metafile.GetPageBounds(page_number)); |
240 if (rect.width() > 0 && rect.height() > 0) { | 240 if (rect.width() > 0 && rect.height() > 0) { |
241 size_ = rect.size(); | 241 size_ = rect.size(); |
242 row_length_ = size_.width() * sizeof(uint32); | 242 row_length_ = size_.width() * sizeof(uint32); |
243 size_t bytes = row_length_ * size_.height(); | 243 size_t bytes = row_length_ * size_.height(); |
244 DCHECK(bytes); | 244 DCHECK(bytes); |
245 data_.resize(bytes); | 245 data_.resize(bytes); |
246 scoped_cftyperef<CGColorSpaceRef> color_space( | 246 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
247 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 247 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
248 scoped_cftyperef<CGContextRef> bitmap_context( | 248 base::mac::ScopedCFTypeRef<CGContextRef> bitmap_context( |
249 CGBitmapContextCreate(&*data_.begin(), size_.width(), size_.height(), | 249 CGBitmapContextCreate(&*data_.begin(), size_.width(), size_.height(), |
250 8, row_length_, color_space, | 250 8, row_length_, color_space, |
251 kCGImageAlphaPremultipliedLast)); | 251 kCGImageAlphaPremultipliedLast)); |
252 DCHECK(bitmap_context.get()); | 252 DCHECK(bitmap_context.get()); |
253 metafile.RenderPage(page_number, bitmap_context, | 253 metafile.RenderPage(page_number, bitmap_context, |
254 CGRectMake(0, 0, size_.width(), size_.height()), | 254 CGRectMake(0, 0, size_.width(), size_.height()), |
255 true, false, false, false); | 255 true, false, false, false); |
256 } | 256 } |
257 #else | 257 #else |
258 NOTIMPLEMENTED(); | 258 NOTIMPLEMENTED(); |
259 #endif | 259 #endif |
260 | 260 |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 } // namespace printing | 264 } // namespace printing |
OLD | NEW |