blob: f6573427486c77392ef3df58f6e53b3df16d6608 [file] [log] [blame]
K Moonbd80ce72019-07-26 19:27:501// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PDF_DOCUMENT_LAYOUT_H_
6#define PDF_DOCUMENT_LAYOUT_H_
7
K Moonff7ec672019-08-14 19:19:568#include <cstddef>
Jeremy Chinsend6fd27ce2019-08-06 00:40:179#include <vector>
10
K Moonff7ec672019-08-14 19:19:5611#include "base/logging.h"
Lei Zhang4906c102019-08-06 00:28:0312#include "pdf/draw_utils/coordinates.h"
K Moon9a62bf42019-08-07 20:05:3613#include "pdf/page_orientation.h"
Jeremy Chinsend6fd27ce2019-08-06 00:40:1714#include "ppapi/cpp/rect.h"
K Moonbd80ce72019-07-26 19:27:5015#include "ppapi/cpp/size.h"
16
17namespace chrome_pdf {
18
19// Layout of pages within a PDF document. Pages are placed as rectangles
20// (possibly rotated) in a non-overlapping vertical sequence.
21//
22// All layout units are pixels.
K Mooneb9e0002019-08-06 19:25:3223//
24// The |Options| class controls the behavior of the layout, such as the default
25// orientation of pages.
K Moonbd80ce72019-07-26 19:27:5026class DocumentLayout final {
27 public:
K Mooneb9e0002019-08-06 19:25:3228 // Options controlling layout behavior.
29 class Options final {
30 public:
31 Options();
32
33 Options(const Options& other);
34 Options& operator=(const Options& other);
35
36 ~Options();
37
K Moon9a62bf42019-08-07 20:05:3638 PageOrientation default_page_orientation() const {
39 return default_page_orientation_;
40 }
K Mooneb9e0002019-08-06 19:25:3241
42 // Rotates default page orientation 90 degrees clockwise.
43 void RotatePagesClockwise();
44
45 // Rotates default page orientation 90 degrees counterclockwise.
46 void RotatePagesCounterclockwise();
47
48 private:
K Moon9a62bf42019-08-07 20:05:3649 PageOrientation default_page_orientation_ = PageOrientation::kOriginal;
K Mooneb9e0002019-08-06 19:25:3250 };
51
Lei Zhang4906c102019-08-06 00:28:0352 static const draw_utils::PageInsetSizes kSingleViewInsets;
53 static constexpr int32_t kBottomSeparator = 4;
54 static constexpr int32_t kHorizontalSeparator = 1;
55
K Moonbd80ce72019-07-26 19:27:5056 DocumentLayout();
57
K Mooneb9e0002019-08-06 19:25:3258 DocumentLayout(const DocumentLayout& other) = delete;
59 DocumentLayout& operator=(const DocumentLayout& other) = delete;
K Moonbd80ce72019-07-26 19:27:5060
61 ~DocumentLayout();
62
K Mooneb9e0002019-08-06 19:25:3263 // Returns the layout options.
64 const Options& options() const { return options_; }
K Moonbd80ce72019-07-26 19:27:5065
K Mooneb9e0002019-08-06 19:25:3266 // Sets the layout options.
67 void set_options(const Options& options) { options_ = options; }
K Moonbd80ce72019-07-26 19:27:5068
69 // Returns the layout's total size.
70 const pp::Size& size() const { return size_; }
71
72 // Sets the layout's total size.
K Moonff7ec672019-08-14 19:19:5673 //
74 // TODO(kmoon): Get rid of this method.
K Moonbd80ce72019-07-26 19:27:5075 void set_size(const pp::Size& size) { size_ = size; }
76
K Moone4bd7522019-08-23 00:12:5677 size_t page_count() const { return page_layouts_.size(); }
Jeremy Chinsen08beb482019-08-07 01:58:5478
K Moonff7ec672019-08-14 19:19:5679 // Gets the layout rectangle for a page. Only valid after computing a layout.
80 const pp::Rect& page_rect(size_t page_index) const {
81 DCHECK_LT(page_index, page_count());
K Moone4bd7522019-08-23 00:12:5682 return page_layouts_[page_index].outer_rect;
83 }
84
85 // Gets the layout rectangle for a page's bounds (which excludes additional
86 // regions like page shadows). Only valid after computing a layout.
87 const pp::Rect& page_bounds_rect(size_t page_index) const {
88 DCHECK_LT(page_index, page_count());
89 return page_layouts_[page_index].inner_rect;
K Moonff7ec672019-08-14 19:19:5690 }
91
92 // Computes layout that represent |page_sizes| formatted for single view.
93 //
94 // TODO(kmoon): Control layout type using an option.
95 void ComputeSingleViewLayout(const std::vector<pp::Size>& page_sizes);
96
97 // Computes layout that represent |page_sizes| formatted for two-up view.
98 //
99 // TODO(kmoon): Control layout type using an option.
100 void ComputeTwoUpViewLayout(const std::vector<pp::Size>& page_sizes);
Jeremy Chinsend6fd27ce2019-08-06 00:40:17101
K Moonbd80ce72019-07-26 19:27:50102 private:
K Moone4bd7522019-08-23 00:12:56103 // Layout of a single page.
104 struct PageLayout {
105 // Bounding rectangle for the page with decorations.
106 pp::Rect outer_rect;
107
108 // Bounding rectangle for the page without decorations.
109 pp::Rect inner_rect;
110 };
111
K Mooneb9e0002019-08-06 19:25:32112 Options options_;
K Moonbd80ce72019-07-26 19:27:50113
114 // Layout's total size.
115 pp::Size size_;
K Moonff7ec672019-08-14 19:19:56116
K Moone4bd7522019-08-23 00:12:56117 std::vector<PageLayout> page_layouts_;
K Moonbd80ce72019-07-26 19:27:50118};
119
120} // namespace chrome_pdf
121
122#endif // PDF_DOCUMENT_LAYOUT_H_