forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument_layout.cc
98 lines (73 loc) · 2.85 KB
/
document_layout.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "pdf/document_layout.h"
#include "base/logging.h"
namespace chrome_pdf {
namespace {
int GetWidestPageWidth(const std::vector<pp::Size>& page_sizes) {
int widest_page_width = 0;
for (const auto& page_size : page_sizes) {
widest_page_width = std::max(widest_page_width, page_size.width());
}
return widest_page_width;
}
} // namespace
const draw_utils::PageInsetSizes DocumentLayout::kSingleViewInsets{
/*left=*/5, /*top=*/3, /*right=*/5, /*bottom=*/7};
DocumentLayout::Options::Options() = default;
DocumentLayout::Options::Options(const Options& other) = default;
DocumentLayout::Options& DocumentLayout::Options::operator=(
const Options& other) = default;
DocumentLayout::Options::~Options() = default;
void DocumentLayout::Options::RotatePagesClockwise() {
default_page_orientation_ = RotateClockwise(default_page_orientation_);
}
void DocumentLayout::Options::RotatePagesCounterclockwise() {
default_page_orientation_ = RotateCounterclockwise(default_page_orientation_);
}
DocumentLayout::DocumentLayout() = default;
DocumentLayout::~DocumentLayout() = default;
void DocumentLayout::ComputeSingleViewLayout(
const std::vector<pp::Size>& page_sizes) {
set_size({GetWidestPageWidth(page_sizes), 0});
page_rects_.resize(page_sizes.size());
for (size_t i = 0; i < page_sizes.size(); ++i) {
if (i != 0) {
// Add space for bottom separator.
EnlargeHeight(kBottomSeparator);
}
const pp::Size& page_size = page_sizes[i];
page_rects_[i] =
draw_utils::GetRectForSingleView(page_size, size_, kSingleViewInsets);
draw_utils::ExpandDocumentSize(page_size, &size_);
}
}
void DocumentLayout::ComputeTwoUpViewLayout(
const std::vector<pp::Size>& page_sizes) {
set_size({GetWidestPageWidth(page_sizes), 0});
page_rects_.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];
if (i % 2 == 0) {
page_rects_[i] = draw_utils::GetLeftRectForTwoUpView(
page_size, {size_.width(), size_.height()}, page_insets);
} else {
page_rects_[i] = draw_utils::GetRightRectForTwoUpView(
page_size, {size_.width(), size_.height()}, page_insets);
EnlargeHeight(std::max(page_size.height(), page_sizes[i - 1].height()));
}
}
if (page_sizes.size() % 2 == 1) {
EnlargeHeight(page_sizes.back().height());
}
size_.set_width(2 * size_.width());
}
void DocumentLayout::EnlargeHeight(int height) {
DCHECK_GE(height, 0);
size_.Enlarge(0, height);
}
} // namespace chrome_pdf