summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorsanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-29 07:18:29 +0000
committersanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-29 07:18:29 +0000
commit6ab86acd95c830be779fdddbbc1230e8b73c21bc (patch)
tree0513fe4fa922c08856287caa0d1d48a7fb6c751f /printing
parenta93885094715c2d23953f9139d61e1071d8006a5 (diff)
downloadchromium_src-6ab86acd95c830be779fdddbbc1230e8b73c21bc.zip
chromium_src-6ab86acd95c830be779fdddbbc1230e8b73c21bc.tar.gz
chromium_src-6ab86acd95c830be779fdddbbc1230e8b73c21bc.tar.bz2
Changed printer page setup units to be in device co-ordinates (this is pixels on Windows and points on the Mac). Also fixed a bug with Mac dpi calculation.
BUG=None. TEST=Test printing on Windows and Mac. Review URL: http://codereview.chromium.org/2351003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48558 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/print_settings.cc69
-rw-r--r--printing/print_settings.h22
-rw-r--r--printing/printed_document.cc9
-rw-r--r--printing/printed_document_mac.cc2
-rw-r--r--printing/printed_document_win.cc4
5 files changed, 63 insertions, 43 deletions
diff --git a/printing/print_settings.cc b/printing/print_settings.cc
index 77c4049..bfc7868 100644
--- a/printing/print_settings.cc
+++ b/printing/print_settings.cc
@@ -32,7 +32,7 @@ void PrintSettings::Clear() {
selection_only = false;
printer_name_.clear();
device_name_.clear();
- page_setup_pixels_.Clear();
+ page_setup_device_units_.Clear();
dpi_ = 0;
landscape_ = false;
}
@@ -60,15 +60,17 @@ void PrintSettings::Init(HDC hdc,
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);
+ // Initialize page_setup_device_units_.
+ gfx::Size physical_size_device_units(GetDeviceCaps(hdc, PHYSICALWIDTH),
+ GetDeviceCaps(hdc, PHYSICALHEIGHT));
+ gfx::Rect printable_area_device_units(GetDeviceCaps(hdc, PHYSICALOFFSETX),
+ GetDeviceCaps(hdc, PHYSICALOFFSETY),
+ GetDeviceCaps(hdc, HORZRES),
+ GetDeviceCaps(hdc, VERTRES));
+
+ SetPrinterPrintableArea(physical_size_device_units,
+ printable_area_device_units,
+ dpi_);
}
#elif defined(OS_MACOSX)
void PrintSettings::Init(PMPrinter printer, PMPageFormat page_format,
@@ -91,7 +93,7 @@ void PrintSettings::Init(PMPrinter printer, PMPageFormat page_format,
for (uint32 i = 1; i <= resolution_count; ++i) {
PMResolution resolution;
PMPrinterGetIndexedPrinterResolution(printer, i, &resolution);
- if (best_resolution.hRes > resolution.hRes)
+ if (resolution.hRes > best_resolution.hRes)
best_resolution = resolution;
}
}
@@ -103,36 +105,41 @@ void PrintSettings::Init(PMPrinter printer, PMPageFormat page_format,
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);
+ // Device units are in points. Units per inch is 72.
+ gfx::Size physical_size_device_units(
+ (paper_rect.right - paper_rect.left),
+ (paper_rect.bottom - paper_rect.top));
+ gfx::Rect printable_area_device_units(
+ (page_rect.left - paper_rect.left),
+ (page_rect.top - paper_rect.top),
+ (page_rect.right - page_rect.left),
+ (page_rect.bottom - page_rect.top));
+
+ SetPrinterPrintableArea(physical_size_device_units,
+ printable_area_device_units,
+ 72);
}
#endif
void PrintSettings::SetPrinterPrintableArea(
- gfx::Size const& physical_size_pixels,
- gfx::Rect const& printable_area_pixels) {
+ gfx::Size const& physical_size_device_units,
+ gfx::Rect const& printable_area_device_units,
+ int units_per_inch) {
int header_footer_text_height = 0;
int margin_printer_units = 0;
if (use_overlays) {
// Hard-code text_height = 0.5cm = ~1/5 of inch.
- header_footer_text_height = ConvertUnit(500, kHundrethsMMPerInch, dpi_);
+ header_footer_text_height = ConvertUnit(500, kHundrethsMMPerInch,
+ units_per_inch);
// Default margins 1.0cm = ~2/5 of an inch.
- margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch, dpi_);
+ margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch,
+ units_per_inch);
}
// Start by setting the user configuration
- page_setup_pixels_.Init(physical_size_pixels,
- printable_area_pixels,
- header_footer_text_height);
+ page_setup_device_units_.Init(physical_size_device_units,
+ printable_area_device_units,
+ header_footer_text_height);
// Apply default margins (not user configurable just yet).
@@ -145,7 +152,7 @@ void PrintSettings::SetPrinterPrintableArea(
margins.top = margin_printer_units;
margins.right = margin_printer_units;
margins.bottom = margin_printer_units;
- page_setup_pixels_.SetRequestedMargins(margins);
+ page_setup_device_units_.SetRequestedMargins(margins);
}
bool PrintSettings::Equals(const PrintSettings& rhs) const {
@@ -158,7 +165,7 @@ bool PrintSettings::Equals(const PrintSettings& rhs) const {
desired_dpi == rhs.desired_dpi &&
overlays.Equals(rhs.overlays) &&
device_name_ == rhs.device_name_ &&
- page_setup_pixels_.Equals(rhs.page_setup_pixels_) &&
+ page_setup_device_units_.Equals(rhs.page_setup_device_units_) &&
dpi_ == rhs.dpi_ &&
landscape_ == rhs.landscape_;
}
diff --git a/printing/print_settings.h b/printing/print_settings.h
index 3a269f7..fc52aeb 100644
--- a/printing/print_settings.h
+++ b/printing/print_settings.h
@@ -41,9 +41,10 @@ class PrintSettings {
const PageRanges& new_ranges, bool print_selection_only);
#endif
- // Set printer printable area in in pixels.
- void SetPrinterPrintableArea(gfx::Size const& physical_size_pixels,
- gfx::Rect const& printable_area_pixels);
+ // Set printer printable area in in device units.
+ void SetPrinterPrintableArea(gfx::Size const& physical_size_device_units,
+ gfx::Rect const& printable_area_device_units,
+ int units_per_inch);
// Equality operator.
// NOTE: printer_name is NOT tested for equality since it doesn't affect the
@@ -56,7 +57,16 @@ class PrintSettings {
}
const std::wstring& device_name() const { return device_name_; }
int dpi() const { return dpi_; }
- const PageSetup& page_setup_pixels() const { return page_setup_pixels_; }
+ const PageSetup& page_setup_device_units() const {
+ return page_setup_device_units_;
+ }
+ int device_units_per_inch() const {
+#if defined(OS_MACOSX)
+ return 72;
+#else // defined(OS_MACOSX)
+ return dpi();
+#endif // defined(OS_MACOSX)
+ }
// Multi-page printing. Each PageRange describes a from-to page combination.
// This permits printing selected pages only.
@@ -105,8 +115,8 @@ class PrintSettings {
// Printer device name as opened by the OS.
std::wstring device_name_;
- // Page setup in pixel units, dpi adjusted.
- PageSetup page_setup_pixels_;
+ // Page setup in device units.
+ PageSetup page_setup_device_units_;
// Printer's device effective dots per inch in both axis.
int dpi_;
diff --git a/printing/printed_document.cc b/printing/printed_document.cc
index 7850073..f49e1e6 100644
--- a/printing/printed_document.cc
+++ b/printing/printed_document.cc
@@ -75,7 +75,8 @@ void PrintedDocument::SetPage(int page_number,
// be shown. Users dislike 0-based counting.
scoped_refptr<PrintedPage> page(
new PrintedPage(page_number + 1,
- metafile, immutable_.settings_.page_setup_pixels().physical_size()));
+ metafile,
+ immutable_.settings_.page_setup_device_units().physical_size()));
{
AutoLock lock(lock_);
mutable_.pages_[page_number] = page;
@@ -195,10 +196,12 @@ void PrintedDocument::PrintHeaderFooter(gfx::NativeDrawingContext context,
const gfx::Size string_size(font.GetStringWidth(output), font.height());
gfx::Rect bounding;
bounding.set_height(string_size.height());
- const gfx::Rect& overlay_area(settings.page_setup_pixels().overlay_area());
+ const gfx::Rect& overlay_area(
+ settings.page_setup_device_units().overlay_area());
// Hard code .25 cm interstice between overlays. Make sure that some space is
// kept between each headers.
- const int interstice = ConvertUnit(250, kHundrethsMMPerInch, settings.dpi());
+ const int interstice = ConvertUnit(250, kHundrethsMMPerInch,
+ settings.device_units_per_inch());
const int max_width = overlay_area.width() / 3 - interstice;
const int actual_width = std::min(string_size.width(), max_width);
switch (x) {
diff --git a/printing/printed_document_mac.cc b/printing/printed_document_mac.cc
index e9bd044..422dacf 100644
--- a/printing/printed_document_mac.cc
+++ b/printing/printed_document_mac.cc
@@ -25,7 +25,7 @@ void PrintedDocument::RenderPrintedPage(
#endif
const printing::PageSetup& page_setup(
- immutable_.settings_.page_setup_pixels());
+ immutable_.settings_.page_setup_device_units());
CGRect target_rect = page_setup.content_area().ToCGRect();
const printing::NativeMetafile* metafile = page.native_metafile();
diff --git a/printing/printed_document_win.cc b/printing/printed_document_win.cc
index 0c17201..42c1b45 100644
--- a/printing/printed_document_win.cc
+++ b/printing/printed_document_win.cc
@@ -50,7 +50,7 @@ void PrintedDocument::RenderPrintedPage(
#endif
const printing::PageSetup& page_setup(
- immutable_.settings_.page_setup_pixels());
+ immutable_.settings_.page_setup_device_units());
// Save the state to make sure the context this function call does not modify
// the device context.
@@ -116,7 +116,7 @@ void PrintedDocument::RenderPrintedPage(
int base_font_size = gfx::Font().height();
int new_font_size = ConvertUnit(10,
immutable_.settings_.desired_dpi,
- immutable_.settings_.dpi());
+ immutable_.settings_.device_units_per_inch());
DCHECK_GT(new_font_size, base_font_size);
gfx::Font font(gfx::Font().DeriveFont(new_font_size - base_font_size));
HGDIOBJ old_font = SelectObject(context, font.hfont());