changeset 1884:3ce2150fae16

implement FltkPlatform::fontExists() + other font handling improvements
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Fri, 28 Jan 2011 21:40:19 +0100
parents 7869218e7309
children 99573d6ceed0
files dw/fltkplatform.cc dw/fltkplatform.hh
diffstat 2 files changed, 25 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkplatform.cc	Thu Jan 27 23:14:33 2011 +0100
+++ b/dw/fltkplatform.cc	Fri Jan 28 21:40:19 2011 +0100
@@ -44,9 +44,14 @@
 container::typed::HashTable <lout::object::ConstString,
                              FltkFont::FontFamily> *FltkFont::systemFonts = NULL;
 
+FltkFont::FontFamily FltkFont::standardFontFamily;
+
 FltkFont::FontFamily::FontFamily ()
 {
-   font[0] = font[1] = font[2] = font[3] = 0;
+   font[0] = FL_HELVETICA;
+   font[1] = FL_HELVETICA_BOLD;
+   font[2] = FL_HELVETICA_ITALIC;
+   font[3] = FL_HELVETICA_BOLD_ITALIC;
 }
 
 void FltkFont::FontFamily::set (Fl_Font f, int attrs)
@@ -101,30 +106,21 @@
       fa |= FL_BOLD;
    if (style != core::style::FONT_STYLE_NORMAL)
       fa |= FL_ITALIC;
+
    object::ConstString nameString (name);
    FontFamily *family = systemFonts->get (&nameString);
+   if (!family)
+      family = &standardFontFamily;
 
-   font = 0;
-   if (family)
-      font = family->get (fa);
-
-   if (font == 0) {
-      font = FL_HELVETICA;
-      font |= fa;
-   }
+   font = family->get (fa);
 
    fl_font(font, size);
    spaceWidth = misc::max(0, (int)fl_width(' ') + letterSpacing);
-   int xh, xw = 0;
-   fl_measure("x", xw, xh, 0);
+   int xx, xy, xw, xh;
+   fl_text_extents("x", xx, xy, xw, xh);
    xHeight = xh;
-   descent = (int)fl_descent();
-   ascent = (int)fl_height() - descent;
-
-   /**
-    * \bug The code above does not seem to work, so this workaround.
-    */
-   xHeight = ascent * 3 / 5;
+   descent = fl_descent();
+   ascent = fl_height() - descent;
 }
 
 FltkFont::~FltkFont ()
@@ -133,14 +129,16 @@
 }
 
 bool
+FltkFont::fontExists (const char *name)
+{
+   object::ConstString familyName (name);
+   return systemFonts->get (&familyName) != NULL;
+}
+
+bool
 FltkPlatform::fontExists (const char *name)
 {
-#if 0
-PORT1.3
-   return ::fltk::font(name) != NULL;
-#else
-   return true;
-#endif
+   return FltkFont::fontExists (name);
 }
 
 FltkFont*
--- a/dw/fltkplatform.hh	Thu Jan 27 23:14:33 2011 +0100
+++ b/dw/fltkplatform.hh	Fri Jan 28 21:40:19 2011 +0100
@@ -22,6 +22,8 @@
          Fl_Font get (int attrs);
    };
 
+   static FontFamily standardFontFamily;
+
    static lout::container::typed::HashTable <lout::object::ConstString,
                                              FontFamily> *systemFonts;
    static lout::container::typed::HashTable <dw::core::style::FontAttrs,
@@ -34,6 +36,7 @@
    Fl_Font font;
 
    static FltkFont *create (core::style::FontAttrs *attrs);
+   static bool fontExists (const char *name);
 };