page_setup.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef PRINTING_PAGE_SETUP_H_
  5. #define PRINTING_PAGE_SETUP_H_
  6. #include "base/component_export.h"
  7. #include "ui/gfx/geometry/rect.h"
  8. namespace printing {
  9. // Margins for a page setup.
  10. class COMPONENT_EXPORT(PRINTING) PageMargins {
  11. public:
  12. PageMargins();
  13. PageMargins(int header, int footer, int left, int right, int top, int bottom);
  14. void Clear();
  15. // Equality operator.
  16. bool Equals(const PageMargins& rhs) const;
  17. // Vertical space for the overlay from the top of the sheet.
  18. int header;
  19. // Vertical space for the overlay from the bottom of the sheet.
  20. int footer;
  21. // Margin on each side of the sheet.
  22. int left;
  23. int right;
  24. int top;
  25. int bottom;
  26. };
  27. // Settings that define the size and printable areas of a page. Unit is
  28. // unspecified.
  29. class COMPONENT_EXPORT(PRINTING) PageSetup {
  30. public:
  31. PageSetup();
  32. PageSetup(const gfx::Size& physical_size,
  33. const gfx::Rect& printable_area,
  34. const PageMargins& requested_margins,
  35. bool forced_margins,
  36. int text_height);
  37. PageSetup(const PageSetup& other);
  38. ~PageSetup();
  39. // Gets a symmetrical printable area.
  40. static gfx::Rect GetSymmetricalPrintableArea(const gfx::Size& page_size,
  41. const gfx::Rect& printable_area);
  42. void Clear();
  43. // Equality operator.
  44. bool Equals(const PageSetup& rhs) const;
  45. void Init(const gfx::Size& physical_size,
  46. const gfx::Rect& printable_area,
  47. int text_height);
  48. // Use `requested_margins` as long as they fall inside the printable area.
  49. void SetRequestedMargins(const PageMargins& requested_margins);
  50. // Ignore the printable area, and set the margins to `requested_margins`.
  51. void ForceRequestedMargins(const PageMargins& requested_margins);
  52. // Flips the orientation of the page and recalculates all page areas.
  53. void FlipOrientation();
  54. const gfx::Size& physical_size() const { return physical_size_; }
  55. const gfx::Rect& overlay_area() const { return overlay_area_; }
  56. const gfx::Rect& content_area() const { return content_area_; }
  57. const gfx::Rect& printable_area() const { return printable_area_; }
  58. const PageMargins& effective_margins() const { return effective_margins_; }
  59. const PageMargins& requested_margins() const { return requested_margins_; }
  60. bool forced_margins() const { return forced_margins_; }
  61. int text_height() const { return text_height_; }
  62. private:
  63. // Store `requested_margins_` and update page setup values.
  64. void SetRequestedMarginsAndCalculateSizes(
  65. const PageMargins& requested_margins);
  66. // Calculate overlay_area_, effective_margins_, and content_area_, based on
  67. // a constraint of `bounds` and `text_height`.
  68. void CalculateSizesWithinRect(const gfx::Rect& bounds, int text_height);
  69. // Physical size of the page, including non-printable margins.
  70. gfx::Size physical_size_;
  71. // The printable area as specified by the printer driver. We can't get
  72. // larger than this.
  73. gfx::Rect printable_area_;
  74. // The printable area for headers and footers.
  75. gfx::Rect overlay_area_;
  76. // The printable area as selected by the user's margins.
  77. gfx::Rect content_area_;
  78. // Effective margins.
  79. PageMargins effective_margins_;
  80. // Requested margins.
  81. PageMargins requested_margins_;
  82. // True when `effective_margins_` respects `printable_area_` else false.
  83. bool forced_margins_;
  84. // Space that must be kept free for the overlays.
  85. int text_height_;
  86. };
  87. } // namespace printing
  88. #endif // PRINTING_PAGE_SETUP_H_