4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * \author Abdelrazak Younes
11 * Full author contact details are available in file CREDITS.
14 #ifndef FONT_METRICS_H
15 #define FONT_METRICS_H
17 #include "support/strfwd.h"
20 * A class holding helper functions for determining
21 * the screen dimensions of fonts.
23 * The geometry is the standard typographical geometry,
26 * --------------+------------------<maxAscent
28 * <-------> (right bearing)
32 * origin>____ | oo oo | oo oo
34 * --------------+---ooooo--|--oooo-<baseline
37 * descent>______| oooo |
39 * --------------+----------+-------<maxDescent
41 * Caution: All char_type and docstring arguments of any method of this class
42 * are no UCS4 chars or strings if the font is a symbol font. They simply
43 * denote the code points of the font instead. You have to keep this in mind
44 * when you implement the methods in a frontend. You must not pass these
45 * parameters to a unicode conversion function in particular.
57 virtual ~FontMetrics() {}
59 /// return the maximum ascent of the font
60 virtual int maxAscent() const = 0;
61 /// return the maximum descent of the font
62 virtual int maxDescent() const = 0;
63 /// return default dimension of the font.
64 /// \warning \c width is set to zero.
65 virtual Dimension const defaultDimension() const = 0;
66 /// return the em size
67 virtual int em() const = 0;
68 /// return the width of a line for underlining
69 virtual int lineWidth() const = 0;
70 /// return the distance from the base line to where an underline
72 virtual int underlinePos() const = 0;
73 /// return the distance from the base line to where the strike out line
75 virtual int strikeoutPos() const = 0;
77 /// return the width of the char in the font
78 virtual int width(char_type c) const = 0;
79 /// return the ascent of the char in the font
80 virtual int ascent(char_type c) const = 0;
81 /// return the descent of the char in the font
82 virtual int descent(char_type c) const = 0;
83 /// return the left bearing of the char in the font
84 virtual int lbearing(char_type c) const = 0;
85 /// return the right bearing of the char in the font
86 virtual int rbearing(char_type c) const = 0;
87 /// return the width of the string in the font
88 virtual int width(docstring const & s) const = 0;
90 virtual int signedWidth(docstring const & s) const = 0;
92 * return the x offset of a position in the string. The
93 * direction of the string is forced, and the returned value
94 * is from the left edge of the word, not from the start of the string.
95 * \param rtl is true for right-to-left layout
96 * \param ws is the amount of extra inter-word space applied text justication.
98 virtual int pos2x(docstring const & s, int pos, bool rtl, double ws) const = 0;
100 * return the position in the string for a given x offset. The
101 * direction of the string is forced, and the returned value
102 * is from the left edge of the word, not from the start of the string.
103 * the offset x is updated to match the closest position in the string.
104 * \param rtl is true for right-to-left layout
105 * \param ws is the amount of extra inter-word space applied text justication.
107 virtual int x2pos(docstring const & s, int & x, bool rtl, double ws) const = 0;
109 * Break string at width at most x.
110 * \return true if successful
111 * \param rtl is true for right-to-left layout
112 * \param force is false for breaking at word separator, true for
113 * arbitrary position.
115 virtual bool breakAt(docstring & s, int & x, bool rtl, bool force) const = 0;
116 /// return char dimension for the font.
117 virtual Dimension const dimension(char_type c) const = 0;
119 * fill in width,ascent,descent with the values for the
120 * given string in the font.
122 virtual void rectText(docstring const & str,
125 int & descent) const = 0;
127 * fill in width,ascent,descent with the values for the
128 * given string in the font for a button with given offset.
130 virtual void buttonText(docstring const & str,
134 int & descent) const = 0;
136 /// return the maximum descent of the font
137 inline int maxHeight() const { return maxAscent() + maxDescent(); }
139 /// return the descent of the char in the font
140 inline int height(char_type c) const { return ascent(c) + descent(c); }
142 /// return the inner width of the char in the font
143 inline int center(char_type c) const {
144 return (rbearing(c) - lbearing(c)) / 2;
147 /// return the number of expanding characters taken into account for
148 /// increased inter-word spacing during justification
149 virtual int countExpanders(docstring const & str) const = 0;
153 } // namespace frontend
158 /// Implementation is in Application.cpp
159 frontend::FontMetrics const & theFontMetrics(Font const & f);
160 frontend::FontMetrics const & theFontMetrics(FontInfo const & fi);
164 #endif // FONT_METRICS_H