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 extern qfont_loader * global_fontloader;
29 QFontMetrics const & metrics(LyXFont const & f) {
30 return global_fontloader->metrics(f);
35 namespace font_metrics {
37 int maxAscent(LyXFont const & f)
39 return metrics(f).ascent();
43 int maxDescent(LyXFont const & f)
45 return metrics(f).descent();
49 int ascent(char c, LyXFont const & f)
51 // FIXME - must do ascent for char not maxascent
52 //QRect r = metrics(f).boundingRect(c);
53 //lyxerr << r.x() << "," << r.y() <<
54 // " : " << r.width() << "," << r.height() << endl;
55 return metrics(f).ascent();
59 int descent(char, LyXFont const & f)
62 return metrics(f).descent();
66 int lbearing(char c, LyXFont const & f)
68 return metrics(f).leftBearing(c);
72 int rbearing(char c, LyXFont const & f)
74 return metrics(f).rightBearing(c);
78 int width(char const * s, size_t ls, LyXFont const & f)
80 if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
81 return metrics(f).width(s, ls);
84 // handle small caps ourselves ...
87 smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
89 QFontMetrics qm = global_fontloader->metrics(f);
90 QFontMetrics qsmallm = global_fontloader->metrics(smallfont);
94 for (size_t i = 0; i < ls; ++i) {
95 char const c = uppercase(s[i]);
97 w += qsmallm.width(&c, 1);
105 int signedWidth(string const & s, LyXFont const & f)
108 return -width(s.substr(1, s.length() - 1), f);
114 void rectText(string const & str, LyXFont const & f,
119 QFontMetrics const & metrics(metrics(f));
122 ascent = metrics.ascent();
123 descent = metrics.descent();
128 void buttonText(string const & str, LyXFont const & f,
133 QFontMetrics const & metrics(metrics(f));
135 static int const d = 3;
137 w = width(str, f) + d * 2 + 2;
138 ascent = metrics.ascent() + d;
139 descent = metrics.descent() + d;
142 } // namespace font_metrics