]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/xfont_loader.C
remove defaults stuff, let Qt handle no toolbar
[lyx.git] / src / frontends / xforms / xfont_loader.C
index dc1694b4b6f61704199aebf960afbc7e63c59b32..4cd0c45bd6e894e9238648ada211399f9e8d5b76 100644 (file)
@@ -11,9 +11,6 @@
 #include <config.h>
 #include <cmath>       // fabs()
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "xfont_loader.h"
 #include "FontInfo.h"
@@ -22,6 +19,7 @@
 #include "lyxrc.h"     // lyxrc.font_*
 #include "BufferView.h"
 #include "frontends/LyXView.h"
+#include "frontends/lyx_gui.h"
 #include "support/systemcall.h"
 #include "support/filetools.h"
 
@@ -92,6 +90,7 @@ void xfont_loader::unload()
 }
 
 namespace {
+
 string const symbolPattern(LyXFont::FONT_FAMILY family)
 {
        switch (family) {
@@ -124,11 +123,40 @@ string const symbolPattern(LyXFont::FONT_FAMILY family)
 
        default:
                return string();
-       }       
+       }
 }
 
+string const fontName(string const & family, string const & foundry)
+{
+       if (foundry.empty() || foundry == "Xft")
+               return "-*-"+family;
+       else
+               return "-"+foundry+"-"+family;
+}
+
+
+bool addFontPath()
+{
+       string const dir =  OnlyPath(LibFileSearch("xfonts", "fonts.dir"));
+       if (!dir.empty()) {
+               int n;
+               char ** p = XGetFontPath(fl_get_display(), &n);
+               if (std::find(p, p + n, dir) != p + n)
+                       return false;
+               lyxerr[Debug::FONT] << "Adding " << dir
+                                   << " to the font path." << endl;
+               string const command = "xset fp+ " + dir;
+               Systemcall s;
+               if (!s.startscript(Systemcall::Wait, command))
+                       return true;
+               lyxerr << "Unable to add " << dir << "to the font path."
+                      << endl;
+       }
+       return false;
 }
 
+} // namespace anon
+
 // Get font info
 /* Takes care of finding which font that can match the given request. Tries
 different alternatives. */
@@ -149,21 +177,9 @@ void xfont_loader::getFontinfo(LyXFont::FONT_FAMILY family,
                    !fontinfo[family][series][shape]->exist() &&
                    first_time) {
                        first_time = false;
-                       string const dir = 
-                               OnlyPath(LibFileSearch("xfonts", "fonts.dir"));
-                       if (!dir.empty()) {
-                               int n;
-                               char ** p = XGetFontPath(fl_get_display(), &n);
-                               if (std::find(p, p+n, dir) != p+n)
-                                       return;
-                               lyxerr << "Adding " << dir << " to the font path.\n";
-                               string const command = "xset fp+ " + dir;
-                               Systemcall s;
-                               if (!s.startscript(Systemcall::Wait, command)) {
-                                       delete fontinfo[family][series][shape];
-                                       fontinfo[family][series][shape] = new FontInfo(pat);    
-                               } else
-                                       lyxerr << "Unable to add font path.\n";
+                       if (addFontPath()) {
+                               delete fontinfo[family][series][shape];
+                               fontinfo[family][series][shape] = new FontInfo(pat);
                        }
                }
                return;
@@ -185,21 +201,27 @@ void xfont_loader::getFontinfo(LyXFont::FONT_FAMILY family,
                switch (family) {
                case LyXFont::ROMAN_FAMILY:
                        switch (cfam) {
-                       case 0: ffamily = lyxrc.roman_font_name; break;
+                       case 0: ffamily = fontName(lyxrc.roman_font_name,
+                                                  lyxrc.roman_font_foundry);
+                               break;
                        case 1: ffamily = "-*-times";
                        default: cfam = 100;
                        }
                        break;
                case LyXFont::SANS_FAMILY:
                        switch (cfam) {
-                       case 0: ffamily = lyxrc.sans_font_name; break;
+                       case 0: ffamily = fontName(lyxrc.sans_font_name,
+                                                  lyxrc.sans_font_foundry);
+                               break;
                        case 1: ffamily = "-*-helvetica";
                        default: cfam = 100;
                        }
                        break;
                case LyXFont::TYPEWRITER_FAMILY:
                        switch (cfam) {
-                       case 0: ffamily = lyxrc.typewriter_font_name; break;
+                       case 0: ffamily = fontName(lyxrc.typewriter_font_name,
+                                                  lyxrc.typewriter_font_foundry);
+                               break;
                        case 1: ffamily = "-*-courier";
                        default: cfam = 100;
                        }
@@ -283,7 +305,7 @@ XFontStruct * xfont_loader::doLoad(LyXFont::FONT_FAMILY family,
                                LyXFont::FONT_SHAPE shape,
                                LyXFont::FONT_SIZE size)
 {
-       if (!lyxrc.use_gui) {
+       if (!lyx_gui::use_gui) {
                if (!dummyXFontStructisGood) {
                        // no character specific info
                        dummyXFontStruct.per_char = 0;
@@ -345,7 +367,7 @@ XFontStruct * xfont_loader::doLoad(LyXFont::FONT_FAMILY family,
 
 bool xfont_loader::available(LyXFont const & f)
 {
-       if (!lyxrc.use_gui)
+       if (!lyx_gui::use_gui)
                return false;
 
        if (!fontinfo[f.family()][f.series()][f.realShape()])