diff options
Diffstat (limited to 'dw')
-rw-r--r-- | dw/fltkplatform.cc | 74 | ||||
-rw-r--r-- | dw/fltkplatform.hh | 10 |
2 files changed, 59 insertions, 25 deletions
diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index d74604c9..e0cc172f 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -42,20 +42,55 @@ container::typed::HashTable <dw::core::style::FontAttrs, FltkFont> (false, false); container::typed::HashTable <lout::object::ConstString, - lout::object::Integer> *FltkFont::systemFonts = NULL; + FltkFont::FontFamily> *FltkFont::systemFonts = NULL; + +FltkFont::FontFamily::FontFamily () +{ + font[0] = font[1] = font[2] = font[3] = 0; +} + +void FltkFont::FontFamily::set (Fl_Font f, int attrs) +{ + int idx = 0; + if (attrs & FL_BOLD) + idx += 1; + if (attrs & FL_ITALIC) + idx += 2; + font[idx] = f; +} + +Fl_Font FltkFont::FontFamily::get (int attrs) +{ + int idx = 0; + if (attrs & FL_BOLD) + idx += 1; + if (attrs & FL_ITALIC) + idx += 2; + return font[idx]; +} FltkFont::FltkFont (core::style::FontAttrs *attrs) { if (!systemFonts) { systemFonts = new container::typed::HashTable - <lout::object::ConstString, lout::object::Integer> (true, true); + <lout::object::ConstString, FontFamily> (true, true); int k = Fl::set_fonts ("-*"); for (int i = 0; i < k; i++) { int t; - const char *name = Fl::get_font_name ((Fl_Font) i, &t); - systemFonts->put(new object::ConstString (name), - new object::Integer (i)); + 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); + } } } @@ -65,27 +100,18 @@ FltkFont::FltkFont (core::style::FontAttrs *attrs) if (weight >= 500) fa |= FL_BOLD; if (style != core::style::FONT_STYLE_NORMAL) - fa |= FL_ITALIC; -#if 0 -PORT1.3 - font = ::fltk::font(name, fa); - if (font == NULL) { - /* - * If using xft, fltk::HELVETICA just means sans, fltk::COURIER - * means mono, and fltk::TIMES means serif. - */ - font = FL_HELVETICA->plus (fa); - } -#else - object::ConstString *nameString = new object::ConstString (name); - object::Integer *fontIndex = systemFonts->get(nameString); - delete nameString; - if (fontIndex) { - font = fontIndex->getValue (); - } else { + fa |= FL_ITALIC; + object::ConstString nameString (name); + FontFamily *family = systemFonts->get (&nameString); + + font = 0; + if (family) + font = family->get (fa); + + if (font == 0) { font = FL_HELVETICA; + font |= fa; } -#endif fl_font(font, size); spaceWidth = misc::max(0, (int)fl_width(' ') + letterSpacing); diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh index d26dad09..9bc2aca7 100644 --- a/dw/fltkplatform.hh +++ b/dw/fltkplatform.hh @@ -14,8 +14,16 @@ namespace fltk { class FltkFont: public core::style::Font { + class FontFamily: public lout::object::Object { + Fl_Font font[4]; + public: + FontFamily (); + void set (Fl_Font, int attrs); + Fl_Font get (int attrs); + }; + static lout::container::typed::HashTable <lout::object::ConstString, - lout::object::Integer> *systemFonts; + FontFamily> *systemFonts; static lout::container::typed::HashTable <dw::core::style::FontAttrs, FltkFont> *fontsTable; |