]> git.pld-linux.org Git - packages/fluxbox.git/blame - fluxbox-fontcache.patch
- fixed
[packages/fluxbox.git] / fluxbox-fontcache.patch
CommitLineData
7b8033e5 1diff -urN fluxbox.orig/src/FbTk/XmbFontImp.cc fluxbox/src/FbTk/XmbFontImp.cc
2--- fluxbox.orig/src/FbTk/XmbFontImp.cc 2004-08-16 11:43:01.921018392 +0200
3+++ fluxbox/src/FbTk/XmbFontImp.cc 2004-08-16 12:21:07.394573600 +0200
4@@ -133,6 +133,7 @@
4ee08cfa 5 if (nmissing) XFreeStringList(missing);
6
7 setlocale(LC_CTYPE, "C");
7b8033e5 8+ cerr << "nmissing! defaulting to C Locale" << endl;
4ee08cfa 9 fs = XCreateFontSet(display, fontname,
10 &missing, &nmissing, &def);
11 setlocale(LC_CTYPE, "");
7b8033e5 12@@ -184,73 +185,101 @@
13
4ee08cfa 14 };
15 namespace FbTk {
7b8033e5 16-
4ee08cfa 17-XmbFontImp::XmbFontImp(const char *filename, bool utf8):m_fontset(0), m_utf8mode(utf8) {
18+std::map <std::string, XmbFontImp::mbFontInfo *> XmbFontImp::fontDict;
7b8033e5 19+void XmbFontImp::freeFont(const std::string &fontname) {
4ee08cfa 20+ std::map <std::string, XmbFontImp::mbFontInfo *>::iterator i;
21+ mbFontInfo *font;
22+ if ((i = XmbFontImp::fontDict.find(fontname)) != fontDict.end()) {
23+ font = i->second;
24+ font->refcount--;
25+ if (font->refcount == 0) {
26+ XFreeFontSet(App::instance()->display(), font->set);
27+ delete font;
28+ XmbFontImp::fontDict.erase(i);
29+ }
30+ }
31+}
4ee08cfa 32+XmbFontImp::XmbFontImp(const char *filename, bool utf8):m_font(0), m_utf8mode(utf8) {
7b8033e5 33 if (filename != 0)
34 load(filename);
4ee08cfa 35 }
36
37 XmbFontImp::~XmbFontImp() {
38- if (m_fontset != 0)
39- XFreeFontSet(App::instance()->display(), m_fontset);
40+ if (m_font != 0)
41+ freeFont(m_font->name);
42 }
43
44 bool XmbFontImp::load(const std::string &fontname) {
45+ std::map <std::string, XmbFontImp::mbFontInfo *>::iterator i;
46+ XmbFontImp::mbFontInfo *font;
47+
48 if (fontname.size() == 0)
49 return false;
50- XFontSet set = createFontSet(fontname.c_str());
51- if (set == 0)
52- return false;
53- if (m_fontset != 0)
54- XFreeFontSet(App::instance()->display(), m_fontset);
55- m_fontset = set;
56- m_setextents = XExtentsOfFontSet(m_fontset);
7b8033e5 57-
4ee08cfa 58+ if ( (i = XmbFontImp::fontDict.find(fontname)) != XmbFontImp::fontDict.end() ) {
59+ /* we"ve already got the font. rock */
60+ font = i->second;
61+ font->refcount++;
62+ m_font = &(*font);
63+ } else {
64+ /* we have to load it anew. */
65+ XFontSet set;
66+ if ( (set = createFontSet(fontname.c_str())) == 0)
67+ return false;
68+ font = new mbFontInfo;
69+ font->set = set;
70+ font->extents = XExtentsOfFontSet(set);
71+ font->name = fontname;
72+ font->refcount = 1;
7b8033e5 73+
4ee08cfa 74+ XmbFontImp::fontDict.insert(std::map <std::string, XmbFontImp::mbFontInfo*>::value_type(fontname, font));
75+ if (m_font) freeFont(m_font->name);
76+ m_font = font;
77+ }
4ee08cfa 78 return true;
79 }
7b8033e5 80
4ee08cfa 81 void XmbFontImp::drawText(Drawable w, int screen, GC gc, const char *text,
82 size_t len, int x, int y) const {
83
84- if (text == 0 || len == 0 || w == 0 || m_fontset == 0)
85+ if (text == 0 || len == 0 || w == 0 || m_font == 0)
86 return;
87 #ifdef X_HAVE_UTF8_STRING
88 if (m_utf8mode) {
89- Xutf8DrawString(App::instance()->display(), w, m_fontset,
7b8033e5 90+ Xutf8DrawString(App::instance()->display(), w, m_font->set,
4ee08cfa 91 gc, x, y,
92 text, len);
93 } else
94 #endif //X_HAVE_UTF8_STRING
95 {
96- XmbDrawString(App::instance()->display(), w, m_fontset,
7b8033e5 97- gc, x, y,
4ee08cfa 98+ XmbDrawString(App::instance()->display(), w, m_font->set,
7b8033e5 99+ gc, x, y,
4ee08cfa 100 text, len);
101 }
102 }
103
104 unsigned int XmbFontImp::textWidth(const char * const text, unsigned int len) const {
105- if (m_fontset == 0)
106+ if (m_font == 0)
107 return 0;
7b8033e5 108
4ee08cfa 109 XRectangle ink, logical;
110 #ifdef X_HAVE_UTF8_STRING
111 if (m_utf8mode) {
112- Xutf8TextExtents(m_fontset, text, len,
113+ Xutf8TextExtents(m_font->set, text, len,
114 &ink, &logical);
7b8033e5 115 if (logical.width != 0)
116 return logical.width;
117 }
4ee08cfa 118 #endif // X_HAVE_UTF8_STRING
4ee08cfa 119
7b8033e5 120- XmbTextExtents(m_fontset, text, len,
121+ XmbTextExtents(m_font->set, text, len,
122 &ink, &logical);
123 return logical.width;
4ee08cfa 124 }
125
126 unsigned int XmbFontImp::height() const {
127- if (m_fontset == 0)
128+ if (m_font == 0)
129 return 0;
130- return m_setextents->max_ink_extent.height;
131+ return m_font->extents->max_ink_extent.height;
132 }
133
134 }; // end namespace FbTk
7b8033e5 135diff -urN fluxbox.orig/src/FbTk/XmbFontImp.hh fluxbox/src/FbTk/XmbFontImp.hh
136--- fluxbox.orig/src/FbTk/XmbFontImp.hh 2004-08-16 11:43:01.922018240 +0200
137+++ fluxbox/src/FbTk/XmbFontImp.hh 2004-08-16 12:07:18.492585856 +0200
4ee08cfa 138@@ -26,6 +26,7 @@
139
140 #include "FontImp.hh"
141
142+#include <map>
143 #include <X11/Xlib.h>
144
145 namespace FbTk {
146@@ -39,12 +40,19 @@
147 virtual void drawText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y) const;
148 unsigned int textWidth(const char * const text, unsigned int len) const;
149 unsigned int height() const;
150- int ascent() const { return m_setextents ? -m_setextents->max_ink_extent.y : 0; }
151- int descent() const { return m_setextents ? m_setextents->max_ink_extent.height + m_setextents->max_ink_extent.y : 0; }
152- bool loaded() const { return m_fontset != 0; }
153+ int ascent() const { return m_font ? -m_font->extents->max_ink_extent.y : 0; }
154+ int descent() const { return m_font ? m_font->extents->max_ink_extent.height + m_font->extents->max_ink_extent.y : 0; }
155+ bool loaded() const { return m_font != 0; }
156 private:
157- XFontSet m_fontset;
158- XFontSetExtents *m_setextents;
159+ struct mbFontInfo {
160+ std::string name;
161+ XFontSet set;
162+ XFontSetExtents *extents;
163+ int refcount;
164+ };
165+ static std::map <std::string, mbFontInfo *> fontDict;
166+ static void freeFont(const std::string &foo);
167+ mbFontInfo *m_font;
168 const bool m_utf8mode;
169 };
170
This page took 0.094512 seconds and 4 git commands to generate.