]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiFontLoader.cpp
do what the FIXME suggested
[lyx.git] / src / frontends / qt4 / GuiFontLoader.cpp
index c12751f0e1a89d1d4c0303942b8fb018cd8a15b5..6ec0bc508d366cac2ce7b1a3c4f116151c6ad37c 100644 (file)
 #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;
 
 QString const math_fonts[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
        "eufm10", "msam10", "msbm10", "wasy10", "esint10"};
@@ -110,7 +100,7 @@ QString getRawName(QString const & family)
                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();
 }
 
@@ -127,8 +117,7 @@ QString const symbolFamily(FontFamily family)
 
 bool isSymbolFamily(FontFamily family)
 {
-       return family >= SYMBOL_FAMILY &&
-              family <= ESINT_FAMILY;
+       return family >= SYMBOL_FAMILY && family <= ESINT_FAMILY;
 }
 
 
@@ -140,10 +129,10 @@ static bool isChosenFont(QFont & font, QString const & 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;
        }
 
@@ -151,10 +140,10 @@ static bool isChosenFont(QFont & font, QString const & family)
 }
 
 
-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();
 
@@ -163,31 +152,35 @@ static pair<QFont, bool> const getSymbolFont(QString const & family)
        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
@@ -202,10 +195,9 @@ GuiFontLoader::GuiFontLoader()
                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"));
        }
 
        for (int i1 = 0; i1 < NUM_FAMILIES; ++i1)
@@ -229,6 +221,11 @@ void GuiFontLoader::update()
 }
 
 
+GuiFontLoader::~GuiFontLoader()
+{
+       update();
+}
+
 /////////////////////////////////////////////////
 
 
@@ -242,12 +239,13 @@ static QString makeFontName(QString const & family, QString const & foundry)
 
 
 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: {
@@ -298,28 +296,25 @@ GuiFontInfo::GuiFontInfo(FontInfo const & f)
                        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);
@@ -328,9 +323,8 @@ GuiFontInfo::GuiFontInfo(FontInfo const & f)
                font2.setPointSizeF(convert<double>(lyxrc.font_sizes[smallfont.size()])
                               * lyxrc.zoom / 100.0);
 
-               metrics.reset(new GuiFontMetrics(font, font2));
+               metrics = GuiFontMetrics(font, font2);
        }
-
 }
 
 
@@ -349,8 +343,9 @@ bool GuiFontLoader::available(FontInfo const & f)
                // 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;