Commit 8915f96d authored by Jeremy Chinsen's avatar Jeremy Chinsen Committed by Commit Bot

Add draw_utils::AdjustBottomGapForRightSidePage().

Currently in PDFiumEngine::FillPageSides() the logic for handling the
bottom gaps of pages on the right side is in the FillPageSides().

This CL moves that logic to
draw_utils::AdjustBottomGapForRightSidePage(), making it testable.

Bug: 51472
Change-Id: I5c5d0929c46745ee315f3b7ce77dc4cb0b44e5f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1726757Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Jeremy Chinsen <chinsenj@google.com>
Cr-Commit-Position: refs/heads/master@{#682888}
parent 45db3a5d
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
namespace chrome_pdf { namespace chrome_pdf {
namespace draw_utils { namespace draw_utils {
void AdjustBottomGapForRightSidePage(int page_x, pp::Rect* bottom_gap) {
bottom_gap->set_x(page_x);
bottom_gap->set_width(bottom_gap->width() / 2);
}
void ExpandDocumentSize(const pp::Size& rect_size, pp::Size* doc_size) { void ExpandDocumentSize(const pp::Size& rect_size, pp::Size* doc_size) {
int width_diff = std::max(0, rect_size.width() - doc_size->width()); int width_diff = std::max(0, rect_size.width() - doc_size->width());
doc_size->Enlarge(width_diff, rect_size.height()); doc_size->Enlarge(width_diff, rect_size.height());
......
...@@ -26,6 +26,12 @@ struct PageInsetSizes { ...@@ -26,6 +26,12 @@ struct PageInsetSizes {
int bottom; int bottom;
}; };
// Given a right page's |bottom_gap|, reduce it to only the part of |bottom_gap|
// that is directly below the right page by translating |bottom_gap| to |page_x|
// and halving its width. This avoids over-drawing empty space on the already
// drawn left page and the empty space to the right of the page.
void AdjustBottomGapForRightSidePage(int page_x, pp::Rect* bottom_gap);
// Given |rect_size|, sets the width of |doc_size| to the max of |rect_size|'s // Given |rect_size|, sets the width of |doc_size| to the max of |rect_size|'s
// width and |doc_size|'s width. Also adds the height of |rect_size| to // width and |doc_size|'s width. Also adds the height of |rect_size| to
// |doc_size|'s height. // |doc_size|'s height.
......
...@@ -40,6 +40,20 @@ void CompareSize(const pp::Size& expected_size, const pp::Size& given_size) { ...@@ -40,6 +40,20 @@ void CompareSize(const pp::Size& expected_size, const pp::Size& given_size) {
} // namespace } // namespace
TEST(CoordinateTest, AdjustBottomGapForRightSidePage) {
pp::Rect bottom_gap(0, 10, 500, 100);
AdjustBottomGapForRightSidePage(250, &bottom_gap);
CompareRect({250, 10, 250, 100}, bottom_gap);
bottom_gap.SetRect(15, 20, 700, 100);
AdjustBottomGapForRightSidePage(365, &bottom_gap);
CompareRect({365, 20, 350, 100}, bottom_gap);
bottom_gap.SetRect(100, 40, 951, 200);
AdjustBottomGapForRightSidePage(450, &bottom_gap);
CompareRect({450, 40, 475, 200}, bottom_gap);
}
TEST(CoordinateTest, ExpandDocumentSize) { TEST(CoordinateTest, ExpandDocumentSize) {
pp::Size doc_size(100, 400); pp::Size doc_size(100, 400);
......
...@@ -2837,9 +2837,8 @@ void PDFiumEngine::FillPageSides(int progressive_index) { ...@@ -2837,9 +2837,8 @@ void PDFiumEngine::FillPageSides(int progressive_index) {
page_in_screen.bottom(), dirty_in_screen); page_in_screen.bottom(), dirty_in_screen);
if (page_index % 2 == 1) { if (page_index % 2 == 1) {
// Only draw over the right two-up view column with empty space. draw_utils::AdjustBottomGapForRightSidePage(page_in_screen.x(),
bottom_in_screen.set_width(bottom_in_screen.width() / 2); &bottom_in_screen);
bottom_in_screen.set_x(page_in_screen.x());
} }
bottom_in_screen = bottom_in_screen.Intersect(dirty_in_screen); bottom_in_screen = bottom_in_screen.Intersect(dirty_in_screen);
......
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