]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiFontLoader.cpp
Use the command-alternatives sequence as defined in menus.bind
[lyx.git] / src / frontends / qt4 / GuiFontLoader.cpp
index 9a662a893b3ce846386588370befeeaeae755f15..4f705330f9d33301d24d2dd2a5422d80b0bbd240 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "LyXRC.h"
 
-#include "support/convert.h"
 #include "support/debug.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
@@ -88,22 +87,41 @@ SymbolFont symbol_fonts[] = {
 size_t const nr_symbol_fonts = sizeof(symbol_fonts) / sizeof(symbol_fonts[0]);
 
 /// BUTT ugly !
-static GuiFontInfo * fontinfo_[NUM_FAMILIES][NUM_SERIES][NUM_SHAPE][NUM_SIZE];
+static GuiFontInfo *
+fontinfo_[NUM_FAMILIES][NUM_SERIES][NUM_SHAPE][NUM_SIZE][NUM_STYLE];
+
+
+// returns a reference to the pointer type (GuiFontInfo *) in the
+// fontinfo_ table.
+GuiFontInfo * & fontinfo_ptr(FontInfo const & f)
+{
+       // The display font and the text font are the same
+       size_t const style = (f.style() == LM_ST_DISPLAY) ? LM_ST_TEXT : f.style();
+       return fontinfo_[f.family()][f.series()][f.realShape()][f.size()][style];
+}
 
 
 // Get font info (font + metrics) for the given LyX font.
 // if not cached, create it.
 GuiFontInfo & fontinfo(FontInfo const & f)
 {
-       // LASSERT: Is there anything we might do here besides crash?
-       LBUFERR(f.family() < NUM_FAMILIES);
-       LBUFERR(f.series() < NUM_SERIES);
-       LBUFERR(f.realShape() < NUM_SHAPE);
-       LBUFERR(f.size() < NUM_SIZE);
-       // fi is a reference to the pointer type (GuiFontInfo *) in the
-       // fontinfo_ table.
-       GuiFontInfo * & fi =
-               fontinfo_[f.family()][f.series()][f.realShape()][f.size()];
+    bool const fontIsRealized =
+            (f.family() < NUM_FAMILIES) &&
+            (f.series() < NUM_SERIES) &&
+            (f.realShape() < NUM_SHAPE) &&
+            (f.size() < NUM_SIZE);
+    if (!fontIsRealized) {
+        // We can reset the font to something sensible in release mode.
+        LATTEST(false);
+        LYXERR0("Unrealized font!");
+        FontInfo f2 = f;
+        f2.realize(sane_font);
+        GuiFontInfo * & fi = fontinfo_ptr(f2);
+        if (!fi)
+            fi = new GuiFontInfo(f2);
+        return *fi;
+    }
+    GuiFontInfo * & fi = fontinfo_ptr(f);
        if (!fi)
                fi = new GuiFontInfo(f);
        return *fi;
@@ -216,7 +234,7 @@ QFont symbolFont(QString const & family, bool * ok)
        return font;
 }
 
-} // namespace anon
+} // namespace
 
 
 FontLoader::FontLoader()
@@ -236,7 +254,8 @@ FontLoader::FontLoader()
                for (int i2 = 0; i2 < NUM_SERIES; ++i2)
                        for (int i3 = 0; i3 < NUM_SHAPE; ++i3)
                                for (int i4 = 0; i4 < NUM_SIZE; ++i4)
-                                       fontinfo_[i1][i2][i3][i4] = 0;
+                                       for (int i5 = 0; i5 < NUM_STYLE; ++i5)
+                                               fontinfo_[i1][i2][i3][i4][i5] = 0;
 }
 
 
@@ -245,9 +264,10 @@ void FontLoader::update()
        for (int i1 = 0; i1 < NUM_FAMILIES; ++i1)
                for (int i2 = 0; i2 < NUM_SERIES; ++i2)
                        for (int i3 = 0; i3 < NUM_SHAPE; ++i3)
-                               for (int i4 = 0; i4 < NUM_SIZE; ++i4) {
-                                       delete fontinfo_[i1][i2][i3][i4];
-                                       fontinfo_[i1][i2][i3][i4] = 0;
+                               for (int i4 = 0; i4 < NUM_SIZE; ++i4)
+                                       for (int i5 = 0; i5 < NUM_STYLE; ++i5) {
+                                       delete fontinfo_[i1][i2][i3][i4][i5];
+                                       fontinfo_[i1][i2][i3][i4][i5] = 0;
                                }
 }
 
@@ -281,7 +301,7 @@ QFont makeQFont(FontInfo const & f)
                switch (f.family()) {
                case ROMAN_FAMILY: {
                        QString family = makeFontName(toqstr(lyxrc.roman_font_name),
-                               toqstr(lyxrc.roman_font_foundry)); 
+                               toqstr(lyxrc.roman_font_foundry));
                        font.setFamily(family);
 #ifdef Q_OS_MAC
 #if QT_VERSION >= 0x040300 //&& QT_VERSION < 0x040800
@@ -343,15 +363,14 @@ QFont makeQFont(FontInfo const & f)
 
        LYXERR(Debug::FONT, "XFLD: " << font.rawName());
 
-       font.setPointSizeF(convert<double>(lyxrc.font_sizes[f.size()])
-                              * lyxrc.zoom / 100.0);
+       font.setPointSizeF(f.realSize() * lyxrc.currentZoom / 100.0);
 
        LYXERR(Debug::FONT, "The font has size: " << font.pointSizeF());
 
        return font;
 }
 
-} // anon namespace
+} // namespace
 
 
 GuiFontInfo::GuiFontInfo(FontInfo const & f)