Skip to content

Commit

Permalink
PrintPreview: [MAC] Set the color setting in print ticket.
Browse files Browse the repository at this point in the history
BUG=none
TEST= Enable print preview on mac. Preview any webpage. Change the color setting. Press the print button. Observe the color in printed output page.

Review URL: http://codereview.chromium.org/6821052

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81286 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kmadhusu@chromium.org committed Apr 12, 2011
1 parent edb2617 commit c7b3c63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions printing/printing_context_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class PrintingContextMac : public PrintingContext {
// Returns true if duplex mode is set.
bool SetDuplexModeIsTwoSided(bool two_sided);

// Sets output color mode in PMPrintSettings.
// Returns true if color mode is set.
bool SetOutputIsColor(bool color);

// The native print info object.
scoped_nsobject<NSPrintInfo> print_info_;

Expand Down
21 changes: 20 additions & 1 deletion printing/printing_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "printing/print_job_constants.h"
#include "printing/print_settings_initializer_mac.h"

static const CFStringRef kColorModel = CFSTR("ColorModel");
static const CFStringRef kGrayColor = CFSTR("Gray");

namespace printing {

// static
Expand Down Expand Up @@ -94,11 +97,13 @@
int copies;
bool collate;
bool two_sided;
bool color;
if (!job_settings.GetBoolean(kSettingLandscape, &landscape) ||
!job_settings.GetString(kSettingPrinterName, &printer_name) ||
!job_settings.GetInteger(kSettingCopies, &copies) ||
!job_settings.GetBoolean(kSettingCollate, &collate) ||
!job_settings.GetBoolean(kSettingTwoSided, &two_sided)) {
!job_settings.GetBoolean(kSettingTwoSided, &two_sided) ||
!job_settings.GetBoolean(kSettingColor, &color)) {
return OnError();
}

Expand All @@ -117,6 +122,9 @@
if (!SetDuplexModeIsTwoSided(two_sided))
return OnError();

if (!SetOutputIsColor(color))
return OnError();

[print_info_.get() updateFromPMPrintSettings];

InitPrintSettingsFromPrintInfo(ranges);
Expand Down Expand Up @@ -185,6 +193,17 @@
return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr;
}

bool PrintingContextMac::SetOutputIsColor(bool color) {
PMPrintSettings pmPrintSettings =
static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]);
CFStringRef output_color = color ? NULL : kGrayColor;

return PMPrintSettingsSetValue(pmPrintSettings,
kColorModel,
output_color,
false) == noErr;
}

void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) {
ResetSettings();
print_info_.reset([print_info retain]);
Expand Down

0 comments on commit c7b3c63

Please sign in to comment.