]> git.lyx.org Git - lyx.git/blob - src/ParagraphMetrics.h
261f0057a369f2ecdb886eaa088a09b4c027be53
[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 "Paragraph.h"
21
22 namespace lyx {
23
24 /**
25  * Each paragraph is broken up into a number of rows on the screen.
26  * This is a list of such on-screen rows, ordered from the top row
27  * downwards.
28  */
29 typedef std::vector<Row> RowList;
30
31 class MetricsInfo;
32 class PainterInfo;
33
34 /// Helper class for Paragraph Metrics.
35 class ParagraphMetrics  {
36 public:
37         /// Default constructor (only here for STL containers).
38         ParagraphMetrics(): par_(0) {};
39         /// The only useful constructor.
40         ParagraphMetrics(Paragraph const & par);
41
42         /// Copy operator.
43         /// Important note: We don't copy \c row_change_status_ and
44         /// \c row_signature_ because those are updated externally with
45         /// \c updateRowChangeStatus() in TextMetrics::redoParagraph().
46         ParagraphMetrics & operator=(ParagraphMetrics const &);
47
48         void reset(Paragraph const & par);
49
50         ///
51         Row & getRow(pos_type pos, bool boundary);
52         ///
53         Row const & getRow(pos_type pos, bool boundary) const;
54         ///
55         size_t pos2row(pos_type pos) const;
56
57         /// BufferView::redoParagraph updates this
58         Dimension const & dim() const { return dim_; }
59         Dimension & dim() { return dim_; }
60         /// total height of paragraph
61         unsigned int height() const { return dim_.height(); }
62         /// total width of paragraph, may differ from workwidth
63         unsigned int width() const { return dim_.width(); }
64         /// ascend of paragraph above baseline
65         unsigned int ascent() const { return dim_.ascent(); }
66         /// descend of paragraph below baseline
67         unsigned int descent() const { return dim_.descent(); }
68         /// Text updates the rows using this access point
69         RowList & rows() { return rows_; }
70         /// The painter and others use this
71         RowList const & rows() const { return rows_; }
72         /// The painter and others use this
73         std::vector<bool> const & rowChangeStatus() const
74         { return row_change_status_; }
75         ///
76         void updateRowChangeStatus();
77         ///
78         int rightMargin(Buffer const & buffer) const;
79         ///
80         int singleWidth(pos_type pos, Font const & Font) const;
81
82         /// dump some information to lyxerr
83         void dump() const;
84
85 private:
86         ///
87         typedef std::vector<size_type> RowSignature;
88         ///
89         size_type calculateRowSignature(Row const &);
90         ///
91         mutable RowList rows_;
92         ///
93         RowSignature row_signature_;
94         ///
95         std::vector<bool> row_change_status_;
96         /// cached dimensions of paragraph
97         Dimension dim_;
98         ///
99         Paragraph const * par_;
100 };
101
102 } // namespace lyx
103
104 #endif // PARAGRAPH_METRICS_H