2 * \file qfont_metrics.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
16 #pragma implementation "frontends/font_metrics.h"
19 #include "support/lstrings.h"
20 #include "font_metrics.h"
21 #include "qfont_loader.h"
24 #include <qfontmetrics.h>
28 QFontMetrics const & metrics(LyXFont const & f) {
29 return fontloader.metrics(f);
34 namespace font_metrics {
36 int maxAscent(LyXFont const & f)
38 return metrics(f).ascent();
42 int maxDescent(LyXFont const & f)
44 return metrics(f).descent();
48 int ascent(char c, LyXFont const & f)
50 QRect r = metrics(f).boundingRect(c);
55 int descent(char c, LyXFont const & f)
57 QRect r = metrics(f).boundingRect(c);
58 return abs(r.bottom());
62 int lbearing(char c, LyXFont const & f)
64 lyxerr << "lb of " << c << " is " << metrics(f).leftBearing(c)
66 return metrics(f).leftBearing(c);
70 int rbearing(char c, LyXFont const & f)
72 QFontMetrics const & m(metrics(f));
74 // Qt rbearing is from the right edge of the char's width().
75 return (m.width(c) - m.rightBearing(c));
79 int width(char const * s, size_t ls, LyXFont const & f)
81 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
82 return metrics(f).width(s, ls);
85 // handle small caps ourselves ...
88 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
90 QFontMetrics qm = fontloader.metrics(f);
91 QFontMetrics qsmallm = fontloader.metrics(smallfont);
95 for (size_t i = 0; i < ls; ++i) {
96 char const c = uppercase(s[i]);
98 w += qsmallm.width(&c, 1);
100 w += qm.width(&c, 1);
106 int signedWidth(string const & s, LyXFont const & f)
109 return -width(s.substr(1, s.length() - 1), f);
115 void rectText(string const & str, LyXFont const & f,
120 QFontMetrics const & m(metrics(f));
122 static int const d = 2;
124 w = width(str, f) + d * 2 + 2;
125 ascent = m.ascent() + d;
126 descent = m.descent() + d;
131 void buttonText(string const & str, LyXFont const & f,
136 QFontMetrics const & m(metrics(f));
138 static int const d = 3;
140 w = width(str, f) + d * 2 + 2;
141 ascent = m.ascent() + d;
142 descent = m.descent() + d;
145 } // namespace font_metrics