From 355e36f7b919a9dd3cfc1244cf91a497e301ffcd Mon Sep 17 00:00:00 2001
From: "kmadhusu@chromium.org"
 <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Wed, 12 Oct 2011 16:26:17 +0000
Subject: PrintPreview: Fix printer color settings issues based on printer
 ppd/schema information.

Show/Hide the color options based on printer ppd/schema information. Some printers does not provide sufficient information in the printer schema/ppd regarding the color settings and they use custom advance settings to print in black & white/greyscale. In those cases, users need to print using native dialog in order to set these advance color settings.

BUG=93811, 93490, 87344, 96658, 98768
TEST= Please refer to bug description.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105087 0039d316-1c4b-4281-b951-d872f2087c98
---
 printing/print_job_constants.cc  | 18 ++++++++
 printing/print_job_constants.h   | 40 ++++++++++++++++-
 printing/print_settings.cc       | 96 ++++++++++++++++++++++++++++++++++++++++
 printing/print_settings.h        | 10 +++++
 printing/printing_context_mac.mm | 20 ++++-----
 5 files changed, 171 insertions(+), 13 deletions(-)

(limited to 'printing')

diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc
index 3efb488..5420e74 100644
--- a/printing/print_job_constants.cc
+++ b/printing/print_job_constants.cc
@@ -121,4 +121,22 @@ const char kSettingPrintToPDF[] = "printToPDF";
 const int FIRST_PAGE_INDEX = 0;
 const int COMPLETE_PREVIEW_DOCUMENT_INDEX = -1;
 
+#if defined (USE_CUPS)
+const char kBlack[] = "Black";
+const char kCMYK[] = "CMYK";
+const char kKCMY[] = "KCMY";
+const char kCMY_K[] = "CMY+K";
+const char kCMY[] = "CMY";
+const char kColor[] = "Color";
+const char kGray[] = "Gray";
+const char kGrayscale[] = "Grayscale";
+const char kGreyscale[] = "Greyscale";
+const char kMonochrome[] = "Monochrome";
+const char kNormal[] = "Normal";
+const char kNormalGray[] = "Normal.Gray";
+const char kRGB[] = "RGB";
+const char kRGBA[] = "RGBA";
+const char kRGB16[] = "RGB16";
+#endif
+
 }  // namespace printing
diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h
index cbdad74..8b3c638 100644
--- a/printing/print_job_constants.h
+++ b/printing/print_job_constants.h
@@ -48,6 +48,25 @@ PRINTING_EXPORT extern const char kSettingPrintToPDF[];
 PRINTING_EXPORT extern const int FIRST_PAGE_INDEX;
 PRINTING_EXPORT extern const int COMPLETE_PREVIEW_DOCUMENT_INDEX;
 
