aboutsummaryrefslogtreecommitdiff
path: root/libX11/src/imConv.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-06-28 22:07:26 +0000
committermarha <marha@users.sourceforge.net>2009-06-28 22:07:26 +0000
commit3562e78743202e43aec8727005182a2558117eca (patch)
tree8f9113a77d12470c5c851a2a8e4cb02e89df7d43 /libX11/src/imConv.c
downloadvcxsrv-3562e78743202e43aec8727005182a2558117eca.tar.gz
vcxsrv-3562e78743202e43aec8727005182a2558117eca.tar.bz2
vcxsrv-3562e78743202e43aec8727005182a2558117eca.zip
Checked in the following released items:
xkeyboard-config-1.4.tar.gz ttf-bitstream-vera-1.10.tar.gz font-alias-1.0.1.tar.gz font-sun-misc-1.0.0.tar.gz font-sun-misc-1.0.0.tar.gz font-sony-misc-1.0.0.tar.gz font-schumacher-misc-1.0.0.tar.gz font-mutt-misc-1.0.0.tar.gz font-misc-misc-1.0.0.tar.gz font-misc-meltho-1.0.0.tar.gz font-micro-misc-1.0.0.tar.gz font-jis-misc-1.0.0.tar.gz font-isas-misc-1.0.0.tar.gz font-dec-misc-1.0.0.tar.gz font-daewoo-misc-1.0.0.tar.gz font-cursor-misc-1.0.0.tar.gz font-arabic-misc-1.0.0.tar.gz font-winitzki-cyrillic-1.0.0.tar.gz font-misc-cyrillic-1.0.0.tar.gz font-cronyx-cyrillic-1.0.0.tar.gz font-screen-cyrillic-1.0.1.tar.gz font-xfree86-type1-1.0.1.tar.gz font-adobe-utopia-type1-1.0.1.tar.gz font-ibm-type1-1.0.0.tar.gz font-bitstream-type1-1.0.0.tar.gz font-bitstream-speedo-1.0.0.tar.gz font-bh-ttf-1.0.0.tar.gz font-bh-type1-1.0.0.tar.gz font-bitstream-100dpi-1.0.0.tar.gz font-bh-lucidatypewriter-100dpi-1.0.0.tar.gz font-bh-100dpi-1.0.0.tar.gz font-adobe-utopia-100dpi-1.0.1.tar.gz font-adobe-100dpi-1.0.0.tar.gz font-util-1.0.1.tar.gz font-bitstream-75dpi-1.0.0.tar.gz font-bh-lucidatypewriter-75dpi-1.0.0.tar.gz font-adobe-utopia-75dpi-1.0.1.tar.gz font-bh-75dpi-1.0.0.tar.gz bdftopcf-1.0.1.tar.gz font-adobe-75dpi-1.0.0.tar.gz mkfontscale-1.0.6.tar.gz openssl-0.9.8k.tar.gz bigreqsproto-1.0.2.tar.gz xtrans-1.2.2.tar.gz resourceproto-1.0.2.tar.gz inputproto-1.4.4.tar.gz compositeproto-0.4.tar.gz damageproto-1.1.0.tar.gz zlib-1.2.3.tar.gz xkbcomp-1.0.5.tar.gz freetype-2.3.9.tar.gz pthreads-w32-2-8-0-release.tar.gz pixman-0.12.0.tar.gz kbproto-1.0.3.tar.gz evieext-1.0.2.tar.gz fixesproto-4.0.tar.gz recordproto-1.13.2.tar.gz randrproto-1.2.2.tar.gz scrnsaverproto-1.1.0.tar.gz renderproto-0.9.3.tar.gz xcmiscproto-1.1.2.tar.gz fontsproto-2.0.2.tar.gz xextproto-7.0.3.tar.gz xproto-7.0.14.tar.gz libXdmcp-1.0.2.tar.gz libxkbfile-1.0.5.tar.gz libfontenc-1.0.4.tar.gz libXfont-1.3.4.tar.gz libX11-1.1.5.tar.gz libXau-1.0.4.tar.gz libxcb-1.1.tar.gz xorg-server-1.5.3.tar.gz
Diffstat (limited to 'libX11/src/imConv.c')
-rw-r--r--libX11/src/imConv.c359
1 files changed, 359 insertions, 0 deletions
diff --git a/libX11/src/imConv.c b/libX11/src/imConv.c
new file mode 100644
index 000000000..e30f8ef95
--- /dev/null
+++ b/libX11/src/imConv.c
@@ -0,0 +1,359 @@
+/* $TOG: imConv.c /main/20 1998/06/17 15:46:41 kaleb $ */
+/******************************************************************
+
+ Copyright 1991, 1992 by Fuji Xerox Co.,Ltd.
+ Copyright 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of Fuji Xerox Co.,Ltd.
+, and that the name of FUJITSU LIMITED not be used in advertising or
+publicity pertaining to distribution of the software without specific,
+ written prior permission.
+Fuji Xerox Co.,Ltd. , and FUJITSU LIMITED makes no representations about
+the suitability of this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJI XEROX CO.,LTD. AND FUJITSU LIMITED DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX CO.,LTD.
+AND FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT
+OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+ Auther: Kazunori Nishihara, Fuji Xerox Co.,Ltd.
+ kaz@ssdev.ksp.fujixerox.co.jp
+ Modifier: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+/* 2000 Modifier: Ivan Pascal The XFree86 Project.
+ */
+/* $XFree86: xc/lib/X11/imConv.c,v 1.32 2003/04/13 19:22:20 dawes Exp $ */
+
+#define NEED_EVENTS
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "XlcPubI.h"
+
+#ifdef XKB
+/*
+ * rather than just call _XLookupString (i.e. the pre-XKB XLookupString)
+ * do this because with XKB the event may have some funky modifiers that
+ * _XLookupString doesn't grok.
+ */
+#include "XKBlib.h"
+#define XLOOKUPSTRING lookup_string
+#else
+#define XLOOKUPSTRING XLookupString
+#endif
+
+typedef unsigned int ucs4_t;
+
+typedef int (*ucstocsConvProc)(
+ XPointer,
+ unsigned char *,
+ ucs4_t,
+ int
+);
+
+struct SubstRec {
+ const char encoding_name[8];
+ const char charset_name[12];
+};
+
+static const struct SubstRec SubstTable[] = {
+ {"STRING", "ISO8859-1"},
+ {"TIS620", "TIS620-0"},
+ {"UTF-8", "ISO10646-1"}
+};
+#define num_substitute (sizeof SubstTable / sizeof SubstTable[0])
+
+/*
+ * Given the name of a charset, returns the pointer to convertors
+ * from UCS char to specified charset char.
+ * This converter is needed for _XimGetCharCode subroutine.
+ */
+XPointer
+_XimGetLocaleCode (
+ _Xconst char* encoding_name)
+{
+ XPointer cvt = _Utf8GetConvByName(encoding_name);
+ if (!cvt && encoding_name) {
+ int i;
+ for (i = 0; i < num_substitute; i++)
+ if (!strcmp(encoding_name, SubstTable[i].encoding_name))
+ return _Utf8GetConvByName(SubstTable[i].charset_name);
+ }
+ return cvt;
+}
+
+/*
+ * Returns the locale dependent representation of a keysym.
+ * The locale's encoding is passed in form of pointer to UCS convertor.
+ * The resulting multi-byte sequence is placed starting at buf (a buffer
+ * with nbytes bytes, nbytes should be >= 8) and is NUL terminated.
+ * Returns the length of the resulting multi-byte sequence, excluding the
+ * terminating NUL byte. Return 0 if the keysym is not representable in the
+ * locale
+ */
+/*ARGSUSED*/
+int
+_XimGetCharCode (
+ XPointer ucs_conv,
+ KeySym keysym,
+ unsigned char* buf,
+ int nbytes)
+{
+ int count = 0;
+ ucstocsConvProc cvt = (ucstocsConvProc) ucs_conv;
+ ucs4_t ucs4;
+
+ if (keysym < 0x80) {
+ buf[0] = (char) keysym;
+ count = 1;
+ } else if (cvt) {
+ ucs4 = KeySymToUcs4(keysym);
+ if (ucs4)
+ count = (*cvt)((XPointer)NULL, buf, ucs4, nbytes);
+ }
+
+ if (count < 0)
+ count = 0;
+ if (count>nbytes)
+ return nbytes;
+ if (count<nbytes)
+ buf[count]= '\0';
+ return count;
+}
+
+#ifdef XKB
+static int lookup_string(
+ XKeyEvent* event,
+ char* buffer,
+ int nbytes,
+ KeySym* keysym,
+ XComposeStatus* status)
+{
+ int ret;
+ unsigned ctrls = XkbGetXlibControls (event->display);
+ XkbSetXlibControls (event->display,
+ XkbLC_ForceLatin1Lookup, XkbLC_ForceLatin1Lookup);
+ ret = XLookupString(event, (char *)buffer, nbytes, keysym, status);
+ XkbSetXlibControls (event->display,
+ XkbLC_ForceLatin1Lookup, ctrls);
+ return ret;
+}
+#endif
+
+#define BUF_SIZE (20)
+
+int
+_XimLookupMBText(
+ Xic ic,
+ XKeyEvent* event,
+ char* buffer,
+ int nbytes,
+ KeySym* keysym,
+ XComposeStatus* status)
+{
+ int count;
+ KeySym symbol;
+ Status dummy;
+ Xim im = (Xim)ic->core.im;
+ XimCommonPrivateRec* private = &im->private.common;
+ unsigned char look[BUF_SIZE];
+ ucs4_t ucs4;
+
+ /* force a latin-1 lookup for compatibility */
+ count = XLOOKUPSTRING(event, (char *)buffer, nbytes, &symbol, status);
+ if (keysym != NULL) *keysym = symbol;
+ if ((nbytes == 0) || (symbol == NoSymbol)) return count;
+
+ if (count > 1) {
+ memcpy(look, (char *)buffer,count);
+ look[count] = '\0';
+ if ((count = im->methods->ctstombs(ic->core.im,
+ (char*) look, count,
+ buffer, nbytes, &dummy)) < 0) {
+ count = 0;
+ }
+ } else if ((count == 0) ||
+ (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
+
+ XPointer from = (XPointer) &ucs4;
+ XPointer to = (XPointer) look;
+ int from_len = 1;
+ int to_len = BUF_SIZE;
+ XPointer args[1];
+ XlcCharSet charset;
+ args[0] = (XPointer) &charset;
+ ucs4 = (ucs4_t) KeySymToUcs4(symbol);
+ if (!ucs4)
+ return 0;
+
+ if (_XlcConvert(private->ucstoc_conv,
+ &from, &from_len, &to, &to_len,
+ args, 1 ) != 0) {
+ count = 0;
+ } else {
+ from = (XPointer) look;
+ to = (XPointer) buffer;
+ from_len = BUF_SIZE - to_len;
+ to_len = nbytes;
+ args[0] = (XPointer) charset;
+ if (_XlcConvert(private->cstomb_conv,
+ &from, &from_len, &to, &to_len,
+ args, 1 ) != 0) {
+ count = 0;
+ } else {
+ count = nbytes - to_len;
+ }
+ }
+ }
+ /* FIXME:
+ * we should make sure that if the character is a Latin1 character
+ * and it's on the right side, and we're in a non-Latin1 locale
+ * that this is a valid Latin1 character for this locale.
+ */
+ return count;
+}
+
+int
+_XimLookupWCText(
+ Xic ic,
+ XKeyEvent* event,
+ wchar_t* buffer,
+ int nbytes,
+ KeySym* keysym,
+ XComposeStatus* status)
+{
+ int count;
+ KeySym symbol;
+ Status dummy;
+ Xim im = (Xim)ic->core.im;
+ XimCommonPrivateRec* private = &im->private.common;
+ unsigned char look[BUF_SIZE];
+ ucs4_t ucs4;
+
+ /* force a latin-1 lookup for compatibility */
+ count = XLOOKUPSTRING(event, (char *)look, nbytes, &symbol, status);
+ if (keysym != NULL) *keysym = symbol;
+ if ((nbytes == 0) || (symbol == NoSymbol)) return count;
+
+ if (count > 1) {
+ if ((count = im->methods->ctstowcs(ic->core.im,
+ (char*) look, count,
+ buffer, nbytes, &dummy)) < 0) {
+ count = 0;
+ }
+ } else if ((count == 0) ||
+ (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
+
+ XPointer from = (XPointer) &ucs4;
+ XPointer to = (XPointer) look;
+ int from_len = 1;
+ int to_len = BUF_SIZE;
+ XPointer args[1];
+ XlcCharSet charset;
+ args[0] = (XPointer) &charset;
+ ucs4 = (ucs4_t) KeySymToUcs4(symbol);
+ if (!ucs4)
+ return 0;
+
+ if (_XlcConvert(private->ucstoc_conv,
+ &from, &from_len, &to, &to_len,
+ args, 1 ) != 0) {
+ count = 0;
+ } else {
+ from = (XPointer) look;
+ to = (XPointer) buffer;
+ from_len = BUF_SIZE - to_len;
+ to_len = nbytes;
+ args[0] = (XPointer) charset;
+
+ if (_XlcConvert(private->cstowc_conv,
+ &from, &from_len, &to, &to_len,
+ args, 1 ) != 0) {
+ count = 0;
+ } else {
+ count = nbytes - to_len;
+ }
+ }
+ } else
+ /* FIXME:
+ * we should make sure that if the character is a Latin1 character
+ * and it's on the right side, and we're in a non-Latin1 locale
+ * that this is a valid Latin1 character for this locale.
+ */
+ buffer[0] = look[0];
+
+ return count;
+}
+
+int
+_XimLookupUTF8Text(
+ Xic ic,
+ XKeyEvent* event,
+ char* buffer,
+ int nbytes,
+ KeySym* keysym,
+ XComposeStatus* status)
+{
+ int count;
+ KeySym symbol;
+ Status dummy;
+ Xim im = (Xim)ic->core.im;
+ XimCommonPrivateRec* private = &im->private.common;
+ unsigned char look[BUF_SIZE];
+ ucs4_t ucs4;
+
+ /* force a latin-1 lookup for compatibility */
+ count = XLOOKUPSTRING(event, (char *)buffer, nbytes, &symbol, status);
+ if (keysym != NULL) *keysym = symbol;
+ if ((nbytes == 0) || (symbol == NoSymbol)) return count;
+
+ if (count > 1) {
+ memcpy(look, (char *)buffer,count);
+ look[count] = '\0';
+ if ((count = im->methods->ctstoutf8(ic->core.im,
+ (char*) look, count,
+ buffer, nbytes, &dummy)) < 0) {
+ count = 0;
+ }
+ } else if ((count == 0) ||
+ (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
+
+ XPointer from = (XPointer) &ucs4;
+ int from_len = 1;
+ XPointer to = (XPointer) buffer;
+ int to_len = nbytes;
+
+ ucs4 = (ucs4_t) KeySymToUcs4(symbol);
+ if (!ucs4)
+ return 0;
+
+ if (_XlcConvert(private->ucstoutf8_conv,
+ &from, &from_len, &to, &to_len,
+ NULL, 0) != 0) {
+ count = 0;
+ } else {
+ count = nbytes - to_len;
+ }
+ }
+ /* FIXME:
+ * we should make sure that if the character is a Latin1 character
+ * and it's on the right side, and we're in a non-Latin1 locale
+ * that this is a valid Latin1 character for this locale.
+ */
+ return count;
+}