changeset 2137:461ec057e8b8

prefer fontFamily over fontStyle should a desired font not exist This fixes missing characters on chinese websites if there specfied font has no italic variant.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 18 Jul 2011 20:52:00 +0200
parents b731a4e0714d
children 27cbf3c78acf
files dw/fltkplatform.cc dw/fltkplatform.hh
diffstat 2 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkplatform.cc	Sat Jul 16 17:13:30 2011 -0400
+++ b/dw/fltkplatform.cc	Mon Jul 18 20:52:00 2011 +0200
@@ -63,14 +63,18 @@
                              FltkFont::FontFamily> *FltkFont::systemFonts =
                              NULL;
 
-FltkFont::FontFamily FltkFont::standardFontFamily;
+FltkFont::FontFamily FltkFont::standardFontFamily (FL_HELVETICA,
+                                                   FL_HELVETICA_BOLD,
+                                                   FL_HELVETICA_ITALIC,
+                                                   FL_HELVETICA_BOLD_ITALIC);
 
-FltkFont::FontFamily::FontFamily ()
+FltkFont::FontFamily::FontFamily (Fl_Font fontNormal, Fl_Font fontBold,
+                                  Fl_Font fontItalic, Fl_Font fontBoldItalic)
 {
-   font[0] = FL_HELVETICA;
-   font[1] = FL_HELVETICA_BOLD;
-   font[2] = FL_HELVETICA_ITALIC;
-   font[3] = FL_HELVETICA_BOLD_ITALIC;
+   font[0] = fontNormal;
+   font[1] = fontBold;
+   font[2] = fontItalic;
+   font[3] = fontBoldItalic;
 }
 
 void FltkFont::FontFamily::set (Fl_Font f, int attrs)
@@ -90,7 +94,10 @@
       idx += 1;
    if (attrs & FL_ITALIC)
       idx += 2;
-   return font[idx];
+
+   // should the desired font style not exist, we
+   // return the normal font of the fontFamily
+   return font[idx] >= 0 ? font[idx] : font[0];
 }
 
 
@@ -163,7 +170,9 @@
          family->set ((Fl_Font) i, t);
          delete familyName;
       } else {
-         family = new FontFamily ();
+         // set first font of family also as normal font in case there 
+         // is no normal (non-bold, non-italic) font
+         family = new FontFamily ((Fl_Font) i, -1, -1, -1);
          family->set ((Fl_Font) i, t);
          systemFonts->put (familyName, family);
       }
--- a/dw/fltkplatform.hh	Sat Jul 16 17:13:30 2011 -0400
+++ b/dw/fltkplatform.hh	Mon Jul 18 20:52:00 2011 +0200
@@ -17,7 +17,8 @@
    class FontFamily: public lout::object::Object {
          Fl_Font font[4];
       public:
-         FontFamily ();
+         FontFamily (Fl_Font fontNormal, Fl_Font fontBold,
+                     Fl_Font fontItalic, Fl_Font fontBoldItalic);
          void set (Fl_Font, int attrs);
          Fl_Font get (int attrs);
    };