Clarify page rectangles in DocumentLayout
This change splits DocumentLayout::page_rect() into two methods,
page_rect() and page_bounds_rect(), to better mirror the corresponding
APIs in PDFEngine, GetPageRect() (page rectangle before insets) and
GetPageBoundsRect() (page rectangle after insets).
The existing page_rect() method is equivalent to PDFEngine's
GetPageBoundsRect(), which is confusing, so it has been renamed to
page_bounds_rect(). The new page_rect() method is equivalent to
PDFEngine's GetPageRect(). (This will be useful in a future change.)
DocumentLayout is now responsible for adding insets to the page
rectangles returned by draw_utils::GetRectForSingleView(), etc.,
eliminating the need to pass the insets to these functions.
Bug: 885110
Change-Id: I4ef345333abbb5b75892c32ffff8dee24e20ef05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1762601
Reviewed-by: Lei Zhang <[email protected]>
Commit-Queue: K Moon <[email protected]>
Cr-Commit-Position: refs/heads/master@{#689735}
diff --git a/pdf/document_layout.cc b/pdf/document_layout.cc
index b1d3172e..c1ef704 100644
--- a/pdf/document_layout.cc
+++ b/pdf/document_layout.cc
@@ -19,6 +19,13 @@
return widest_page_width;
}
+pp::Rect InsetRect(pp::Rect rect,
+ const draw_utils::PageInsetSizes& inset_sizes) {
+ rect.Inset(inset_sizes.left, inset_sizes.top, inset_sizes.right,
+ inset_sizes.bottom);
+ return rect;
+}
+
} // namespace
const draw_utils::PageInsetSizes DocumentLayout::kSingleViewInsets{
@@ -48,7 +55,7 @@
const std::vector<pp::Size>& page_sizes) {
set_size({GetWidestPageWidth(page_sizes), 0});
- page_rects_.resize(page_sizes.size());
+ page_layouts_.resize(page_sizes.size());
for (size_t i = 0; i < page_sizes.size(); ++i) {
if (i != 0) {
// Add space for bottom separator.
@@ -56,8 +63,10 @@
}
const pp::Size& page_size = page_sizes[i];
- page_rects_[i] =
- draw_utils::GetRectForSingleView(page_size, size_, kSingleViewInsets);
+ pp::Rect page_rect = draw_utils::GetRectForSingleView(page_size, size_);
+ page_layouts_[i].outer_rect = page_rect;
+ page_layouts_[i].inner_rect = InsetRect(page_rect, kSingleViewInsets);
+
draw_utils::ExpandDocumentSize(page_size, &size_);
}
}
@@ -66,21 +75,24 @@
const std::vector<pp::Size>& page_sizes) {
set_size({GetWidestPageWidth(page_sizes), 0});
- page_rects_.resize(page_sizes.size());
+ page_layouts_.resize(page_sizes.size());
for (size_t i = 0; i < page_sizes.size(); ++i) {
draw_utils::PageInsetSizes page_insets =
draw_utils::GetPageInsetsForTwoUpView(
i, page_sizes.size(), kSingleViewInsets, kHorizontalSeparator);
const pp::Size& page_size = page_sizes[i];
+ pp::Rect page_rect;
if (i % 2 == 0) {
- page_rects_[i] = draw_utils::GetLeftRectForTwoUpView(
- page_size, {size_.width(), size_.height()}, page_insets);
+ page_rect = draw_utils::GetLeftRectForTwoUpView(
+ page_size, {size_.width(), size_.height()});
} else {
- page_rects_[i] = draw_utils::GetRightRectForTwoUpView(
- page_size, {size_.width(), size_.height()}, page_insets);
+ page_rect = draw_utils::GetRightRectForTwoUpView(
+ page_size, {size_.width(), size_.height()});
EnlargeHeight(std::max(page_size.height(), page_sizes[i - 1].height()));
}
+ page_layouts_[i].outer_rect = page_rect;
+ page_layouts_[i].inner_rect = InsetRect(page_rect, page_insets);
}
if (page_sizes.size() % 2 == 1) {