diff options
-rw-r--r-- | printing/print_job_constants.cc | 3 | ||||
-rw-r--r-- | printing/print_job_constants.h | 1 | ||||
-rw-r--r-- | printing/printing_context_mac.h | 4 | ||||
-rw-r--r-- | printing/printing_context_mac.mm | 14 |
4 files changed, 21 insertions, 1 deletions
diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc index 5442690..31075f6 100644 --- a/printing/print_job_constants.cc +++ b/printing/print_job_constants.cc @@ -24,4 +24,7 @@ const char kSettingPrintToPDF[] = "printToPDF"; // Printer name. const char kSettingPrinterName[] = "printerName"; +// Print job duplex setting. +const char kSettingTwoSided[] = "twoSided"; + } // namespace printing diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h index b34915c..42c6f69 100644 --- a/printing/print_job_constants.h +++ b/printing/print_job_constants.h @@ -13,6 +13,7 @@ extern const char kSettingCopies[]; extern const char kSettingLandscape[]; extern const char kSettingPrintToPDF[]; extern const char kSettingPrinterName[]; +extern const char kSettingTwoSided[]; } // namespace printing diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h index e19ceba..0979b18 100644 --- a/printing/printing_context_mac.h +++ b/printing/printing_context_mac.h @@ -63,6 +63,10 @@ class PrintingContextMac : public PrintingContext { // Returns true if the orientation was set. bool SetOrientationIsLandscape(bool landscape); + // Sets duplex mode in PMPrintSettings. + // Returns true if duplex mode is set. + bool SetDuplexModeIsTwoSided(bool two_sided); + // The native print info object. scoped_nsobject<NSPrintInfo> print_info_; diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm index 25f0ef6..063197e 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -93,10 +93,12 @@ PrintingContext::Result PrintingContextMac::UpdatePrintSettings( std::string printer_name; int copies; bool collate; + bool two_sided; 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(kSettingCollate, &collate) || + !job_settings.GetBoolean(kSettingTwoSided, &two_sided)) { return OnError(); } @@ -112,6 +114,9 @@ PrintingContext::Result PrintingContextMac::UpdatePrintSettings( if (!SetOrientationIsLandscape(landscape)) return OnError(); + if (!SetDuplexModeIsTwoSided(two_sided)) + return OnError(); + [print_info_.get() updateFromPMPrintSettings]; InitPrintSettingsFromPrintInfo(ranges); @@ -173,6 +178,13 @@ bool PrintingContextMac::SetOrientationIsLandscape(bool landscape) { return true; } +bool PrintingContextMac::SetDuplexModeIsTwoSided(bool two_sided) { + PMDuplexMode duplexSetting = two_sided ? kPMDuplexNoTumble : kPMDuplexNone; + PMPrintSettings pmPrintSettings = + static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]); + return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr; +} + void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { ResetSettings(); print_info_.reset([print_info retain]); |