2 * \file xfont_metrics.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
21 #include "xftFontMetrics.h"
24 #include "xftFontLoader.h"
29 #include "support/lstrings.h"
34 #include <boost/scoped_array.hpp>
47 inline int XGlyphAscent(XGlyphInfo const & info)
53 inline int XGlyphDescent(XGlyphInfo const & info)
55 return info.height - info.y;
59 inline int XGlyphLbearing(XGlyphInfo const & info)
65 inline int XGlyphRbearing(XGlyphInfo const & info)
67 return -info.x + info.width;
71 inline int XGlyphLogWidth(XGlyphInfo const & info)
79 font_metrics::font_metrics(XftFont * f, XftFont * scf)
85 int font_metrics::maxAscent() const
91 int font_metrics::maxDescent() const
97 int font_metrics::ascent(char_type c) const
100 XftTextExtents32(getDisplay(), font,
101 reinterpret_cast<FcChar32 *>(&c),
104 return XGlyphAscent(glyph);
108 int font_metrics::descent(char_type c) const
111 XftTextExtents32(getDisplay(), font,
112 reinterpret_cast<FcChar32 *>(&c),
115 return XGlyphDescent(glyph);
119 int font_metrics::lbearing(char_type c) const
122 XftTextExtents32(getDisplay(), font,
123 reinterpret_cast<FcChar32 *>(&c),
126 return XGlyphLbearing(glyph);
130 int font_metrics::rbearing(char_type c) const
133 XftTextExtents32(getDisplay(), font,
134 reinterpret_cast<FcChar32 *>(&c),
137 return XGlyphRbearing(glyph);
141 int font_metrics::width(char_type const * s, size_t n) const
145 XftTextExtents32(getDisplay(),
147 reinterpret_cast<FcChar32 const *>(s),
150 return XGlyphLogWidth(glyph);
153 for (size_t i = 0; i < n; ++i) {
154 char_type c = lyx::support::uppercase(s[i]);
156 XftTextExtents32(getDisplay(),
158 reinterpret_cast<FcChar32 *>(&c),
161 result += XGlyphLogWidth(glyph);
163 XftTextExtents32(getDisplay(),
165 reinterpret_cast<FcChar32 *>(&c),
168 result += XGlyphLogWidth(glyph);
176 int font_metrics::signedWidth(docstring const & s) const
181 return width(s.substr(1, s.length() - 1).c_str(), s.length() - 1);
183 return width(s.c_str(), s.length());
187 void font_metrics::rectText(docstring const & str,
192 static int const d = 2;
193 width = font_metrics::width(str.c_str(), str.length()) + d * 2 + 2;
194 ascent = font_metrics::maxAscent() + d;
195 descent = font_metrics::maxDescent() + d;
199 void font_metrics::buttonText(docstring const & str,
204 static int const d = 3;
206 width = font_metrics::width(str.c_str(), str.length()) + d * 2 + 2;
207 ascent = font_metrics::maxAscent() + d;
208 descent = font_metrics::maxDescent() + d;