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