// // Copyright (C) 1996 Ben Ross // // You may distribute under the terms of the GNU General Public // License as specified in the COPYING file. // // $Id: XeFontTable.C,v 1.2 2001/08/01 11:22:25 ben Exp $ #include #include XeFontTable::~XeFontTable(void) { __gnu_cxx::hash_map::iterator iter = begin(); while (iter != end()) { XFreeFont(gDisplay, iter->second); iter++; } } XFontStruct* XeFontTable::getFont(const char* fontname) { char** fonts; int count; fonts = XListFonts(gDisplay, fontname, 1, &count); if (!count) { XFreeFontNames(fonts); return NULL; } std::string availFont = fonts[0]; __gnu_cxx::hash_map::iterator existing = find(availFont); XFreeFontNames(fonts); if (existing != end()) { #if 0 std::cerr << "XeFontTable::getFont returning existing font: " << availFont << " (" << existing->second->fid << ")" << std::endl; #endif return existing->second; } XFontStruct* theFont = NULL; theFont = XLoadQueryFont(gDisplay, availFont.c_str()); if (!theFont) // Unable to load this font. return NULL; (*this)[availFont] = theFont; return theFont; }