aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/XmbFontImp.cc
diff options
context:
space:
mode:
authorsimonb <simonb>2006-05-07 03:41:27 (GMT)
committersimonb <simonb>2006-05-07 03:41:27 (GMT)
commit520f552be79581be50156bb7785e7ef0ce946b07 (patch)
tree82edcbb794f6b89804a2a7f75e0122afcc074f94 /src/FbTk/XmbFontImp.cc
parent0e9fa988ff41cc32a390f70443669a6df45f3e44 (diff)
downloadfluxbox-520f552be79581be50156bb7785e7ef0ce946b07.zip
fluxbox-520f552be79581be50156bb7785e7ef0ce946b07.tar.bz2
handle utf-8 strings properly.
use utf8 internally
Diffstat (limited to 'src/FbTk/XmbFontImp.cc')
-rw-r--r--src/FbTk/XmbFontImp.cc31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/FbTk/XmbFontImp.cc b/src/FbTk/XmbFontImp.cc
index 87eed8f..160b0be 100644
--- a/src/FbTk/XmbFontImp.cc
+++ b/src/FbTk/XmbFontImp.cc
@@ -123,7 +123,9 @@ XFontSet createFontSet(const char *fontname, bool& utf8mode) {
123#ifdef HAVE_SETLOCALE 123#ifdef HAVE_SETLOCALE
124 if (utf8mode) { 124 if (utf8mode) {
125 orig_locale = setlocale(LC_CTYPE, NULL); 125 orig_locale = setlocale(LC_CTYPE, NULL);
126 setlocale(LC_CTYPE, "UTF-8"); 126 if (setlocale(LC_CTYPE, "UTF-8") == NULL) {
127 utf8mode = false;
128 }
127 } 129 }
128#endif // HAVE_SETLOCALE 130#endif // HAVE_SETLOCALE
129 fs = XCreateFontSet(display, 131 fs = XCreateFontSet(display,
@@ -146,11 +148,13 @@ XFontSet createFontSet(const char *fontname, bool& utf8mode) {
146 fs = XCreateFontSet(display, fontname, 148 fs = XCreateFontSet(display, fontname,
147 &missing, &nmissing, &def); 149 &missing, &nmissing, &def);
148 setlocale(LC_CTYPE, orig_locale.c_str()); 150 setlocale(LC_CTYPE, orig_locale.c_str());
151 return fs;
149 } 152 }
150 if (utf8mode) 153 if (utf8mode)
151 setlocale(LC_CTYPE, orig_locale.c_str()); 154 setlocale(LC_CTYPE, orig_locale.c_str());
152#endif // HAVE_SETLOCALE 155#endif // HAVE_SETLOCALE
153 156
157 // set to false because our strings won't be utf8-happy
154 utf8mode = false; 158 utf8mode = false;
155 159
156 return fs; 160 return fs;
@@ -186,7 +190,7 @@ bool XmbFontImp::load(const std::string &fontname) {
186 return true; 190 return true;
187} 191}
188 192
189void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const char *text, 193void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const FbString &text,
190 size_t len, int x, int y, FbTk::Orientation orient) const { 194 size_t len, int x, int y, FbTk::Orientation orient) const {
191 195
192 if (m_fontset == 0) 196 if (m_fontset == 0)
@@ -197,13 +201,16 @@ void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const cha
197 if (m_utf8mode) { 201 if (m_utf8mode) {
198 Xutf8DrawString(d.display(), d.drawable(), m_fontset, 202 Xutf8DrawString(d.display(), d.drawable(), m_fontset,
199 main_gc, x, y, 203 main_gc, x, y,
200 text, len); 204 text.data(), len);
201 } else 205 } else
202#endif //X_HAVE_UTF8_STRING 206#endif //X_HAVE_UTF8_STRING
203 { 207 {
208 std::string localestr = text;
209 localestr.erase(len, std::string::npos);
210 localestr = FbStringUtil::FbStrToLocale(localestr);
204 XmbDrawString(d.display(), d.drawable(), m_fontset, 211 XmbDrawString(d.display(), d.drawable(), m_fontset,
205 main_gc, x, y, 212 main_gc, x, y,
206 text, len); 213 localestr.data(), localestr.size());
207 } 214 }
208 return; 215 return;
209 } 216 }
@@ -233,13 +240,16 @@ void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const cha
233 if (m_utf8mode) { 240 if (m_utf8mode) {
234 Xutf8DrawString(dpy, canvas.drawable(), m_fontset, 241 Xutf8DrawString(dpy, canvas.drawable(), m_fontset,
235 font_gc.gc(), xpos, ypos, 242 font_gc.gc(), xpos, ypos,
236 text, len); 243 text.data(), len);
237 } else 244 } else
238#endif //X_HAVE_UTF8_STRING 245#endif //X_HAVE_UTF8_STRING
239 { 246 {
247 std::string localestr = text;
248 localestr.erase(len, std::string::npos);
249 localestr = FbStringUtil::FbStrToLocale(localestr);
240 XmbDrawString(dpy, canvas.drawable(), m_fontset, 250 XmbDrawString(dpy, canvas.drawable(), m_fontset,
241 font_gc.gc(), xpos, ypos, 251 font_gc.gc(), xpos, ypos,
242 text, len); 252 localestr.data(), localestr.size());
243 } 253 }
244 254
245 canvas.rotate(orient); 255 canvas.rotate(orient);
@@ -268,21 +278,24 @@ void XmbFontImp::drawText(const FbDrawable &d, int screen, GC main_gc, const cha
268 278
269} 279}
270 280
271unsigned int XmbFontImp::textWidth(const char * const text, unsigned int len) const { 281unsigned int XmbFontImp::textWidth(const FbString &text, unsigned int len) const {
272 if (m_fontset == 0) 282 if (m_fontset == 0)
273 return 0; 283 return 0;
274 284
275 XRectangle ink, logical; 285 XRectangle ink, logical;
276#ifdef X_HAVE_UTF8_STRING 286#ifdef X_HAVE_UTF8_STRING
277 if (m_utf8mode) { 287 if (m_utf8mode) {
278 Xutf8TextExtents(m_fontset, text, len, 288 Xutf8TextExtents(m_fontset, text.data(), len,
279 &ink, &logical); 289 &ink, &logical);
280 if (logical.width != 0) 290 if (logical.width != 0)
281 return logical.width; 291 return logical.width;
282 } 292 }
283#endif // X_HAVE_UTF8_STRING 293#endif // X_HAVE_UTF8_STRING
284 294
285 XmbTextExtents(m_fontset, text, len, 295 std::string localestr = text;
296 localestr.erase(len, std::string::npos);
297 localestr = FbStringUtil::FbStrToLocale(localestr);
298 XmbTextExtents(m_fontset, localestr.data(), localestr.size(),
286 &ink, &logical); 299 &ink, &logical);
287 return logical.width; 300 return logical.width;
288} 301}