+#if defined (USE_CUPS)
+// Printer color models
+PRINTING_EXPORT extern const char kBlack[];
+PRINTING_EXPORT extern const char kCMYK[];
+PRINTING_EXPORT extern const char kKCMY[];
+PRINTING_EXPORT extern const char kCMY_K[];
+PRINTING_EXPORT extern const char kCMY[];
+PRINTING_EXPORT extern const char kColor[];
+PRINTING_EXPORT extern const char kGray[];
+PRINTING_EXPORT extern const char kGrayscale[];
+PRINTING_EXPORT extern const char kGreyscale[];
+PRINTING_EXPORT extern const char kMonochrome[];
+PRINTING_EXPORT extern const char kNormal[];
+PRINTING_EXPORT extern const char kNormalGray[];
+PRINTING_EXPORT extern const char kRGB[];
+PRINTING_EXPORT extern const char kRGBA[];
+PRINTING_EXPORT extern const char kRGB16[];
+#endif
+
 // Print job duplex mode values.
 enum DuplexMode {
   UNKNOWN_DUPLEX_MODE = -1,
@@ -70,10 +89,27 @@ enum VerticalHeaderFooterPosition {
 };
 
 // Print job color mode values.
-enum ColorMode {
-  GRAY = 1,
+enum ColorModels {
+  UNKNOWN_COLOR_MODEL,
+  GRAY,
   COLOR,
   CMYK,
+  CMY,
+  KCMY,
+  CMY_K,  // CMY_K represents CMY+K.
+  BLACK,
+  RGB,
+  RGB16,
+  RGBA,
+  COLORMODE_COLOR,  // Used in samsung printer ppds.
+  COLORMODE_MONOCHROME,  // Used in samsung printer ppds.
+  HP_COLOR_COLOR, // Used in HP color printer ppds.
+  HP_COLOR_BLACK, // Used in HP color printer ppds.
+  PRINTOUTMODE_NORMAL,  // Used in foomatic ppds.
+  PRINTOUTMODE_NORMAL_GRAY,  // Used in foomatic ppds.
+  PROCESSCOLORMODEL_CMYK,  // Used in canon printer ppds.
+  PROCESSCOLORMODEL_GREYSCALE,  // Used in canon printer ppds.
+  PROCESSCOLORMODEL_RGB,  // Used in canon printer ppds
 };
 
 }  // namespace printing
diff --git a/printing/print_settings.cc b/printing/print_settings.cc
index d08d02f5..06aac453d 100644
--- a/printing/print_settings.cc
+++ b/printing/print_settings.cc
@@ -10,6 +10,102 @@
 
 namespace printing {
 
+#if defined (USE_CUPS)
+void GetColorModelForMode(
+    int color_mode, std::string* color_setting_name, std::string* color_value) {
+#if defined(OS_MACOSX)
+  const char kCUPSColorMode[] = "ColorMode";
+  const char kCUPSColorModel[] = "ColorModel";
+  const char kCUPSPrintoutMode[] = "PrintoutMode";
+  const char kCUPSProcessColorModel[] = "ProcessColorModel";
+#else
+  const char kCUPSColorMode[] = "cups-ColorMode";
+  const char kCUPSColorModel[] = "cups-ColorModel";
+  const char kCUPSPrintoutMode[] = "cups-PrintoutMode";
+  const char kCUPSProcessColorModel[] = "cups-ProcessColorModel";
+#endif
+
+  color_setting_name->assign(kCUPSColorModel);
+  switch (color_mode) {
+    case printing::COLOR:
+      color_value->assign(printing::kColor);
+      break;
+    case printing::CMYK:
+      color_value->assign(printing::kCMYK);
+      break;
+    case printing::PRINTOUTMODE_NORMAL:
+      color_value->assign(printing::kNormal);
+      color_setting_name->assign(kCUPSPrintoutMode);
+      break;
+    case printing::PRINTOUTMODE_NORMAL_GRAY:
+      color_value->assign(printing::kNormalGray);
+      color_setting_name->assign(kCUPSPrintoutMode);
+      break;
+    case printing::RGB16:
+      color_value->assign(printing::kRGB16);
+      break;
+    case printing::RGBA:
+      color_value->assign(printing::kRGBA);
+      break;
+    case printing::RGB:
+      color_value->assign(printing::kRGB);
+      break;
+    case printing::CMY:
+      color_value->assign(printing::kCMY);
+      break;
+    case printing::CMY_K:
+      color_value->assign(printing::kCMY_K);
+      break;
+    case printing::BLACK:
+      color_value->assign(printing::kBlack);
+      break;
+    case printing::GRAY:
+      color_value->assign(printing::kGray);
+      break;
+    case printing::COLORMODE_COLOR:
+      color_setting_name->assign(kCUPSColorMode);
+      color_value->assign(printing::kColor);
+      break;
+    case printing::COLORMODE_MONOCHROME:
+      color_setting_name->assign(kCUPSColorMode);
+      color_value->assign(printing::kMonochrome);
+      break;
+    case printing::HP_COLOR_COLOR:
+      color_setting_name->assign(kColor);
+      color_value->assign(printing::kColor);
+      break;
+    case printing::HP_COLOR_BLACK:
+      color_setting_name->assign(kColor);
+      color_value->assign(printing::kBlack);
+      break;
+    case printing::PROCESSCOLORMODEL_CMYK:
+      color_setting_name->assign(kCUPSProcessColorModel);
+      color_value->assign(printing::kCMYK);
+      break;
+    case printing::PROCESSCOLORMODEL_GREYSCALE:
+      color_setting_name->assign(kCUPSProcessColorModel);
+      color_value->assign(printing::kGreyscale);
+      break;
+    case printing::PROCESSCOLORMODEL_RGB:
+      color_setting_name->assign(kCUPSProcessColorModel);
+      color_value->assign(printing::kRGB);
+      break;
+    default:
+      color_value->assign(printing::kGrayscale);
+      break;
+  }
+}
+#endif
+
+bool isColorModelSelected(int model) {
+  return (model != printing::GRAY &&
+          model != printing::BLACK &&
+          model != printing::PRINTOUTMODE_NORMAL_GRAY &&
+          model != printing::COLORMODE_MONOCHROME &&
+          model != printing::PROCESSCOLORMODEL_GREYSCALE &&
+          model != printing::HP_COLOR_BLACK);
+}
+
 // Global SequenceNumber used for generating unique cookie values.
 static base::AtomicSequenceNumber cookie_seq(base::LINKER_INITIALIZED);
 
diff --git a/printing/print_settings.h b/printing/print_settings.h
index 4e40231..6101684 100644
--- a/printing/print_settings.h
+++ b/printing/print_settings.h
@@ -15,6 +15,16 @@
 
 namespace printing {
 
+// Returns true if color model is selected.
+bool isColorModelSelected(int model);
+
+#if defined (USE_CUPS)
+  // Get the color model setting name and value for the |color_mode|.
+  void GetColorModelForMode(int color_mode,
+                            std::string* color_setting_name,
+                            std::string* color_value);
+#endif
+
 // OS-independent print settings.
 class PRINTING_EXPORT PrintSettings {
  public:
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm
index 15348a0..bfb9817 100644
--- a/printing/printing_context_mac.mm
+++ b/printing/printing_context_mac.mm
@@ -15,10 +15,6 @@
 #include "base/values.h"
 #include "printing/print_settings_initializer_mac.h"
 
-static const CFStringRef kColorModel = CFSTR("ColorModel");
-static const CFStringRef kGrayColor = CFSTR("Gray");
-static const CFStringRef kCMYK = CFSTR("CMYK");
-
 namespace printing {
 
 // static
@@ -253,15 +249,17 @@ bool PrintingContextMac::SetDuplexModeInPrintSettings(DuplexMode mode) {
 bool PrintingContextMac::SetOutputColor(int color_mode) {
   PMPrintSettings pmPrintSettings =
       static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]);
-  CFStringRef output_color = NULL;
-  if (color_mode == printing::GRAY)
-    output_color = kGrayColor;
-  else if (color_mode == printing::CMYK)
-    output_color = kCMYK;
+  std::string color_setting_name;
+  std::string color_value;
+  printing::GetColorModelForMode(color_mode, &color_setting_name, &color_value);
+  base::mac::ScopedCFTypeRef<CFStringRef> color_setting(
+      base::SysUTF8ToCFStringRef(color_setting_name));
+  base::mac::ScopedCFTypeRef<CFStringRef> output_color(
+      base::SysUTF8ToCFStringRef(color_value));
 
   return PMPrintSettingsSetValue(pmPrintSettings,
-                                 kColorModel,
-                                 output_color,
+                                 color_setting.get(),
+                                 output_color.get(),
                                  false) == noErr;
 }
 
-- 
cgit v1.1