2 * \file qfont_metrics.C
3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
7 * \author John Levon <moz@compsoc.man.ac.uk>
14 #pragma implementation "frontends/font_metrics.h"
17 #include "support/lstrings.h"
18 #include "font_metrics.h"
19 #include "qfont_loader.h"
22 #include <qfontmetrics.h>
26 QFontMetrics const & metrics(LyXFont const & f) {
27 return fontloader.metrics(f);
32 namespace font_metrics {
34 int maxAscent(LyXFont const & f)
36 return metrics(f).ascent();
40 int maxDescent(LyXFont const & f)
42 return metrics(f).descent();
46 int ascent(char c, LyXFont const & f)
48 // FIXME - must do ascent for char not maxascent
49 //QRect r = metrics(f).boundingRect(c);
50 //lyxerr << r.x() << "," << r.y() <<
51 // " : " << r.width() << "," << r.height() << endl;
52 return metrics(f).ascent();
56 int descent(char, LyXFont const & f)
59 return metrics(f).descent();
63 int lbearing(char c, LyXFont const & f)
65 return metrics(f).leftBearing(c);
69 int rbearing(char c, LyXFont const & f)
71 return metrics(f).rightBearing(c);
75 int width(char const * s, size_t ls, LyXFont const & f)
77 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
78 return metrics(f).width(s, ls);
81 // handle small caps ourselves ...
84 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
86 QFontMetrics qm = fontloader.metrics(f);
87 QFontMetrics qsmallm = fontloader.metrics(smallfont);
91 for (size_t i = 0; i < ls; ++i) {
92 char const c = uppercase(s[i]);
94 w += qsmallm.width(&c, 1);
102 int signedWidth(string const & s, LyXFont const & f)
105 return -width(s.substr(1, s.length() - 1), f);
111 void rectText(string const & str, LyXFont const & f,
116 QFontMetrics const & m(metrics(f));
120 descent = m.descent();
125 void buttonText(string const & str, LyXFont const & f,
130 QFontMetrics const & m(metrics(f));
132 static int const d = 3;
134 w = width(str, f) + d * 2 + 2;
135 ascent = m.ascent() + d;
136 descent = m.descent() + d;
139 } // namespace font_metrics