1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team.
26 * GTK+ DirectFB backend
27 * Copyright (C) 2001-2002 convergence integrated media GmbH
28 * Copyright (C) 2002-2004 convergence GmbH
29 * Written by Denis Oliver Kropp <dok@convergence.de> and
30 * Sven Neumann <sven@convergence.de>
38 #include "gdkdirectfb.h"
41 *--------------------------------------------------------------
50 *--------------------------------------------------------------
56 if (!setlocale (LC_ALL,""))
57 g_warning ("locale not supported by C library");
59 return setlocale (LC_ALL, NULL);
64 * Returns a multi-byte string converted from the specified array
65 * of wide characters. The string is newly allocated. The array of
66 * wide characters must be null-terminated. If the conversion is
67 * failed, it returns NULL.
69 * On Win32, we always use UTF-8.
72 gdk_wcstombs (const GdkWChar *src)
82 const GdkWChar c = *wcp++;
90 else if (c < 0x200000)
92 else if (c < 0x4000000)
98 mbstr = g_malloc (len + 1);
117 else if (c < 0x10000)
122 else if (c < 0x200000)
127 else if (c < 0x4000000)
141 case 6: bp[5] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
142 case 5: bp[4] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
143 case 4: bp[3] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
144 case 3: bp[2] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
145 case 2: bp[1] = (c & 0x3f) | 0x80; c >>= 6; /* Fall through */
146 case 1: bp[0] = c | first;
161 * Converts the specified string into GDK wide characters, and,
162 * returns the number of wide characters written. The string 'src'
163 * must be null-terminated. If the conversion is failed, it returns
166 * On Win32, the string is assumed to be in UTF-8. Also note that
167 * GdkWChar is 32 bits, while wchar_t, and the wide characters the
168 * Windows API uses, are 16 bits!
171 /* First a helper function for not zero-terminated strings */
173 gdk_nmbstowcs (GdkWChar *dest,
184 while (cp != end && dest != dest + dest_max)
186 gint i, mask = 0, len;
194 else if ((c & 0xe0) == 0xc0)
199 else if ((c & 0xf0) == 0xe0)
204 else if ((c & 0xf8) == 0xf0)
209 else if ((c & 0xfc) == 0xf8)
214 else if ((c & 0xfc) == 0xfc)
225 *dest = (cp[0] & mask);
226 for (i = 1; i < len; i++)
228 if ((cp[i] & 0xc0) != 0x80)
231 *dest |= (cp[i] & 0x3f);
249 gdk_mbstowcs (GdkWChar *dest,
253 return gdk_nmbstowcs (dest, src, strlen (src), dest_max);
257 /* A version that converts to wchar_t wide chars */
260 gdk_nmbstowchar_ts (wchar_t *dest,
273 while (cp != end && wcp != dest + dest_max)
275 gint i, mask = 0, len;
283 else if ((c & 0xe0) == 0xc0)
288 else if ((c & 0xf0) == 0xe0)
293 else /* Other lengths are not possible with 16-bit wchar_t! */
299 *wcp = (cp[0] & mask);
300 for (i = 1; i < len; i++)
302 if ((cp[i] & 0xc0) != 0x80)
305 *wcp |= (cp[i] & 0x3f);