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>
33 /// A map from a Text to the map of paragraphs metrics
37 /// Default constructor (only here for STL containers).
38 TextMetrics(): text_(0) {}
39 /// The only useful constructor.
40 TextMetrics(BufferView *, Text *);
42 ParagraphMetrics const & parMetrics(pit_type) const;
44 Dimension const & dimension() const;
45 Dimension const & dimension();
47 /// compute text metrics.
48 bool metrics(MetricsInfo & mi, Dimension & dim);
50 /// Rebreaks the given paragraph.
51 /// \retval true if a full screen redraw is needed.
52 /// \retval false if a single paragraph redraw is enough.
53 bool redoParagraph(pit_type const pit);
54 /// Clear cache of paragraph metrics
55 void clear() { par_metrics_.clear(); }
58 int ascent() const { return dim_.asc; }
60 int descent() const { return dim_.des; }
61 /// current text width.
62 int width() const { return dim_.wid; }
63 /// current text heigth.
64 int height() const { return dim_.height(); }
67 int maxWidth() const { return max_width_; }
69 int singleWidth(pit_type const pit, pos_type pos) const;
72 int rightMargin(ParagraphMetrics const & pm) const;
73 int rightMargin(pit_type const pit) const;
75 /** this calculates the specified parameters. needed when setting
76 * the cursor and when creating a visible row */
77 void computeRowMetrics(pit_type pit, Row & row) const;
80 void draw(PainterInfo & pi, int x, int y) const;
82 void drawParagraph(PainterInfo & pi, pit_type pit, int x, int y,
83 bool repaintAll) const;
87 ParagraphMetrics & parMetrics(pit_type, bool redo_paragraph);
89 /// the minimum space a manual label needs on the screen in pixels
90 int labelFill(pit_type const pit, Row const & row) const;
93 int labelEnd(pit_type const pit) const;
95 /// sets row.end to the pos value *after* which a row should break.
96 /// for example, the pos after which isNewLine(pos) == true
97 pit_type rowBreakPoint(
103 /// sets row.width to the minimum space a row needs on the screen in pixel
107 pos_type const first,
111 /// Calculate and set the height of the row
112 boost::tuple<int, int> rowHeight(
114 pos_type const first,
120 /// returns the column near the specified x-coordinate of the row.
121 /// x is an absolute screen coord, it is set to the real beginning
123 pos_type getColumnNearX(pit_type pit, Row const & row, int & x,
124 bool & boundary) const;
126 /// returns pos in given par at given x coord.
127 pos_type x2pos(pit_type pit, int row, int x) const;
129 // FIXME: is there a need for this?
130 //int pos2x(pit_type pit, pos_type pos) const;
134 /// The BufferView owner.
137 /// The text contents (the model).
138 /// \todo FIXME: this should be const.
142 /// A map from paragraph index number to paragraph metrics
143 typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
145 mutable ParMetricsCache par_metrics_;
149 /// FIXME: transfer this code in CoordCache here.
151 /// A map from paragraph index number to screen point
152 typedef std::map<pit_type, Point> InnerParPosCache;
153 /// A map from a Text to the map of paragraphs to screen points
154 typedef std::map<Text const *, InnerParPosCache> ParPosCache;
155 /// Paragraph grouped by owning text
160 /// return the default height of a row in pixels, considering font zoom
161 int defaultRowHeight();
165 #endif // TEXT_METRICS_H