diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index ab14ef2..f0ac7b5 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -52,9 +52,7 @@ container::typed::HashTable (false, false); -container::typed::HashTable *FltkFont::systemFonts = - NULL; +std::optional< std::map< std::string, std::unique_ptr< FltkFont::FontFamily > > > FltkFont::systemFonts; FltkFont::FontFamily FltkFont::standardFontFamily (FL_HELVETICA, FL_HELVETICA_BOLD, @@ -108,10 +106,12 @@ FltkFont::FltkFont (core::style::FontAttrs *attrs) if (style != core::style::FONT_STYLE_NORMAL) fa |= FL_ITALIC; - object::ConstString nameString (name); - FontFamily *family = systemFonts->get (&nameString); - if (!family) + FontFamily *family= nullptr; + if ( not systemFonts->contains( name ) ) family = &standardFontFamily; + else + family= systemFonts->at( name ).get(); + assert( family ); font = family->get (fa); @@ -141,8 +141,7 @@ static void strstrip(char *big, const char *little) void FltkFont::initSystemFonts () { - systemFonts = new container::typed::HashTable - (true, true); + systemFonts.emplace(); int k = Fl::set_fonts ("-*-iso10646-1"); for (int i = 0; i < k; i++) { @@ -158,19 +157,16 @@ void FltkFont::initSystemFonts () _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) { + auto &family = (*systemFonts)[ name ]; + if( family ) { family->set ((Fl_Font) i, t); - delete familyName; } else { // 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); + family = std::make_unique< FontFamily >( (Fl_Font) i, -1, -1, -1 ); + family->set( (Fl_Font) i, t ); } } } @@ -180,8 +176,7 @@ FltkFont::fontExists (const char *name) { if (!systemFonts) initSystemFonts (); - object::ConstString familyName (name); - return systemFonts->get (&familyName) != NULL; + return systemFonts->contains(name); } Fl_Font @@ -189,10 +184,8 @@ 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); + if( systemFonts->contains( name ) ) + return systemFonts->at( name )->get (attrs); else return FL_HELVETICA; } diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh index 92ac540..134fadc 100644 --- a/dw/fltkplatform.hh +++ b/dw/fltkplatform.hh @@ -25,8 +25,7 @@ class FltkFont: public core::style::Font static FontFamily standardFontFamily; - static lout::container::typed::HashTable *systemFonts; + static std::optional< std::map< std::string, std::unique_ptr< FontFamily > > > systemFonts; static lout::container::typed::HashTable *fontsTable;