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/printing_context_mac.h" | 5 #include "printing/printing_context_mac.h" |
6 | 6 |
7 #import <ApplicationServices/ApplicationServices.h> | 7 #import <ApplicationServices/ApplicationServices.h> |
8 #import <AppKit/AppKit.h> | 8 #import <AppKit/AppKit.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/mac/scoped_nsautorelease_pool.h" | 12 #include "base/mac/scoped_nsautorelease_pool.h" |
13 #include "base/mac/scoped_nsexception_enabler.h" | 13 #include "base/mac/scoped_nsexception_enabler.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "printing/print_settings_initializer_mac.h" | 16 #include "printing/print_settings_initializer_mac.h" |
17 | 17 |
18 static const CFStringRef kColorModel = CFSTR("ColorModel"); | |
19 static const CFStringRef kGrayColor = CFSTR("Gray"); | |
20 static const CFStringRef kCMYK = CFSTR("CMYK"); | |
21 | |
22 namespace printing { | 18 namespace printing { |
23 | 19 |
24 // static | 20 // static |
25 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | 21 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
26 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); | 22 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); |
27 } | 23 } |
28 | 24 |
29 PrintingContextMac::PrintingContextMac(const std::string& app_locale) | 25 PrintingContextMac::PrintingContextMac(const std::string& app_locale) |
30 : PrintingContext(app_locale), | 26 : PrintingContext(app_locale), |
31 print_info_([[NSPrintInfo sharedPrintInfo] copy]), | 27 print_info_([[NSPrintInfo sharedPrintInfo] copy]), |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 242 } |
247 | 243 |
248 PMPrintSettings pmPrintSettings = | 244 PMPrintSettings pmPrintSettings = |
249 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); | 245 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); |
250 return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr; | 246 return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr; |
251 } | 247 } |
252 | 248 |
253 bool PrintingContextMac::SetOutputColor(int color_mode) { | 249 bool PrintingContextMac::SetOutputColor(int color_mode) { |
254 PMPrintSettings pmPrintSettings = | 250 PMPrintSettings pmPrintSettings = |
255 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); | 251 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); |
256 CFStringRef output_color = NULL; | 252 std::string color_setting_name; |
257 if (color_mode == printing::GRAY) | 253 std::string color_value; |
258 output_color = kGrayColor; | 254 printing::GetColorModelForMode(color_mode, &color_setting_name, &color_value); |
259 else if (color_mode == printing::CMYK) | 255 base::mac::ScopedCFTypeRef<CFStringRef> color_setting( |
260 output_color = kCMYK; | 256 base::SysUTF8ToCFStringRef(color_setting_name)); |
| 257 base::mac::ScopedCFTypeRef<CFStringRef> output_color( |
| 258 base::SysUTF8ToCFStringRef(color_value)); |
261 | 259 |
262 return PMPrintSettingsSetValue(pmPrintSettings, | 260 return PMPrintSettingsSetValue(pmPrintSettings, |
263 kColorModel, | 261 color_setting.get(), |
264 output_color, | 262 output_color.get(), |
265 false) == noErr; | 263 false) == noErr; |
266 } | 264 } |
267 | 265 |
268 PageRanges PrintingContextMac::GetPageRangesFromPrintInfo() { | 266 PageRanges PrintingContextMac::GetPageRangesFromPrintInfo() { |
269 PageRanges page_ranges; | 267 PageRanges page_ranges; |
270 NSDictionary* print_info_dict = [print_info_.get() dictionary]; | 268 NSDictionary* print_info_dict = [print_info_.get() dictionary]; |
271 if (![[print_info_dict objectForKey:NSPrintAllPages] boolValue]) { | 269 if (![[print_info_dict objectForKey:NSPrintAllPages] boolValue]) { |
272 PageRange range; | 270 PageRange range; |
273 range.from = [[print_info_dict objectForKey:NSPrintFirstPage] intValue] - 1; | 271 range.from = [[print_info_dict objectForKey:NSPrintFirstPage] intValue] - 1; |
274 range.to = [[print_info_dict objectForKey:NSPrintLastPage] intValue] - 1; | 272 range.to = [[print_info_dict objectForKey:NSPrintLastPage] intValue] - 1; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 void PrintingContextMac::ReleaseContext() { | 377 void PrintingContextMac::ReleaseContext() { |
380 print_info_.reset(); | 378 print_info_.reset(); |
381 context_ = NULL; | 379 context_ = NULL; |
382 } | 380 } |
383 | 381 |
384 gfx::NativeDrawingContext PrintingContextMac::context() const { | 382 gfx::NativeDrawingContext PrintingContextMac::context() const { |
385 return context_; | 383 return context_; |
386 } | 384 } |
387 | 385 |
388 } // namespace printing | 386 } // namespace printing |
OLD | NEW |