1 diff -ur fluxbox-0.9.9_20040713.orig/src/FbTk/XmbFontImp.cc fluxbox-0.9.9_20040713/src/FbTk/XmbFontImp.cc
2 --- fluxbox-0.9.9_20040713.orig/src/FbTk/XmbFontImp.cc 2004-02-10 20:03:42.000000000 +0100
3 +++ fluxbox-0.9.9_20040713/src/FbTk/XmbFontImp.cc 2004-07-14 00:46:07.017261128 +0200
5 if (nmissing) XFreeStringList(missing);
7 setlocale(LC_CTYPE, "C");
8 + cerr << "nmissing! defaulting to C Locale" << endl;
9 fs = XCreateFontSet(display, fontname,
10 &missing, &nmissing, &def);
11 setlocale(LC_CTYPE, "");
16 -XmbFontImp::XmbFontImp(const char *filename, bool utf8):m_fontset(0), m_utf8mode(utf8) {
17 +std::map <std::string, XmbFontImp::mbFontInfo *> XmbFontImp::fontDict;
19 +void XmbFontImp::freeFont(const std::string &fontname) {
20 + std::map <std::string, XmbFontImp::mbFontInfo *>::iterator i;
22 + if ((i = XmbFontImp::fontDict.find(fontname)) != fontDict.end()) {
25 + if (font->refcount == 0) {
26 + XFreeFontSet(App::instance()->display(), font->set);
28 + XmbFontImp::fontDict.erase(i);
33 +XmbFontImp::XmbFontImp(const char *filename, bool utf8):m_font(0), m_utf8mode(utf8) {
35 #ifdef X_HAVE_UTF8_STRING
36 cerr<<"Using utf8 = "<<utf8<<endl;
40 XmbFontImp::~XmbFontImp() {
42 - XFreeFontSet(App::instance()->display(), m_fontset);
44 + freeFont(m_font->name);
47 bool XmbFontImp::load(const std::string &fontname) {
48 + std::map <std::string, XmbFontImp::mbFontInfo *>::iterator i;
49 + XmbFontImp::mbFontInfo *font;
51 if (fontname.size() == 0)
53 - XFontSet set = createFontSet(fontname.c_str());
57 - XFreeFontSet(App::instance()->display(), m_fontset);
59 - m_setextents = XExtentsOfFontSet(m_fontset);
60 + if ( (i = XmbFontImp::fontDict.find(fontname)) != XmbFontImp::fontDict.end() ) {
61 + /* we"ve already got the font. rock */
66 + /* we have to load it anew. */
68 + if ( (set = createFontSet(fontname.c_str())) == 0)
70 + font = new mbFontInfo;
72 + font->extents = XExtentsOfFontSet(set);
73 + font->name = fontname;
76 + XmbFontImp::fontDict.insert(std::map <std::string, XmbFontImp::mbFontInfo*>::value_type(fontname, font));
77 + if (m_font) freeFont(m_font->name);
84 void XmbFontImp::drawText(Drawable w, int screen, GC gc, const char *text,
85 size_t len, int x, int y) const {
87 - if (text == 0 || len == 0 || w == 0 || m_fontset == 0)
88 + if (text == 0 || len == 0 || w == 0 || m_font == 0)
90 #ifdef X_HAVE_UTF8_STRING
92 - Xutf8DrawString(App::instance()->display(), w, m_fontset,
93 + Xutf8DrawString(App::instance()->display(), w, m_font->set,
97 #endif //X_HAVE_UTF8_STRING
99 - XmbDrawString(App::instance()->display(), w, m_fontset,
100 + XmbDrawString(App::instance()->display(), w, m_font->set,
106 unsigned int XmbFontImp::textWidth(const char * const text, unsigned int len) const {
107 - if (m_fontset == 0)
110 XRectangle ink, logical;
111 #ifdef X_HAVE_UTF8_STRING
113 - Xutf8TextExtents(m_fontset, text, len,
114 + Xutf8TextExtents(m_font->set, text, len,
117 #endif // X_HAVE_UTF8_STRING
119 - XmbTextExtents(m_fontset, text, len,
120 + XmbTextExtents(m_font->set, text, len,
127 unsigned int XmbFontImp::height() const {
128 - if (m_fontset == 0)
131 - return m_setextents->max_ink_extent.height;
132 + return m_font->extents->max_ink_extent.height;
135 }; // end namespace FbTk
136 diff -ur fluxbox-0.9.9_20040713.orig/src/FbTk/XmbFontImp.hh fluxbox-0.9.9_20040713/src/FbTk/XmbFontImp.hh
137 --- fluxbox-0.9.9_20040713.orig/src/FbTk/XmbFontImp.hh 2003-12-16 18:06:52.000000000 +0100
138 +++ fluxbox-0.9.9_20040713/src/FbTk/XmbFontImp.hh 2004-07-14 00:52:19.028706792 +0200
141 #include "FontImp.hh"
144 #include <X11/Xlib.h>
148 virtual void drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const;
149 unsigned int textWidth(const char * const text, unsigned int len) const;
150 unsigned int height() const;
151 - int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; }
152 - int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; }
153 - bool loaded() const { return m_fontset != 0; }
154 + int ascent() const { return m_font ? -m_font->extents->max_ink_extent.y : 0; }
155 + int descent() const { return m_font ? m_font->extents->max_ink_extent.height + m_font->extents->max_ink_extent.y : 0; }
156 + bool loaded() const { return m_font != 0; }
158 - XFontSet m_fontset;
159 - XFontSetExtents *m_setextents;
160 + struct mbFontInfo {
163 + XFontSetExtents *extents;
166 + static std::map <std::string, mbFontInfo *> fontDict;
167 + static void freeFont(const std::string &foo);
168 + mbFontInfo *m_font;
169 const bool m_utf8mode;