Commit acc6afad authored by Jeremy Chinsen's avatar Jeremy Chinsen Committed by Commit Bot

Add GetPageInsetsForTwoUpView() to pdf/draw_utils.

In PDFiumEngine, currently the size of the shadows surrounding a
page is constant because there is only a single page view. With
the addition of two-up view, the sizes of the shadows will depend
on the position of the page within its document.

draw_utils::GetPageInsetsForTwoUpView() is a function that takes
the position of the page within the document and shadow sizes,
and returns the proper configuration of inset sizes for two-up
view. Having this as a separate function makes this logic testable
and reduces the future complexity of PDFiumEngine.

Bug: 51472
Change-Id: Icecbb05f672b10ca682ae383308abb96075b64ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1707951
Commit-Queue: Jeremy Chinsen <chinsenj@google.com>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679590}
parent 9eeb650b
......@@ -17,6 +17,25 @@ void ExpandDocumentSize(const pp::Size& rect_size, pp::Size* doc_size) {
doc_size->Enlarge(width_diff, rect_size.height());
}
PageInsetSizes GetPageInsetsForTwoUpView(
size_t page_index,
size_t num_of_pages,
const PageInsetSizes& single_view_insets,
int horizontal_separator) {
DCHECK_GE(page_index, 0u);
DCHECK_LT(page_index, num_of_pages);
// Don't change |two_up_insets| if the page is on the left side and is the
// last page. In this case, the shadows on both sides should be the same size.
PageInsetSizes two_up_insets = single_view_insets;
if (page_index % 2 == 1)
two_up_insets.left = horizontal_separator;
else if (page_index != num_of_pages - 1)
two_up_insets.right = horizontal_separator;
return two_up_insets;
}
pp::Rect GetLeftFillRect(const pp::Rect& page_rect,
const PageInsetSizes& inset_sizes,
int bottom_separator) {
......
......@@ -5,6 +5,8 @@
#ifndef PDF_DRAW_UTILS_COORDINATES_H_
#define PDF_DRAW_UTILS_COORDINATES_H_
#include "stddef.h"
#include "ppapi/cpp/rect.h"
namespace pp {
......@@ -29,6 +31,15 @@ struct PageInsetSizes {
// |doc_size|'s height.
void ExpandDocumentSize(const pp::Size& rect_size, pp::Size* doc_size);
// Given |page_index|, and |num_of_pages|, return the configuration of
// |single_view_insets| and |horizontal_separator| for the current page in
// two-up view.
PageInsetSizes GetPageInsetsForTwoUpView(
size_t page_index,
size_t num_of_pages,
const PageInsetSizes& single_view_insets,
int horizontal_separator);
// Given |page_rect| in document coordinates, |inset_sizes|, and
// |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,
......
......@@ -13,10 +13,19 @@ namespace draw_utils {
namespace {
constexpr int kBottomSeparator = 4;
constexpr int kHorizontalSeparator = 1;
constexpr PageInsetSizes kLeftInsets{5, 3, 1, 7};
constexpr PageInsetSizes kRightInsets{1, 3, 5, 7};
constexpr PageInsetSizes kSingleViewInsets{5, 3, 5, 7};
void CompareInsetSizes(const PageInsetSizes& expected_insets,
const PageInsetSizes& given_insets) {
EXPECT_EQ(expected_insets.left, given_insets.left);
EXPECT_EQ(expected_insets.top, given_insets.top);
EXPECT_EQ(expected_insets.right, given_insets.right);
EXPECT_EQ(expected_insets.bottom, given_insets.bottom);
}
} // namespace
TEST(CoordinateTest, ExpandDocumentSize) {
......@@ -44,6 +53,28 @@ TEST(CoordinateTest, ExpandDocumentSize) {
EXPECT_EQ(1450, doc_size.height());
}
TEST(CoordinateTest, GetPageInsetsForTwoUpView) {
// Page is on the left side and isn't the last page in the document.
CompareInsetSizes(kLeftInsets,
GetPageInsetsForTwoUpView(0, 10, kSingleViewInsets,
kHorizontalSeparator));
// Page is on the left side and is the last page in the document.
CompareInsetSizes(kSingleViewInsets,
GetPageInsetsForTwoUpView(10, 11, kSingleViewInsets,
kHorizontalSeparator));
// Only one page in the document.
CompareInsetSizes(
kSingleViewInsets,
GetPageInsetsForTwoUpView(0, 1, kSingleViewInsets, kHorizontalSeparator));
// Page is on the right side of the document.
CompareInsetSizes(
kRightInsets,
GetPageInsetsForTwoUpView(1, 4, kSingleViewInsets, kHorizontalSeparator));
}
TEST(CoordinateTest, GetLeftFillRect) {
// Testing various rectangles with different positions and sizes.
pp::Rect page_rect(10, 20, 400, 500);
......
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