Chromium Code Reviews| 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"); | 18 static const CFStringRef kColorModel = CFSTR("ColorModel"); |
| 19 static const CFStringRef kGrayColor = CFSTR("Gray"); | |
| 20 static const CFStringRef kCMYK = CFSTR("CMYK"); | |
| 21 | 19 |
| 22 namespace printing { | 20 namespace printing { |
| 23 | 21 |
| 24 // static | 22 // static |
| 25 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | 23 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
| 26 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); | 24 return static_cast<PrintingContext*>(new PrintingContextMac(app_locale)); |
| 27 } | 25 } |
| 28 | 26 |
| 29 PrintingContextMac::PrintingContextMac(const std::string& app_locale) | 27 PrintingContextMac::PrintingContextMac(const std::string& app_locale) |
| 30 : PrintingContext(app_locale), | 28 : PrintingContext(app_locale), |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 } | 244 } |
| 247 | 245 |
| 248 PMPrintSettings pmPrintSettings = | 246 PMPrintSettings pmPrintSettings = |
| 249 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); | 247 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); |
| 250 return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr; | 248 return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr; |
| 251 } | 249 } |
| 252 | 250 |
| 253 bool PrintingContextMac::SetOutputColor(int color_mode) { | 251 bool PrintingContextMac::SetOutputColor(int color_mode) { |
| 254 PMPrintSettings pmPrintSettings = | 252 PMPrintSettings pmPrintSettings = |
| 255 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); | 253 static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); |
| 256 CFStringRef output_color = NULL; | 254 base::mac::ScopedCFTypeRef<CFStringRef> color_setting(kColorModel); |
|
vandebo (ex-Chrome)
2011/10/07 18:23:30
Can this code be shared with the gtk code somehow?
kmadhusu
2011/10/10 23:34:26
Done.
| |
| 257 if (color_mode == printing::GRAY) | 255 base::mac::ScopedCFTypeRef<CFStringRef> output_color; |
| 258 output_color = kGrayColor; | 256 if (color_mode == GRAY) { |
| 259 else if (color_mode == printing::CMYK) | 257 output_color.reset(base::SysUTF8ToCFStringRef(kGray)); |
| 260 output_color = kCMYK; | 258 } else if (color_mode == CMYK) { |
| 259 output_color.reset(base::SysUTF8ToCFStringRef(kCMYK)); | |
| 260 } else if (color_mode == RGB) { | |
| 261 output_color.reset(base::SysUTF8ToCFStringRef(kRGB)); | |
| 262 } else if (color_mode == RGB16) { | |
| 263 output_color.reset(base::SysUTF8ToCFStringRef(kRGB16)); | |
| 264 } else if (color_mode == RGBA) { | |
| 265 output_color.reset(base::SysUTF8ToCFStringRef(kRGBA)); | |
| 266 } else if (color_mode == HP_COLOR_COLOR) { | |
| 267 color_setting.reset(base::SysUTF8ToCFStringRef(kColor)); | |
| 268 output_color.reset(base::SysUTF8ToCFStringRef(kColor)); | |
| 269 } else if (color_mode == HP_COLOR_BLACK) { | |
| 270 color_setting.reset(base::SysUTF8ToCFStringRef(kColor)); | |
| 271 output_color.reset(base::SysUTF8ToCFStringRef(kBlack)); | |
| 272 } | |
| 261 | 273 |
| 262 return PMPrintSettingsSetValue(pmPrintSettings, | 274 return PMPrintSettingsSetValue(pmPrintSettings, |
| 263 kColorModel, | 275 color_setting.get(), |
| 264 output_color, | 276 output_color.get(), |
| 265 false) == noErr; | 277 false) == noErr; |
| 266 } | 278 } |
| 267 | 279 |
| 268 PageRanges PrintingContextMac::GetPageRangesFromPrintInfo() { | 280 PageRanges PrintingContextMac::GetPageRangesFromPrintInfo() { |
| 269 PageRanges page_ranges; | 281 PageRanges page_ranges; |
| 270 NSDictionary* print_info_dict = [print_info_.get() dictionary]; | 282 NSDictionary* print_info_dict = [print_info_.get() dictionary]; |
| 271 if (![[print_info_dict objectForKey:NSPrintAllPages] boolValue]) { | 283 if (![[print_info_dict objectForKey:NSPrintAllPages] boolValue]) { |
| 272 PageRange range; | 284 PageRange range; |
| 273 range.from = [[print_info_dict objectForKey:NSPrintFirstPage] intValue] - 1; | 285 range.from = [[print_info_dict objectForKey:NSPrintFirstPage] intValue] - 1; |
| 274 range.to = [[print_info_dict objectForKey:NSPrintLastPage] intValue] - 1; | 286 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() { | 391 void PrintingContextMac::ReleaseContext() { |
| 380 print_info_.reset(); | 392 print_info_.reset(); |
| 381 context_ = NULL; | 393 context_ = NULL; |
| 382 } | 394 } |
| 383 | 395 |
| 384 gfx::NativeDrawingContext PrintingContextMac::context() const { | 396 gfx::NativeDrawingContext PrintingContextMac::context() const { |
| 385 return context_; | 397 return context_; |
| 386 } | 398 } |
| 387 | 399 |
| 388 } // namespace printing | 400 } // namespace printing |
| OLD | NEW |