]> git.lyx.org Git - lyx.git/blob - src/frontends/FontMetrics.h
document docstring abuse for symbol font code points
[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/docstring.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 namespace frontend {
51
52 class FontMetrics
53 {
54 public:
55         virtual ~FontMetrics() {}
56
57         /// return the maximum ascent of the font
58         virtual int maxAscent() const = 0;
59         /// return the maximum descent of the font
60         virtual int maxDescent() const = 0;
61         /// return the ascent of the char in the font
62         virtual int ascent(char_type c) const = 0;
63         /// return the descent of the char in the font
64         virtual int descent(char_type c) const = 0;
65         /// return the left bearing of the char in the font
66         virtual int lbearing(char_type c) const = 0;
67         /// return the right bearing of the char in the font
68         virtual int rbearing(char_type c) const = 0;
69         /// return the width of the string in the font
70         virtual int width(char_type const * s, size_t n) const = 0;
71         /// FIXME ??
72         virtual int signedWidth(docstring const & s) const = 0;
73         /**
74          * fill in width,ascent,descent with the values for the
75          * given string in the font.
76          */
77         virtual void rectText(docstring const & str,
78                 int & width,
79                 int & ascent,
80                 int & descent) const = 0;
81         /**
82          * fill in width,ascent,descent with the values for the
83          * given string in the font for a button.
84          */
85         virtual void buttonText(docstring const & str,
86                 int & width,
87                 int & ascent,
88                 int & descent) const = 0;
89
90         /// return the maximum descent of the font
91         inline int maxHeight() const {
92                 return maxAscent() + maxDescent();
93         }
94
95         /// return the descent of the char in the font
96         inline int height(char_type c) const
97         {
98                 return ascent(c) + descent(c);
99         }
100
101         /// return the inner width of the char in the font
102         inline int center(char_type c) const {
103                 return (rbearing(c) - lbearing(c)) / 2;
104         }
105
106         /// return the width of the char in the font
107         inline int width(char_type c) const
108         {
109                 char_type tmp[2] = { c, L'\0'};
110                 return width(tmp, 1);
111         }
112
113         /// return the width of the string in the font
114         inline int width(docstring const & s) const
115         {
116             return s.empty() ? 0 : width(s.data(), s.length());
117         }
118 };
119
120
121 } // namespace frontend
122
123 class LyXFont;
124
125 /// Implementation is in Application.C
126 frontend::FontMetrics const & theFontMetrics(LyXFont const & f);
127
128 } // namespace lyx
129
130 #endif // FONT_METRICS_H