diff options
author | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-07 21:31:39 +0000 |
---|---|---|
committer | sverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-07 21:31:39 +0000 |
commit | 8ff1d42631e79e842669dc3051d91ed7db80f1dc (patch) | |
tree | 55c1987549e982bfbf60a33fad3b60b5113d7864 /printing/print_settings.cc | |
parent | 395f9295b3e370746846dbe6073a0d43ab7e4af5 (diff) | |
download | chromium_src-8ff1d42631e79e842669dc3051d91ed7db80f1dc.zip chromium_src-8ff1d42631e79e842669dc3051d91ed7db80f1dc.tar.gz chromium_src-8ff1d42631e79e842669dc3051d91ed7db80f1dc.tar.bz2 |
Move printing related stuff to the root printing project from the browser project. This simplifies further refactoring and eases understanding of the printing part of Chrome.
Also renamed win_printing_context to printing_context_win (correct naming convention) and added stub implementations for _linux and mac.
Now all but one file is compiling on all platforms.
TEST=none (no functional change).
BUG=none
Review URL: http://codereview.chromium.org/149212
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/print_settings.cc')
-rw-r--r-- | printing/print_settings.cc | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/printing/print_settings.cc b/printing/print_settings.cc new file mode 100644 index 0000000..b76821b --- /dev/null +++ b/printing/print_settings.cc @@ -0,0 +1,116 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "printing/print_settings.h" + +#include "base/atomic_sequence_num.h" +#include "base/logging.h" +#include "printing/units.h" + +namespace printing { + +// Global SequenceNumber used for generating unique cookie values. +static base::AtomicSequenceNumber cookie_seq(base::LINKER_INITIALIZED); + +PrintSettings::PrintSettings() + : min_shrink(1.25), + max_shrink(2.0), + desired_dpi(72), + selection_only(false), + dpi_(0), + landscape_(false) { +} + +void PrintSettings::Clear() { + ranges.clear(); + min_shrink = 1.25; + max_shrink = 2.; + desired_dpi = 72; + selection_only = false; + printer_name_.clear(); + device_name_.clear(); + page_setup_pixels_.Clear(); + dpi_ = 0; + landscape_ = false; +} + +#ifdef WIN32 +void PrintSettings::Init(HDC hdc, + const DEVMODE& dev_mode, + const PageRanges& new_ranges, + const std::wstring& new_device_name, + bool print_selection_only) { + DCHECK(hdc); + printer_name_ = dev_mode.dmDeviceName; + device_name_ = new_device_name; + ranges = new_ranges; + landscape_ = dev_mode.dmOrientation == DMORIENT_LANDSCAPE; + selection_only = print_selection_only; + + dpi_ = GetDeviceCaps(hdc, LOGPIXELSX); + // No printer device is known to advertise different dpi in X and Y axis; even + // the fax device using the 200x100 dpi setting. It's ought to break so many + // applications that it's not even needed to care about. WebKit doesn't + // support different dpi settings in X and Y axis. + DCHECK_EQ(dpi_, GetDeviceCaps(hdc, LOGPIXELSY)); + + DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORX), 0); + DCHECK_EQ(GetDeviceCaps(hdc, SCALINGFACTORY), 0); + + // Initialize page_setup_pixels_. + gfx::Size physical_size_pixels(GetDeviceCaps(hdc, PHYSICALWIDTH), + GetDeviceCaps(hdc, PHYSICALHEIGHT)); + gfx::Rect printable_area_pixels(GetDeviceCaps(hdc, PHYSICALOFFSETX), + GetDeviceCaps(hdc, PHYSICALOFFSETY), + GetDeviceCaps(hdc, HORZRES), + GetDeviceCaps(hdc, VERTRES)); + + SetPrinterPrintableArea(physical_size_pixels, printable_area_pixels); +} +#endif + +void PrintSettings::SetPrinterPrintableArea( + gfx::Size const& physical_size_pixels, + gfx::Rect const& printable_area_pixels) { + + int margin_printer_units = ConvertUnit(500, kHundrethsMMPerInch, dpi_); + + // Start by setting the user configuration + // Hard-code text_height = 0.5cm = ~1/5 of inch + page_setup_pixels_.Init(physical_size_pixels, + printable_area_pixels, + margin_printer_units); + + // Now apply user configured settings. + PageMargins margins; + margins.header = margin_printer_units; + margins.footer = margin_printer_units; + margins.left = margin_printer_units; + margins.top = margin_printer_units; + margins.right = margin_printer_units; + margins.bottom = margin_printer_units; + page_setup_pixels_.SetRequestedMargins(margins); +} + +bool PrintSettings::Equals(const PrintSettings& rhs) const { + // Do not test the display device name (printer_name_) for equality since it + // may sometimes be chopped off at 30 chars. As long as device_name is the + // same, that's fine. + return ranges == rhs.ranges && + min_shrink == rhs.min_shrink && + max_shrink == rhs.max_shrink && + desired_dpi == rhs.desired_dpi && + overlays.Equals(rhs.overlays) && + device_name_ == rhs.device_name_ && + page_setup_pixels_.Equals(rhs.page_setup_pixels_) && + dpi_ == rhs.dpi_ && + landscape_ == rhs.landscape_; +} + +int PrintSettings::NewCookie() { + // A cookie of 0 is used to mark a document as unassigned, count from 1. + return cookie_seq.GetNext() + 1; +} + +} // namespace printing |