diff options
author | simonb <simonb> | 2006-05-07 03:41:27 (GMT) |
---|---|---|
committer | simonb <simonb> | 2006-05-07 03:41:27 (GMT) |
commit | 520f552be79581be50156bb7785e7ef0ce946b07 (patch) | |
tree | 82edcbb794f6b89804a2a7f75e0122afcc074f94 /src/FbTk/XFontImp.cc | |
parent | 0e9fa988ff41cc32a390f70443669a6df45f3e44 (diff) | |
download | fluxbox-520f552be79581be50156bb7785e7ef0ce946b07.zip fluxbox-520f552be79581be50156bb7785e7ef0ce946b07.tar.bz2 |
handle utf-8 strings properly.
use utf8 internally
Diffstat (limited to 'src/FbTk/XFontImp.cc')
-rw-r--r-- | src/FbTk/XFontImp.cc | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/FbTk/XFontImp.cc b/src/FbTk/XFontImp.cc index 1bf54a7..f356224 100644 --- a/src/FbTk/XFontImp.cc +++ b/src/FbTk/XFontImp.cc | |||
@@ -81,7 +81,7 @@ bool XFontImp::load(const std::string &fontname) { | |||
81 | return true; | 81 | return true; |
82 | } | 82 | } |
83 | 83 | ||
84 | void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *text, size_t len, int x, int y, FbTk::Orientation orient) const { | 84 | void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const { |
85 | if (m_fontstruct == 0) | 85 | if (m_fontstruct == 0) |
86 | return; | 86 | return; |
87 | 87 | ||
@@ -91,15 +91,23 @@ void XFontImp::drawText(const FbDrawable &w, int screen, GC gc, const char *text | |||
91 | return; | 91 | return; |
92 | } | 92 | } |
93 | 93 | ||
94 | std::string localestr = text; | ||
95 | localestr.erase(len, std::string::npos); | ||
96 | localestr = FbStringUtil::FbStrToLocale(localestr); | ||
97 | |||
94 | XSetFont(w.display(), gc, m_fontstruct->fid); | 98 | XSetFont(w.display(), gc, m_fontstruct->fid); |
95 | XDrawString(w.display(), w.drawable(), gc, x, y, text, len); | 99 | XDrawString(w.display(), w.drawable(), gc, x, y, localestr.data(), localestr.size()); |
96 | } | 100 | } |
97 | 101 | ||
98 | unsigned int XFontImp::textWidth(const char * const text, unsigned int size) const { | 102 | unsigned int XFontImp::textWidth(const FbString &text, unsigned int size) const { |
99 | if (text == 0 || m_fontstruct == 0) | 103 | if (text.empty() || m_fontstruct == 0) |
100 | return 0; | 104 | return 0; |
101 | 105 | ||
102 | return XTextWidth(m_fontstruct, text, size); | 106 | std::string localestr = text; |
107 | localestr.erase(size, std::string::npos); | ||
108 | localestr = FbStringUtil::FbStrToLocale(localestr); | ||
109 | |||
110 | return XTextWidth(m_fontstruct, localestr.data(), localestr.size()); | ||
103 | } | 111 | } |
104 | 112 | ||
105 | unsigned int XFontImp::height() const { | 113 | unsigned int XFontImp::height() const { |
@@ -308,7 +316,7 @@ void XFontImp::freeRotFont(XRotFontStruct *rotfont) { | |||
308 | rotfont = 0; | 316 | rotfont = 0; |
309 | } | 317 | } |
310 | 318 | ||
311 | void XFontImp::drawRotText(Drawable w, int screen, GC gc, const char *text, size_t len, int x, int y, FbTk::Orientation orient) const { | 319 | void XFontImp::drawRotText(Drawable w, int screen, GC gc, const FbString &text, size_t len, int x, int y, FbTk::Orientation orient) const { |
312 | 320 | ||
313 | Display *dpy = App::instance()->display(); | 321 | Display *dpy = App::instance()->display(); |
314 | static GC my_gc = 0; | 322 | static GC my_gc = 0; |
@@ -316,7 +324,7 @@ void XFontImp::drawRotText(Drawable w, int screen, GC gc, const char *text, size | |||
316 | 324 | ||
317 | XRotFontStruct *rotfont = m_rotfonts[orient]; | 325 | XRotFontStruct *rotfont = m_rotfonts[orient]; |
318 | 326 | ||
319 | if (text == NULL || len<1) | 327 | if (text.empty() || len<1) |
320 | return; | 328 | return; |
321 | 329 | ||
322 | if (my_gc == 0) | 330 | if (my_gc == 0) |
@@ -327,10 +335,16 @@ void XFontImp::drawRotText(Drawable w, int screen, GC gc, const char *text, size | |||
327 | // vertical or upside down | 335 | // vertical or upside down |
328 | 336 | ||
329 | XSetFillStyle(dpy, my_gc, FillStippled); | 337 | XSetFillStyle(dpy, my_gc, FillStippled); |
338 | std::string localestr = text; | ||
339 | localestr.erase(len, std::string::npos); | ||
340 | localestr = FbStringUtil::FbStrToLocale(localestr); | ||
341 | const char *ctext = localestr.data(); | ||
342 | len = localestr.size(); | ||
343 | |||
330 | 344 | ||
331 | // loop through each character in texting | 345 | // loop through each character in texting |
332 | for (size_t i = 0; i<len; i++) { | 346 | for (size_t i = 0; i<len; i++) { |
333 | ichar = text[i]-32; | 347 | ichar = ctext[i]-32; |
334 | 348 | ||
335 | // make sure it's a printing character | 349 | // make sure it's a printing character |
336 | if (ichar >= 0 && ichar<95) { | 350 | if (ichar >= 0 && ichar<95) { |