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"
30 /// A map from a LyXText to the map of paragraphs metrics
34 /// Default constructor (only here for STL containers).
35 TextMetrics(): text_(0) {}
36 /// The only useful constructor.
37 TextMetrics(BufferView *, LyXText *);
39 ParagraphMetrics const & parMetrics(pit_type) const;
41 Dimension const & dimension() const;
42 Dimension const & dimension();
44 /// compute text metrics.
45 bool metrics(MetricsInfo & mi, Dimension & dim);
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);
53 int ascent() const { return dim_.asc; }
55 int descent() const { return dim_.des; }
56 /// current text width.
57 int width() const { return dim_.wid; }
58 /// current text heigth.
59 int height() const { return dim_.height(); }
62 int maxWidth() const { return max_width_; }
65 int rightMargin(ParagraphMetrics const & pm) const;
66 int rightMargin(pit_type const pit) const;
68 /** this calculates the specified parameters. needed when setting
69 * the cursor and when creating a visible row */
70 RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
75 ParagraphMetrics & parMetrics(pit_type, bool redo_paragraph);
77 /// the minimum space a manual label needs on the screen in pixels
78 int labelFill(Paragraph const & par, Row const & row) const;
81 int labelEnd(pit_type const pit) const;
83 /// sets row.end to the pos value *after* which a row should break.
84 /// for example, the pos after which isNewLine(pos) == true
85 void rowBreakPoint(int width, pit_type const pit, Row & row) const;
87 /// sets row.width to the minimum space a row needs on the screen in pixel
88 void setRowWidth(int right_margin, pit_type const pit, Row & row) const;
90 /// Calculate and set the height of the row
91 void setHeightOfRow(pit_type, Row & row);
95 /// returns the column near the specified x-coordinate of the row.
96 /// x is an absolute screen coord, it is set to the real beginning
98 pos_type getColumnNearX(pit_type pit, Row const & row, int & x,
99 bool & boundary) const;
101 /// returns pos in given par at given x coord.
102 pos_type x2pos(pit_type pit, int row, int x) const;
104 // FIXME: is there a need for this?
105 //int pos2x(pit_type pit, pos_type pos) const;
109 /// The BufferView owner.
112 /// The text contents (the model).
113 /// \todo FIXME: this should be const.
117 /// A map from paragraph index number to paragraph metrics
118 typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
120 mutable ParMetricsCache par_metrics_;
124 /// FIXME: transfer this code in CoordCache here.
126 /// A map from paragraph index number to screen point
127 typedef std::map<pit_type, Point> InnerParPosCache;
128 /// A map from a LyXText to the map of paragraphs to screen points
129 typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
130 /// Paragraph grouped by owning text
135 /// return the default height of a row in pixels, considering font zoom
136 int defaultRowHeight();
140 #endif // TEXT_METRICS_H