changeset 2074:9657be74b813

port preferred font code to fltk-1.3
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 06 Jun 2011 21:04:05 +0200
parents 136471768e3c
children c9511d891f7e
files dw/fltkplatform.cc dw/fltkplatform.hh src/dillo.cc
diffstat 3 files changed, 41 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkplatform.cc	Wed Jun 01 23:32:38 2011 +0000
+++ b/dw/fltkplatform.cc	Mon Jun 06 21:04:05 2011 +0200
@@ -75,30 +75,12 @@
    return font[idx];
 }
 
+
+
 FltkFont::FltkFont (core::style::FontAttrs *attrs)
 {
-   if (!systemFonts) {
-      systemFonts = new container::typed::HashTable
-         <lout::object::ConstString, FontFamily> (true, true);
-
-      int k = Fl::set_fonts ("-*");
-      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);
-         FontFamily *family = systemFonts->get (familyName);
-
-         if (family) {
-            family->set ((Fl_Font) i, t);
-            delete familyName;
-         } else {
-            family = new FontFamily ();
-            family->set ((Fl_Font) i, t);
-            systemFonts->put (familyName, family);
-         }
-      }
-   }
+   if (!systemFonts)
+      initSystemFonts ();
 
    copyAttrs (attrs);
 
@@ -129,9 +111,35 @@
    fontsTable->remove (this);
 }
 
+void FltkFont::initSystemFonts ()
+{
+   systemFonts = new container::typed::HashTable
+      <lout::object::ConstString, FontFamily> (true, true);
+
+   int k = Fl::set_fonts ("-*");
+   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);
+      FontFamily *family = systemFonts->get (familyName);
+
+      if (family) {
+         family->set ((Fl_Font) i, t);
+         delete familyName;
+      } else {
+         family = new FontFamily ();
+         family->set ((Fl_Font) i, t);
+         systemFonts->put (familyName, family);
+      }
+   }
+}
+
 bool
 FltkFont::fontExists (const char *name)
 {
+   if (!systemFonts)
+      initSystemFonts ();
    object::ConstString familyName (name);
    return systemFonts->get (&familyName) != NULL;
 }
--- a/dw/fltkplatform.hh	Wed Jun 01 23:32:38 2011 +0000
+++ b/dw/fltkplatform.hh	Mon Jun 06 21:04:05 2011 +0200
@@ -32,6 +32,8 @@
    FltkFont (core::style::FontAttrs *attrs);
    ~FltkFont ();
 
+   static void initSystemFonts ();
+
 public:
    Fl_Font font;
 
--- a/src/dillo.cc	Wed Jun 01 23:32:38 2011 +0000
+++ b/src/dillo.cc	Mon Jun 06 21:04:05 2011 +0200
@@ -48,6 +48,8 @@
 #include "cookies.h"
 #include "auth.h"
 
+#include "dw/fltkcore.hh"
+
 /*
  * Command line options structure
  */
@@ -213,14 +215,12 @@
    fl_measure(o->value, W, H, interpret_symbols);
 }
 
-#if 0
-PORT1.3
 /*
  * Tell the user if default/pref fonts can't be found.
  */
 static void checkFont(const char *name, const char *type)
 {
-   if (::fltk::font(name) == NULL)
+   if (! dw::fltk::FltkFont::fontExists(name))
       MSG_WARN("preferred %s font \"%s\" not found.\n", type, name);
 }
 
@@ -232,7 +232,7 @@
    checkFont(prefs.font_cursive, "cursive");
    checkFont(prefs.font_fantasy, "fantasy");
 }
-#endif
+
 /*
  * Given a command line argument, build a DilloUrl for it.
  */
@@ -371,16 +371,13 @@
    // Use to permit '&' interpretation.
    Fl::set_labeltype(FL_FREE_LABELTYPE,custMenuLabelDraw,custMenuLabelMeasure);
 
-#if 0
-PORT1.3
    checkPreferredFonts();
+
    /* use preferred font for UI */
-   fltk::Font *dfont = fltk::font(prefs.font_sans_serif, 0);
-   if (dfont) {
-      fltk::Widget::default_style->textfont(dfont);
-      fltk::Widget::default_style->labelfont(dfont);
-   }
-#endif
+   Fl::set_font(FL_HELVETICA, prefs.font_sans_serif); // 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);