Index: printing/print_settings.cc |
diff --git a/printing/print_settings.cc b/printing/print_settings.cc |
index 97de679239fe01f0a4f18d14c8fdaa4621ece9ab..ece87fdc0c8a37fd9e51e783fbe3b9c6892c35dd 100644 |
--- a/printing/print_settings.cc |
+++ b/printing/print_settings.cc |
@@ -17,7 +17,7 @@ PrintSettings::PrintSettings() |
max_shrink(2.0), |
desired_dpi(72), |
selection_only(false), |
- use_overlays(true), |
+ margin_type(DEFAULT_MARGINS), |
display_header_footer(false), |
dpi_(0), |
landscape_(false), |
@@ -50,33 +50,54 @@ void PrintSettings::SetPrinterPrintableArea( |
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, |
- units_per_inch); |
- // Default margins 1.0cm = ~2/5 of an inch. |
- margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch, |
+ if (margin_type == NO_MARGINS) { |
+ gfx::Rect page_rect(physical_size_device_units.width(), |
+ physical_size_device_units.height()); |
+ page_setup_device_units_.Init(physical_size_device_units, page_rect, 0); |
+ } else { |
+ int header_footer_text_height = 0; |
+ if (display_header_footer) { |
+ // Hard-code text_height = 0.5cm = ~1/5 of inch. |
+ header_footer_text_height = ConvertUnit(500, kHundrethsMMPerInch, |
+ units_per_inch); |
+ } |
+ // Start by setting the user configuration |
+ page_setup_device_units_.Init(physical_size_device_units, |
+ printable_area_device_units, |
+ header_footer_text_height); |
+ |
+ PageMargins margins; |
+ margins.header = header_footer_text_height; |
+ margins.footer = header_footer_text_height; |
+ if (margin_type == CUSTOM_MARGINS) { |
+ margins.top = ConvertUnitDouble(custom_margins_in_points_.top, |
+ printing::kPointsPerInch, |
+ units_per_inch); |
+ margins.bottom = ConvertUnitDouble(custom_margins_in_points_.bottom, |
+ printing::kPointsPerInch, |
+ units_per_inch); |
+ margins.left = ConvertUnitDouble(custom_margins_in_points_.left, |
+ printing::kPointsPerInch, |
units_per_inch); |
+ margins.right = ConvertUnitDouble(custom_margins_in_points_.right, |
+ printing::kPointsPerInch, |
+ units_per_inch); |
+ } else { |
+ // Default margins 1.0cm = ~2/5 of an inch. |
+ int margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch, |
+ units_per_inch); |
+ margins.top = margin_printer_units; |
+ margins.bottom = margin_printer_units; |
+ margins.left = margin_printer_units; |
+ margins.right = margin_printer_units; |
+ } |
+ page_setup_device_units_.SetRequestedMargins(margins); |
} |
- // Start by setting the user configuration |
- 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). |
- // Since the font height is half the margin we put the header and footers at |
- // the font height from the margins. |
- PageMargins margins; |
- margins.header = header_footer_text_height; |
- margins.footer = header_footer_text_height; |
- margins.left = margin_printer_units; |
- margins.top = margin_printer_units; |
- margins.right = margin_printer_units; |
- margins.bottom = margin_printer_units; |
- page_setup_device_units_.SetRequestedMargins(margins); |
+void PrintSettings::SetCustomMargins(const PageMargins& margins_in_points) { |
+ custom_margins_in_points_ = margins_in_points; |
+ margin_type = CUSTOM_MARGINS; |
} |
bool PrintSettings::Equals(const PrintSettings& rhs) const { |