diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 18:46:21 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 18:46:21 +0000 |
commit | b75dca87f3ff3ee3ab003960276ec7bb49d4c734 (patch) | |
tree | 8026f1f38f82a5d7c922ba5245e38a5ecf3a61d8 /printing/print_settings.cc | |
parent | 7ff3f63b8c66408a382adc88458a6e70038cad8d (diff) | |
download | chromium_src-b75dca87f3ff3ee3ab003960276ec7bb49d4c734.zip chromium_src-b75dca87f3ff3ee3ab003960276ec7bb49d4c734.tar.gz chromium_src-b75dca87f3ff3ee3ab003960276ec7bb49d4c734.tar.bz2 |
Implement the basic OS-level printing mechanics on Mac
Part two of printing implementation on the Mac. This adds a Mac implementation of PrintSettings to get page setup and printer information, basic PDF->context rendering in PrintedDocument, and most of PrintingContext to allow getting print settings (both default and interactive).
Reworks the message flow a bit when asking for print settings on the Mac, since it can only be done from the UI thread. Uses a modal dialog for now, but will later be modified further to allow for a sheet.
BUG=13158
TEST=None; no user-visible effect yet.
Review URL: http://codereview.chromium.org/268036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28857 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/print_settings.cc')
-rw-r--r-- | printing/print_settings.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/printing/print_settings.cc b/printing/print_settings.cc index 4df0483..4764952 100644 --- a/printing/print_settings.cc +++ b/printing/print_settings.cc @@ -6,6 +6,7 @@ #include "base/atomic_sequence_num.h" #include "base/logging.h" +#include "base/sys_string_conversions.h" #include "printing/units.h" namespace printing { @@ -68,6 +69,51 @@ void PrintSettings::Init(HDC hdc, SetPrinterPrintableArea(physical_size_pixels, printable_area_pixels); } +#elif defined(OS_MACOSX) +void PrintSettings::Init(PMPrinter printer, PMPageFormat page_format, + const PageRanges& new_ranges, + bool print_selection_only) { + printer_name_ = base::SysCFStringRefToWide(PMPrinterGetName(printer)); + device_name_ = base::SysCFStringRefToWide(PMPrinterGetID(printer)); + ranges = new_ranges; + PMOrientation orientation = kPMPortrait; + PMGetOrientation(page_format, &orientation); + landscape_ = orientation == kPMLandscape; + selection_only = print_selection_only; + + UInt32 resolution_count = 0; + PMResolution best_resolution = { 72.0, 72.0 }; + OSStatus status = PMPrinterGetPrinterResolutionCount(printer, + &resolution_count); + if (status == noErr) { + // Resolution indexes are 1-based. + for (uint32 i = 1; i <= resolution_count; ++i) { + PMResolution resolution; + PMPrinterGetIndexedPrinterResolution(printer, i, &resolution); + if (best_resolution.hRes > resolution.hRes) + best_resolution = resolution; + } + } + dpi_ = best_resolution.hRes; + // See comment in the Windows code above. + DCHECK_EQ(dpi_, best_resolution.vRes); + + // Get printable area and paper rects (in points) + PMRect page_rect, paper_rect; + PMGetAdjustedPageRect(page_format, &page_rect); + PMGetAdjustedPaperRect(page_format, &paper_rect); + const double pixels_per_point = dpi_ / 72.0; + gfx::Size physical_size_pixels( + (paper_rect.right - paper_rect.left) * pixels_per_point, + (paper_rect.bottom - paper_rect.top) * pixels_per_point); + gfx::Rect printable_area_pixels( + (page_rect.left - paper_rect.left) * pixels_per_point, + (page_rect.top - paper_rect.top) * pixels_per_point, + (page_rect.right - page_rect.left) * pixels_per_point, + (page_rect.bottom - page_rect.top) * pixels_per_point); + + SetPrinterPrintableArea(physical_size_pixels, printable_area_pixels); +} #endif void PrintSettings::SetPrinterPrintableArea( |