Sfinx v0.1.0
[sfinx.git] / patches / fltk-1.1.x-locale2utf8.diff
blobd5608b7ce66a0734f5cb7e14c965c54889343a25
1 diff -ur fltk-1.1.x-r5917.o/config.h fltk-1.1.x-r5917/config.h
2 --- fltk-1.1.x-r5917.o/config.h 2007-06-29 21:08:29.000000000 +0300
3 +++ fltk-1.1.x-r5917/config.h 2007-06-29 21:08:57.000000000 +0300
4 @@ -295,6 +295,8 @@
5 #define HAVE_DLFCN_H 1
6 #define HAVE_DLSYM 1
8 +#define LOCALE2UTF8 1
11 * End of "$Id: configh.in 5678 2007-02-08 20:14:30Z mike $".
13 diff -ur fltk-1.1.x-r5917.o/fluid/fluid.cxx fltk-1.1.x-r5917/fluid/fluid.cxx
14 --- fltk-1.1.x-r5917.o/fluid/fluid.cxx 2007-02-20 20:43:10.000000000 +0200
15 +++ fltk-1.1.x-r5917/fluid/fluid.cxx 2007-06-29 21:09:27.000000000 +0300
16 @@ -2170,8 +2170,11 @@
18 #endif
20 +#include <locale.h>
22 int main(int argc,char **argv) {
23 int i = 1;
24 + setlocale(LC_ALL, "");
25 if (!Fl::args(argc,argv,i,arg) || i < argc-1) {
26 fprintf(stderr,"usage: %s <switches> name.fl\n"
27 " -c : write .cxx and .h and exit\n"
28 diff -ur fltk-1.1.x-r5917.o/src/fl_font_xft.cxx fltk-1.1.x-r5917/src/fl_font_xft.cxx
29 --- fltk-1.1.x-r5917.o/src/fl_font_xft.cxx 2006-10-30 16:16:08.000000000 +0200
30 +++ fltk-1.1.x-r5917/src/fl_font_xft.cxx 2007-06-29 21:11:57.000000000 +0300
31 @@ -92,7 +92,7 @@
32 int fl_size_ = 0;
33 XFontStruct* fl_xfont = 0;
34 void *fl_xftfont = 0;
35 -const char* fl_encoding_ = "iso8859-1";
36 +const char* fl_encoding_ = "koi8-r";
37 Fl_FontSize* fl_fontsize = 0;
39 void fl_font(int fnum, int size) {
40 @@ -172,10 +172,36 @@
41 else return -1;
44 +#ifdef LOCALE2UTF8
46 +#include <locale.h>
47 +#include <iconv.h>
48 +#include <langinfo.h>
49 +#include <errno.h>
51 +extern iconv_t iconv_cd;
53 +#endif
55 double fl_width(const char *str, int n) {
56 if (!current_font) return -1.0;
57 XGlyphInfo i;
58 +#ifdef LOCALE2UTF8
59 + size_t insize = n, avail = insize * 2 + 128, t = avail;
60 + char *inptr = (char *)str, *outptr = new char[avail], *out_orig = outptr;
61 + if (!outptr)
62 + Fl::fatal("iconv: unsufficient memory !");
63 + //iconv (iconv_cd, NULL, NULL, &outptr, &t);
64 + t = avail;
65 + size_t nconv = iconv (iconv_cd, &inptr, &insize, &outptr, &avail);
66 + if (nconv == (size_t) -1)
67 + Fl::fatal("iconv error: %s (%s)", strerror(errno), str);
68 + XftTextExtentsUtf8(fl_display, current_font, (XftChar8 *)out_orig,
69 + t - avail, &i);
70 + delete [] out_orig;
71 +#else
72 XftTextExtents8(fl_display, current_font, (XftChar8 *)str, n, &i);
73 +#endif
74 return i.xOff;
77 @@ -259,8 +285,22 @@
78 color.color.green = ((int)g)*0x101;
79 color.color.blue = ((int)b)*0x101;
80 color.color.alpha = 0xffff;
82 - XftDrawString8(draw, &color, current_font, x, y, (XftChar8 *)str, n);
83 +#ifdef LOCALE2UTF8
84 + size_t insize = n, avail = insize * 2 + 128, t = avail;
85 + char *inptr = (char *)str, *outptr = new char[avail], *out_orig = outptr;
86 + if (!outptr)
87 + Fl::fatal("iconv: unsufficient memory !");
88 + // iconv (iconv_cd, NULL, NULL, &outptr, &t);
89 + t = avail;
90 + size_t nconv = iconv (iconv_cd, &inptr, &insize, &outptr, &avail);
91 + if (nconv == (size_t) -1)
92 + Fl::fatal("iconv error: %s (%s)", strerror(errno), str);
93 + XftDrawStringUtf8(draw, &color, current_font, x, y,
94 + (XftChar8 *)out_orig, t - avail);
95 + delete [] out_orig;
96 +#else
97 + XftDrawString8(draw, &color, current_font, x, y, (XftChar8 *)str, n);
98 +#endif
101 void fl_draw(const char* str, int n, float x, float y) {
102 diff -ur fltk-1.1.x-r5917.o/src/Fl_x.cxx fltk-1.1.x-r5917/src/Fl_x.cxx
103 --- fltk-1.1.x-r5917.o/src/Fl_x.cxx 2007-06-18 16:08:57.000000000 +0300
104 +++ fltk-1.1.x-r5917/src/Fl_x.cxx 2007-06-29 21:13:09.000000000 +0300
105 @@ -45,6 +45,15 @@
106 # include <unistd.h>
107 # include <sys/time.h>
109 +#ifdef LOCALE2UTF8
110 +#include <locale.h>
111 +#include <iconv.h>
112 +#include <langinfo.h>
113 +#include <errno.h>
115 +iconv_t iconv_cd;
116 +#endif
118 ////////////////////////////////////////////////////////////////
119 // interface to poll/select call:
121 @@ -360,11 +369,25 @@
122 #if !USE_COLORMAP
123 Fl::visual(FL_RGB);
124 #endif
125 +#ifdef LOCALE2UTF8
126 +// Fl::warning("Code page for iconv is set to \"%s\"", nl_langinfo(CODESET));
127 + iconv_cd = iconv_open ("UTF8", nl_langinfo(CODESET));
128 + if (iconv_cd == (iconv_t) -1) {
129 + if (errno == EINVAL)
130 + Fl::fatal("conversion from \'%s\' to UTF8 not available",
131 + nl_langinfo(CODESET));
132 + else
133 + Fl::fatal("iconv_open: %s", strerror(errno));
135 +#endif
138 void fl_close_display() {
139 Fl::remove_fd(ConnectionNumber(fl_display));
140 XCloseDisplay(fl_display);
141 +#ifdef LOCALE2UTF8
142 + iconv_close (iconv_cd);
143 +#endif
146 static int fl_workarea_xywh[4] = { -1, -1, -1, -1 };