File: coordinates.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (134 lines) | stat: -rw-r--r-- 6,022 bytes parent folder | download | duplicates (9)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PDF_DRAW_UTILS_COORDINATES_H_
#define PDF_DRAW_UTILS_COORDINATES_H_

#include <stddef.h>

#include <vector>

#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"

namespace gfx {
class Point;
class Size;
}  // namespace gfx

namespace chrome_pdf {
namespace draw_utils {

// Struct for sending a page's gfx::Rect object along with its corresponding
// index in the PDF document.
struct IndexedPage {
  IndexedPage(int index, const gfx::Rect& rect);
  IndexedPage(const IndexedPage& other);
  IndexedPage& operator=(const IndexedPage& other);
  ~IndexedPage();

  int index;
  gfx::Rect rect;
};

// 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, gfx::Rect* bottom_gap);

// Given `doc_width`, horizontally center `rect` within the document.
// `doc_width` must be greater than or equal to `rect`.
void CenterRectHorizontally(int doc_width, gfx::Rect* rect);

// 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
// `doc_size`'s height.
void ExpandDocumentSize(const gfx::Size& rect_size, gfx::Size* doc_size);

// Given `page_rect_bottom` and `bottom_rect` in the same coordinate space,
// return a gfx::Rect object representing the portion of `bottom_rect` that is
// below `page_rect_bottom`. Returns an empty rectangle if `page_rect_bottom`
// is greater than or equal to `bottom_rect.bottom()`.
gfx::Rect GetBottomGapBetweenRects(int page_rect_bottom,
                                   const gfx::Rect& bottom_rect);

// Given `visible_pages` and `visible_screen` in the same coordinates, return
// the index of the page in `visible_pages` which has the largest proportion of
// its area intersecting with `visible_screen`. If there is a tie, return the
// page with the lower index. Returns -1 if `visible_pages` is empty. Returns
// first page in `visible_pages` if no page intersects with `visible_screen`.
int GetMostVisiblePage(const std::vector<IndexedPage>& visible_pages,
                       const gfx::Rect& visible_screen);

// 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.
gfx::Insets GetPageInsetsForTwoUpView(size_t page_index,
                                      size_t num_of_pages,
                                      const gfx::Insets& single_view_insets,
                                      int horizontal_separator);

// Given `rect_size` and `document_size` create a horizontally centered
// gfx::Rect placed at the bottom of the current document.
gfx::Rect GetRectForSingleView(const gfx::Size& rect_size,
                               const gfx::Size& document_size);

// Given `rect` in document coordinates, a `position` in screen coordinates,
// and a `zoom` factor, returns the rectangle in screen coordinates (i.e.
// 0,0 is top left corner of plugin area). An empty `rect` will always
// result in an empty output rect. For `zoom`, a value of 1 means 100%.
// `zoom` is never less than or equal to 0.
gfx::Rect GetScreenRect(const gfx::Rect& rect,
                        const gfx::Point& position,
                        double zoom);

// Given `page_y`, `page_height`, `insets`, `doc_width`, and `bottom_separator`
// all in the same coordinate space, return the page and its surrounding border
// areas and `bottom_separator`. This includes the sides if the page is narrower
// than the document.
gfx::Rect GetSurroundingRect(int page_y,
                             int page_height,
                             const gfx::Insets& insets,
                             int doc_width,
                             int bottom_separator);

// Given `page_rect` in document coordinates, `insets`, and `bottom_separator`,
// return a gfx::Rect object representing the gap on the left side of the page
// created by insetting the page. I.e. the difference, on the left side, between
// the initial `page_rect` and the `page_rect` inset with `insets` (current
// value of `page_rect`). The x coordinate of `page_rect` must be greater than
// or equal to `insets.left`.
gfx::Rect GetLeftFillRect(const gfx::Rect& page_rect,
                          const gfx::Insets& insets,
                          int bottom_separator);

// Same as GetLeftFillRect(), but for the right side of `page_rect` and also
// depends on the `doc_width`. Additionally, `doc_width` must be greater than or
// equal to the sum of `page_rect.right` and `insets.right`.
gfx::Rect GetRightFillRect(const gfx::Rect& page_rect,
                           const gfx::Insets& insets,
                           int doc_width,
                           int bottom_separator);

// Same as GetLeftFillRect(), but for the bottom side of `page_rect`.
gfx::Rect GetBottomFillRect(const gfx::Rect& page_rect,
                            const gfx::Insets& insets,
                            int bottom_separator);

// Given `rect_size`, create a gfx::Rect where the top-right corner lies at
// `position`. The width of `rect_size` must be less than or equal to the x
// value for `position`.
gfx::Rect GetLeftRectForTwoUpView(const gfx::Size& rect_size,
                                  const gfx::Point& position);

// Given `rect_size`, create a gfx::Rect where the top-left corner lies at
// `position`.
gfx::Rect GetRightRectForTwoUpView(const gfx::Size& rect_size,
                                   const gfx::Point& position);

}  // namespace draw_utils
}  // namespace chrome_pdf

#endif  // PDF_DRAW_UTILS_COORDINATES_H_