]> git.lyx.org Git - lyx.git/blob - src/TextMetrics.h
Fixed some lines that were too long. It compiled afterwards.
[lyx.git] / src / TextMetrics.h
1 // -*- C++ -*-
2 /**
3  * \file TextMetrics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef TEXT_METRICS_H
15 #define TEXT_METRICS_H
16
17 #include "ParagraphMetrics.h"
18
19 #include "support/types.h"
20
21 #include <map>
22
23
24 namespace lyx {
25
26 class BufferView;
27 class Text;
28 class MetricsInfo;
29
30 /// A map from a Text to the map of paragraphs metrics
31 class TextMetrics
32 {
33 public:
34         /// Default constructor (only here for STL containers).
35         TextMetrics(): text_(0) {}
36         /// The only useful constructor.
37         TextMetrics(BufferView *, Text *);
38         ///
39         ParagraphMetrics const & parMetrics(pit_type) const;
40         ///
41         Dimension const & dimension() const;
42         Dimension const & dimension();
43
44         /// compute text metrics.
45         bool metrics(MetricsInfo & mi, Dimension & dim);
46
47         /// Rebreaks the given paragraph.
48         /// \retval true if a full screen redraw is needed.
49         /// \retval false if a single paragraph redraw is enough.
50         bool redoParagraph(pit_type const pit);
51         /// Clear cache of paragraph metrics
52         void clear() { par_metrics_.clear(); }
53
54         ///
55         int ascent() const { return dim_.asc; }
56         ///
57         int descent() const { return dim_.des; }
58         /// current text width.
59         int width() const { return dim_.wid; }
60         /// current text heigth.
61         int height() const { return dim_.height(); }
62
63         ///
64         int maxWidth() const { return max_width_; }
65
66         ///
67         int rightMargin(ParagraphMetrics const & pm) const;
68         int rightMargin(pit_type const pit) const;
69
70         /** this calculates the specified parameters. needed when setting
71          * the cursor and when creating a visible row */
72         RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
73
74
75 private:
76         ///
77         ParagraphMetrics & parMetrics(pit_type, bool redo_paragraph);
78
79         /// the minimum space a manual label needs on the screen in pixels
80         int labelFill(Paragraph const & par, Row const & row) const;
81
82         /// FIXME??
83         int labelEnd(pit_type const pit) const;
84
85         /// sets row.end to the pos value *after* which a row should break.
86         /// for example, the pos after which isNewLine(pos) == true
87         void rowBreakPoint(int width, pit_type const pit, Row & row) const;
88
89         /// sets row.width to the minimum space a row needs on the screen in pixel
90         void setRowWidth(int right_margin, pit_type const pit, Row & row) const;
91
92         /// Calculate and set the height of the row
93         void setHeightOfRow(pit_type, Row & row);
94
95 // Temporary public:
96 public:
97         /// returns the column near the specified x-coordinate of the row.
98         /// x is an absolute screen coord, it is set to the real beginning
99         /// of this column.
100         pos_type getColumnNearX(pit_type pit, Row const & row, int & x,
101                 bool & boundary) const;
102
103         /// returns pos in given par at given x coord.
104         pos_type x2pos(pit_type pit, int row, int x) const;
105
106         // FIXME: is there a need for this?
107         //int pos2x(pit_type pit, pos_type pos) const;
108
109 private:
110
111         /// The BufferView owner.
112         BufferView * bv_;
113
114         /// The text contents (the model).
115         /// \todo FIXME: this should be const.
116         Text * text_;
117
118         bool main_text_;
119         /// A map from paragraph index number to paragraph metrics
120         typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
121         ///
122         mutable ParMetricsCache par_metrics_;
123         Dimension dim_;
124         int max_width_;
125
126         /// FIXME: transfer this code in CoordCache here.
127         /*
128         /// A map from paragraph index number to screen point
129         typedef std::map<pit_type, Point> InnerParPosCache;
130         /// A map from a Text to the map of paragraphs to screen points
131         typedef std::map<Text const *, InnerParPosCache> ParPosCache;
132         /// Paragraph grouped by owning text
133         ParPosCache pars_;
134         */
135 };
136
137 /// return the default height of a row in pixels, considering font zoom
138 int defaultRowHeight();
139
140 } // namespace lyx
141
142 #endif // TEXT_METRICS_H