Commit 807fa7ef authored by Jeremy Chinsen's avatar Jeremy Chinsen Committed by Commit Bot

Add draw_utils::GetBottomGapBetweenRects().

Currently draw_utils::GetBottomFillRect() returns the gap on the
bottom side of a page created by insetting the page. However,
in two-up view, the bottom gap for a page has height equal to the
difference in height between the current page and its adjacent one.

draw_utils::GetBottomGapBetweenRects() takes the bottom component of
a page and a rectangle, returning the portion of the rectangle that
is below the page. This will be used in PDFiumEngine to compute the
bottom empty space for a page in two-up view as mentioned above.

Bug: 51472
Change-Id: I436600264106340ca6699799359149f29c797844
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1721318Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Jeremy Chinsen <chinsenj@google.com>
Cr-Commit-Position: refs/heads/master@{#682097}
parent cc647bae
...@@ -17,6 +17,15 @@ void ExpandDocumentSize(const pp::Size& rect_size, pp::Size* doc_size) { ...@@ -17,6 +17,15 @@ void ExpandDocumentSize(const pp::Size& rect_size, pp::Size* doc_size) {
doc_size->Enlarge(width_diff, rect_size.height()); doc_size->Enlarge(width_diff, rect_size.height());
} }
pp::Rect GetBottomGapBetweenRects(int page_rect_bottom,
const pp::Rect& bottom_rect) {
if (page_rect_bottom >= bottom_rect.bottom())
return pp::Rect(0, 0, 0, 0);
return pp::Rect(bottom_rect.x(), page_rect_bottom, bottom_rect.width(),
bottom_rect.bottom() - page_rect_bottom);
}
PageInsetSizes GetPageInsetsForTwoUpView( PageInsetSizes GetPageInsetsForTwoUpView(
size_t page_index, size_t page_index,
size_t num_of_pages, size_t num_of_pages,
......
...@@ -31,6 +31,13 @@ struct PageInsetSizes { ...@@ -31,6 +31,13 @@ struct PageInsetSizes {
// |doc_size|'s height. // |doc_size|'s height.
void ExpandDocumentSize(const pp::Size& rect_size, pp::Size* doc_size); void ExpandDocumentSize(const pp::Size& rect_size, pp::Size* doc_size);
// Given |page_rect_bottom| and |bottom_rect| in the same coordinate space,
// return a pp::Rect object representing the portion of |bottom_rect| that is
// below |page_rect_bottom|. Returns an empty rectangle if |page_rect_bottom|
// is greater than or equal to |bottom_rect.bottom()|.
pp::Rect GetBottomGapBetweenRects(int page_rect_bottom,
const pp::Rect& bottom_rect);
// Given |page_index|, and |num_of_pages|, return the configuration of // Given |page_index|, and |num_of_pages|, return the configuration of
// |single_view_insets| and |horizontal_separator| for the current page in // |single_view_insets| and |horizontal_separator| for the current page in
// two-up view. // two-up view.
...@@ -40,6 +47,7 @@ PageInsetSizes GetPageInsetsForTwoUpView( ...@@ -40,6 +47,7 @@ PageInsetSizes GetPageInsetsForTwoUpView(
const PageInsetSizes& single_view_insets, const PageInsetSizes& single_view_insets,
int horizontal_separator); int horizontal_separator);
// TODO (chinsenj): move Get*FillRect() functions to bottom of coordinates.h.
// Given |page_rect| in document coordinates, |inset_sizes|, and // Given |page_rect| in document coordinates, |inset_sizes|, and
// |bottom_separator|, return a pp::Rect object representing the gap on the // |bottom_separator|, return a pp::Rect object representing the gap on the
// left side of the page created by insetting the page. I.e. the difference, // left side of the page created by insetting the page. I.e. the difference,
......
...@@ -61,6 +61,21 @@ TEST(CoordinateTest, ExpandDocumentSize) { ...@@ -61,6 +61,21 @@ TEST(CoordinateTest, ExpandDocumentSize) {
CompareSize({250, 1450}, doc_size); CompareSize({250, 1450}, doc_size);
} }
TEST(CoordinateTest, GetBottomGapBetweenRects) {
CompareRect({95, 600, 350, 50},
GetBottomGapBetweenRects(600, {95, 200, 350, 450}));
CompareRect({200, 500, 350, 10},
GetBottomGapBetweenRects(500, {200, 0, 350, 510}));
// Test rectangle with a negative bottom value.
CompareRect({150, -100, 400, 150},
GetBottomGapBetweenRects(-100, {150, 0, 400, 50}));
// Test case where |page_rect_bottom| >= |dirty_rect.bottom()|.
CompareRect({0, 0, 0, 0}, GetBottomGapBetweenRects(1400, {0, 10, 300, 500}));
}
TEST(CoordinateTest, GetPageInsetsForTwoUpView) { TEST(CoordinateTest, GetPageInsetsForTwoUpView) {
// Page is on the left side and isn't the last page in the document. // Page is on the left side and isn't the last page in the document.
CompareInsetSizes(kLeftInsets, CompareInsetSizes(kLeftInsets,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment