]> git.lyx.org Git - lyx.git/blob - src/ParagraphMetrics.h
Introduce new helpers ParagraphMetrics::top/bottom
[lyx.git] / src / ParagraphMetrics.h
1 // -*- C++ -*-
2 /**
3  * \file ParagraphMetrics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  * \author André Pönitz
11  * \author Jürgen Vigna
12  * \author Abdelrazak Younes
13  *
14  * Full author contact details are available in file CREDITS.
15  */
16
17 #ifndef PARAGRAPH_METRICS_H
18 #define PARAGRAPH_METRICS_H
19
20 #include "Dimension.h"
21 #include "Row.h"
22
23 namespace lyx {
24
25 class BufferView;
26 class Paragraph;
27
28 /// Helper class for paragraph metrics.
29 class ParagraphMetrics {
30 public:
31         /// Default constructor (only here for STL containers).
32         ParagraphMetrics() {}
33         /// The only useful constructor.
34         explicit ParagraphMetrics(Paragraph const & par);
35
36         /// Copy operator.
37         ParagraphMetrics & operator=(ParagraphMetrics const &);
38
39         void reset(Paragraph const & par);
40
41         ///
42         Row const & getRow(pos_type pos, bool boundary) const;
43         ///
44         size_t pos2row(pos_type pos) const;
45
46         /// TextMetrics::redoParagraph updates this
47         Dimension const & dim() const { return dim_; }
48         Dimension & dim() { return dim_; }
49         /// total height of paragraph
50         int height() const { return dim_.height(); }
51         /// total width of paragraph, may differ from workwidth
52         int width() const { return dim_.width(); }
53         /// ascend of paragraph above baseline
54         int ascent() const { return dim_.ascent(); }
55         /// descend of paragraph below baseline
56         int descent() const { return dim_.descent(); }
57         /// Text updates the rows using this access point
58         RowList & rows() { return rows_; }
59         /// The painter and others use this
60         RowList const & rows() const { return rows_; }
61         ///
62         int rightMargin(BufferView const & bv) const;
63         ///
64         Paragraph const & par() const { return *par_; }
65
66         /// dump some information to lyxerr
67         void dump() const;
68
69         ///
70         bool hfillExpansion(Row const & row, pos_type pos) const;
71
72         /// The vertical position of the baseline of the first line of the paragraph
73         int position() const { return position_; }
74         void setPosition(int position);
75         /// The vertical position of the top of the paragraph
76         int top() const { return position_ - dim_.ascent(); }
77         /// The vertical position of the bottom of the paragraph
78         int bottom() const { return position_ + dim_.descent(); }
79         ///
80         int id() const { return id_; }
81
82 private:
83         ///
84         int position_ = 0;
85         ///
86         int id_ = -1;
87         ///
88         mutable RowList rows_;
89         /// cached dimensions of paragraph
90         Dimension dim_;
91         ///
92         Paragraph const * par_ = nullptr;
93 };
94
95 } // namespace lyx
96
97 #endif // PARAGRAPH_METRICS_H