LyX 1.5.0 is released
[lyx.git] / src / frontends / FontMetrics.h
blob04a6f7c7cf84d6292772f503b8729410458e535a
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.
7 * \author unknown
8 * \author John Levon
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/docstring.h"
19 /**
20 * A class holding helper functions for determining
21 * the screen dimensions of fonts.
23 * The geometry is the standard typographical geometry,
24 * as follows :
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
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.
48 namespace lyx {
50 class Dimension;
52 namespace frontend {
54 class FontMetrics
56 public:
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 width of the char in the font
67 virtual int width(char_type c) const = 0;
68 /// return the ascent of the char in the font
69 virtual int ascent(char_type c) const = 0;
70 /// return the descent of the char in the font
71 virtual int descent(char_type c) const = 0;
72 /// return the left bearing of the char in the font
73 virtual int lbearing(char_type c) const = 0;
74 /// return the right bearing of the char in the font
75 virtual int rbearing(char_type c) const = 0;
76 /// return the width of the string in the font
77 virtual int width(docstring const & s) const = 0;
78 /// FIXME ??
79 virtual int signedWidth(docstring const & s) const = 0;
80 /// return char dimension for the font.
81 virtual Dimension const dimension(char_type c) const = 0;
82 /**
83 * fill in width,ascent,descent with the values for the
84 * given string in the font.
86 virtual void rectText(docstring const & str,
87 int & width,
88 int & ascent,
89 int & descent) const = 0;
90 /**
91 * fill in width,ascent,descent with the values for the
92 * given string in the font for a button.
94 virtual void buttonText(docstring const & str,
95 int & width,
96 int & ascent,
97 int & descent) const = 0;
99 /// return the maximum descent of the font
100 inline int maxHeight() const {
101 return maxAscent() + maxDescent();
104 /// return the descent of the char in the font
105 inline int height(char_type c) const
107 return ascent(c) + descent(c);
110 /// return the inner width of the char in the font
111 inline int center(char_type c) const {
112 return (rbearing(c) - lbearing(c)) / 2;
117 } // namespace frontend
119 class Font;
121 /// Implementation is in Application.cpp
122 frontend::FontMetrics const & theFontMetrics(Font const & f);
124 } // namespace lyx
126 #endif // FONT_METRICS_H