Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 36004 | Differences between
and this patch

Collapse All | Expand All

(-)fluxbox-0.9.6.org/src/FbTk/XftFontImp.cc (-5 / +61 lines)
Lines 24-34 Link Here
24
#include "XftFontImp.hh"
24
#include "XftFontImp.hh"
25
#include "App.hh"
25
#include "App.hh"
26
26
27
#include <langinfo.h>  
28
#include <iconv.h>
29
#include <errno.h>
30
27
#ifdef HAVE_CONFIG_H
31
#ifdef HAVE_CONFIG_H
28
#include "config.h"
32
#include "config.h"
29
#endif //HAVE_CONFIG_H
33
#endif //HAVE_CONFIG_H
30
namespace FbTk {
34
namespace FbTk {
31
35
36
  extern "C" {
37
38
    static char * locale_to_utf8 (const char *text)
39
    {      
40
      char *loc;
41
      char *utf_str, *from, *to;
42
      static iconv_t conv = (iconv_t)-1;
43
      size_t from_len, to_len;
44
      size_t r;
45
      if (conv == (iconv_t)-1) {
46
        loc = (char *)strdup (nl_langinfo (CODESET));
47
        conv = iconv_open ("UTF-8", loc);
48
        free (loc);
49
      }
50
      from = (char *)text;
51
      from_len = strlen (text);
52
      to_len = from_len * 6 + 1;
53
      utf_str = to = (char *)malloc ((sizeof (char)) * from_len * 6 + 1);
54
      r = iconv (conv, &from, &from_len, &to, &to_len);
55
      // success or incomplete sequence
56
      if (r != (size_t)-1 || errno == EINVAL) {
57
        *to = '\0';
58
        utf_str = (char *)realloc (utf_str, strlen (utf_str) + 1);
59
        return utf_str;
60
      }
61
      free (utf_str);
62
      return strdup (text);
63
    }
64
  }
65
32
XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0),
66
XftFontImp::XftFontImp(const char *name, bool utf8):m_xftfont(0),
33
                                                    m_utf8mode(utf8) {
67
                                                    m_utf8mode(utf8) {
34
    if (name != 0)
68
    if (name != 0)
Lines 98-112 Link Here
98
                          m_xftfont,
132
                          m_xftfont,
99
                          x, y,
133
                          x, y,
100
                          (XftChar8 *)(text), len);
134
                          (XftChar8 *)(text), len);
101
    } else 
135
    } else {
102
#endif // HAVE_XFT_UTF8_STRING
136
      char *utf_str = locale_to_utf8 (text);
103
	{
137
      size_t utf_len = strlen (utf_str);
138
      XftDrawStringUtf8(draw,
139
                        &xftcolor,
140
                        m_xftfont,
141
                        x, y,
142
                        (XftChar8 *)(utf_str), utf_len);
143
      free (utf_str);
144
    }
145
#else
146
  {
104
            XftDrawString8(draw,
147
            XftDrawString8(draw,
105
                           &xftcolor,
148
                           &xftcolor,
106
                           m_xftfont,
149
                           m_xftfont,
107
                           x, y,
150
                           x, y,
108
                           (XftChar8 *)(text), len);
151
                           (XftChar8 *)(text), len);
109
	}
152
	}
153
#endif // HAVE_XFT_UTF8_STRING
110
154
111
    XftColorFree(disp, DefaultVisual(disp, screen), 
155
    XftColorFree(disp, DefaultVisual(disp, screen), 
112
                 DefaultColormap(disp, screen), &xftcolor);
156
                 DefaultColormap(disp, screen), &xftcolor);
Lines 123-136 Link Here
123
                           m_xftfont,
167
                           m_xftfont,
124
                           (XftChar8 *)text, len,
168
                           (XftChar8 *)text, len,
125
                           &ginfo);
169
                           &ginfo);
126
    } else 
170
    } else {
127
#endif  //HAVE_XFT_UTF8_STRING
171
      char *tmp = strdup(text);
172
      tmp[len] = '\0';
173
      char *utf_str = locale_to_utf8 (tmp);
174
      size_t utf_len = strlen (utf_str);
175
      XftTextExtentsUtf8(App::instance()->display(),
176
                         m_xftfont,
177
                         (XftChar8 *)utf_str, utf_len,
178
                         &ginfo);
179
      free (utf_str);
180
      free (tmp);
181
    }
182
#else
128
	{
183
	{
129
            XftTextExtents8(App::instance()->display(),
184
            XftTextExtents8(App::instance()->display(),
130
                            m_xftfont,
185
                            m_xftfont,
131
                            (XftChar8 *)text, len,
186
                            (XftChar8 *)text, len,
132
                            &ginfo);
187
                            &ginfo);
133
	}
188
	}
189
#endif  //HAVE_XFT_UTF8_STRING
134
    return ginfo.xOff;
190
    return ginfo.xOff;
135
}
191
}
136
192

Return to bug 36004