Another string map.

This time the font tables.
This commit is contained in:
2025-08-11 04:01:27 -04:00
parent aa6fdaddb3
commit 06a2b527a6
2 changed files with 15 additions and 23 deletions

View File

@ -52,9 +52,7 @@ container::typed::HashTable <dw::core::style::FontAttrs,
new container::typed::HashTable <dw::core::style::FontAttrs,
FltkFont> (false, false);
container::typed::HashTable <lout::object::ConstString,
FltkFont::FontFamily> *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
<lout::object::ConstString, FontFamily> (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);
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 = std::make_unique< FontFamily >( (Fl_Font) i, -1, -1, -1 );
family->set( (Fl_Font) i, t );
systemFonts->put (familyName, family);
}
}
}
@ -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;
}

View File

@ -25,8 +25,7 @@ class FltkFont: public core::style::Font
static FontFamily standardFontFamily;
static lout::container::typed::HashTable <lout::object::ConstString,
FontFamily> *systemFonts;
static std::optional< std::map< std::string, std::unique_ptr< FontFamily > > > systemFonts;
static lout::container::typed::HashTable <dw::core::style::FontAttrs,
FltkFont> *fontsTable;