4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * \author Abdelrazak Younes
11 * Full author contact details are available in file CREDITS.
14 #ifndef TEXT_METRICS_H
15 #define TEXT_METRICS_H
17 #include "ParagraphMetrics.h"
19 #include "support/types.h"
21 #include <boost/utility.hpp>
22 #include <boost/tuple/tuple.hpp>
34 /// A map from a Text to the map of paragraphs metrics
38 /// Default constructor (only here for STL containers).
39 TextMetrics(): text_(0) {}
40 /// The only useful constructor.
41 TextMetrics(BufferView *, Text *);
43 ParagraphMetrics const & parMetrics(pit_type) const;
45 Dimension const & dimension() const;
46 Dimension const & dimension();
48 /// compute text metrics.
49 bool metrics(MetricsInfo & mi, Dimension & dim);
51 /// Rebreaks the given paragraph.
52 /// \retval true if a full screen redraw is needed.
53 /// \retval false if a single paragraph redraw is enough.
54 bool redoParagraph(pit_type const pit);
55 /// Clear cache of paragraph metrics
56 void clear() { par_metrics_.clear(); }
59 int ascent() const { return dim_.asc; }
61 int descent() const { return dim_.des; }
62 /// current text width.
63 int width() const { return dim_.wid; }
64 /// current text heigth.
65 int height() const { return dim_.height(); }
68 int maxWidth() const { return max_width_; }
70 int singleWidth(pit_type const pit, pos_type pos) const;
73 int rightMargin(ParagraphMetrics const & pm) const;
74 int rightMargin(pit_type const pit) const;
76 /** this calculates the specified parameters. needed when setting
77 * the cursor and when creating a visible row */
78 void computeRowMetrics(pit_type pit, Row & row) const;
81 void draw(PainterInfo & pi, int x, int y) const;
82 /// draw textselection
83 void drawSelection(PainterInfo & pi, int x, int y) const;
85 void drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) const;
89 ParagraphMetrics & parMetrics(pit_type, bool redo_paragraph);
91 /// the minimum space a manual label needs on the screen in pixels
92 int labelFill(pit_type const pit, Row const & row) const;
95 int labelEnd(pit_type const pit) const;
97 /// sets row.end to the pos value *after* which a row should break.
98 /// for example, the pos after which isNewLine(pos) == true
99 pit_type rowBreakPoint(
105 /// sets row.width to the minimum space a row needs on the screen in pixel
109 pos_type const first,
113 /// Calculate and set the height of the row
114 boost::tuple<int, int> rowHeight(
116 pos_type const first,
120 /// draw selection for a single row
121 void drawRowSelection(PainterInfo & pi, int x, Row const & row,
122 DocIterator const & beg, DocIterator const & end,
123 bool drawOnBegMargin, bool drawOnEndMargin) const;
127 /// returns the column near the specified x-coordinate of the row.
128 /// x is an absolute screen coord, it is set to the real beginning
130 pos_type getColumnNearX(pit_type pit, Row const & row, int & x,
131 bool & boundary) const;
133 /// returns pos in given par at given x coord.
134 pos_type x2pos(pit_type pit, int row, int x) const;
136 // FIXME: is there a need for this?
137 //int pos2x(pit_type pit, pos_type pos) const;
141 /// The BufferView owner.
144 /// The text contents (the model).
145 /// \todo FIXME: this should be const.
149 /// A map from paragraph index number to paragraph metrics
150 typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
152 mutable ParMetricsCache par_metrics_;
156 /// FIXME: transfer this code in CoordCache here.
158 /// A map from paragraph index number to screen point
159 typedef std::map<pit_type, Point> InnerParPosCache;
160 /// A map from a Text to the map of paragraphs to screen points
161 typedef std::map<Text const *, InnerParPosCache> ParPosCache;
162 /// Paragraph grouped by owning text
167 /// return the default height of a row in pixels, considering font zoom
168 int defaultRowHeight();
172 #endif // TEXT_METRICS_H