]> git.lyx.org Git - lyx.git/blob - src/frontends/FontMetrics.h
Add method FontMetrics::italic()
[lyx.git] / src / frontends / FontMetrics.h
1 // -*- C++ -*-
2 /**
3  * \file FontMetrics.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author unknown
8  * \author John Levon
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef FONT_METRICS_H
15 #define FONT_METRICS_H
16
17 #include "support/strfwd.h"
18
19 /**
20  * A class holding helper functions for determining
21  * the screen dimensions of fonts.
22  *
23  * The geometry is the standard typographical geometry,
24  * as follows :
25  *
26  * --------------+------------------<maxAscent
27  *               |          |
28  *               <-------> (right bearing)
29  *               <-> (left bearing)
30  * char ascent>___          |
31  *               ^   oooo   |  oooo
32  *   origin>____ |  oo  oo  | oo  oo
33  *              \|  oo  oo  | oo  oo
34  * --------------+---ooooo--|--oooo-<baseline
35  *               |      oo  |
36  * char          |  oo  oo  |
37  * descent>______|   oooo   |
38  *               <-  width ->
39  * --------------+----------+-------<maxDescent
40  *
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.
46  */
47
48 namespace lyx {
49
50 class Dimension;
51
52 namespace frontend {
53
54 class FontMetrics
55 {
56 public:
57         virtual ~FontMetrics() {}
58
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 x height
69         virtual int xHeight() const = 0;
70         /// return the width of a line for underlining
71         virtual int lineWidth() const = 0;
72         /// return the distance from the base line to where an underline
73         /// should be drawn.
74         virtual int underlinePos() const = 0;
75         /// return the distance from the base line to where the strike out line
76         /// should be drawn.
77         virtual int strikeoutPos() const = 0;
78         /// return true if font is not upright (italic or oblique)
79         virtual bool italic() const = 0;
80
81         /// return the width of the char in the font
82         virtual int width(char_type c) const = 0;
83         /// return the ascent of the char in the font
84         virtual int ascent(char_type c) const = 0;
85         /// return the descent of the char in the font
86         virtual int descent(char_type c) const = 0;
87         /// return the left bearing of the char in the font
88         virtual int lbearing(char_type c) const = 0;
89         /// return the right bearing of the char in the font
90         virtual int rbearing(char_type c) const = 0;
91         /// return the width of the string in the font
92         virtual int width(docstring const & s) const = 0;
93         /// FIXME ??
94         virtual int signedWidth(docstring const & s) const = 0;
95         /**
96          * return the x offset of a position in the string. The
97          * direction of the string is forced, and the returned value
98          * is from the left edge of the word, not from the start of the string.
99          * \param rtl is true for right-to-left layout
100          * \param ws is the amount of extra inter-word space applied text justification.
101          */
102         virtual int pos2x(docstring const & s, int pos, bool rtl, double ws) const = 0;
103         /**
104          * return the position in the string for a given x offset. The
105          * direction of the string is forced, and the returned value
106          * is from the left edge of the word, not from the start of the string.
107          * the offset x is updated to match the closest position in the string.
108          * \param rtl is true for right-to-left layout
109          * \param ws is the amount of extra inter-word space applied text justification.
110          */
111         virtual int x2pos(docstring const & s, int & x, bool rtl, double ws) const = 0;
112         /**
113          * Break string at width at most x.
114          * \return true if successful
115          * \param rtl is true for right-to-left layout
116          * \param force is false for breaking at word separator, true for
117          *   arbitrary position.
118          */
119         virtual bool breakAt(docstring & s, int & x, bool rtl, bool force) const = 0;
120         /// return char dimension for the font.
121         virtual Dimension const dimension(char_type c) const = 0;
122         /**
123          * fill in width,ascent,descent with the values for the
124          * given string in the font.
125          */
126         virtual void rectText(docstring const & str,
127                 int & width,
128                 int & ascent,
129                 int & descent) const = 0;
130         /**
131          * fill in width,ascent,descent with the values for the
132          * given string in the font for a button with given offset.
133          */
134         virtual void buttonText(docstring const & str,
135                 const int offset,
136                 int & width,
137                 int & ascent,
138                 int & descent) const = 0;
139
140         /// return the maximum descent of the font
141         inline int maxHeight() const { return maxAscent() + maxDescent(); }
142
143         /// return the descent of the char in the font
144         inline int height(char_type c) const { return ascent(c) + descent(c); }
145
146         /// return the inner width of the char in the font
147         inline int center(char_type c) const {
148                 return (rbearing(c) - lbearing(c)) / 2;
149         }
150
151         /// return the number of expanding characters taken into account for
152         /// increased inter-word spacing during justification
153         virtual int countExpanders(docstring const & str) const = 0;
154 };
155
156
157 } // namespace frontend
158
159 class Font;
160 class FontInfo;
161
162 /// Implementation is in Application.cpp
163 frontend::FontMetrics const & theFontMetrics(Font const & f);
164 frontend::FontMetrics const & theFontMetrics(FontInfo const & fi);
165
166 } // namespace lyx
167
168 #endif // FONT_METRICS_H