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
22 #include "xftFontLoader.h"
23 #include "font_metrics.h"
28 #include "support/lstrings.h"
33 #include <boost/scoped_array.hpp>
46 inline XftFont * getXftFont(LyXFont const & f)
48 return fontLoader.load(f.family(), f.series(),
49 f.realShape(), f.size());
53 inline int XGlyphAscent(XGlyphInfo const & info)
59 inline int XGlyphDescent(XGlyphInfo const & info)
61 return info.height - info.y;
65 inline int XGlyphLbearing(XGlyphInfo const & info)
71 inline int XGlyphRbearing(XGlyphInfo const & info)
73 return -info.x + info.width;
77 inline int XGlyphLogWidth(XGlyphInfo const & info)
85 int font_metrics::maxAscent(LyXFont const & f)
87 XftFont * font = getXftFont(f);
92 int font_metrics::maxDescent(LyXFont const & f)
94 XftFont * font = getXftFont(f);
99 int font_metrics::ascent(char_type c,LyXFont const & f)
101 XftFont * font = getXftFont(f);
103 XftTextExtents32(getDisplay(), font,
104 reinterpret_cast<FcChar32 *>(&c),
107 return XGlyphAscent(glyph);
111 int font_metrics::descent(char_type c,LyXFont const & f)
113 XftFont * font = getXftFont(f);
115 XftTextExtents32(getDisplay(), font,
116 reinterpret_cast<FcChar32 *>(&c),
119 return XGlyphDescent(glyph);
123 int font_metrics::lbearing(char_type c,LyXFont const & f)
125 XftFont * font = getXftFont(f);
127 XftTextExtents32(getDisplay(), font,
128 reinterpret_cast<FcChar32 *>(&c),
131 return XGlyphLbearing(glyph);
135 int font_metrics::rbearing(char_type c,LyXFont const & f)
137 XftFont * font = getXftFont(f);
139 XftTextExtents32(getDisplay(), font,
140 reinterpret_cast<FcChar32 *>(&c),
143 return XGlyphRbearing(glyph);
147 int font_metrics::width(char_type const * s, size_t n, LyXFont const & f)
149 XftFont * font = getXftFont(f);
151 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE){
152 XftTextExtents32(getDisplay(),
154 reinterpret_cast<FcChar32 const *>(s),
157 return XGlyphLogWidth(glyph);
160 LyXFont smallfont(f);
161 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
162 XftFont * fontS = getXftFont(smallfont);
163 for (size_t i = 0; i < n; ++i) {
164 char_type c = lyx::support::uppercase(s[i]);
166 XftTextExtents32(getDisplay(),
168 reinterpret_cast<FcChar32 *>(&c),
171 result += XGlyphLogWidth(glyph);
173 XftTextExtents32(getDisplay(),
175 reinterpret_cast<FcChar32 *>(&c),
178 result += XGlyphLogWidth(glyph);
186 int font_metrics::signedWidth(docstring const & s, LyXFont const & f)
191 return width(s.substr(1, s.length() - 1), f);
197 void font_metrics::rectText(docstring const & str, LyXFont const & font,
202 static int const d = 2;
203 width = font_metrics::width(str, font) + d * 2 + 2;
204 ascent = font_metrics::maxAscent(font) + d;
205 descent = font_metrics::maxDescent(font) + d;
209 void font_metrics::buttonText(docstring const & str, LyXFont const & font,
214 static int const d = 3;
216 width = font_metrics::width(str, font) + d * 2 + 2;
217 ascent = font_metrics::maxAscent(font) + d;
218 descent = font_metrics::maxDescent(font) + d;