blob: 117d8a72e89623324e22faff8ada46145276efb4 [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
Jeremy Chinsend6fd27ce2019-08-06 00:40:178#include <vector>
9
Lei Zhang4906c102019-08-06 00:28:0310#include "pdf/draw_utils/coordinates.h"
Jeremy Chinsend6fd27ce2019-08-06 00:40:1711#include "ppapi/cpp/rect.h"
K Moonbd80ce72019-07-26 19:27:5012#include "ppapi/cpp/size.h"
13
14namespace chrome_pdf {
15
16// Layout of pages within a PDF document. Pages are placed as rectangles
17// (possibly rotated) in a non-overlapping vertical sequence.
18//
19// All layout units are pixels.
K Moonbd80ce72019-07-26 19:27:5020class DocumentLayout final {
21 public:
Lei Zhang4906c102019-08-06 00:28:0322 static const draw_utils::PageInsetSizes kSingleViewInsets;
23 static constexpr int32_t kBottomSeparator = 4;
24 static constexpr int32_t kHorizontalSeparator = 1;
25
K Moonbd80ce72019-07-26 19:27:5026 DocumentLayout();
27
28 DocumentLayout(const DocumentLayout& other);
29 DocumentLayout& operator=(const DocumentLayout& other);
30
31 ~DocumentLayout();
32
33 // Returns an integer from 0 to 3 (inclusive), encoding the default
34 // orientation of the document's pages.
35 //
36 // A return value of 0 indicates the original page orientation, with each
37 // increment indicating clockwise rotation by an additional 90 degrees.
38 //
39 // TODO(kmoon): Return an enum (class) instead of an integer.
40 int default_page_orientation() const { return default_page_orientation_; }
41
42 // Rotates all pages 90 degrees clockwise. Does not recompute layout.
43 void RotatePagesClockwise();
44
45 // Rotates all pages 90 degrees counterclockwise. Does not recompute layout.
46 void RotatePagesCounterclockwise();
47
48 // Returns the layout's total size.
49 const pp::Size& size() const { return size_; }
50
51 // Sets the layout's total size.
52 void set_size(const pp::Size& size) { size_ = size; }
53
Jeremy Chinsend6fd27ce2019-08-06 00:40:1754 // Given |page_rects| and the layout's size is set to a single-view layout,
55 // return |page_rects| formatted for two-up view and update the layout's size
56 // to the size of the new two-up view layout.
57 std::vector<pp::Rect> GetTwoUpViewLayout(
58 const std::vector<pp::Rect>& page_rects);
59
K Moonbd80ce72019-07-26 19:27:5060 // Increases the layout's total height by |height|.
61 void EnlargeHeight(int height);
62
63 // Appends a rectangle of size |page_rect| to the layout. This will increase
64 // the layout's height by the page's height, and increase the layout's width
65 // to at least the page's width.
66 void AppendPageRect(const pp::Size& page_rect);
67
68 private:
69 // Orientations are non-negative integers modulo 4.
70 //
71 // TODO(kmoon): Doesn't match return type of default_page_orientation().
72 // Callers expect int, but internally, we want unsigned semantics. This will
73 // be cleaned up when we switch to an enum.
74 unsigned int default_page_orientation_ = 0;
75
76 // Layout's total size.
77 pp::Size size_;
78};
79
80} // namespace chrome_pdf
81
82#endif // PDF_DOCUMENT_LAYOUT_H_