2002-06-19 03:38:44 +00:00
|
|
|
/**
|
|
|
|
* \file qfont_metrics.C
|
|
|
|
* Copyright 1995-2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author unknown
|
|
|
|
* \author John Levon <moz@compsoc.man.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "frontends/font_metrics.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "font_metrics.h"
|
|
|
|
#include "qfont_loader.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <qfontmetrics.h>
|
|
|
|
#include <qfont.h>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
QFontMetrics const & metrics(LyXFont const & f) {
|
2002-06-19 05:20:29 +00:00
|
|
|
return fontloader.metrics(f);
|
2002-06-19 03:38:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
namespace font_metrics {
|
|
|
|
|
|
|
|
int maxAscent(LyXFont const & f)
|
|
|
|
{
|
|
|
|
return metrics(f).ascent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int maxDescent(LyXFont const & f)
|
|
|
|
{
|
|
|
|
return metrics(f).descent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ascent(char c, LyXFont const & f)
|
|
|
|
{
|
|
|
|
// FIXME - must do ascent for char not maxascent
|
|
|
|
//QRect r = metrics(f).boundingRect(c);
|
|
|
|
//lyxerr << r.x() << "," << r.y() <<
|
|
|
|
// " : " << r.width() << "," << r.height() << endl;
|
|
|
|
return metrics(f).ascent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int descent(char, LyXFont const & f)
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return metrics(f).descent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int lbearing(char c, LyXFont const & f)
|
|
|
|
{
|
|
|
|
return metrics(f).leftBearing(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int rbearing(char c, LyXFont const & f)
|
|
|
|
{
|
|
|
|
return metrics(f).rightBearing(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int width(char const * s, size_t ls, LyXFont const & f)
|
|
|
|
{
|
|
|
|
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
|
|
|
return metrics(f).width(s, ls);
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle small caps ourselves ...
|
|
|
|
|
|
|
|
LyXFont smallfont(f);
|
|
|
|
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
QFontMetrics qm = fontloader.metrics(f);
|
|
|
|
QFontMetrics qsmallm = fontloader.metrics(smallfont);
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
int w = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ls; ++i) {
|
|
|
|
char const c = uppercase(s[i]);
|
|
|
|
if (c != s[i])
|
|
|
|
w += qsmallm.width(&c, 1);
|
|
|
|
else
|
|
|
|
w += qm.width(&c, 1);
|
|
|
|
}
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int signedWidth(string const & s, LyXFont const & f)
|
|
|
|
{
|
|
|
|
if (s[0] == '-')
|
|
|
|
return -width(s.substr(1, s.length() - 1), f);
|
|
|
|
else
|
|
|
|
return width(s, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void rectText(string const & str, LyXFont const & f,
|
|
|
|
int & w,
|
|
|
|
int & ascent,
|
|
|
|
int & descent)
|
|
|
|
{
|
|
|
|
QFontMetrics const & metrics(metrics(f));
|
|
|
|
|
|
|
|
w = width(str, f);
|
|
|
|
ascent = metrics.ascent();
|
|
|
|
descent = metrics.descent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void buttonText(string const & str, LyXFont const & f,
|
|
|
|
int & w,
|
|
|
|
int & ascent,
|
|
|
|
int & descent)
|
|
|
|
{
|
|
|
|
QFontMetrics const & metrics(metrics(f));
|
|
|
|
|
|
|
|
static int const d = 3;
|
|
|
|
|
|
|
|
w = width(str, f) + d * 2 + 2;
|
|
|
|
ascent = metrics.ascent() + d;
|
|
|
|
descent = metrics.descent() + d;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace font_metrics
|