mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-08 20:32:49 +00:00
simplify function calls
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10243 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3b93cd9123
commit
46e3547945
@ -52,6 +52,25 @@ using std::string;
|
||||
#endif
|
||||
|
||||
|
||||
int qfont_loader::font_info::charwidth(Uchar val) const
|
||||
{
|
||||
// Starting with version 3.1.0, Qt/X11 does its own caching of
|
||||
// character width, so it is not necessary to provide ours.
|
||||
#if defined (USE_LYX_FONTCACHE)
|
||||
#error xxx
|
||||
font_info::WidthCache::const_iterator cit = widthcache.find(val);
|
||||
if (cit != widthcache.end())
|
||||
return cit->second;
|
||||
|
||||
int const w = metrics.width(QChar(val));
|
||||
widthcache[val] = w;
|
||||
return w;
|
||||
#else
|
||||
return metrics.width(QChar(val));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
void qfont_loader::initFontPath()
|
||||
{
|
||||
@ -351,26 +370,6 @@ qfont_loader::font_info * qfont_loader::getfontinfo(LyXFont const & f)
|
||||
}
|
||||
|
||||
|
||||
int qfont_loader::charwidth(LyXFont const & f, Uchar val)
|
||||
{
|
||||
// Starting with version 3.1.0, Qt/X11 does its own caching of
|
||||
// character width, so it is not necessary to provide ours.
|
||||
#if defined (USE_LYX_FONTCACHE)
|
||||
font_info * fi = getfontinfo(f);
|
||||
|
||||
font_info::WidthCache::const_iterator cit = fi->widthcache.find(val);
|
||||
if (cit != fi->widthcache.end())
|
||||
return cit->second;
|
||||
|
||||
int const w = fi->metrics.width(QChar(val));
|
||||
fi->widthcache[val] = w;
|
||||
return w;
|
||||
#else
|
||||
return getfontinfo(f)->metrics.width(QChar(val));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool qfont_loader::available(LyXFont const & f)
|
||||
{
|
||||
if (!lyx_gui::use_gui)
|
||||
|
@ -32,6 +32,26 @@
|
||||
*/
|
||||
class qfont_loader {
|
||||
public:
|
||||
/// hold info about a particular font
|
||||
class font_info {
|
||||
public:
|
||||
font_info(LyXFont const & f);
|
||||
|
||||
/// return pixel width for the given unicode char
|
||||
int charwidth(Uchar val) const;
|
||||
|
||||
/// the font instance
|
||||
QFont font;
|
||||
/// metrics on the font
|
||||
QFontMetrics metrics;
|
||||
|
||||
#if defined(USE_LYX_FONTCACHE)
|
||||
typedef std::map<Uchar, int> WidthCache;
|
||||
/// cache of char widths
|
||||
WidthCache widthcache;
|
||||
#endif
|
||||
};
|
||||
|
||||
qfont_loader();
|
||||
|
||||
~qfont_loader();
|
||||
@ -50,36 +70,16 @@ public:
|
||||
return getfontinfo(f)->metrics;
|
||||
}
|
||||
|
||||
/// return pixel width for the given unicode char
|
||||
int charwidth(LyXFont const & f, Uchar val);
|
||||
|
||||
/// Called before QApplication is initialized
|
||||
static void initFontPath();
|
||||
|
||||
/// Called the first time when available() can't load a symbol font
|
||||
static void addToFontPath();
|
||||
|
||||
private:
|
||||
/// hold info about a particular font
|
||||
class font_info {
|
||||
public:
|
||||
font_info(LyXFont const & f);
|
||||
|
||||
/// the font instance
|
||||
QFont font;
|
||||
/// metrics on the font
|
||||
QFontMetrics metrics;
|
||||
|
||||
#if defined(USE_LYX_FONTCACHE)
|
||||
typedef std::map<Uchar, int> WidthCache;
|
||||
/// cache of char widths
|
||||
WidthCache widthcache;
|
||||
#endif
|
||||
};
|
||||
|
||||
/// get font info (font + metrics) for the given LyX font. Does not fail.
|
||||
font_info * getfontinfo(LyXFont const & f);
|
||||
|
||||
private:
|
||||
/// BUTT ugly !
|
||||
font_info * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
|
||||
};
|
||||
|
@ -22,31 +22,13 @@
|
||||
using std::string;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
QFontMetrics const & metrics(LyXFont const & f)
|
||||
{
|
||||
return fontloader.metrics(f);
|
||||
}
|
||||
|
||||
|
||||
int charwidth(Uchar val, LyXFont const & f)
|
||||
{
|
||||
if (!lyx_gui::use_gui)
|
||||
return 1;
|
||||
return fontloader.charwidth(f, val);
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
namespace font_metrics {
|
||||
|
||||
int maxAscent(LyXFont const & f)
|
||||
{
|
||||
if (!lyx_gui::use_gui)
|
||||
return 1;
|
||||
return metrics(f).ascent();
|
||||
return fontloader.metrics(f).ascent();
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +38,7 @@ int maxDescent(LyXFont const & f)
|
||||
return 1;
|
||||
// We add 1 as the value returned by QT is different than X
|
||||
// See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
|
||||
return metrics(f).descent() + 1;
|
||||
return fontloader.metrics(f).descent() + 1;
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +46,7 @@ int ascent(char c, LyXFont const & f)
|
||||
{
|
||||
if (!lyx_gui::use_gui)
|
||||
return 1;
|
||||
QRect const & r = metrics(f).boundingRect(c);
|
||||
QRect const & r = fontloader.metrics(f).boundingRect(c);
|
||||
// Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
|
||||
// value by the height: (x, -y-height, width, height).
|
||||
// Other versions return: (x, -y, width, height)
|
||||
@ -80,7 +62,7 @@ int descent(char c, LyXFont const & f)
|
||||
{
|
||||
if (!lyx_gui::use_gui)
|
||||
return 1;
|
||||
QRect const & r = metrics(f).boundingRect(c);
|
||||
QRect const & r = fontloader.metrics(f).boundingRect(c);
|
||||
// Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
|
||||
// value by the height: (x, -y-height, width, height).
|
||||
// Other versions return: (x, -y, width, height)
|
||||
@ -96,7 +78,7 @@ int lbearing(char c, LyXFont const & f)
|
||||
{
|
||||
if (!lyx_gui::use_gui)
|
||||
return 1;
|
||||
return metrics(f).leftBearing(c);
|
||||
return fontloader.metrics(f).leftBearing(c);
|
||||
}
|
||||
|
||||
|
||||
@ -104,7 +86,7 @@ int rbearing(char c, LyXFont const & f)
|
||||
{
|
||||
if (!lyx_gui::use_gui)
|
||||
return 1;
|
||||
QFontMetrics const & m = metrics(f);
|
||||
QFontMetrics const & m = fontloader.metrics(f);
|
||||
|
||||
// Qt rbearing is from the right edge of the char's width().
|
||||
return m.width(c) - m.rightBearing(c);
|
||||
@ -157,14 +139,14 @@ int width(char const * s, size_t ls, LyXFont const & f)
|
||||
return smallcapswidth(s, ls, f);
|
||||
|
||||
Encoding const * encoding = fontencoding(f);
|
||||
qfont_loader::font_info * fi = fontloader.getfontinfo(f);
|
||||
|
||||
if (ls == 1)
|
||||
return charwidth(encoding->ucs(s[0]), f);
|
||||
if (ls == 1)
|
||||
return fi->charwidth(encoding->ucs(s[0]));
|
||||
|
||||
int w = 0;
|
||||
|
||||
for (size_t i = 0; i < ls; ++i)
|
||||
w += charwidth(encoding->ucs(s[i]), f);
|
||||
w += fi->charwidth(encoding->ucs(s[i]));
|
||||
|
||||
return w;
|
||||
}
|
||||
@ -182,7 +164,7 @@ int signedWidth(string const & s, LyXFont const & f)
|
||||
void rectText(string const & str, LyXFont const & f,
|
||||
int & w, int & ascent, int & descent)
|
||||
{
|
||||
QFontMetrics const & m = metrics(f);
|
||||
QFontMetrics const & m = fontloader.metrics(f);
|
||||
static int const d = 2;
|
||||
w = width(str, f) + d * 2 + 2;
|
||||
ascent = m.ascent() + d;
|
||||
@ -194,7 +176,7 @@ void rectText(string const & str, LyXFont const & f,
|
||||
void buttonText(string const & str, LyXFont const & f,
|
||||
int & w, int & ascent, int & descent)
|
||||
{
|
||||
QFontMetrics const & m = metrics(f);
|
||||
QFontMetrics const & m = fontloader.metrics(f);
|
||||
static int const d = 3;
|
||||
w = width(str, f) + d * 2 + 2;
|
||||
ascent = m.ascent() + d;
|
||||
|
Loading…
Reference in New Issue
Block a user