mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
rename qfont_loader and font_info to mathc LyX naming conventions
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10247 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b0dd800145
commit
7173717c8c
@ -227,7 +227,6 @@ void QLPainter::text(int x, int y, char const * s, size_t ls,
|
||||
encoding = encodings.symbol_encoding();
|
||||
|
||||
QString str;
|
||||
#if QT_VERSION >= 300
|
||||
str.setLength(ls);
|
||||
for (size_t i = 0; i < ls; ++i)
|
||||
// Brain-dead MSVC wants at(i) rather than operator[]
|
||||
@ -235,20 +234,12 @@ void QLPainter::text(int x, int y, char const * s, size_t ls,
|
||||
// HACK: QT3 refuses to show single compose characters
|
||||
if (ls == 1 && str[0].unicode() >= 0x05b0 && str[0].unicode() <= 0x05c2)
|
||||
str = ' ' + str;
|
||||
#else
|
||||
for (size_t i = 0; i < ls; ++i)
|
||||
str += QChar(encoding->ucs(s[i]));
|
||||
#endif
|
||||
|
||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
||||
qp_->setFont(fontloader.get(f));
|
||||
#if QT_VERSION >= 300
|
||||
// We need to draw the text as LTR as we use our own bidi
|
||||
// code.
|
||||
qp_->drawText(x, y, str, -1, QPainter::LTR);
|
||||
#else
|
||||
qp_->drawText(x, y, str);
|
||||
#endif
|
||||
} else {
|
||||
smallCapsText(x, y, str, f);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
qfont_loader fontloader;
|
||||
FontLoader fontloader;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
@ -165,7 +165,7 @@ bool use_gui = true;
|
||||
void parse_init(int & argc, char * argv[])
|
||||
{
|
||||
// Force adding of font path _before_ QApplication is initialized
|
||||
qfont_loader::initFontPath();
|
||||
FontLoader::initFontPath();
|
||||
|
||||
static LQApplication app(argc, argv);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* \file qfont_loader.C
|
||||
* \file FontLoader.C
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
@ -52,27 +52,7 @@ 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()
|
||||
void FontLoader::initFontPath()
|
||||
{
|
||||
#ifdef Q_WS_MACX
|
||||
CFBundleRef myAppBundle = CFBundleGetMainBundle();
|
||||
@ -154,10 +134,10 @@ size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_font);
|
||||
|
||||
string getRawName(string const & family)
|
||||
{
|
||||
for (size_t i = 0; i < nr_symbol_fonts; ++i) {
|
||||
for (size_t i = 0; i < nr_symbol_fonts; ++i)
|
||||
if (family == symbol_fonts[i].family)
|
||||
return symbol_fonts[i].xlfd;
|
||||
}
|
||||
|
||||
lyxerr[Debug::FONT] << "BUG: family not found !" << endl;
|
||||
return string();
|
||||
}
|
||||
@ -246,47 +226,32 @@ pair<QFont, bool> const getSymbolFont(string const & family)
|
||||
} // namespace anon
|
||||
|
||||
|
||||
qfont_loader::qfont_loader()
|
||||
FontLoader::FontLoader()
|
||||
{
|
||||
for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) {
|
||||
for (int i2 = 0; i2 < 2; ++i2) {
|
||||
for (int i3 = 0; i3 < 4; ++i3) {
|
||||
for (int i4 = 0; i4 < 10; ++i4) {
|
||||
for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
|
||||
for (int i2 = 0; i2 < 2; ++i2)
|
||||
for (int i3 = 0; i3 < 4; ++i3)
|
||||
for (int i4 = 0; i4 < 10; ++i4)
|
||||
fontinfo_[i1][i2][i3][i4] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
qfont_loader::~qfont_loader()
|
||||
void FontLoader::update()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void qfont_loader::update()
|
||||
{
|
||||
for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1) {
|
||||
for (int i2 = 0; i2 < 2; ++i2) {
|
||||
for (int i3 = 0; i3 < 4; ++i3) {
|
||||
for (int i1 = 0; i1 < LyXFont::NUM_FAMILIES; ++i1)
|
||||
for (int i2 = 0; i2 < 2; ++i2)
|
||||
for (int i3 = 0; i3 < 4; ++i3)
|
||||
for (int i4 = 0; i4 < 10; ++i4) {
|
||||
delete fontinfo_[i1][i2][i3][i4];
|
||||
fontinfo_[i1][i2][i3][i4] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QFont const & qfont_loader::get(LyXFont const & f)
|
||||
{
|
||||
return getfontinfo(f)->font;
|
||||
}
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
|
||||
qfont_loader::font_info::font_info(LyXFont const & f)
|
||||
FontInfo::FontInfo(LyXFont const & f)
|
||||
: metrics(font)
|
||||
{
|
||||
|
||||
@ -358,19 +323,38 @@ qfont_loader::font_info::font_info(LyXFont const & f)
|
||||
}
|
||||
|
||||
|
||||
qfont_loader::font_info * qfont_loader::getfontinfo(LyXFont const & f)
|
||||
int FontInfo::width(Uchar val) const
|
||||
{
|
||||
font_info * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
|
||||
if (fi)
|
||||
return fi;
|
||||
// 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
|
||||
FontInfo::WidthCache::const_iterator cit = widthcache.find(val);
|
||||
if (cit != widthcache.end())
|
||||
return cit->second;
|
||||
|
||||
font_info * fi2 = new font_info(f);
|
||||
fontinfo_[f.family()][f.series()][f.realShape()][f.size()] = fi2;
|
||||
return fi2;
|
||||
int const w = metrics.width(QChar(val));
|
||||
widthcache[val] = w;
|
||||
return w;
|
||||
#else
|
||||
return metrics.width(QChar(val));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool qfont_loader::available(LyXFont const & f)
|
||||
FontInfo & FontLoader::fontinfo(LyXFont const & f)
|
||||
{
|
||||
FontInfo * fi = fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
|
||||
if (fi)
|
||||
return *fi;
|
||||
|
||||
FontInfo * fi2 = new FontInfo(f);
|
||||
fontinfo_[f.family()][f.series()][f.realShape()][f.size()] = fi2;
|
||||
return *fi2;
|
||||
}
|
||||
|
||||
|
||||
bool FontLoader::available(LyXFont const & f)
|
||||
{
|
||||
if (!lyx_gui::use_gui)
|
||||
return false;
|
||||
|
@ -30,31 +30,31 @@
|
||||
* Qt font loader for LyX. Matches LyXFonts against
|
||||
* actual QFont instances, and also caches metrics.
|
||||
*/
|
||||
class qfont_loader {
|
||||
class FontInfo {
|
||||
public:
|
||||
/// hold info about a particular font
|
||||
class font_info {
|
||||
public:
|
||||
font_info(LyXFont const & f);
|
||||
FontInfo(LyXFont const & f);
|
||||
|
||||
/// return pixel width for the given unicode char
|
||||
int charwidth(Uchar val) const;
|
||||
/// return pixel width for the given unicode char
|
||||
int width(Uchar val) const;
|
||||
|
||||
/// the font instance
|
||||
QFont font;
|
||||
/// metrics on the font
|
||||
QFontMetrics metrics;
|
||||
/// 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;
|
||||
typedef std::map<Uchar, int> WidthCache;
|
||||
/// cache of char widths
|
||||
WidthCache widthcache;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
qfont_loader();
|
||||
|
||||
~qfont_loader();
|
||||
class FontLoader {
|
||||
public:
|
||||
/// hold info about a particular font
|
||||
///
|
||||
FontLoader();
|
||||
|
||||
/// update fonts after zoom, dpi, font names, or norm change
|
||||
void update();
|
||||
@ -63,11 +63,13 @@ public:
|
||||
bool available(LyXFont const & f);
|
||||
|
||||
/// get the QFont for this LyXFont
|
||||
QFont const & get(LyXFont const & f);
|
||||
QFont const & get(LyXFont const & f) {
|
||||
return fontinfo(f).font;
|
||||
}
|
||||
|
||||
/// get the QFont metrics for this LyXFont
|
||||
QFontMetrics const & metrics(LyXFont const & f) {
|
||||
return getfontinfo(f)->metrics;
|
||||
return fontinfo(f).metrics;
|
||||
}
|
||||
|
||||
/// Called before QApplication is initialized
|
||||
@ -77,13 +79,13 @@ public:
|
||||
static void addToFontPath();
|
||||
|
||||
/// get font info (font + metrics) for the given LyX font. Does not fail.
|
||||
font_info * getfontinfo(LyXFont const & f);
|
||||
FontInfo & fontinfo(LyXFont const & f);
|
||||
|
||||
private:
|
||||
/// BUTT ugly !
|
||||
font_info * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
|
||||
FontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
|
||||
};
|
||||
|
||||
extern qfont_loader fontloader;
|
||||
extern FontLoader fontloader;
|
||||
|
||||
#endif // QFONT_LOADER_H
|
||||
|
@ -108,7 +108,7 @@ int smallcapswidth(char const * s, size_t ls, LyXFont const & f)
|
||||
return 1;
|
||||
// handle small caps ourselves ...
|
||||
|
||||
LyXFont smallfont(f);
|
||||
LyXFont smallfont = f;
|
||||
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
|
||||
|
||||
QFontMetrics const & qm = fontloader.metrics(f);
|
||||
@ -139,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);
|
||||
FontInfo & fi = fontloader.fontinfo(f);
|
||||
|
||||
if (ls == 1)
|
||||
return fi->charwidth(encoding->ucs(s[0]));
|
||||
return fi.width(encoding->ucs(s[0]));
|
||||
|
||||
int w = 0;
|
||||
for (size_t i = 0; i < ls; ++i)
|
||||
w += fi->charwidth(encoding->ucs(s[i]));
|
||||
w += fi.width(encoding->ucs(s[i]));
|
||||
|
||||
return w;
|
||||
}
|
||||
@ -184,3 +184,4 @@ void buttonText(string const & str, LyXFont const & f,
|
||||
}
|
||||
|
||||
} // namespace font_metrics
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user