Commit a9ee3ee8 authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

[CrOS Printing] Refactor GetColorModelForMode()

The switch statment found in GetColorModelForMode() is useful for
determining whether a ColorMode is color or monochrome. Move it into a
new static function for other classes to use.

Change-Id: I834e503744c698ca82a2ef841f9b22484c49b414
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1888737
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710567}
parent d7caf251
...@@ -35,42 +35,16 @@ namespace printing { ...@@ -35,42 +35,16 @@ namespace printing {
namespace { namespace {
// convert from a ColorMode setting to a print-color-mode value from PWG 5100.13 // Convert from a ColorMode setting to a print-color-mode value from PWG 5100.13
const char* GetColorModelForMode(int color_mode) { const char* GetColorModelForMode(int color_mode) {
const char* mode_string; const char* mode_string;
switch (color_mode) { base::Optional<bool> is_color =
case COLOR: PrintingContextChromeos::ColorModeIsColor(color_mode);
case CMYK: if (is_color.has_value()) {
case CMY: mode_string = is_color.value() ? CUPS_PRINT_COLOR_MODE_COLOR
case KCMY: : CUPS_PRINT_COLOR_MODE_MONOCHROME;
case CMY_K: } else {
case RGB: mode_string = nullptr;
case RGB16:
case RGBA:
case COLORMODE_COLOR:
case BROTHER_CUPS_COLOR:
case BROTHER_BRSCRIPT3_COLOR:
case HP_COLOR_COLOR:
case PRINTOUTMODE_NORMAL:
case PROCESSCOLORMODEL_CMYK:
case PROCESSCOLORMODEL_RGB:
mode_string = CUPS_PRINT_COLOR_MODE_COLOR;
break;
case GRAY:
case BLACK:
case GRAYSCALE:
case COLORMODE_MONOCHROME:
case BROTHER_CUPS_MONO:
case BROTHER_BRSCRIPT3_BLACK:
case HP_COLOR_BLACK:
case PRINTOUTMODE_NORMAL_GRAY:
case PROCESSCOLORMODEL_GREYSCALE:
mode_string = CUPS_PRINT_COLOR_MODE_MONOCHROME;
break;
default:
mode_string = nullptr;
LOG(WARNING) << "Unrecognized color mode";
break;
} }
return mode_string; return mode_string;
...@@ -245,6 +219,41 @@ PrintingContextChromeos::~PrintingContextChromeos() { ...@@ -245,6 +219,41 @@ PrintingContextChromeos::~PrintingContextChromeos() {
ReleaseContext(); ReleaseContext();
} }
// static
base::Optional<bool> PrintingContextChromeos::ColorModeIsColor(int color_mode) {
switch (color_mode) {
case COLOR:
case CMYK:
case CMY:
case KCMY:
case CMY_K:
case RGB:
case RGB16:
case RGBA:
case COLORMODE_COLOR:
case BROTHER_CUPS_COLOR:
case BROTHER_BRSCRIPT3_COLOR:
case HP_COLOR_COLOR:
case PRINTOUTMODE_NORMAL:
case PROCESSCOLORMODEL_CMYK:
case PROCESSCOLORMODEL_RGB:
return true;
case GRAY:
case BLACK:
case GRAYSCALE:
case COLORMODE_MONOCHROME:
case BROTHER_CUPS_MONO:
case BROTHER_BRSCRIPT3_BLACK:
case HP_COLOR_BLACK:
case PRINTOUTMODE_NORMAL_GRAY:
case PROCESSCOLORMODEL_GREYSCALE:
return false;
default:
LOG(WARNING) << "Unrecognized color mode.";
return base::nullopt;
}
}
void PrintingContextChromeos::AskUserForSettings( void PrintingContextChromeos::AskUserForSettings(
int max_pages, int max_pages,
bool has_selection, bool has_selection,
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "printing/backend/cups_connection.h" #include "printing/backend/cups_connection.h"
#include "printing/backend/cups_deleters.h" #include "printing/backend/cups_deleters.h"
#include "printing/backend/cups_printer.h" #include "printing/backend/cups_printer.h"
...@@ -22,6 +23,10 @@ class PRINTING_EXPORT PrintingContextChromeos : public PrintingContext { ...@@ -22,6 +23,10 @@ class PRINTING_EXPORT PrintingContextChromeos : public PrintingContext {
explicit PrintingContextChromeos(Delegate* delegate); explicit PrintingContextChromeos(Delegate* delegate);
~PrintingContextChromeos() override; ~PrintingContextChromeos() override;
// Returns true if the ColorMode setting is a color ColorMode and false if it
// is a monochrome ColorMode.
static base::Optional<bool> ColorModeIsColor(int color_mode);
// PrintingContext implementation. // PrintingContext implementation.
void AskUserForSettings(int max_pages, void AskUserForSettings(int max_pages,
bool has_selection, bool has_selection,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment