]> git.lyx.org Git - features.git/commitdiff
Fix math fonts problem
authorDekel Tsur <dekelts@tau.ac.il>
Mon, 3 Mar 2003 21:31:38 +0000 (21:31 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Mon, 3 Mar 2003 21:31:38 +0000 (21:31 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6329 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/qfont_loader.C

index 2dc49de8fc97c62937a836f164e2a97b25a3dae2..a0c5045f9b06771edc05d08cc5165d0c1e36d0bb 100644 (file)
@@ -1,3 +1,8 @@
+2003-03-03  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * qfont_loader.C (available): Rewrite as the old version did not
+       work properly.
+
 2003-02-28  Alfredo Braunstein <abraunst@libero.it>
 
        * QLImage.C 
index abb6119217e901eded8264771dcd8dabb5ce5373..ef937fb243b14c4b2cb5c85d413ad8b286ec67b4 100644 (file)
@@ -25,6 +25,8 @@
 #include <qstringlist.h>
 #include "support/lstrings.h"
 
+#include <boost/tuple/tuple.hpp>
+
 #ifdef Q_WS_X11
 #include <qwidget.h>
 #include <X11/Xlib.h>
@@ -33,7 +35,9 @@
 #endif
 
 using std::endl;
-
+using std::vector;
+using std::pair;
+using std::make_pair;
 
 namespace {
 
@@ -135,7 +139,7 @@ bool isSymbolFamily(LyXFont::FONT_FAMILY family)
 }
 
 
-QFont const getSymbolFont(string const & family)
+pair<QFont, bool> const getSymbolFont(string const & family)
 {
        lyxerr[Debug::FONT] << "Looking for font family "
                << family << " ... ";
@@ -148,14 +152,14 @@ QFont const getSymbolFont(string const & family)
        // Note Qt lies about family, so we use rawName.
        if (contains(fromqstr(font.rawName()), family)) {
                lyxerr[Debug::FONT] << " got it !" << endl;
-               return font;
+               return make_pair<QFont, bool>(font, true);
        }
 
        font.setFamily(toqstr(upper));
 
        if (contains(fromqstr(font.rawName()), upper)) {
                lyxerr[Debug::FONT] << " got it (uppercase version) !" << endl;
-               return font;
+               return make_pair<QFont, bool>(font, true);
        }
 
        // A simple setFamily() fails on Qt 2
@@ -164,61 +168,13 @@ QFont const getSymbolFont(string const & family)
 
        if (contains(fromqstr(font.rawName()), family)) {
                lyxerr[Debug::FONT] << " got it (raw version) !" << endl;
-               return font;
+               return make_pair<QFont, bool>(font, true);
        }
 
        lyxerr[Debug::FONT] << " FAILED :-(" << endl;
-       return font;
-}
-
-
-bool isAvailable(LyXFont const & f)
-{
-       static std::vector<bool> cache(LyXFont::NUM_FAMILIES, false);
-       static std::vector<bool> cache_initialized(LyXFont::NUM_FAMILIES, false);
-       static bool first_call = true;
-
-       LyXFont::FONT_FAMILY lyxfamily = f.family();
-       if (cache_initialized[lyxfamily])
-               return cache[lyxfamily];
-       cache_initialized[lyxfamily] = true;
-
-       if (first_call && isSymbolFamily(lyxfamily)) {
-               first_call = false;
-               addFontPath();
-       }
-
-       string const tmp = symbolFamily(lyxfamily);
-
-       if (tmp.empty())
-               return false;
-
-       QString const family(toqstr(tmp));
-
-       lyxerr[Debug::FONT] << "Family " << tmp
-              << " isAvailable ?";
-
-       QFontDatabase db;
-       // pass false for match-locale: LaTeX fonts
-       // do not have non-matching locale according
-       // to Qt 2
-       QStringList sl(db.families(false));
-
-       for (QStringList::Iterator it = sl.begin(); it != sl.end(); ++it) {
-               // Case-insensitive for Cmmi10 vs. cmmi10
-               if ((*it).lower().startsWith(family.lower())) {
-                       lyxerr[Debug::FONT]
-                               << "found family "
-                               << fromqstr(*it) << endl;
-                       cache[lyxfamily] = true;
-                       return true;
-               }
-       }
-       lyxerr[Debug::FONT] << " no." << endl;
-       return false;
+       return make_pair<QFont, bool>(font, false);
 }
 
-
 } // namespace anon
 
 
@@ -258,16 +214,7 @@ void qfont_loader::update()
 
 QFont const & qfont_loader::get(LyXFont const & f)
 {
-       static bool first_call = true;
-
-       if (first_call && isSymbolFamily(f.family())) {
-               first_call = false;
-               addFontPath();
-       }
-
-       QFont const & ret(getfontinfo(f)->font);
-
-       return ret;
+       return getfontinfo(f)->font;
 }
 
 
@@ -277,7 +224,8 @@ qfont_loader::font_info::font_info(LyXFont const & f)
 
        string const pat = symbolFamily(f.family());
        if (!pat.empty()) {
-               font = getSymbolFont(pat);
+               bool tmp;
+               boost::tie(font, tmp) = getSymbolFont(pat);
        } else {
                switch (f.family()) {
                case LyXFont::ROMAN_FAMILY:
@@ -377,5 +325,41 @@ bool qfont_loader::available(LyXFont const & f)
        if (!lyxrc.use_gui)
                return false;
 
-       return isAvailable(f);
+       static vector<bool> cache_set(LyXFont::NUM_FAMILIES, false);
+       static vector<bool> cache(LyXFont::NUM_FAMILIES, false);
+
+       LyXFont::FONT_FAMILY family = f.family();
+       if (cache_set[family])
+               return cache[family];
+       cache_set[family] = true;
+
+       string const pat = symbolFamily(family);
+       if (!pat.empty()) {
+               pair<QFont, bool> tmp = getSymbolFont(pat);
+               if (tmp.second) {
+                       cache[family] = true;
+                       return true;
+               }
+
+               // If the font is a tex symbol font and it is not available,
+               // we try to add the xfonts directory to the font path.
+               static bool first_time = true;
+               if (!first_time || family == LyXFont::SYMBOL_FAMILY
+                   || family == LyXFont::WASY_FAMILY)
+                       return false;
+
+               first_time = false;
+               addFontPath();
+               tmp = getSymbolFont(pat);
+               if (tmp.second) {
+                       cache[family] = true;
+                       return true;
+               }
+               // We don't need to set cache[family] to false, as it
+               //is initialized to false;
+               return false;
+       }
+
+       // We don't care about non-symbol fonts
+       return false;
 }