changeset 2075:c9511d891f7e

switch fltk font handling to Fl::get_font_name() entirely This seems to give more consitent results when xft is disabled.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Thu, 09 Jun 2011 21:23:44 +0200
parents 9657be74b813
children 859808e6d518
files dw/fltkplatform.cc dw/fltkplatform.hh src/dillo.cc
diffstat 3 files changed, 39 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkplatform.cc	Mon Jun 06 21:04:05 2011 +0200
+++ b/dw/fltkplatform.cc	Thu Jun 09 21:23:44 2011 +0200
@@ -111,17 +111,34 @@
    fontsTable->remove (this);
 }
 
+static void strstrip(char *big, const char *little)
+{
+   if (strlen(big) >= strlen(little) &&
+      strcasecmp(big + strlen(big) - strlen(little), little) == 0)
+      *(big + strlen(big) - strlen(little)) = '\0';
+}
+
 void FltkFont::initSystemFonts ()
 {
    systemFonts = new container::typed::HashTable
       <lout::object::ConstString, FontFamily> (true, true);
 
-   int k = Fl::set_fonts ("-*");
+   int k = Fl::set_fonts ("-*-iso10646-1");
    for (int i = 0; i < k; i++) {
       int t;
-      Fl::get_font_name ((Fl_Font) i, &t);
-      const char *name = Fl::get_font ((Fl_Font) i);
-      object::String *familyName = new object::String(name + 1);
+      char *name = strdup (Fl::get_font_name ((Fl_Font) i, &t));
+
+      // normalize font family names (strip off "bold", "italic")
+      if (t & FL_ITALIC)
+         strstrip(name, " italic");
+      if (t & FL_BOLD)
+         strstrip(name, " bold");
+
+      MSG("Found font: %s%s%s\n", name, t & FL_BOLD ? " bold" : "",
+                                  t & FL_ITALIC ? " italic" : "");
+
+      object::String *familyName = new object::String(name);
+      free (name);
       FontFamily *family = systemFonts->get (familyName);
 
       if (family) {
@@ -144,6 +161,19 @@
    return systemFonts->get (&familyName) != NULL;
 }
 
+Fl_Font
+FltkFont::get (const char *name, int attrs)
+{
+   if (!systemFonts)
+      initSystemFonts ();
+   object::ConstString familyName (name);
+   FontFamily *family = systemFonts->get (&familyName);
+   if (family)
+      return family->get (attrs);
+   else
+      return FL_HELVETICA;
+}
+
 bool
 FltkPlatform::fontExists (const char *name)
 {
--- a/dw/fltkplatform.hh	Mon Jun 06 21:04:05 2011 +0200
+++ b/dw/fltkplatform.hh	Thu Jun 09 21:23:44 2011 +0200
@@ -39,6 +39,7 @@
 
    static FltkFont *create (core::style::FontAttrs *attrs);
    static bool fontExists (const char *name);
+   static Fl_Font get (const char *name, int attrs);
 };
 
 
--- a/src/dillo.cc	Mon Jun 06 21:04:05 2011 +0200
+++ b/src/dillo.cc	Thu Jun 09 21:23:44 2011 +0200
@@ -374,9 +374,10 @@
    checkPreferredFonts();
 
    /* use preferred font for UI */
-   Fl::set_font(FL_HELVETICA, prefs.font_sans_serif); // this seems to be the
-                                                      // only way to set the
-                                                      // default font in fltk1.3
+   Fl_Font defaultFont = dw::fltk::FltkFont::get (prefs.font_sans_serif, 0);
+   Fl::set_font(FL_HELVETICA, defaultFont); // this seems to be the
+                                            // only way to set the
+                                            // default font in fltk1.3
 
    // Create a new UI/bw pair
    BrowserWindow *bw = a_UIcmd_browser_window_new(0, 0, xid, NULL);