#include "GuiFontLoader.h"
#include "qt_helpers.h"
-#include "debug.h"
#include "LyXRC.h"
#include "support/convert.h"
+#include "support/debug.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/Systemcall.h"
#include "support/Package.h"
#include "support/os.h"
-#include <boost/tuple/tuple.hpp>
-
#include <QFontInfo>
#include <QFontDatabase>
-using lyx::support::contains;
-using lyx::support::package;
-using lyx::support::addPath;
-using lyx::support::addName;
-
-using std::endl;
-using std::make_pair;
-
-using std::pair;
-using std::vector;
+using namespace std;
+using namespace lyx::support;
-#if QT_VERSION >= 0x040200
QString const math_fonts[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
"eufm10", "msam10", "msbm10", "wasy10", "esint10"};
int const num_math_fonts = sizeof(math_fonts) / sizeof(*math_fonts);
-#endif
namespace lyx {
if (family == symbol_fonts[i].family)
return symbol_fonts[i].xlfd;
- LYXERR(Debug::FONT) << "BUG: family not found !" << endl;
+ LYXERR(Debug::FONT, "BUG: family not found !");
return QString();
}
bool isSymbolFamily(FontFamily family)
{
- return family >= SYMBOL_FAMILY &&
- family <= ESINT_FAMILY;
+ return family >= SYMBOL_FAMILY && family <= ESINT_FAMILY;
}
// positions.
QFontInfo fi(font);
- LYXERR(Debug::FONT) << "got: " << fromqstr(fi.family()) << endl;
+ LYXERR(Debug::FONT, "got: " << fromqstr(fi.family()));
if (fi.family().contains(family)) {
- LYXERR(Debug::FONT) << " got it ";
+ LYXERR(Debug::FONT, " got it ");
return true;
}
}
-static pair<QFont, bool> const getSymbolFont(QString const & family)
+QFont symbolFont(QString const & family, bool * ok)
{
- LYXERR(Debug::FONT) << "Looking for font family "
- << fromqstr(family) << " ... ";
+ LYXERR(Debug::FONT, "Looking for font family "
+ << fromqstr(family) << " ... ");
QString upper = family;
upper[0] = family[0].toUpper();
font.setFamily(family);
if (isChosenFont(font, family)) {
- LYXERR(Debug::FONT) << "normal!" << endl;
- return make_pair<QFont, bool>(font, true);
+ LYXERR(Debug::FONT, "normal!");
+ *ok = true;
+ return font;
}
- LYXERR(Debug::FONT) << "Trying " << fromqstr(upper) << " ... ";
+ LYXERR(Debug::FONT, "Trying " << fromqstr(upper) << " ... ");
font.setFamily(upper);
if (isChosenFont(font, upper)) {
- LYXERR(Debug::FONT) << "upper!" << endl;
- return make_pair<QFont, bool>(font, true);
+ LYXERR(Debug::FONT, "upper!");
+ *ok = true;
+ return font;
}
// A simple setFamily() fails on Qt 2
QString const rawName = getRawName(family);
- LYXERR(Debug::FONT) << "Trying " << fromqstr(rawName) << " ... ";
+ LYXERR(Debug::FONT, "Trying " << fromqstr(rawName) << " ... ");
font.setRawName(rawName);
if (isChosenFont(font, family)) {
- LYXERR(Debug::FONT) << "raw version!" << endl;
- return make_pair<QFont, bool>(font, true);
+ LYXERR(Debug::FONT, "raw version!");
+ *ok = true;
+ return font;
}
- LYXERR(Debug::FONT) << " FAILED :-(" << endl;
- return make_pair<QFont, bool>(font, false);
+ LYXERR(Debug::FONT, " FAILED :-(");
+ *ok = false;
+ return font;
}
} // namespace anon
GuiFontLoader::GuiFontLoader()
{
-#if QT_VERSION >= 0x040200
QString const fonts_dir =
toqstr(addPath(package().system_support().absFilename(), "fonts"));
QString const font_file = fonts_dir + '/' + math_fonts[i] + ".ttf";
int fontID = QFontDatabase::addApplicationFont(font_file);
- LYXERR(Debug::FONT) << "Adding font " << fromqstr(font_file)
+ LYXERR(Debug::FONT, "Adding font " << fromqstr(font_file)
<< static_cast<const char *>
- (fontID < 0 ? " FAIL" : " OK")
- << endl;
+ (fontID < 0 ? " FAIL" : " OK"));
}
-#endif
for (int i1 = 0; i1 < NUM_FAMILIES; ++i1)
for (int i2 = 0; i2 < 2; ++i2)
}
+GuiFontLoader::~GuiFontLoader()
+{
+ update();
+}
+
/////////////////////////////////////////////////
GuiFontInfo::GuiFontInfo(FontInfo const & f)
+ : metrics(QFont())
{
font.setKerning(false);
QString const pat = symbolFamily(f.family());
if (!pat.isEmpty()) {
- bool tmp;
- boost::tie(font, tmp) = getSymbolFont(pat);
+ bool ok;
+ font = symbolFont(pat, &ok);
} else {
switch (f.family()) {
case ROMAN_FAMILY: {
break;
}
- LYXERR(Debug::FONT) << "Font '" << to_utf8(stateText(f))
- << "' matched by\n" << fromqstr(font.family()) << endl;
+ LYXERR(Debug::FONT, "Font '" << to_utf8(stateText(f))
+ << "' matched by\n" << fromqstr(font.family()));
// Is this an exact match?
if (font.exactMatch())
- LYXERR(Debug::FONT) << "This font is an exact match" << endl;
+ LYXERR(Debug::FONT, "This font is an exact match");
else
- LYXERR(Debug::FONT) << "This font is NOT an exact match"
- << endl;
+ LYXERR(Debug::FONT, "This font is NOT an exact match");
- LYXERR(Debug::FONT) << "XFLD: " << fromqstr(font.rawName()) << endl;
+ LYXERR(Debug::FONT, "XFLD: " << fromqstr(font.rawName()));
font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
* lyxrc.zoom / 100.0);
- LYXERR(Debug::FONT) << "The font has size: "
- << font.pointSizeF() << endl;
+ LYXERR(Debug::FONT, "The font has size: " << font.pointSizeF());
if (f.realShape() != SMALLCAPS_SHAPE) {
- metrics.reset(new GuiFontMetrics(font));
- }
- else {
+ metrics = GuiFontMetrics(font);
+ } else {
// handle small caps ourselves ...
FontInfo smallfont = f;
smallfont.decSize().decSize().setShape(UP_SHAPE);
font2.setPointSizeF(convert<double>(lyxrc.font_sizes[smallfont.size()])
* lyxrc.zoom / 100.0);
- metrics.reset(new GuiFontMetrics(font, font2));
+ metrics = GuiFontMetrics(font, font2);
}
-
}
// We don't care about non-symbol fonts
return false;
- pair<QFont, bool> tmp = getSymbolFont(pat);
- if (!tmp.second)
+ bool ok;
+ symbolFont(pat, &ok);
+ if (!ok)
return false;
cache[family] = true;