]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiFontLoader.cpp
Get rid of Qt4 code in src/
[lyx.git] / src / frontends / qt / GuiFontLoader.cpp
index 69dba8d45d4bcf7d90b7577d8b70e074cf55b8f8..ebc38575558cdc6b2911e3e0fa2c706ecdeb25da 100644 (file)
 
 #include <config.h>
 
-#include "FontLoader.h"
+#include "GuiFontLoader.h"
 
-#include "FontInfo.h"
+#include "FontLoader.h"
+#include "Font.h"
 #include "GuiFontMetrics.h"
 #include "qt_helpers.h"
 
 #include "support/debug.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/Systemcall.h"
 #include "support/Package.h"
 #include "support/os.h"
 
+#include "GuiApplication.h"
+
 #include <QFontInfo>
 #include <QFontDatabase>
 
-#include "support/lassert.h"
-
 using namespace std;
 using namespace lyx::support;
 
 QString const math_fonts[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
-       "esint10", "eufm10", "msam10", "msbm10", "rsfs10", "stmary10",
-       "wasy10"};
+       "dsrom10", "esint10", "eufm10", "msam10", "msbm10", "rsfs10",
+       "stmary10", "wasy10"};
 int const num_math_fonts = sizeof(math_fonts) / sizeof(*math_fonts);
 
 namespace lyx {
@@ -74,6 +76,7 @@ SymbolFont symbol_fonts[] = {
        { CMEX_FAMILY,  "cmex10"},
        { MSA_FAMILY,   "msam10"},
        { MSB_FAMILY,   "msbm10"},
+       { DS_FAMILY,    "dsrom10"},
        { EUFRAK_FAMILY,"eufm10"},
        { RSFS_FAMILY,  "rsfs10"},
        { STMARY_FAMILY,"stmary10"},
@@ -109,8 +112,8 @@ GuiFontInfo & fontinfo(FontInfo const & f)
             (f.size() < NUM_SIZE);
     if (!fontIsRealized) {
         // We can reset the font to something sensible in release mode.
+        LYXERR0("Unrealized font!" << f);
         LATTEST(false);
-        LYXERR0("Unrealized font!");
         FontInfo f2 = f;
         f2.realize(sane_font);
         GuiFontInfo * & fi = fontinfo_ptr(f2);
@@ -152,14 +155,11 @@ static bool isChosenFont(QFont & font, QString const & family,
        // positions.
        QFontInfo fi(font);
 
-       LYXERR(Debug::FONT, "got: " << fi.family());
+       LYXERR_NOPOS(Debug::FONT, "got: " << fi.family());
 
        if (fi.family().contains(family)
-#if QT_VERSION >= 0x040800
-           && (style.isEmpty() || fi.styleName().contains(style))
-#endif
-           ) {
-               LYXERR(Debug::FONT, " got it ");
+           && (style.isEmpty() || fi.styleName().contains(style))) {
+               LYXERR_NOENDL(Debug::FONT, " got it ");
                return true;
        }
 
@@ -169,50 +169,48 @@ static bool isChosenFont(QFont & font, QString const & family,
 
 QFont symbolFont(QString const & family, bool * ok)
 {
-       LYXERR(Debug::FONT, "Looking for font family " << family << " ... ");
+       LYXERR_NOENDL(Debug::FONT, "Looking for font family " << family << " ... ");
        QString upper = family;
        upper[0] = family[0].toUpper();
 
        QFont font;
-       font.setFamily(family);
-#if QT_VERSION >= 0x040800
+       if (guiApp->platformName() == "xcb"
+           || guiApp->platformName().contains("wayland")) {
+               // On *nix we have to also specify the foundry to be able to
+               // discriminate our fonts when the texlive fonts are managed by
+               // fontconfig. Unfortunately, doing the same on Windows breaks things.
+               font.setFamily(family + QLatin1String(" [LyEd]"));
+       } else {
+               font.setFamily(family);
+       }
+       font.setStyleStrategy(QFont::NoFontMerging);
        font.setStyleName("LyX");
 
        if (isChosenFont(font, family, "LyX")) {
-               LYXERR(Debug::FONT, "lyx!");
+               LYXERR_NOPOS(Debug::FONT, "lyx!");
                *ok = true;
                return font;
        }
 
-       LYXERR(Debug::FONT, "Trying normal " << family << " ... ");
+       LYXERR_NOENDL(Debug::FONT, "Trying normal " << family << " ... ");
        font.setStyleName(QString());
-#endif
 
        if (isChosenFont(font, family, QString())) {
-               LYXERR(Debug::FONT, "normal!");
+               LYXERR_NOPOS(Debug::FONT, "normal!");
                *ok = true;
                return font;
        }
 
-       LYXERR(Debug::FONT, "Trying " << upper << " ... ");
+       LYXERR_NOENDL(Debug::FONT, "Trying " << upper << " ... ");
        font.setFamily(upper);
 
        if (isChosenFont(font, upper, QString())) {
-               LYXERR(Debug::FONT, "upper!");
+               LYXERR_NOPOS(Debug::FONT, "upper!");
                *ok = true;
                return font;
        }
 
-       LYXERR(Debug::FONT, "Trying " << family << " ... ");
-       font.setFamily(family);
-
-       if (isChosenFont(font, family, QString())) {
-               LYXERR(Debug::FONT, "raw version!");
-               *ok = true;
-               return font;
-       }
-
-       LYXERR(Debug::FONT, " FAILED :-(");
+       LYXERR_NOPOS(Debug::FONT, " FAILED :-(");
        *ok = false;
        return font;
 }
@@ -287,13 +285,12 @@ QFont makeQFont(FontInfo const & f)
                                toqstr(lyxrc.roman_font_foundry));
                        font.setFamily(family);
 #ifdef Q_OS_MAC
-#if QT_VERSION >= 0x040300 //&& QT_VERSION < 0x040800
+                       // FIXME KILLQT4: Double-check that this is fixed in Qt5
                        // Workaround for a Qt bug, see http://www.lyx.org/trac/ticket/3684
                        // and http://bugreports.qt.nokia.com/browse/QTBUG-11145.
                        // FIXME: Check whether this is really fixed in Qt 4.8
                        if (family == "Times" && !font.exactMatch())
                                font.setFamily("Times New Roman");
-#endif
 #endif
                        break;
                }
@@ -399,13 +396,9 @@ bool FontLoader::canBeDisplayed(char_type c)
 {
        // bug 8493
        if (c == 0x0009)
+               // FIXME KILLQT4: get rid of this function if not needed anymore
                // FIXME check whether this is still needed for Qt5
                return false;
-#if QT_VERSION < 0x050000 && defined(QT_MAC_USE_COCOA) && (QT_MAC_USE_COCOA > 0)
-       // bug 7954, see also comment in GuiPainter::text()
-       if (c == 0x00ad)
-               return false;
-#endif
        return true;
 }