summaryrefslogtreecommitdiff
path: root/src/xutf8
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2009-03-18 04:47:01 +0000
committerGreg Ercolano <erco@seriss.com>2009-03-18 04:47:01 +0000
commit6cbde8909b551f9561f0a06c210fb9fc059c4485 (patch)
tree3d24e8bf8197cd62ccc5662523d0e88428d2e3a5 /src/xutf8
parent5d601837b99ceb6285718034959bf38ca4a749cb (diff)
xutf8 files code conformance:
o C files containing C++ "//" comments -> C style "/* */" comments o Converted unintended doxygen style comments to regular C comments o FLTK brace/indent coding standard conformance o Tested linux + sgi o Avoided mods to xutf8/lcUniConv [libiconv/FSF code] to avoid unwanted diffs with future updates of that lib as per Fabien's fltk.dev request 03/14/09. (Those files already compliant anyway) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6698 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/xutf8')
-rw-r--r--src/xutf8/case.c180
-rw-r--r--src/xutf8/is_right2left.c78
-rw-r--r--src/xutf8/is_spacing.c109
-rw-r--r--src/xutf8/keysym2Ucs.c6
-rw-r--r--src/xutf8/test.c379
-rw-r--r--src/xutf8/test2.c285
-rw-r--r--src/xutf8/ucs2fontmap.c13
-rw-r--r--src/xutf8/utf8Input.c649
-rw-r--r--src/xutf8/utf8Utils.c333
-rw-r--r--src/xutf8/utf8Wrap.c1509
-rw-r--r--src/xutf8/utils/conv_gen.c268
-rw-r--r--src/xutf8/utils/convert_map.c260
-rw-r--r--src/xutf8/utils/create_table.c179
-rw-r--r--src/xutf8/utils/euc_tw.c54
14 files changed, 2110 insertions, 2192 deletions
diff --git a/src/xutf8/case.c b/src/xutf8/case.c
index aad8afe9b..e21c96202 100644
--- a/src/xutf8/case.c
+++ b/src/xutf8/case.c
@@ -30,104 +30,96 @@
#include "headers/case.h"
#include <stdlib.h>
-
int
-XUtf8Tolower(
- int ucs)
-{
- int ret;
-
- if (ucs <= 0x02B6) {
- if (ucs >= 0x0041) {
- ret = ucs_table_0041[ucs - 0x0041];
- if (ret > 0) return ret;
- }
- return ucs;
- }
-
- if (ucs <= 0x0556) {
- if (ucs >= 0x0386) {
- ret = ucs_table_0386[ucs - 0x0386];
- if (ret > 0) return ret;
- }
- return ucs;
- }
-
- if (ucs <= 0x10C5) {
- if (ucs >= 0x10A0) {
- ret = ucs_table_10A0[ucs - 0x10A0];
- if (ret > 0) return ret;
- }
- return ucs;
- }
-
- if (ucs <= 0x1FFC) {
- if (ucs >= 0x1E00) {
- ret = ucs_table_1E00[ucs - 0x1E00];
- if (ret > 0) return ret;
- }
- return ucs;
- }
-
- if (ucs <= 0x2133) {
- if (ucs >= 0x2102) {
- ret = ucs_table_2102[ucs - 0x2102];
- if (ret > 0) return ret;
- }
- return ucs;
- }
-
- if (ucs <= 0x24CF) {
- if (ucs >= 0x24B6) {
- ret = ucs_table_24B6[ucs - 0x24B6];
- if (ret > 0) return ret;
- }
- return ucs;
- }
-
- if (ucs <= 0x33CE) {
- if (ucs >= 0x33CE) {
- ret = ucs_table_33CE[ucs - 0x33CE];
- if (ret > 0) return ret;
- }
- return ucs;
- }
-
- if (ucs <= 0xFF3A) {
- if (ucs >= 0xFF21) {
- ret = ucs_table_FF21[ucs - 0xFF21];
- if (ret > 0) return ret;
- }
- return ucs;
- }
-
- return ucs;
+XUtf8Tolower(int ucs) {
+ int ret;
+ if (ucs <= 0x02B6) {
+ if (ucs >= 0x0041) {
+ ret = ucs_table_0041[ucs - 0x0041];
+ if (ret > 0) return ret;
+ }
+ return ucs;
+ }
+
+ if (ucs <= 0x0556) {
+ if (ucs >= 0x0386) {
+ ret = ucs_table_0386[ucs - 0x0386];
+ if (ret > 0) return ret;
+ }
+ return ucs;
+ }
+
+ if (ucs <= 0x10C5) {
+ if (ucs >= 0x10A0) {
+ ret = ucs_table_10A0[ucs - 0x10A0];
+ if (ret > 0) return ret;
+ }
+ return ucs;
+ }
+
+ if (ucs <= 0x1FFC) {
+ if (ucs >= 0x1E00) {
+ ret = ucs_table_1E00[ucs - 0x1E00];
+ if (ret > 0) return ret;
+ }
+ return ucs;
+ }
+
+ if (ucs <= 0x2133) {
+ if (ucs >= 0x2102) {
+ ret = ucs_table_2102[ucs - 0x2102];
+ if (ret > 0) return ret;
+ }
+ return ucs;
+ }
+
+ if (ucs <= 0x24CF) {
+ if (ucs >= 0x24B6) {
+ ret = ucs_table_24B6[ucs - 0x24B6];
+ if (ret > 0) return ret;
+ }
+ return ucs;
+ }
+
+ if (ucs <= 0x33CE) {
+ if (ucs >= 0x33CE) {
+ ret = ucs_table_33CE[ucs - 0x33CE];
+ if (ret > 0) return ret;
+ }
+ return ucs;
+ }
+
+ if (ucs <= 0xFF3A) {
+ if (ucs >= 0xFF21) {
+ ret = ucs_table_FF21[ucs - 0xFF21];
+ if (ret > 0) return ret;
+ }
+ return ucs;
+ }
+
+ return ucs;
}
int
-XUtf8Toupper(
- int ucs)
-{
- int i;
- static unsigned short *table = NULL;
-
- if (!table) {
- table = (unsigned short*) malloc(
- sizeof(unsigned short) * 0x10000);
- for (i = 0; i < 0x10000; i++) {
- table[i] = (unsigned short) i;
- }
- for (i = 0; i < 0x10000; i++) {
- int l;
- l = XUtf8Tolower(i);
- if (l != i) table[l] = (unsigned short) i;
- }
-
- }
- if (ucs >= 0x10000 || ucs < 0) return ucs;
- return table[ucs];
+XUtf8Toupper(int ucs) {
+ int i;
+ static unsigned short *table = NULL;
+
+ if (!table) {
+ table = (unsigned short*) malloc(sizeof(unsigned short) * 0x10000);
+ for (i = 0; i < 0x10000; i++) {
+ table[i] = (unsigned short) i;
+ }
+ for (i = 0; i < 0x10000; i++) {
+ int l;
+ l = XUtf8Tolower(i);
+ if (l != i) table[l] = (unsigned short) i;
+ }
+ }
+ if (ucs >= 0x10000 || ucs < 0) return ucs;
+ return table[ucs];
}
/*
- * End of "$Id$".
- */
+* End of "$Id$".
+*/
diff --git a/src/xutf8/is_right2left.c b/src/xutf8/is_right2left.c
index 7ef5af7df..737b85266 100644
--- a/src/xutf8/is_right2left.c
+++ b/src/xutf8/is_right2left.c
@@ -28,57 +28,55 @@
*/
unsigned short
-XUtf8IsRightToLeft(
- unsigned int ucs)
-{
+XUtf8IsRightToLeft(unsigned int ucs) {
#if 0
- /* for debug only */
- if (ucs <= 0x005A) {
- if (ucs >= 0x0041) return 1;
- return 0;
- }
+ /* for debug only */
+ if (ucs <= 0x005A) {
+ if (ucs >= 0x0041) return 1;
+ return 0;
+ }
#endif
- /* HEBREW */
- if (ucs <= 0x05F4) {
- if (ucs >= 0x0591) return 1;
- return 0;
- }
-
- /* ARABIC */
- if (ucs <= 0x06ED) {
- if (ucs >= 0x060C) return 1;
- return 0;
- }
+ /* HEBREW */
+ if (ucs <= 0x05F4) {
+ if (ucs >= 0x0591) return 1;
+ return 0;
+ }
+
+ /* ARABIC */
+ if (ucs <= 0x06ED) {
+ if (ucs >= 0x060C) return 1;
+ return 0;
+ }
- if (ucs <= 0x06F9) {
- if (ucs >= 0x06F0) return 1;
- return 0;
- }
+ if (ucs <= 0x06F9) {
+ if (ucs >= 0x06F0) return 1;
+ return 0;
+ }
- if (ucs == 0x200F) return 1;
+ if (ucs == 0x200F) return 1;
- if (ucs == 0x202B) return 1;
+ if (ucs == 0x202B) return 1;
- if (ucs == 0x202E) return 1;
+ if (ucs == 0x202E) return 1;
- if (ucs <= 0xFB4F) {
- if (ucs >= 0xFB1E) return 1;
- return 0;
- }
-
- if (ucs <= 0xFDFB) {
- if (ucs >= 0xFB50) return 1;
- return 0;
- }
+ if (ucs <= 0xFB4F) {
+ if (ucs >= 0xFB1E) return 1;
+ return 0;
+ }
+
+ if (ucs <= 0xFDFB) {
+ if (ucs >= 0xFB50) return 1;
+ return 0;
+ }
- if (ucs <= 0xFEFC) {
- if (ucs >= 0xFE70) return 1;
- return 0;
- }
+ if (ucs <= 0xFEFC) {
+ if (ucs >= 0xFE70) return 1;
+ return 0;
+ }
- return 0;
+ return 0;
}
/*
diff --git a/src/xutf8/is_spacing.c b/src/xutf8/is_spacing.c
index 548dd84ff..94557302c 100644
--- a/src/xutf8/is_spacing.c
+++ b/src/xutf8/is_spacing.c
@@ -29,63 +29,60 @@
#include "headers/spacing.h"
-
unsigned short
-XUtf8IsNonSpacing(
- unsigned int ucs)
-{
-
- if (ucs <= 0x0361) {
- if (ucs >= 0x0300) return ucs_table_0300[ucs - 0x0300];
- return 0;
- }
-
- if (ucs <= 0x0486) {
- if (ucs >= 0x0483) return ucs_table_0483[ucs - 0x0483];
- return 0;
- }
-
- if (ucs <= 0x05C4) {
- if (ucs >= 0x0591) return ucs_table_0591[ucs - 0x0591];
- return 0;
- }
-
- if (ucs <= 0x06ED) {
- if (ucs >= 0x064B) return ucs_table_064B[ucs - 0x064B];
- return 0;
- }
-
- if (ucs <= 0x0D4D) {
- if (ucs >= 0x0901) return ucs_table_0901[ucs - 0x0901];
- return 0;
- }
-
- if (ucs <= 0x0FB9) {
- if (ucs >= 0x0E31) return ucs_table_0E31[ucs - 0x0E31];
- return 0;
- }
-
- if (ucs <= 0x20E1) {
- if (ucs >= 0x20D0) return ucs_table_20D0[ucs - 0x20D0];
- return 0;
- }
-
- if (ucs <= 0x309A) {
- if (ucs >= 0x302A) return ucs_table_302A[ucs - 0x302A];
- return 0;
- }
-
- if (ucs <= 0xFB1E) {
- if (ucs >= 0xFB1E) return ucs_table_FB1E[ucs - 0xFB1E];
- return 0;
- }
-
- if (ucs <= 0xFE23) {
- if (ucs >= 0xFE20) return ucs_table_FE20[ucs - 0xFE20];
- return 0;
- }
-
- return 0;
+XUtf8IsNonSpacing(unsigned int ucs) {
+
+ if (ucs <= 0x0361) {
+ if (ucs >= 0x0300) return ucs_table_0300[ucs - 0x0300];
+ return 0;
+ }
+
+ if (ucs <= 0x0486) {
+ if (ucs >= 0x0483) return ucs_table_0483[ucs - 0x0483];
+ return 0;
+ }
+
+ if (ucs <= 0x05C4) {
+ if (ucs >= 0x0591) return ucs_table_0591[ucs - 0x0591];
+ return 0;
+ }
+
+ if (ucs <= 0x06ED) {
+ if (ucs >= 0x064B) return ucs_table_064B[ucs - 0x064B];
+ return 0;
+ }
+
+ if (ucs <= 0x0D4D) {
+ if (ucs >= 0x0901) return ucs_table_0901[ucs - 0x0901];
+ return 0;
+ }
+
+ if (ucs <= 0x0FB9) {
+ if (ucs >= 0x0E31) return ucs_table_0E31[ucs - 0x0E31];
+ return 0;
+ }
+
+ if (ucs <= 0x20E1) {
+ if (ucs >= 0x20D0) return ucs_table_20D0[ucs - 0x20D0];
+ return 0;
+ }
+
+ if (ucs <= 0x309A) {
+ if (ucs >= 0x302A) return ucs_table_302A[ucs - 0x302A];
+ return 0;
+ }
+
+ if (ucs <= 0xFB1E) {
+ if (ucs >= 0xFB1E) return ucs_table_FB1E[ucs - 0xFB1E];
+ return 0;
+ }
+
+ if (ucs <= 0xFE23) {
+ if (ucs >= 0xFE20) return ucs_table_FE20[ucs - 0xFE20];
+ return 0;
+ }
+
+ return 0;
}
/*
diff --git a/src/xutf8/keysym2Ucs.c b/src/xutf8/keysym2Ucs.c
index 028b6cef6..5bf23d19a 100644
--- a/src/xutf8/keysym2Ucs.c
+++ b/src/xutf8/keysym2Ucs.c
@@ -30,10 +30,8 @@
#include "../../FL/Xutf8.h"
#include "imKStoUCS.c"
-
-long XKeysymToUcs(KeySym keysym)
-{
- return (long) KeySymToUcs4(keysym);
+long XKeysymToUcs(KeySym keysym) {
+ return (long) KeySymToUcs4(keysym);
}
#endif /* X11 only */
diff --git a/src/xutf8/test.c b/src/xutf8/test.c
index 95a5c342f..75b17a930 100644
--- a/src/xutf8/test.c
+++ b/src/xutf8/test.c
@@ -26,7 +26,9 @@
/*
* UTF-8 X test program (It contains MINIMAL code to support XIM !!!)
*
-To test it do :
+ ****************
+ * To test it do:
+ ****************
kinput2 -canna
XMODIFIERS="@im=kinput2"; export XMODIFIERS
@@ -51,7 +53,7 @@ export LANG=ko_KR; export XMODIFIERS="@im=Ami"
export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_TW"
export LANG=zh_TW; export XMODIFIERS="@im=xcin-zh_CN"
export LANG=C; export XMODIFIERS="@im=interxim"
-*/
+**********************************************************/
#include <stdlib.h>
#include <string.h>
@@ -80,208 +82,209 @@ GC gc;
int x = 2;
int y = 40;
-int main(int argc, char**argv)
-{
- char **missing_charset_list;
- int missing_charset_count;
- XGCValues xgcv;
- unsigned long mask;
- Display* dpy;
- int scr;
- Window w, root;
- XSetWindowAttributes set_attr;
- int i;
- XIMStyle *style;
- static char buf[128];
- KeySym keysym = 0;
- Status status;
- XWMHints wm_hints;
- XClassHint class_hints;
- XIMStyle input_style = 0;
- char **font_name_list;
- char *def_string;
- XFontStruct **font_struct_list;
- char **font_encoding_list;
- int nb_font;
- int len = 0;
- int no_xim = 0;
+int main(int argc, char**argv) {
+ char **missing_charset_list;
+ int missing_charset_count;
+ XGCValues xgcv;
+ unsigned long mask;
+ Display* dpy;
+ int scr;
+ Window w, root;
+ XSetWindowAttributes set_attr;
+ int i;
+ XIMStyle *style;
+ static char buf[128];
+ KeySym keysym = 0;
+ Status status;
+ XWMHints wm_hints;
+ XClassHint class_hints;
+ XIMStyle input_style = 0;
+ char **font_name_list;
+ char *def_string;
+ XFontStruct **font_struct_list;
+ char **font_encoding_list;
+ int nb_font;
+ int len = 0;
+ int no_xim = 0;
- printf ("A -> %c \n", XUtf8Tolower('A'));
- if (!setlocale(LC_ALL, ""))
- puts("locale not supported by C library, locale unchanged");
+ printf ("A -> %c \n", XUtf8Tolower('A'));
+ if (!setlocale(LC_ALL, ""))
+ puts("locale not supported by C library, locale unchanged");
- if (!XSetLocaleModifiers(""))
- puts("X locale modifiers not supported, using default");
-
- dpy = XOpenDisplay(0);
- if (!dpy) { puts("cannot open display.\n"); exit(-1); }
- scr = DefaultScreen(dpy);
- root = RootWindow(dpy, scr);
- set_attr.event_mask = KeyPressMask|FocusChangeMask;
- set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
- set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
- w = XCreateWindow(dpy, root, 10,10,200,100,0,
- DefaultDepth(dpy, DefaultScreen(dpy)),
- InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
- CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
- if (!w) { puts("cannot creat window.\n"); exit(-1); }
+ if (!XSetLocaleModifiers(""))
+ puts("X locale modifiers not supported, using default");
+
+ dpy = XOpenDisplay(0);
+ if (!dpy) { puts("cannot open display.\n"); exit(-1); }
+ scr = DefaultScreen(dpy);
+ root = RootWindow(dpy, scr);
+ set_attr.event_mask = KeyPressMask|FocusChangeMask;
+ set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
+ set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
+ w = XCreateWindow(dpy, root, 10,10,200,100,0,
+ DefaultDepth(dpy, DefaultScreen(dpy)),
+ InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
+ CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
+ if (!w) {
+ puts("cannot creat window.\n");
+ exit(-1);
+ }
- class_hints.res_name = "test";
- class_hints.res_class = "Test";
- wm_hints.input = True;
- wm_hints.flags = InputHint;
+ class_hints.res_name = "test";
+ class_hints.res_class = "Test";
+ wm_hints.input = True;
+ wm_hints.flags = InputHint;
- XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
- NULL, &wm_hints, &class_hints);
+ XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
+ NULL, &wm_hints, &class_hints);
- XMapWindow(dpy, w);
- xim_im = XOpenIM(dpy, NULL, "test", "Test");
- if (!xim_im) {
- puts("cannot Open Input Manager: Try default.\n");
- XSetLocaleModifiers("@im=");
- xim_im = XOpenIM(dpy, NULL, "test", "Test");
- if (!xim_im) { puts("Failed exiting.\n"); exit(-1); }
- }
- XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
- for (i = 0, style = xim_styles->supported_styles;
- i < xim_styles->count_styles; i++, style++)
- {
- if (i == 0 && *style == (XIMStatusNone|XIMPreeditNone)) {
- printf("this is not a XIM server !!!\n");
- no_xim = 1;
- }
- printf("input style : 0x%X\n", *style);
- }
+ XMapWindow(dpy, w);
+ xim_im = XOpenIM(dpy, NULL, "test", "Test");
+ if (!xim_im) {
+ puts("cannot Open Input Manager: Try default.\n");
+ XSetLocaleModifiers("@im=");
+ xim_im = XOpenIM(dpy, NULL, "test", "Test");
+ if (!xim_im) {
+ puts("Failed exiting.\n");
+ exit(-1);
+ }
+ }
+ XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
+ for (i = 0, style = xim_styles->supported_styles;
+ i < xim_styles->count_styles; i++, style++) {
+ if (i == 0 && *style == (XIMStatusNone|XIMPreeditNone)) {
+ printf("this is not a XIM server !!!\n");
+ no_xim = 1;
+ }
+ printf("input style : 0x%X\n", *style);
+ }
- xim_ic = XCreateIC(xim_im,
- XNInputStyle,
- (XIMPreeditNothing | XIMStatusNothing),
- XNClientWindow, w,
- XNFocusWindow, w,
- NULL);
- if (!xim_ic) { puts("cannot create Input Context.\n"); exit(-1);}
- XFree(xim_styles);
- XSetICFocus(xim_ic);
-
- /***************************************************************/
- /** I don't recommand to use a font base name list similar
- * to the following one in a real application ;-)
- * You should use an iso8859-1 font, plus a single font for
- * your language. */
- /***************************************************************/
- fontset = XCreateUtf8FontStruct(dpy,
- "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
- "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-ksc5601.1987-0,"
- "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
- "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
- "-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
-
- /* THIS PART IS NOT REQUIERED */
- nb_font = fontset->nb_font;
+ xim_ic = XCreateIC(xim_im,
+ XNInputStyle,
+ (XIMPreeditNothing | XIMStatusNothing),
+ XNClientWindow, w,
+ XNFocusWindow, w,
+ NULL);
+ if (!xim_ic) {
+ puts("cannot create Input Context.\n");
+ exit(-1);
+ }
+ XFree(xim_styles);
+ XSetICFocus(xim_ic);
- while (nb_font > 0) {
- nb_font--;
- if (fontset->fonts[nb_font]) {
- printf("encoding=\"\" fid=%d \n %s\n",
- // fontset->encodings[nb_font],
- fontset->fonts[nb_font]->fid,
- fontset->font_name_list[nb_font]);
- }
- }
- /* END OF NOT REQUIERED PART*/
+ /***************************************************************
+ * I don't recommend to use a font base name list similar
+ * to the following one in a real application ;-)
+ * You should use an iso8859-1 font, plus a single font for
+ * your language.
+ ***************************************************************/
+ fontset = XCreateUtf8FontStruct(dpy,
+ "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
+ "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-ksc5601.1987-0,"
+ "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
+ "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
- mask = (GCForeground | GCBackground);
- xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
- xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
+ /* THIS PART IS NOT REQUIERED */
+ nb_font = fontset->nb_font;
- gc = XCreateGC(dpy, w, mask, &xgcv);
- if (!gc) { puts("cannot create Graphic Context.\n"); exit(-1);}
+ while (nb_font > 0) {
+ nb_font--;
+ if (fontset->fonts[nb_font]) {
+ printf("encoding=\"\" fid=%d \n %s\n",
+ // fontset->encodings[nb_font],
+ fontset->fonts[nb_font]->fid,
+ fontset->font_name_list[nb_font]);
+ }
+ }
+ /* END OF NOT REQUIERED PART*/
+ mask = (GCForeground | GCBackground);
+ xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
+ xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
- /***************************************************************/
- while (1) {
- int filtered;
- static XEvent xevent;
- static XVaNestedList list1 = 0;
- int r;
+ gc = XCreateGC(dpy, w, mask, &xgcv);
+ if (!gc) {
+ puts("cannot create Graphic Context.\n");
+ exit(-1);
+ }
- XNextEvent(dpy, &xevent);
- if (xevent.type == KeyPress) {
- XKeyEvent *e = (XKeyEvent*) &xevent;
- printf ("0x%X %d\n", e->state, e->keycode);
- }
- if (xevent.type == DestroyNotify) {
- /* XIM server has crashed */
- no_xim = 1;
- XSetLocaleModifiers("@im=");
- xim_im = XOpenIM(dpy, NULL, "test", "Test");
- if (xim_im) {
- xim_ic = XCreateIC(xim_im,
- XNInputStyle, (XIMPreeditNothing |
- XIMStatusNothing),
- XNClientWindow, w,
- XNFocusWindow, w,
- NULL);
- } else {
- xim_ic = NULL;
- }
- if (!xim_ic) {
- puts("Crash recovery failed. exiting.\n");
- exit(-1);
- }
- }
- if (xevent.type != DestroyNotify) {
- filtered = XFilterEvent(&xevent, 0);
- }
- if (xevent.type == FocusOut && xim_ic) XUnsetICFocus(xim_ic);
- if (xevent.type == FocusIn && xim_ic) XSetICFocus(xim_ic);
+ /***************************************************************/
+ while (1) {
+ int filtered;
+ static XEvent xevent;
+ static XVaNestedList list1 = 0;
+ int r;
- if (xevent.type == KeyPress && !filtered) {
- len = XUtf8LookupString(xim_ic, &xevent.xkey,
- buf, 127, &keysym, &status);
-
- if (len == 1 && buf[0] == '\b') {
- x -= XUtf8TextWidth(fontset, buf, len);
- XUtf8DrawImageString(dpy, w, fontset, gc,
- x, y, buf, len);
- } else if (len == 1 && buf[0] == '\r') {
- y += fontset->ascent + fontset->descent;
- x = 0;
- XCloseIM(xim_im);
- } else {
- XUtf8DrawImageString(dpy, w, fontset, gc,
- x, y, buf, len);
- x += XUtf8TextWidth(fontset, buf, len);
- }
+ XNextEvent(dpy, &xevent);
+ if (xevent.type == KeyPress) {
+ XKeyEvent *e = (XKeyEvent*) &xevent;
+ printf ("0x%X %d\n", e->state, e->keycode);
+ }
+ if (xevent.type == DestroyNotify) {
+ /* XIM server has crashed */
+ no_xim = 1;
+ XSetLocaleModifiers("@im=");
+ xim_im = XOpenIM(dpy, NULL, "test", "Test");
+ if (xim_im) {
+ xim_ic = XCreateIC(xim_im,
+ XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
+ XNClientWindow, w,
+ XNFocusWindow, w,
+ NULL);
+ } else {
+ xim_ic = NULL;
+ }
+ if (!xim_ic) {
+ puts("Crash recovery failed. exiting.\n");
+ exit(-1);
+ }
+ }
+ if (xevent.type != DestroyNotify) {
+ filtered = XFilterEvent(&xevent, 0);
+ }
+ if (xevent.type == FocusOut && xim_ic) XUnsetICFocus(xim_ic);
+ if (xevent.type == FocusIn && xim_ic) XSetICFocus(xim_ic);
+ if (xevent.type == KeyPress && !filtered) {
+ len = XUtf8LookupString(xim_ic, &xevent.xkey,
+ buf, 127, &keysym, &status);
- XUtf8DrawString(dpy, w, fontset, gc, 0, 20,
- jp_txt, strlen(jp_txt));
-
- XUtf8DrawString(dpy, w, fontset, gc, 50, 90,
- rtl_txt, strlen(rtl_txt));
- XUtf8DrawRtlString(dpy, w, fontset, gc,
- 50, 90, rtl_txt, strlen(rtl_txt));
- buf[len] = 0;
- printf("'%s' %d %x\n", buf, keysym, keysym);
- buf[0] = 0;
+ if (len == 1 && buf[0] == '\b') {
+ x -= XUtf8TextWidth(fontset, buf, len);
+ XUtf8DrawImageString(dpy, w, fontset, gc,
+ x, y, buf, len);
+ } else if (len == 1 && buf[0] == '\r') {
+ y += fontset->ascent + fontset->descent;
+ x = 0;
+ XCloseIM(xim_im);
+ } else {
+ XUtf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len);
+ x += XUtf8TextWidth(fontset, buf, len);
+ }
- }
- if (filtered) {
- printf("Dead key\n");
- }
- }
- XFreeUtf8FontStruct(dpy, fontset);
- return 0;
+ XUtf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt));
+ XUtf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt));
+ XUtf8DrawRtlString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt));
+ buf[len] = 0;
+ printf("'%s' %d %x\n", buf, keysym, keysym);
+ buf[0] = 0;
+ }
+ if (filtered) {
+ printf("Dead key\n");
+ }
+ }
+ XFreeUtf8FontStruct(dpy, fontset);
+ return 0;
}
/*
diff --git a/src/xutf8/test2.c b/src/xutf8/test2.c
index 8f0407ffa..2d985b64e 100644
--- a/src/xutf8/test2.c
+++ b/src/xutf8/test2.c
@@ -26,7 +26,9 @@
/*
* UTF-8 X test program
*
-To test it do :
+ *****************
+ * To test it do :
+ *****************
kinput2 -canna
XMODIFIERS="@im=kinput2"; export XMODIFIERS
@@ -68,9 +70,9 @@ export LD_PRELOAD="/usr/src/x11/xc/exports/lib/libX11.so /usr/src/x11/xc/exports
#include <X11/Xmd.h>
char *jp_txt = "é UTF-8 e\xCC\x82=\xC3\xAA"
- " \357\274\270\357\274\254\357\274\246\357\274"
- "\244\345\220\215\343\201\247\346\214\207 \345\256\232"
- "\343\201\231\343\202\213";
+ " \357\274\270\357\274\254\357\274\246\357\274"
+ "\244\345\220\215\343\201\247\346\214\207 \345\256\232"
+ "\343\201\231\343\202\213";
char *rtl_txt = "->e\xCC\x82=\xC3\xAA";
@@ -82,149 +84,138 @@ GC gc;
int x = 2;
int y = 40;
-int main(int argc, char**argv)
-{
- char **missing_charset_list;
- int missing_charset_count;
- XGCValues xgcv;
- unsigned long mask;
- Display* dpy;
- int scr;
- Window w, root;
- XSetWindowAttributes set_attr;
- int i;
- XIMStyle *style;
- static char buf[128];
- KeySym keysym = 0;
- Status status;
- XWMHints wm_hints;
- XClassHint class_hints;
- XIMStyle input_style = 0;
- char **font_name_list;
- char *def_string;
- XFontStruct **font_struct_list;
- char **font_encoding_list;
- int nb_font;
- int len = 0;
- int no_xim = 0;
- char **missing_charset_list_return;
- int missing_charset_count_return;
- char *def_string_return;
-
- if (!setlocale(LC_ALL, ""))
- puts("locale not supported by C library, locale unchanged");
-
- if (!XSetLocaleModifiers(""))
- puts("X locale modifiers not supported, using default");
-
- dpy = XOpenDisplay(0);
- scr = DefaultScreen(dpy);
- root = RootWindow(dpy, scr);
- set_attr.event_mask = KeyPressMask|FocusChangeMask;
- set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
- set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
- w = XCreateWindow(dpy, root, 10,10,200,100,0,
- DefaultDepth(dpy, DefaultScreen(dpy)),
- InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
- CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
-
- class_hints.res_name = "test";
- class_hints.res_class = "Test";
- wm_hints.input = True;
- wm_hints.flags = InputHint;
-
- XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
- NULL, &wm_hints, &class_hints);
-
- XMapWindow(dpy, w);
- xim_im = XOpenIM(dpy, NULL, "test", "Test");
- XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
- for (i = 0, style = xim_styles->supported_styles;
- i < xim_styles->count_styles; i++, style++)
- {
- if (*style == (XIMStatusNone|XIMPreeditNone)) {
- printf("this is not a XIM server !!!\n");
- no_xim = 1;
- }
- printf("input style : 0x%X\n", *style);
- }
- XFree(xim_styles);
-
- xim_ic = XCreateIC(xim_im,
- XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
- XNClientWindow, w,
- XNFocusWindow, w,
- NULL);
- XSetICFocus(xim_ic);
-
- /***************************************************************/
- /** I don't recommand to use a font base name list similar
- * to the following one in a real application ;-) */
- /***************************************************************/
- fontset = XCreateFontSet(dpy,
- "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
- "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
- "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
- "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
- "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
- "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
- &missing_charset_list_return,
- &missing_charset_count_return,
- &def_string_return);
- mask = (GCForeground | GCBackground);
- xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
- xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
-
- gc = XCreateGC(dpy, w, mask, &xgcv);
-
-
- /***************************************************************/
- while (1) {
- int filtered;
- static XEvent xevent;
- static XVaNestedList list1 = 0;
- int r;
-
- XNextEvent(dpy, &xevent);
- if (xevent.type == KeyPress) {
- XKeyEvent *e = (XKeyEvent*) &xevent;
- printf ("0x%X %d\n", e->state, e->keycode);
- }
- filtered = XFilterEvent(&xevent, w);
- if (xevent.type == FocusOut) XUnsetICFocus(xim_ic);
- if (xevent.type == FocusIn) XSetICFocus(xim_ic);
-
- if (xevent.type == KeyPress && !filtered) {
- len = Xutf8LookupString(xim_ic, &xevent.xkey,
- buf, 127, &keysym, &status);
-
- Xutf8DrawImageString(dpy, w, fontset, gc,
- x, y, buf, len);
-
-
- Xutf8DrawString(dpy, w, fontset, gc, 0, 20,
- jp_txt, strlen(jp_txt));
-
- Xutf8DrawString(dpy, w, fontset, gc, 50, 90,
- rtl_txt, strlen(rtl_txt));
- buf[len] = 0;
- printf("'%s' %d\n", buf, keysym);
- buf[0] = 0;
- XCloseIM(xim_im);
- }
- if (filtered) {
- printf("Dead key\n");
- }
- }
- XFreeFontSet(dpy, fontset);
- return 0;
+int main(int argc, char**argv) {
+ char **missing_charset_list;
+ int missing_charset_count;
+ XGCValues xgcv;
+ unsigned long mask;
+ Display* dpy;
+ int scr;
+ Window w, root;
+ XSetWindowAttributes set_attr;
+ int i;
+ XIMStyle *style;
+ static char buf[128];
+ KeySym keysym = 0;
+ Status status;
+ XWMHints wm_hints;
+ XClassHint class_hints;
+ XIMStyle input_style = 0;
+ char **font_name_list;
+ char *def_string;
+ XFontStruct **font_struct_list;
+ char **font_encoding_list;
+ int nb_font;
+ int len = 0;
+ int no_xim = 0;
+ char **missing_charset_list_return;
+ int missing_charset_count_return;
+ char *def_string_return;
+
+ if (!setlocale(LC_ALL, ""))
+ puts("locale not supported by C library, locale unchanged");
+
+ if (!XSetLocaleModifiers(""))
+ puts("X locale modifiers not supported, using default");
+
+ dpy = XOpenDisplay(0);
+ scr = DefaultScreen(dpy);
+ root = RootWindow(dpy, scr);
+ set_attr.event_mask = KeyPressMask|FocusChangeMask;
+ set_attr.background_pixel = WhitePixel(dpy, DefaultScreen(dpy));
+ set_attr.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
+ w = XCreateWindow(dpy, root, 10,10,200,100,0,
+ DefaultDepth(dpy, DefaultScreen(dpy)),
+ InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
+ CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
+
+ class_hints.res_name = "test";
+ class_hints.res_class = "Test";
+ wm_hints.input = True;
+ wm_hints.flags = InputHint;
+
+ XmbSetWMProperties(dpy, w, "test", "test", NULL, 0,
+ NULL, &wm_hints, &class_hints);
+
+ XMapWindow(dpy, w);
+ xim_im = XOpenIM(dpy, NULL, "test", "Test");
+ XGetIMValues(xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
+ for (i = 0, style = xim_styles->supported_styles;
+ i < xim_styles->count_styles; i++, style++) {
+ if (*style == (XIMStatusNone|XIMPreeditNone)) {
+ printf("this is not a XIM server !!!\n");
+ no_xim = 1;
+ }
+ printf("input style : 0x%X\n", *style);
+ }
+ XFree(xim_styles);
+
+ xim_ic = XCreateIC(xim_im,
+ XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
+ XNClientWindow, w,
+ XNFocusWindow, w,
+ NULL);
+ XSetICFocus(xim_ic);
+
+ /***************************************************************
+ * I don't recommend to use a font base name list similar
+ * to the following one in a real application ;-)
+ ***************************************************************/
+ fontset = XCreateFontSet(dpy,
+ "-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
+ "-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-6,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-8,"
+ "-*-symbol-*-*-*-*-*-*-*-*-*-*-adobe-fontspecific,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-iso8859-2,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0208.1983-0,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0212.1990-0,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0,"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-jisx0201.1976-0,"
+ "-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1[0x300 0x400_0x500],"
+ "-*-*-*-*-*-*-*-*-*-*-*-*-*-*",
+ &missing_charset_list_return,
+ &missing_charset_count_return,
+ &def_string_return);
+ mask = (GCForeground | GCBackground);
+ xgcv.foreground = BlackPixel(dpy, DefaultScreen(dpy));
+ xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
+
+ gc = XCreateGC(dpy, w, mask, &xgcv);
+
+ /***************************************************************/
+ while (1) {
+ int filtered;
+ static XEvent xevent;
+ static XVaNestedList list1 = 0;
+ int r;
+
+ XNextEvent(dpy, &xevent);
+ if (xevent.type == KeyPress) {
+ XKeyEvent *e = (XKeyEvent*) &xevent;
+ printf ("0x%X %d\n", e->state, e->keycode);
+ }
+ filtered = XFilterEvent(&xevent, w);
+ if (xevent.type == FocusOut) XUnsetICFocus(xim_ic);
+ if (xevent.type == FocusIn) XSetICFocus(xim_ic);
+
+ if (xevent.type == KeyPress && !filtered) {
+ len = Xutf8LookupString(xim_ic, &xevent.xkey, buf, 127, &keysym, &status);
+ Xutf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len);
+ Xutf8DrawString(dpy, w, fontset, gc, 0, 20, jp_txt, strlen(jp_txt));
+ Xutf8DrawString(dpy, w, fontset, gc, 50, 90, rtl_txt, strlen(rtl_txt));
+ buf[len] = 0;
+ printf("'%s' %d\n", buf, keysym);
+ buf[0] = 0;
+ XCloseIM(xim_im);
+ }
+ if (filtered) {
+ printf("Dead key\n");
+ }
+ }
+ XFreeFontSet(dpy, fontset);
+ return 0;
}
/*
diff --git a/src/xutf8/ucs2fontmap.c b/src/xutf8/ucs2fontmap.c
index 50535f6ef..f1b966981 100644
--- a/src/xutf8/ucs2fontmap.c
+++ b/src/xutf8/ucs2fontmap.c
@@ -32,8 +32,8 @@
#define conv_t void*
#define ucs4_t unsigned int
typedef struct {
- unsigned short indx;
- unsigned short used;
+ unsigned short indx;
+ unsigned short used;
} Summary16;
@@ -62,10 +62,10 @@ typedef struct {
#include "headers/symbol_.h"
#include "headers/dingbats_.h"
- /*************** conv_gen.c ************/
+/*************** conv_gen.c ************/
+
/*const*/
-int ucs2fontmap(char *s, unsigned int ucs, int enc)
-{
+int ucs2fontmap(char *s, unsigned int ucs, int enc) {
switch(enc) {
case 0: /* iso10646-1 */
s[0] = (char) ((ucs & 0xFF00) >> 8);
@@ -302,8 +302,7 @@ int ucs2fontmap(char *s, unsigned int ucs, int enc)
};
/*const*/
-int encoding_number(const char *enc)
-{
+int encoding_number(const char *enc) {
if (!enc || !strncmp(enc, "iso10646-1", 10)) {
return 0;
} else if (!strcmp(enc, "iso8859-1")) {
diff --git a/src/xutf8/utf8Input.c b/src/xutf8/utf8Input.c
index 7fe9ff17e..8882c9ecf 100644
--- a/src/xutf8/utf8Input.c
+++ b/src/xutf8/utf8Input.c
@@ -48,8 +48,8 @@
#define conv_t void*
#define ucs4_t unsigned int
typedef struct {
- unsigned short indx;
- unsigned short used;
+ unsigned short indx;
+ unsigned short used;
} Summary16;
#include "lcUniConv/big5.h"
@@ -60,376 +60,347 @@ typedef struct {
#include "lcUniConv/ksc5601.h"
int
-XConvertEucTwToUtf8(
- char* buffer_return,
- int len)
-{
- /* FIXME */
+XConvertEucTwToUtf8(char* buffer_return, int len) {
+ /* FIXME */
#if HAVE_LIBC_ICONV
- iconv_t cd;
- int cdl;
+ iconv_t cd;
+ int cdl;
#else
- int i = 0;
+ int i = 0;
#endif
- int l = 0;
- char *buf, *b;
+ int l = 0;
+ char *buf, *b;
- if (len < 1) return 0;
- b = buf = (char*) malloc((unsigned)len);
- memcpy(buf, buffer_return, (unsigned) len);
+ if (len < 1) return 0;
+ b = buf = (char*) malloc((unsigned)len);
+ memcpy(buf, buffer_return, (unsigned) len);
#if HAVE_LIBC_ICONV
- l = cdl = len;
- cd = iconv_open("EUC-TW", "UTF-8");
- iconv(cd, &b, &len, &buffer_return, &cdl);
- iconv_close(cd);
- l -= cdl;
+ l = cdl = len;
+ cd = iconv_open("EUC-TW", "UTF-8");
+ iconv(cd, &b, &len, &buffer_return, &cdl);
+ iconv_close(cd);
+ l -= cdl;
#else
- while (i < len) {
- unsigned int ucs;
- unsigned char c;
- c = (unsigned char) buf[i];
- if (c < 0x80) {
- ucs = c;
- i++;
- } else if (c >= 0xa1 && c < 0xff && len - i > 1 ) {
- unsigned char b[2];
- b[0] = (unsigned char) c - 0x80;
- b[1] = (unsigned char) buf[i + 1] - 0x80;
- ucs = ' '; i += 2;
- } else if (c == 0x8e && len - i > 3) {
- unsigned char b[2];
- unsigned char c1 = buf[i + 1];
- unsigned char c2 = buf[i + 2];
- unsigned char c3 = buf[i + 3];
- b[0] = (unsigned char) buf[i + 2] - 0x80;
- b[1] = (unsigned char) buf[i + 3] - 0x80;
- if (c1 >= 0xa1 && c1 <= 0xb0) {
- if (c2 >= 0xa1 && c2 < 0xff && c3 >= 0xa1 &&
- c3 < 0xff)
- {
- ucs = ' '; i += 4;
- } else {
- ucs = '?'; i++;
- }
- } else {
- ucs = '?'; i++;
- }
- } else {
- ucs = '?';
- i++;
- }
- l += XConvertUcsToUtf8(ucs, buffer_return + l);
+ while (i < len) {
+ unsigned int ucs;
+ unsigned char c;
+ c = (unsigned char) buf[i];
+ if (c < 0x80) {
+ ucs = c;
+ i++;
+ } else if (c >= 0xa1 && c < 0xff && len - i > 1 ) {
+ unsigned char b[2];
+ b[0] = (unsigned char) c - 0x80;
+ b[1] = (unsigned char) buf[i + 1] - 0x80;
+ ucs = ' '; i += 2;
+ } else if (c == 0x8e && len - i > 3) {
+ unsigned char b[2];
+ unsigned char c1 = buf[i + 1];
+ unsigned char c2 = buf[i + 2];
+ unsigned char c3 = buf[i + 3];
+ b[0] = (unsigned char) buf[i + 2] - 0x80;
+ b[1] = (unsigned char) buf[i + 3] - 0x80;
+ if (c1 >= 0xa1 && c1 <= 0xb0) {
+ if (c2 >= 0xa1 && c2 < 0xff && c3 >= 0xa1 && c3 < 0xff) {
+ ucs = ' '; i += 4;
+ } else {
+ ucs = '?'; i++;
}
+ } else {
+ ucs = '?'; i++;
+ }
+ } else {
+ ucs = '?';
+ i++;
+ }
+ l += XConvertUcsToUtf8(ucs, buffer_return + l);
+ }
#endif
- free(buf);
- return l;
+ free(buf);
+ return l;
}
int
-XConvertEucKrToUtf8(
- char* buffer_return,
- int len)
-{
- int i = 0, l = 0;
- char *buf;
-
- if (len < 1) return 0;
-
- buf = (char*) malloc((unsigned)len);
- memcpy(buf, buffer_return, (unsigned)len);
-
- while (i < len) {
- unsigned int ucs;
- unsigned char c, c1;
- c = (unsigned char) buf[i];
- if (c < 0x80) {
- ucs = c;
- i++;
- } else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
- c1 = (unsigned char) buf[i + 1];
- if (c1 >= 0xa1 && c1 < 0xff) {
- unsigned char b[2];
- b[0] = c - 0x80;
- b[1] = c1 - 0x80;
- if (ksc5601_mbtowc(NULL, &ucs, b, 2) < 1) {
- ucs = '?';
- }
- } else {
- ucs = '?';
- }
- i += 2;
- } else {
- ucs = '?';
- i++;
- }
- l += XConvertUcsToUtf8(ucs, buffer_return + l);
+XConvertEucKrToUtf8(char* buffer_return, int len) {
+ int i = 0, l = 0;
+ char *buf;
+
+ if (len < 1) return 0;
+
+ buf = (char*) malloc((unsigned)len);
+ memcpy(buf, buffer_return, (unsigned)len);
+
+ while (i < len) {
+ unsigned int ucs;
+ unsigned char c, c1;
+ c = (unsigned char) buf[i];
+ if (c < 0x80) {
+ ucs = c;
+ i++;
+ } else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
+ c1 = (unsigned char) buf[i + 1];
+ if (c1 >= 0xa1 && c1 < 0xff) {
+ unsigned char b[2];
+ b[0] = c - 0x80;
+ b[1] = c1 - 0x80;
+ if (ksc5601_mbtowc(NULL, &ucs, b, 2) < 1) {
+ ucs = '?';
}
- free(buf);
- return l;
+ } else {
+ ucs = '?';
+ }
+ i += 2;
+ } else {
+ ucs = '?';
+ i++;
+ }
+ l += XConvertUcsToUtf8(ucs, buffer_return + l);
+ }
+ free(buf);
+ return l;
}
int
-XConvertBig5ToUtf8(
- char* buffer_return,
- int len)
-{
- int i = 0, l = 0;
- char *buf;
-
- if (len < 1) return 0;
- buf = (char*) malloc((unsigned)len);
- memcpy(buf, buffer_return, (unsigned)len);
-
- if (len == 1) {
- l += XConvertUcsToUtf8((unsigned int)buf[i], buffer_return + l);
- }
- while (i + 1 < len) {
- unsigned int ucs;
- unsigned char b[2];
- b[0] = (unsigned char) buf[i];
- b[1] = (unsigned char) buf[i + 1];
- if (big5_mbtowc(NULL, &ucs, b, 2) == 2) {
- i += 2;
- } else {
- ucs = '?';
- i++;
- }
- l += XConvertUcsToUtf8(ucs, buffer_return + l);
- }
- free(buf);
- return l;
+XConvertBig5ToUtf8(char* buffer_return, int len) {
+ int i = 0, l = 0;
+ char *buf;
+
+ if (len < 1) return 0;
+ buf = (char*) malloc((unsigned)len);
+ memcpy(buf, buffer_return, (unsigned)len);
+
+ if (len == 1) {
+ l += XConvertUcsToUtf8((unsigned int)buf[i], buffer_return + l);
+ }
+ while (i + 1 < len) {
+ unsigned int ucs;
+ unsigned char b[2];
+ b[0] = (unsigned char) buf[i];
+ b[1] = (unsigned char) buf[i + 1];
+ if (big5_mbtowc(NULL, &ucs, b, 2) == 2) {
+ i += 2;
+ } else {
+ ucs = '?';
+ i++;
+ }
+ l += XConvertUcsToUtf8(ucs, buffer_return + l);
+ }
+ free(buf);
+ return l;
}
int
-XConvertGb2312ToUtf8(
- char* buffer_return,
- int len)
-{
- int i = 0, l = 0;
- char *buf;
-
- if (len < 1) return 0;
- buf = (char*) malloc((unsigned)len);
- memcpy(buf, buffer_return, (unsigned)len);
-
- if (len == 1) {
- l += XConvertUcsToUtf8((unsigned int)buf[i], buffer_return + l);
- }
- while (i + 1 < len) {
- unsigned int ucs;
- unsigned char b[2];
- b[0] = (unsigned char) buf[i];
- b[1] = (unsigned char) buf[i + 1];
- if (gb2312_mbtowc(NULL, &ucs, b, 2) == 2) {
- i += 2;
- } else {
- ucs = '?';
- i++;
- }
- l += XConvertUcsToUtf8(ucs, buffer_return + l);
- }
- free(buf);
- return l;
+XConvertGb2312ToUtf8(char* buffer_return, int len) {
+ int i = 0, l = 0;
+ char *buf;
+
+ if (len < 1) return 0;
+ buf = (char*) malloc((unsigned)len);
+ memcpy(buf, buffer_return, (unsigned)len);
+
+ if (len == 1) {
+ l += XConvertUcsToUtf8((unsigned int)buf[i], buffer_return + l);
+ }
+ while (i + 1 < len) {
+ unsigned int ucs;
+ unsigned char b[2];
+ b[0] = (unsigned char) buf[i];
+ b[1] = (unsigned char) buf[i + 1];
+ if (gb2312_mbtowc(NULL, &ucs, b, 2) == 2) {
+ i += 2;
+ } else {
+ ucs = '?';
+ i++;
+ }
+ l += XConvertUcsToUtf8(ucs, buffer_return + l);
+ }
+ free(buf);
+ return l;
}
int
-XConvertEucCnToUtf8(
- char* buffer_return,
- int len)
-{
- int i = 0, l = 0;
- char *buf;
-
- if (len < 1) return 0;
- buf = (char*) malloc((unsigned)len);
- memcpy(buf, buffer_return, (unsigned)len);
-
- while (i < len) {
- unsigned int ucs;
- unsigned char c, c1;
- c = (unsigned char) buf[i];
- if (c < 0x80) {
- ucs = c;
- i++;
- } else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
- c1 = (unsigned char) buf[i + 1];
- if (c1 >= 0xa1 && c1 < 0xff) {
- unsigned char b[2];
- b[0] = (unsigned char) c;
- b[1] = (unsigned char) c1;
- if (gb2312_mbtowc(NULL, &ucs, b, 2) < 1) {
- ucs = '?';
- }
- } else {
- ucs = '?';
- }
- i += 2;
- } else {
- ucs = '?';
- i++;
- }
- l += XConvertUcsToUtf8(ucs, buffer_return + l);
- }
- free(buf);
- return l;
+XConvertEucCnToUtf8(char* buffer_return, int len) {
+ int i = 0, l = 0;
+ char *buf;
+
+ if (len < 1) return 0;
+ buf = (char*) malloc((unsigned)len);
+ memcpy(buf, buffer_return, (unsigned)len);
+
+ while (i < len) {
+ unsigned int ucs;
+ unsigned char c, c1;
+ c = (unsigned char) buf[i];
+ if (c < 0x80) {
+ ucs = c;
+ i++;
+ } else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
+ c1 = (unsigned char) buf[i + 1];
+ if (c1 >= 0xa1 && c1 < 0xff) {
+ unsigned char b[2];
+ b[0] = (unsigned char) c;
+ b[1] = (unsigned char) c1;
+ if (gb2312_mbtowc(NULL, &ucs, b, 2) < 1) {
+ ucs = '?';
+ }
+ } else {
+ ucs = '?';
+ }
+ i += 2;
+ } else {
+ ucs = '?';
+ i++;
+ }
+ l += XConvertUcsToUtf8(ucs, buffer_return + l);
+ }
+ free(buf);
+ return l;
}
int
-XConvertEucJpToUtf8(
- char* buffer_return,
- int len)
-{
- int i = 0, l = 0;
- char *buf;
-
- if (len < 1) return 0;
- buf = (char*) malloc((unsigned)len);
- memcpy(buf, buffer_return, (unsigned)len);
-
- while (i < len) {
- unsigned int ucs;
- unsigned char c, c1;
- c = (unsigned char) buf[i];
- if (c < 0x80) {
- ucs = c;
- i++;
- } else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
- c1 = (unsigned char) buf[i + 1];
- if (c < 0xF5 && c1 >= 0xa1) {
- unsigned char b[2];
- b[0] = c - 0x80;
- b[1] = c1 - 0x80;
- if (jisx0208_mbtowc(NULL, &ucs, b, 2) < 1) {
- ucs = '?';
- }
- } else if (c1 >= 0xA1 && c1 < 0xFF) {
- ucs = 0xE000 + 94 * (c - 0xF5) + (c1 - 0xA1);
- } else {
- ucs = '?';
- }
- i += 2;
- } else if (c == 0x8E && len - i > 1) {
- c1 = (unsigned char) buf[i + 1];
- if (c1 >= 0xa1 && c1 <= 0xe0) {
- if (jisx0201_mbtowc(NULL, &ucs, &c1, 1) != 1) {
- ucs = '?';
- }
- } else {
- ucs = '?';
- }
- i += 2;
- } else if (c == 0x8F && len - i > 2) {
- c = (unsigned char) buf[i + 1];
- c1 = (unsigned char) buf[i + 2];
- if (c >= 0xa1 && c < 0xff) {
- if (c < 0xf5 && c1 >= 0xa1 && c1 < 0xff) {
- unsigned char b[2];
- b[0] = c - 0x80;
- b[1] = c1 - 0x80;
- if (jisx0212_mbtowc(NULL, &ucs, b, 2)
- < 1)
- {
- ucs = '?';
- }
- } else {
- ucs = '?';
- }
- } else {
- if (c1 >= 0xa1 && c1 < 0xff) {
- ucs = 0xe3ac + 94 * (c - 0xF5) +
- (c1 - 0xA1);
- } else {
- ucs = '?';
- }
- }
- i += 3;
- } else {
- ucs = '?';
- i++;
- }
- l += XConvertUcsToUtf8(ucs, buffer_return + l);
+XConvertEucJpToUtf8(char* buffer_return, int len) {
+ int i = 0, l = 0;
+ char *buf;
+
+ if (len < 1) return 0;
+ buf = (char*) malloc((unsigned)len);
+ memcpy(buf, buffer_return, (unsigned)len);
+
+ while (i < len) {
+ unsigned int ucs;
+ unsigned char c, c1;
+ c = (unsigned char) buf[i];
+ if (c < 0x80) {
+ ucs = c;
+ i++;
+ } else if (c >= 0xA1 && c < 0xFF && len - i > 1) {
+ c1 = (unsigned char) buf[i + 1];
+ if (c < 0xF5 && c1 >= 0xa1) {
+ unsigned char b[2];
+ b[0] = c - 0x80;
+ b[1] = c1 - 0x80;
+ if (jisx0208_mbtowc(NULL, &ucs, b, 2) < 1) {
+ ucs = '?';
+ }
+ } else if (c1 >= 0xA1 && c1 < 0xFF) {
+ ucs = 0xE000 + 94 * (c - 0xF5) + (c1 - 0xA1);
+ } else {
+ ucs = '?';
+ }
+ i += 2;
+ } else if (c == 0x8E && len - i > 1) {
+ c1 = (unsigned char) buf[i + 1];
+ if (c1 >= 0xa1 && c1 <= 0xe0) {
+ if (jisx0201_mbtowc(NULL, &ucs, &c1, 1) != 1) {
+ ucs = '?';
+ }
+ } else {
+ ucs = '?';
+ }
+ i += 2;
+ } else if (c == 0x8F && len - i > 2) {
+ c = (unsigned char) buf[i + 1];
+ c1 = (unsigned char) buf[i + 2];
+ if (c >= 0xa1 && c < 0xff) {
+ if (c < 0xf5 && c1 >= 0xa1 && c1 < 0xff) {
+ unsigned char b[2];
+ b[0] = c - 0x80;
+ b[1] = c1 - 0x80;
+ if (jisx0212_mbtowc(NULL, &ucs, b, 2) < 1) {
+ ucs = '?';
+ }
+ } else {
+ ucs = '?';
}
- free(buf);
- return l;
+ } else {
+ if (c1 >= 0xa1 && c1 < 0xff) {
+ ucs = 0xe3ac + 94 * (c - 0xF5) + (c1 - 0xA1);
+ } else {
+ ucs = '?';
+ }
+ }
+ i += 3;
+ } else {
+ ucs = '?';
+ i++;
+ }
+ l += XConvertUcsToUtf8(ucs, buffer_return + l);
+ }
+ free(buf);
+ return l;
}
int
-XConvertEucToUtf8(
- const char* locale,
- char* buffer_return,
- int len,
- int bytes_buffer)
-{
- if (!locale/* || strstr(locale, "UTF") || strstr(locale, "utf")*/) {
- return len;
- }
+XConvertEucToUtf8(const char* locale,
+ char* buffer_return,
+ int len,
+ int bytes_buffer) {
- if (strstr(locale, "ja")) {
- return XConvertEucJpToUtf8(buffer_return, len);
- } else if (strstr(locale, "Big5") || strstr(locale, "big5")) { /* BIG5 */
- return XConvertBig5ToUtf8(buffer_return, len);
- } else if (strstr(locale, "zh") || strstr(locale, "chinese-")) {
- if (strstr(locale, "TW") || strstr(locale, "chinese-t")) {
- if (strstr(locale, "EUC") || strstr(locale, "euc") ||
- strstr(locale, "chinese-t"))
- {
- return XConvertEucTwToUtf8(buffer_return, len);
- }
- return XConvertBig5ToUtf8(buffer_return, len);
- }
- if (strstr(locale, "EUC") || strstr(locale, "euc")) {
- return XConvertEucCnToUtf8(buffer_return, len);
- }
- return XConvertGb2312ToUtf8(buffer_return, len);
- } else if (strstr(locale, "ko")) {
- return XConvertEucKrToUtf8(buffer_return, len);
- }
- return len;
-}
+ if (!locale/* || strstr(locale, "UTF") || strstr(locale, "utf")*/) {
+ return len;
+ }
+ if (strstr(locale, "ja")) {
+ return XConvertEucJpToUtf8(buffer_return, len);
+ } else if (strstr(locale, "Big5") || strstr(locale, "big5")) { /* BIG5 */
+ return XConvertBig5ToUtf8(buffer_return, len);
+ } else if (strstr(locale, "zh") || strstr(locale, "chinese-")) {
+ if (strstr(locale, "TW") || strstr(locale, "chinese-t")) {
+ if (strstr(locale, "EUC") || strstr(locale, "euc") || strstr(locale, "chinese-t")) {
+ return XConvertEucTwToUtf8(buffer_return, len);
+ }
+ return XConvertBig5ToUtf8(buffer_return, len);
+ }
+ if (strstr(locale, "EUC") || strstr(locale, "euc")) {
+ return XConvertEucCnToUtf8(buffer_return, len);
+ }
+ return XConvertGb2312ToUtf8(buffer_return, len);
+ } else if (strstr(locale, "ko")) {
+ return XConvertEucKrToUtf8(buffer_return, len);
+ }
+ return len;
+}
int
-XUtf8LookupString(
- XIC ic,
- XKeyPressedEvent* event,
- char* buffer_return,
- int bytes_buffer,
- KeySym* keysym,
- Status* status_return)
-{
- long ucs = -1;
- int len;
- len = XmbLookupString(ic, event, buffer_return, bytes_buffer / 5,
- keysym, status_return);
- if (*status_return == XBufferOverflow) {
- return len * 5;
- }
- if (*keysym > 0 && *keysym < 0x100 && len == 1) {
- if (*keysym < 0x80) {
- ucs = (unsigned char)buffer_return[0];
- } else {
- ucs = *keysym;
- }
- } else if (((*keysym >= 0x100 && *keysym <= 0xf000) ||
- (*keysym & 0xff000000U) == 0x01000000))
- {
- ucs = XKeysymToUcs(*keysym);
- } else {
- ucs = -2;
- }
-
- if (ucs > 0) {
- len = XConvertUcsToUtf8((unsigned)ucs, (char *)buffer_return);
- } else if (len > 0) {
- XIM im;
- if (!ic) return 0;
- im = XIMOfIC(ic);
- if (!im) return 0;
- len = XConvertEucToUtf8(XLocaleOfIM(im),
- buffer_return, len, bytes_buffer);
- }
- return len;
+XUtf8LookupString(XIC ic,
+ XKeyPressedEvent* event,
+ char* buffer_return,
+ int bytes_buffer,
+ KeySym* keysym,
+ Status* status_return) {
+
+ long ucs = -1;
+ int len;
+ len = XmbLookupString(ic, event, buffer_return, bytes_buffer / 5,
+ keysym, status_return);
+ if (*status_return == XBufferOverflow) {
+ return len * 5;
+ }
+ if (*keysym > 0 && *keysym < 0x100 && len == 1) {
+ if (*keysym < 0x80) {
+ ucs = (unsigned char)buffer_return[0];
+ } else {
+ ucs = *keysym;
+ }
+ } else if (((*keysym >= 0x100 && *keysym <= 0xf000) ||
+ (*keysym & 0xff000000U) == 0x01000000))
+ {
+ ucs = XKeysymToUcs(*keysym);
+ } else {
+ ucs = -2;
+ }
+
+ if (ucs > 0) {
+ len = XConvertUcsToUtf8((unsigned)ucs, (char *)buffer_return);
+ } else if (len > 0) {
+ XIM im;
+ if (!ic) return 0;
+ im = XIMOfIC(ic);
+ if (!im) return 0;
+ len = XConvertEucToUtf8(XLocaleOfIM(im), buffer_return, len, bytes_buffer);
+ }
+ return len;
}
#endif /* X11 only */
diff --git a/src/xutf8/utf8Utils.c b/src/xutf8/utf8Utils.c
index 9ad8e4d81..6c177a719 100644
--- a/src/xutf8/utf8Utils.c
+++ b/src/xutf8/utf8Utils.c
@@ -39,73 +39,69 @@
* Returns -1 if the UTF-8 string is not valid
*/
int
-XConvertUtf8ToUcs(
- const unsigned char *buf,
- int len,
- unsigned int *ucs)
-{
- if (buf[0] & 0x80) {
- if (buf[0] & 0x40) {
- if (buf[0] & 0x20) {
- if (buf[0] & 0x10) {
- if (buf[0] & 0x08) {
- if (buf[0] & 0x04) {
- if (buf[0] & 0x02) {
- /* bad UTF-8 string */
- } else {
- /* 0x04000000 - 0x7FFFFFFF */
- }
- } else if (len > 4
- && (buf[1] & 0xC0) == 0x80
- && (buf[2] & 0xC0) == 0x80
- && (buf[3] & 0xC0) == 0x80
- && (buf[4] & 0xC0) == 0x80)
- {
- /* 0x00200000 - 0x03FFFFFF */
- *ucs = ((buf[0] & ~0xF8) << 24) +
- ((buf[1] & ~0x80) << 18) +
- ((buf[2] & ~0x80) << 12) +
- ((buf[3] & ~0x80) << 6) +
- (buf[4] & ~0x80);
- if (*ucs > 0x001FFFFF && *ucs < 0x01000000) return 5;
- }
- } else if (len > 3
- && (buf[1] & 0xC0) == 0x80
- && (buf[2] & 0xC0) == 0x80
- && (buf[3] & 0xC0) == 0x80)
- {
- /* 0x00010000 - 0x001FFFFF */
- *ucs = ((buf[0] & ~0xF0) << 18) +
- ((buf[1] & ~0x80) << 12) +
- ((buf[2] & ~0x80) << 6) +
- (buf[3] & ~0x80);
- if (*ucs > 0x0000FFFF) return 4;
- }
- } else if (len > 2 &&
- (buf[1] & 0xC0) == 0x80 &&
- (buf[2] & 0xC0) == 0x80)
- {
- /* 0x00000800 - 0x0000FFFF */
- *ucs = ((buf[0] & ~0xE0) << 12) +
- ((buf[1] & ~0x80) << 6) +
- (buf[2] & ~0x80);
- if (*ucs > 0x000007FF) return 3;
- }
- } else if (len > 1 && (buf[1] & 0xC0) == 0x80) {
- /* 0x00000080 - 0x000007FF */
- *ucs = ((buf[0] & ~0xC0) << 6) +
- (buf[1] & ~0x80);
- if (*ucs > 0x0000007F) return 2;
+XConvertUtf8ToUcs(const unsigned char *buf,
+ int len,
+ unsigned int *ucs) {
+
+ if (buf[0] & 0x80) {
+ if (buf[0] & 0x40) {
+ if (buf[0] & 0x20) {
+ if (buf[0] & 0x10) {
+ if (buf[0] & 0x08) {
+ if (buf[0] & 0x04) {
+ if (buf[0] & 0x02) {
+ /* bad UTF-8 string */
+ } else {
+ /* 0x04000000 - 0x7FFFFFFF */
+ }
+ } else if (len > 4
+ && (buf[1] & 0xC0) == 0x80
+ && (buf[2] & 0xC0) == 0x80
+ && (buf[3] & 0xC0) == 0x80
+ && (buf[4] & 0xC0) == 0x80) {
+ /* 0x00200000 - 0x03FFFFFF */
+ *ucs = ((buf[0] & ~0xF8) << 24) +
+ ((buf[1] & ~0x80) << 18) +
+ ((buf[2] & ~0x80) << 12) +
+ ((buf[3] & ~0x80) << 6) +
+ (buf[4] & ~0x80);
+ if (*ucs > 0x001FFFFF && *ucs < 0x01000000) return 5;
+ }
+ } else if (len > 3
+ && (buf[1] & 0xC0) == 0x80
+ && (buf[2] & 0xC0) == 0x80
+ && (buf[3] & 0xC0) == 0x80) {
+ /* 0x00010000 - 0x001FFFFF */
+ *ucs = ((buf[0] & ~0xF0) << 18) +
+ ((buf[1] & ~0x80) << 12) +
+ ((buf[2] & ~0x80) << 6) +
+ (buf[3] & ~0x80);
+ if (*ucs > 0x0000FFFF) return 4;
}
- }
- } else if (len > 0) {
- /* 0x00000000 - 0x0000007F */
- *ucs = buf[0];
- return 1;
- }
-
- *ucs = (unsigned int) '?'; /* bad utf-8 string */
- return -1;
+ } else if (len > 2
+ && (buf[1] & 0xC0) == 0x80
+ && (buf[2] & 0xC0) == 0x80) {
+ /* 0x00000800 - 0x0000FFFF */
+ *ucs = ((buf[0] & ~0xE0) << 12) +
+ ((buf[1] & ~0x80) << 6) +
+ (buf[2] & ~0x80);
+ if (*ucs > 0x000007FF) return 3;
+ }
+ } else if (len > 1 && (buf[1] & 0xC0) == 0x80) {
+ /* 0x00000080 - 0x000007FF */
+ *ucs = ((buf[0] & ~0xC0) << 6) +
+ (buf[1] & ~0x80);
+ if (*ucs > 0x0000007F) return 2;
+ }
+ }
+ } else if (len > 0) {
+ /* 0x00000000 - 0x0000007F */
+ *ucs = buf[0];
+ return 1;
+ }
+
+ *ucs = (unsigned int) '?'; /* bad utf-8 string */
+ return -1;
}
/*
@@ -113,38 +109,37 @@ XConvertUtf8ToUcs(
* NOTE : the buffer (buf) must be at least 5 bytes long !!!
*/
int
-XConvertUcsToUtf8(
- unsigned int ucs,
- char *buf)
-{
- if (ucs < 0x000080) {
- buf[0] = ucs;
- return 1;
- } else if (ucs < 0x000800) {
- buf[0] = 0xC0 | (ucs >> 6);
- buf[1] = 0x80 | (ucs & 0x3F);
- return 2;
- } else if (ucs < 0x010000) {
- buf[0] = 0xE0 | (ucs >> 12);
- buf[1] = 0x80 | ((ucs >> 6) & 0x3F);
- buf[2] = 0x80 | (ucs & 0x3F);
- return 3;
- } else if (ucs < 0x00200000) {
- buf[0] = 0xF0 | (ucs >> 18);
- buf[1] = 0x80 | ((ucs >> 12) & 0x3F);
- buf[2] = 0x80 | ((ucs >> 6) & 0x3F);
- buf[3] = 0x80 | (ucs & 0x3F);
- return 4;
- } else if (ucs < 0x01000000) {
- buf[0] = 0xF8 | (ucs >> 24);
- buf[1] = 0x80 | ((ucs >> 18) & 0x3F);
- buf[2] = 0x80 | ((ucs >> 12) & 0x3F);
- buf[3] = 0x80 | ((ucs >> 6) & 0x3F);
- buf[4] = 0x80 | (ucs & 0x3F);
- return 5;
- }
- buf[0] = '?';
- return -1;
+XConvertUcsToUtf8(unsigned int ucs,
+ char *buf) {
+
+ if (ucs < 0x000080) {
+ buf[0] = ucs;
+ return 1;
+ } else if (ucs < 0x000800) {
+ buf[0] = 0xC0 | (ucs >> 6);
+ buf[1] = 0x80 | (ucs & 0x3F);
+ return 2;
+ } else if (ucs < 0x010000) {
+ buf[0] = 0xE0 | (ucs >> 12);
+ buf[1] = 0x80 | ((ucs >> 6) & 0x3F);
+ buf[2] = 0x80 | (ucs & 0x3F);
+ return 3;
+ } else if (ucs < 0x00200000) {
+ buf[0] = 0xF0 | (ucs >> 18);
+ buf[1] = 0x80 | ((ucs >> 12) & 0x3F);
+ buf[2] = 0x80 | ((ucs >> 6) & 0x3F);
+ buf[3] = 0x80 | (ucs & 0x3F);
+ return 4;
+ } else if (ucs < 0x01000000) {
+ buf[0] = 0xF8 | (ucs >> 24);
+ buf[1] = 0x80 | ((ucs >> 18) & 0x3F);
+ buf[2] = 0x80 | ((ucs >> 12) & 0x3F);
+ buf[3] = 0x80 | ((ucs >> 6) & 0x3F);
+ buf[4] = 0x80 | (ucs & 0x3F);
+ return 5;
+ }
+ buf[0] = '?';
+ return -1;
}
/*
@@ -152,92 +147,88 @@ XConvertUcsToUtf8(
* (returns -1 if not valid)
*/
int
-XUtf8CharByteLen(
- const unsigned char *buf,
- int len)
-{
- unsigned int ucs;
- return XConvertUtf8ToUcs(buf, len, &ucs);
+XUtf8CharByteLen(const unsigned char *buf,
+ int len) {
+ unsigned int ucs;
+ return XConvertUtf8ToUcs(buf, len, &ucs);
}
/*
* returns the quantity of Unicode chars in the UTF-8 string
*/
int
-XCountUtf8Char(
- const unsigned char *buf,
- int len)
-{
- int i = 0;
- int nbc = 0;
- while (i < len) {
- int cl = XUtf8CharByteLen(buf + i, len - i);
- if (cl < 1) cl = 1;
- nbc++;
- i += cl;
- }
- return nbc;
+XCountUtf8Char(const unsigned char *buf,
+ int len) {
+
+ int i = 0;
+ int nbc = 0;
+ while (i < len) {
+ int cl = XUtf8CharByteLen(buf + i, len - i);
+ if (cl < 1) cl = 1;
+ nbc++;
+ i += cl;
+ }
+ return nbc;
}
/*
* Same as XConvertUtf8ToUcs but no sanity check is done.
*/
int
-XFastConvertUtf8ToUcs(
- const unsigned char *buf,
- int len,
- unsigned int *ucs)
-{
- if (buf[0] & 0x80) {
- if (buf[0] & 0x40) {
- if (buf[0] & 0x20) {
- if (buf[0] & 0x10) {
- if (buf[0] & 0x08) {
- if (buf[0] & 0x04) {
- if (buf[0] & 0x02) {
- /* bad UTF-8 string */
- } else {
- /* 0x04000000 - 0x7FFFFFFF */
- }
- } else if (len > 4) {
- /* 0x00200000 - 0x03FFFFFF */
- *ucs = ((buf[0] & ~0xF8) << 24) +
- ((buf[1] & ~0x80) << 18) +
- ((buf[2] & ~0x80) << 12) +
- ((buf[3] & ~0x80) << 6) +
- (buf[4] & ~0x80);
- return 5;
- }
- } else if (len > 3) {
- /* 0x00010000 - 0x001FFFFF */
- *ucs = ((buf[0] & ~0xF0) << 18) +
- ((buf[1] & ~0x80) << 12) +
- ((buf[2] & ~0x80) << 6) +
- (buf[3] & ~0x80);
- return 4;
- }
- } else if (len > 2) {
- /* 0x00000800 - 0x0000FFFF */
- *ucs = ((buf[0] & ~0xE0) << 12) +
- ((buf[1] & ~0x80) << 6) +
- (buf[2] & ~0x80);
- return 3;
- }
- } else if (len > 1) {
- /* 0x00000080 - 0x000007FF */
- *ucs = ((buf[0] & ~0xC0) << 6) +
- (buf[1] & ~0x80);
- return 2;
+XFastConvertUtf8ToUcs(const unsigned char *buf,
+ int len,
+ unsigned int *ucs) {
+
+ if (buf[0] & 0x80) {
+ if (buf[0] & 0x40) {
+ if (buf[0] & 0x20) {
+ if (buf[0] & 0x10) {
+ if (buf[0] & 0x08) {
+ if (buf[0] & 0x04) {
+ if (buf[0] & 0x02) {
+ /* bad UTF-8 string */
+ } else {
+ /* 0x04000000 - 0x7FFFFFFF */
+ }
+ } else if (len > 4) {
+ /* 0x00200000 - 0x03FFFFFF */
+ *ucs = ((buf[0] & ~0xF8) << 24) +
+ ((buf[1] & ~0x80) << 18) +
+ ((buf[2] & ~0x80) << 12) +
+ ((buf[3] & ~0x80) << 6) +
+ (buf[4] & ~0x80);
+ return 5;
+ }
+ } else if (len > 3) {
+ /* 0x00010000 - 0x001FFFFF */
+ *ucs = ((buf[0] & ~0xF0) << 18) +
+ ((buf[1] & ~0x80) << 12) +
+ ((buf[2] & ~0x80) << 6) +
+ (buf[3] & ~0x80);
+ return 4;
}
- }
- } else if (len > 0) {
- /* 0x00000000 - 0x0000007F */
- *ucs = buf[0];
- return 1;
- }
-
- *ucs = (unsigned int) '?'; /* bad utf-8 string */
- return -1;
+ } else if (len > 2) {
+ /* 0x00000800 - 0x0000FFFF */
+ *ucs = ((buf[0] & ~0xE0) << 12) +
+ ((buf[1] & ~0x80) << 6) +
+ (buf[2] & ~0x80);
+ return 3;
+ }
+ } else if (len > 1) {
+ /* 0x00000080 - 0x000007FF */
+ *ucs = ((buf[0] & ~0xC0) << 6) +
+ (buf[1] & ~0x80);
+ return 2;
+ }
+ }
+ } else if (len > 0) {
+ /* 0x00000000 - 0x0000007F */
+ *ucs = buf[0];
+ return 1;
+ }
+
+ *ucs = (unsigned int) '?'; /* bad utf-8 string */
+ return -1;
}
#endif /* X11 only */
diff --git a/src/xutf8/utf8Wrap.c b/src/xutf8/utf8Wrap.c
index 88d9fc5f2..4961ac0f4 100644
--- a/src/xutf8/utf8Wrap.c
+++ b/src/xutf8/utf8Wrap.c
@@ -49,45 +49,44 @@
static int
get_font_list(
const char *base_font_name_list,
- char ***flist)
-{
- const char *ptr;
- const char *p;
- int nb;
- int nb_name;
-
- ptr = base_font_name_list;
- p = NULL;
- nb = 0;
- nb_name = 1;
-
- while (*ptr) {
- if (*ptr == ',') nb_name++;
- ptr++;
- }
-
- *flist = (char **) malloc(sizeof(char*) * nb_name);
- ptr = base_font_name_list;
-
- while (*ptr) {
- int l = 0, i = 0;
-
- while(isspace(*ptr)) ptr++;
- p = ptr;
- while (*ptr && *ptr != ',') { ptr++; l++; }
- if (l > 2) {
- (*flist)[nb] = (char*) malloc((unsigned)l + 2);
- while (p != ptr) { ((*flist)[nb])[i] = *p; i++; p++; }
- (*flist)[nb][i] = '\0';
- nb++;
- }
- if (*ptr) ptr++;
- }
- if (nb < 1) {
- free(*flist);
- *flist = (char**)NULL;
- }
- return nb;
+ char ***flist) {
+ const char *ptr;
+ const char *p;
+ int nb;
+ int nb_name;
+
+ ptr = base_font_name_list;
+ p = NULL;
+ nb = 0;
+ nb_name = 1;
+
+ while (*ptr) {
+ if (*ptr == ',') nb_name++;
+ ptr++;
+ }
+
+ *flist = (char **) malloc(sizeof(char*) * nb_name);
+ ptr = base_font_name_list;
+
+ while (*ptr) {
+ int l = 0, i = 0;
+
+ while(isspace(*ptr)) ptr++;
+ p = ptr;
+ while (*ptr && *ptr != ',') { ptr++; l++; }
+ if (l > 2) {
+ (*flist)[nb] = (char*) malloc((unsigned)l + 2);
+ while (p != ptr) { ((*flist)[nb])[i] = *p; i++; p++; }
+ (*flist)[nb][i] = '\0';
+ nb++;
+ }
+ if (*ptr) ptr++;
+ }
+ if (nb < 1) {
+ free(*flist);
+ *flist = (char**)NULL;
+ }
+ return nb;
}
/*********************************************************************/
@@ -95,26 +94,24 @@ get_font_list(
/** (mainly used for adobe-symbol and adobe-zapfdingbats) **/
/*********************************************************************/
static int
-font_spec_enc(
- char *font)
-{
- int ret;
- char *enc;
- char *end;
-
- enc = font;
- while (*enc != '-') enc++;
- enc++;
- while (*enc != '-') enc++;
- enc++;
- end = enc;
- while (*end != '-') end++;
- *end = '\0';
-
- ret = encoding_number(enc);
- *end = '-';
-
- return ret;
+font_spec_enc(char *font) {
+ int ret;
+ char *enc;
+ char *end;
+
+ enc = font;
+ while (*enc != '-') enc++;
+ enc++;
+ while (*enc != '-') enc++;
+ enc++;
+ end = enc;
+ while (*end != '-') end++;
+ *end = '\0';
+
+ ret = encoding_number(enc);
+ *end = '-';
+
+ return ret;
}
@@ -122,174 +119,168 @@ font_spec_enc(
/** get the sub range of a iso10646-1 font **/
/*********************************************************************/
static void
-get_range(
- const char *enc,
- int *min,
- int *max)
-{
- const char *ptr = enc;
- const char *ptr1;
-
- if (!enc) return;
-
- while (*ptr && *ptr != '-') ptr++;
- if (!*ptr) return;
- while (*ptr && *ptr != '[') ptr++;
- if (!*ptr) return;
- *min = 0xFFFF;
- *max = 0;
- while (*ptr && *ptr != ']') {
- int val;
- ptr++;
- ptr1 = ptr;
- while (*ptr && *ptr != ']' && *ptr != ' ' && *ptr != '_') ptr++;
- val = strtol(ptr1, NULL, 0);
- if (val < *min) *min = val;
- if (val > *max) *max = val;
- }
+get_range(const char *enc,
+ int *min,
+ int *max) {
+
+ const char *ptr = enc;
+ const char *ptr1;
+
+ if (!enc) return;
+
+ while (*ptr && *ptr != '-') ptr++;
+ if (!*ptr) return;
+ while (*ptr && *ptr != '[') ptr++;
+ if (!*ptr) return;
+ *min = 0xFFFF;
+ *max = 0;
+ while (*ptr && *ptr != ']') {
+ int val;
+ ptr++;
+ ptr1 = ptr;
+ while (*ptr && *ptr != ']' && *ptr != ' ' && *ptr != '_') ptr++;
+ val = strtol(ptr1, NULL, 0);
+ if (val < *min) *min = val;
+ if (val > *max) *max = val;
+ }
}
/*********************************************************************/
/** get the internal encoding number of each fonts **/
/*********************************************************************/
static int *
-get_encodings(
- char **font_name_list,
- int *ranges,
- int nb_font)
-{
- int *font_encoding_list;
- int i;
- i = 0;
-
- font_encoding_list = (int *) malloc(sizeof(int) * nb_font);
- while (i < nb_font) {
- char *ptr;
- int ec;
- ptr = font_name_list[i];
- ec = 0;
- font_encoding_list[i] = -1;
- ranges[i * 2] = 0;
- ranges[i * 2 + 1] = 0xFFFF;
-
- if (ptr && strstr(ptr, "fontspecific")) {
- font_encoding_list[i] = font_spec_enc(ptr);
- ptr = NULL;
- }
- while (ptr && *ptr) {
- if (*ptr == '-') {
- ec++;
- if (ec == 13) {
- font_encoding_list[i] =
- encoding_number(ptr + 1);
- if (font_encoding_list[i] == 0) {
- get_range(ptr + 1,
- ranges + i * 2,
- ranges + i * 2 + 1);
- }
- break;
- }
- }
- ptr++;
- }
- if (font_encoding_list[i] < 0) font_encoding_list[i] = 1;
- i++;
+get_encodings(char **font_name_list,
+ int *ranges,
+ int nb_font) {
+
+ int *font_encoding_list;
+ int i;
+ i = 0;
+
+ font_encoding_list = (int *) malloc(sizeof(int) * nb_font);
+ while (i < nb_font) {
+ char *ptr;
+ int ec;
+ ptr = font_name_list[i];
+ ec = 0;
+ font_encoding_list[i] = -1;
+ ranges[i * 2] = 0;
+ ranges[i * 2 + 1] = 0xFFFF;
+
+ if (ptr && strstr(ptr, "fontspecific")) {
+ font_encoding_list[i] = font_spec_enc(ptr);
+ ptr = NULL;
+ }
+ while (ptr && *ptr) {
+ if (*ptr == '-') {
+ ec++;
+ if (ec == 13) {
+ font_encoding_list[i] = encoding_number(ptr + 1);
+ if (font_encoding_list[i] == 0) {
+ get_range(ptr + 1,
+ ranges + i * 2,
+ ranges + i * 2 + 1);
+ }
+ break;
}
- return font_encoding_list;
+ }
+ ptr++;
+ }
+ if (font_encoding_list[i] < 0) font_encoding_list[i] = 1;
+ i++;
+ }
+ return font_encoding_list;
}
/*********************************************************************/
/** find the first font which matches the name and load it. **/
/*********************************************************************/
XFontStruct *
-find_best_font(
- Display *dpy,
- char **name)
-{
- char **list;
- int cnt;
- XFontStruct *s;
-
- list = XListFonts(dpy, *name, 1, &cnt);
- if (cnt && list) {
- free(*name);
- *name = strdup(list[0]);
- s = XLoadQueryFont(dpy, *name);
- XFreeFontNames(list);
- return s;
- }
- return NULL;
+find_best_font(Display *dpy,
+ char **name) {
+
+ char **list;
+ int cnt;
+ XFontStruct *s;
+
+ list = XListFonts(dpy, *name, 1, &cnt);
+ if (cnt && list) {
+ free(*name);
+ *name = strdup(list[0]);
+ s = XLoadQueryFont(dpy, *name);
+ XFreeFontNames(list);
+ return s;
+ }
+ return NULL;
}
/*********************************************************************/
/** load all fonts **/
/*********************************************************************/
static void
-load_fonts(
- Display *dpy,
- XUtf8FontStruct *font_set)
-{
- int i;
- char **list;
-
- i = 0;
- list = NULL;
-
- font_set->fonts = (XFontStruct**)
- malloc(sizeof(XFontStruct*) * font_set->nb_font);
-
- font_set->ranges = (int*)
- malloc(sizeof(int) * font_set->nb_font * 2);
-
- font_set->descent = 0;
- font_set->ascent = 0;
- font_set->fid = 0;
-
- while (i < font_set->nb_font) {
- XFontStruct *fnt;
-
- fnt = font_set->fonts[i] =
- find_best_font(dpy, &(font_set->font_name_list[i]));
- if (fnt) {
- font_set->fid = fnt->fid;
- if (fnt->ascent > font_set->ascent) {
- font_set->ascent = fnt->ascent;
- }
- if (fnt->descent > font_set->descent) {
- font_set->descent = fnt->descent;
- }
- } else {
- free(font_set->font_name_list[i]);
- font_set->font_name_list[i] = NULL;
- }
- i++;
+load_fonts(Display *dpy,
+ XUtf8FontStruct *font_set) {
+
+ int i;
+ char **list;
+
+ i = 0;
+ list = NULL;
+
+ font_set->fonts = (XFontStruct**) malloc(sizeof(XFontStruct*) *
+ font_set->nb_font);
+
+ font_set->ranges = (int*) malloc(sizeof(int) *
+ font_set->nb_font * 2);
+
+ font_set->descent = 0;
+ font_set->ascent = 0;
+ font_set->fid = 0;
+
+ while (i < font_set->nb_font) {
+ XFontStruct *fnt;
+
+ fnt = font_set->fonts[i] =
+ find_best_font(dpy, &(font_set->font_name_list[i]));
+ if (fnt) {
+ font_set->fid = fnt->fid;
+ if (fnt->ascent > font_set->ascent) {
+ font_set->ascent = fnt->ascent;
+ }
+ if (fnt->descent > font_set->descent) {
+ font_set->descent = fnt->descent;
+ }
+ } else {
+ free(font_set->font_name_list[i]);
+ font_set->font_name_list[i] = NULL;
+ }
+ i++;
+ }
+
+ font_set->encodings =
+ get_encodings(font_set->font_name_list,
+ font_set->ranges, font_set->nb_font);
+
+ /* unload fonts with same encoding */
+ for (i = 0; i < font_set->nb_font; i++) {
+ if (font_set->font_name_list[i]) {
+ int j;
+ for (j = 0; j < i; j++) {
+ if (font_set->font_name_list[j] &&
+ font_set->encodings[j] ==
+ font_set->encodings[i] &&
+ font_set->ranges[2*j] ==
+ font_set->ranges[2*i] &&
+ font_set->ranges[(2*j)+1] &&
+ font_set->ranges[(2*i)+1]) {
+ XFreeFont(dpy, font_set->fonts[i]);
+ free(font_set->font_name_list[i]);
+ font_set->font_name_list[i] = NULL;
+ font_set->fonts[i] = 0;
}
-
- font_set->encodings =
- get_encodings(font_set->font_name_list,
- font_set->ranges, font_set->nb_font);
-
- /* unload fonts with same encoding */
- for (i = 0; i < font_set->nb_font; i++) {
- if (font_set->font_name_list[i]) {
- int j;
- for (j = 0; j < i; j++) {
- if (font_set->font_name_list[j] &&
- font_set->encodings[j] ==
- font_set->encodings[i] &&
- font_set->ranges[2*j] ==
- font_set->ranges[2*i] &&
- font_set->ranges[(2*j)+1] &&
- font_set->ranges[(2*i)+1])
- {
- XFreeFont(dpy, font_set->fonts[i]);
- free(font_set->font_name_list[i]);
- font_set->font_name_list[i] = NULL;
- font_set->fonts[i] = 0;
- }
- }
- }
- }
+ }
+ }
+ }
}
/*********************************************************************/
@@ -297,30 +288,28 @@ load_fonts(
/** list of fonts. XLoad all fonts. **/
/*********************************************************************/
XUtf8FontStruct *
-XCreateUtf8FontStruct (
- Display *dpy,
- const char *base_font_name_list)
-{
- XUtf8FontStruct *font_set;
-
- font_set = (XUtf8FontStruct*)
- malloc(sizeof(XUtf8FontStruct));
-
- if (!font_set) {
- return NULL;
- }
-
- font_set->nb_font = get_font_list(base_font_name_list,
- &font_set->font_name_list);
-
- if (font_set->nb_font < 1) {
- free(font_set);
- return NULL;
- }
+XCreateUtf8FontStruct(Display *dpy,
+ const char *base_font_name_list) {
+
+ XUtf8FontStruct *font_set;
+
+ font_set = (XUtf8FontStruct*)malloc(sizeof(XUtf8FontStruct));
+
+ if (!font_set) {
+ return NULL;
+ }
- load_fonts(dpy, font_set);
+ font_set->nb_font = get_font_list(base_font_name_list,
+ &font_set->font_name_list);
- return font_set;
+ if (font_set->nb_font < 1) {
+ free(font_set);
+ return NULL;
+ }
+
+ load_fonts(dpy, font_set);
+
+ return font_set;
}
@@ -328,126 +317,120 @@ XCreateUtf8FontStruct (
/** draw a Right To Left UTF-8 string using multiple fonts as needed. **/
/*****************************************************************************/
void
-XUtf8DrawRtlString(
- Display *display,
- Drawable d,
- XUtf8FontStruct *font_set,
- GC gc,
- int x,
- int y,
- const char *string,
- int num_bytes)
-{
- int *encodings; /* encodings array */
- XFontStruct **fonts; /* fonts array */
- XChar2b buf[128]; /* drawing buffer */
- XChar2b *ptr; /* pointer to the drawing buffer */
- int fnum; /* index of the current font in the fonts array*/
- int i; /* current byte in the XChar2b buffer */
- int first; /* first valid font index */
- int last_fnum; /* font index of the previous char */
- int nb_font; /* quantity of fonts in the font array */
- char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
- int *ranges; /* sub range of iso10646 */
-
- nb_font = font_set->nb_font;
-
- if (nb_font < 1) {
- /* there is no font in the font_set :-( */
- return;
- }
-
- ranges = font_set->ranges;
- fonts = font_set->fonts;
- encodings = font_set->encodings;
- i = 0;
- fnum = 0;
- ptr = buf + 128;
-
- while(fnum < nb_font && !fonts[fnum]) fnum++;
- if (fnum >= nb_font) {
- /* there is no valid font for the X server */
- return;
- }
-
- first = fnum;
- last_fnum = fnum;
-
- while (num_bytes > 0) {
- int ulen; /* byte length of the UTF-8 char */
- unsigned int ucs; /* Unicode value of the UTF-8 char */
- unsigned int no_spc; /* Spacing char equivalent of a
- non-spacing char */
-
- if (i > 120) {
- /*** draw the buffer **/
- XSetFont(display, gc, fonts[fnum]->fid);
- x -= XTextWidth16(fonts[fnum], ptr, i);
- XDrawString16(display, d, gc, x, y, ptr, i);
- i = 0;
- ptr = buf + 128;
- }
-
- ulen = XFastConvertUtf8ToUcs((unsigned char*)string,
- num_bytes, &ucs);
-
- if (ulen < 1) ulen = 1;
-
- no_spc = XUtf8IsNonSpacing(ucs);
- if (no_spc) ucs = no_spc;
-
- /*
- * find the first encoding which can be used to
- * draw the glyph
- */
- fnum = first;
- while (fnum < nb_font) {
- if (fonts[fnum] &&
- ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
- {
- if (encodings[fnum] != 0 ||
- (ucs >= ranges[fnum * 2] &&
- ucs <= ranges[fnum * 2 + 1]))
- {
- break;
- }
- }
- fnum++;
- }
- if (fnum == nb_font) {
- /** the char is not valid in all encodings ->
- * draw it using the first font :-( **/
- fnum = first;
- ucs2fontmap(glyph, '?', encodings[fnum]);
- }
-
- if (last_fnum != fnum || no_spc) {
- XSetFont(display, gc, fonts[last_fnum]->fid);
- x -= XTextWidth16(fonts[last_fnum], ptr, i);
- XDrawString16(display, d, gc, x, y, ptr, i);
- i = 0;
- ptr = buf + 127;
- (*ptr).byte1 = glyph[0];
- (*ptr).byte2 = glyph[1];
- if (no_spc) {
- x += XTextWidth16(fonts[fnum], ptr, 1);
- }
- } else {
- ptr--;
- (*ptr).byte1 = glyph[0];
- (*ptr).byte2 = glyph[1];
- }
- last_fnum = fnum;
- i++;
- string += ulen;
- num_bytes -= ulen;
+XUtf8DrawRtlString(Display *display,
+ Drawable d,
+ XUtf8FontStruct *font_set,
+ GC gc,
+ int x,
+ int y,
+ const char *string,
+ int num_bytes) {
+
+ int *encodings; /* encodings array */
+ XFontStruct **fonts; /* fonts array */
+ XChar2b buf[128]; /* drawing buffer */
+ XChar2b *ptr; /* pointer to the drawing buffer */
+ int fnum; /* index of the current font in the fonts array*/
+ int i; /* current byte in the XChar2b buffer */
+ int first; /* first valid font index */
+ int last_fnum; /* font index of the previous char */
+ int nb_font; /* quantity of fonts in the font array */
+ char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
+ int *ranges; /* sub range of iso10646 */
+
+ nb_font = font_set->nb_font;
+
+ if (nb_font < 1) {
+ /* there is no font in the font_set :-( */
+ return;
+ }
+
+ ranges = font_set->ranges;
+ fonts = font_set->fonts;
+ encodings = font_set->encodings;
+ i = 0;
+ fnum = 0;
+ ptr = buf + 128;
+
+ while(fnum < nb_font && !fonts[fnum]) fnum++;
+ if (fnum >= nb_font) {
+ /* there is no valid font for the X server */
+ return;
+ }
+
+ first = fnum;
+ last_fnum = fnum;
+
+ while (num_bytes > 0) {
+ int ulen; /* byte length of the UTF-8 char */
+ unsigned int ucs; /* Unicode value of the UTF-8 char */
+ unsigned int no_spc; /* Spacing char equivalent of a non-spacing char */
+
+ if (i > 120) {
+ /*** draw the buffer **/
+ XSetFont(display, gc, fonts[fnum]->fid);
+ x -= XTextWidth16(fonts[fnum], ptr, i);
+ XDrawString16(display, d, gc, x, y, ptr, i);
+ i = 0;
+ ptr = buf + 128;
+ }
+
+ ulen = XFastConvertUtf8ToUcs((unsigned char*)string, num_bytes, &ucs);
+
+ if (ulen < 1) ulen = 1;
+
+ no_spc = XUtf8IsNonSpacing(ucs);
+ if (no_spc) ucs = no_spc;
+
+ /*
+ * find the first encoding which can be used to
+ * draw the glyph
+ */
+ fnum = first;
+ while (fnum < nb_font) {
+ if (fonts[fnum] && ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
+ if (encodings[fnum] != 0 ||
+ (ucs >= ranges[fnum * 2] && ucs <= ranges[fnum * 2 + 1])) {
+ break;
}
-
- if (i < 1) return;
-
- XSetFont(display, gc, fonts[fnum]->fid);
- x -= XTextWidth16(fonts[last_fnum], ptr, i);
- XDrawString16(display, d, gc, x, y, ptr, i);
+ }
+ fnum++;
+ }
+ if (fnum == nb_font) {
+ /* the char is not valid in all encodings ->
+ * draw it using the first font :-(
+ */
+ fnum = first;
+ ucs2fontmap(glyph, '?', encodings[fnum]);
+ }
+
+ if (last_fnum != fnum || no_spc) {
+ XSetFont(display, gc, fonts[last_fnum]->fid);
+ x -= XTextWidth16(fonts[last_fnum], ptr, i);
+ XDrawString16(display, d, gc, x, y, ptr, i);
+ i = 0;
+ ptr = buf + 127;
+ (*ptr).byte1 = glyph[0];
+ (*ptr).byte2 = glyph[1];
+ if (no_spc) {
+ x += XTextWidth16(fonts[fnum], ptr, 1);
+ }
+ } else {
+ ptr--;
+ (*ptr).byte1 = glyph[0];
+ (*ptr).byte2 = glyph[1];
+ }
+ last_fnum = fnum;
+ i++;
+ string += ulen;
+ num_bytes -= ulen;
+ }
+
+ if (i < 1) return;
+
+ XSetFont(display, gc, fonts[fnum]->fid);
+ x -= XTextWidth16(fonts[last_fnum], ptr, i);
+ XDrawString16(display, d, gc, x, y, ptr, i);
}
@@ -455,117 +438,112 @@ XUtf8DrawRtlString(
/** draw an UTF-8 string using multiple fonts as needed. **/
/*****************************************************************************/
void
-XUtf8DrawString(
- Display *display,
- Drawable d,
- XUtf8FontStruct *font_set,
- GC gc,
- int x,
- int y,
- const char *string,
- int num_bytes)
-{
- int *encodings; /* encodings array */
- XFontStruct **fonts; /* fonts array */
- XChar2b buf[128]; /* drawing buffer */
- int fnum; /* index of the current font in the fonts array*/
- int i; /* current byte in the XChar2b buffer */
- int first; /* first valid font index */
- int last_fnum; /* font index of the previous char */
- int nb_font; /* quantity of fonts in the font array */
- char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
- int *ranges; /* sub range of iso10646 */
-
- nb_font = font_set->nb_font;
-
- if (nb_font < 1) {
- /* there is no font in the font_set :-( */
- return;
- }
- ranges = font_set->ranges;
- fonts = font_set->fonts;
- encodings = font_set->encodings;
- i = 0;
- fnum = 0;
-
- while(fnum < nb_font && !fonts[fnum]) fnum++;
- if (fnum >= nb_font) {
- /* there is no valid font for the X server */
- return;
- }
-
- first = fnum;
- last_fnum = fnum;
-
- while (num_bytes > 0) {
- int ulen; /* byte length of the UTF-8 char */
- unsigned int ucs; /* Unicode value of the UTF-8 char */
- unsigned int no_spc; /* Spacing char equivalent of a
- non-spacing char */
-
- if (i > 120) {
- /*** draw the buffer **/
- XSetFont(display, gc, fonts[fnum]->fid);
- XDrawString16(display, d, gc, x, y, buf, i);
- x += XTextWidth16(fonts[fnum], buf, i);
- i = 0;
- }
-
- ulen = XFastConvertUtf8ToUcs((unsigned char*)string,
- num_bytes, &ucs);
-
- if (ulen < 1) ulen = 1;
-
- no_spc = XUtf8IsNonSpacing(ucs);
- if (no_spc) ucs = no_spc;
-
- /*
- * find the first encoding which can be used to
- * draw the glyph
- */
- fnum = first;
- while (fnum < nb_font) {
- if (fonts[fnum] &&
- ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
- {
- if (encodings[fnum] != 0 ||
- (ucs >= ranges[fnum * 2] &&
- ucs <= ranges[fnum * 2 + 1]))
- {
- break;
- }
- }
- fnum++;
- }
- if (fnum == nb_font) {
- /** the char is not valid in all encodings ->
- * draw it using the first font :-( **/
- fnum = first;
- ucs2fontmap(glyph, '?', encodings[fnum]);
- }
-
- if (last_fnum != fnum || no_spc) {
- XSetFont(display, gc, fonts[last_fnum]->fid);
- XDrawString16(display, d, gc, x, y, buf, i);
- x += XTextWidth16(fonts[last_fnum], buf, i);
- i = 0;
- (*buf).byte1 = glyph[0];
- (*buf).byte2 = glyph[1];
- if (no_spc) {
- x -= XTextWidth16(fonts[fnum], buf, 1);
- }
- } else {
- (*(buf + i)).byte1 = glyph[0];
- (*(buf + i)).byte2 = glyph[1];
- }
- last_fnum = fnum;
- i++;
- string += ulen;
- num_bytes -= ulen;
+XUtf8DrawString(Display *display,
+ Drawable d,
+ XUtf8FontStruct *font_set,
+ GC gc,
+ int x,
+ int y,
+ const char *string,
+ int num_bytes) {
+
+ int *encodings; /* encodings array */
+ XFontStruct **fonts; /* fonts array */
+ XChar2b buf[128]; /* drawing buffer */
+ int fnum; /* index of the current font in the fonts array*/
+ int i; /* current byte in the XChar2b buffer */
+ int first; /* first valid font index */
+ int last_fnum; /* font index of the previous char */
+ int nb_font; /* quantity of fonts in the font array */
+ char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
+ int *ranges; /* sub range of iso10646 */
+
+ nb_font = font_set->nb_font;
+
+ if (nb_font < 1) {
+ /* there is no font in the font_set :-( */
+ return;
+ }
+ ranges = font_set->ranges;
+ fonts = font_set->fonts;
+ encodings = font_set->encodings;
+ i = 0;
+ fnum = 0;
+
+ while(fnum < nb_font && !fonts[fnum]) fnum++;
+ if (fnum >= nb_font) {
+ /* there is no valid font for the X server */
+ return;
+ }
+
+ first = fnum;
+ last_fnum = fnum;
+
+ while (num_bytes > 0) {
+ int ulen; /* byte length of the UTF-8 char */
+ unsigned int ucs; /* Unicode value of the UTF-8 char */
+ unsigned int no_spc; /* Spacing char equivalent of a non-spacing char */
+
+ if (i > 120) {
+ /*** draw the buffer **/
+ XSetFont(display, gc, fonts[fnum]->fid);
+ XDrawString16(display, d, gc, x, y, buf, i);
+ x += XTextWidth16(fonts[fnum], buf, i);
+ i = 0;
+ }
+
+ ulen = XFastConvertUtf8ToUcs((unsigned char*)string, num_bytes, &ucs);
+
+ if (ulen < 1) ulen = 1;
+
+ no_spc = XUtf8IsNonSpacing(ucs);
+ if (no_spc) ucs = no_spc;
+
+ /*
+ * find the first encoding which can be used to
+ * draw the glyph
+ */
+ fnum = first;
+ while (fnum < nb_font) {
+ if (fonts[fnum] && ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
+ if (encodings[fnum] != 0 ||
+ (ucs >= ranges[fnum * 2] &&
+ ucs <= ranges[fnum * 2 + 1])) {
+ break;
}
-
- XSetFont(display, gc, fonts[fnum]->fid);
- XDrawString16(display, d, gc, x, y, buf, i);
+ }
+ fnum++;
+ }
+ if (fnum == nb_font) {
+ /* the char is not valid in all encodings ->
+ * draw it using the first font :-(
+ */
+ fnum = first;
+ ucs2fontmap(glyph, '?', encodings[fnum]);
+ }
+
+ if (last_fnum != fnum || no_spc) {
+ XSetFont(display, gc, fonts[last_fnum]->fid);
+ XDrawString16(display, d, gc, x, y, buf, i);
+ x += XTextWidth16(fonts[last_fnum], buf, i);
+ i = 0;
+ (*buf).byte1 = glyph[0];
+ (*buf).byte2 = glyph[1];
+ if (no_spc) {
+ x -= XTextWidth16(fonts[fnum], buf, 1);
+ }
+ } else {
+ (*(buf + i)).byte1 = glyph[0];
+ (*(buf + i)).byte2 = glyph[1];
+ }
+ last_fnum = fnum;
+ i++;
+ string += ulen;
+ num_bytes -= ulen;
+ }
+
+ XSetFont(display, gc, fonts[fnum]->fid);
+ XDrawString16(display, d, gc, x, y, buf, i);
}
@@ -574,345 +552,332 @@ XUtf8DrawString(
/** returns the pixel width of a UTF-8 string **/
/*****************************************************************************/
int
-XUtf8TextWidth(
- XUtf8FontStruct *font_set,
- const char *string,
- int num_bytes)
-{
- int x;
- int *encodings; /* encodings array */
- XFontStruct **fonts; /* fonts array */
- XChar2b buf[128]; /* drawing buffer */
- int fnum; /* index of the current font in the fonts array*/
- int i; /* current byte in the XChar2b buffer */
- int first; /* first valid font index */
- int last_fnum; /* font index of the previous char */
- int nb_font; /* quantity of fonts in the font array */
- char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
- int *ranges; /* sub range of iso10646 */
-
- nb_font = font_set->nb_font;
- x = 0;
-
- if (nb_font < 1) {
- /* there is no font in the font_set :-( */
- return x;
+XUtf8TextWidth(XUtf8FontStruct *font_set,
+ const char *string,
+ int num_bytes) {
+
+ int x;
+ int *encodings; /* encodings array */
+ XFontStruct **fonts; /* fonts array */
+ XChar2b buf[128]; /* drawing buffer */
+ int fnum; /* index of the current font in the fonts array*/
+ int i; /* current byte in the XChar2b buffer */
+ int first; /* first valid font index */
+ int last_fnum; /* font index of the previous char */
+ int nb_font; /* quantity of fonts in the font array */
+ char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
+ int *ranges; /* sub range of iso10646 */
+
+ nb_font = font_set->nb_font;
+ x = 0;
+
+ if (nb_font < 1) {
+ /* there is no font in the font_set :-( */
+ return x;
+ }
+
+ ranges = font_set->ranges;
+ fonts = font_set->fonts;
+ encodings = font_set->encodings;
+ i = 0;
+ fnum = 0;
+
+ while(fnum < nb_font && !fonts[fnum]) fnum++;
+ if (fnum >= nb_font) {
+ /* there is no valid font for the X server */
+ return x;
+ }
+
+ first = fnum;
+ last_fnum = fnum;
+
+ while (num_bytes > 0) {
+ int ulen; /* byte length of the UTF-8 char */
+ unsigned int ucs; /* Unicode value of the UTF-8 char */
+ unsigned int no_spc; /* Spacing char equivalent of a non-spacing char */
+
+ if (i > 120) {
+ /*** measure the buffer **/
+ x += XTextWidth16(fonts[fnum], buf, i);
+ i = 0;
+ }
+
+ ulen = XFastConvertUtf8ToUcs((unsigned char*)string, num_bytes, &ucs);
+
+ if (ulen < 1) ulen = 1;
+
+ no_spc = XUtf8IsNonSpacing(ucs);
+ if (no_spc) {
+ ucs = no_spc;
+ }
+
+ /*
+ * find the first encoding which can be used to
+ * draw the glyph
+ */
+ fnum = first;
+ while (fnum < nb_font) {
+ if (fonts[fnum] && ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
+ if (encodings[fnum] != 0 ||
+ (ucs >= ranges[fnum * 2] &&
+ ucs <= ranges[fnum * 2 + 1])) {
+ break;
}
-
- ranges = font_set->ranges;
- fonts = font_set->fonts;
- encodings = font_set->encodings;
- i = 0;
- fnum = 0;
-
- while(fnum < nb_font && !fonts[fnum]) fnum++;
- if (fnum >= nb_font) {
- /* there is no valid font for the X server */
- return x;
- }
-
- first = fnum;
- last_fnum = fnum;
-
- while (num_bytes > 0) {
- int ulen; /* byte length of the UTF-8 char */
- unsigned int ucs; /* Unicode value of the UTF-8 char */
- unsigned int no_spc; /* Spacing char equivalent of a
- non-spacing char */
-
- if (i > 120) {
- /*** measure the buffer **/
- x += XTextWidth16(fonts[fnum], buf, i);
- i = 0;
- }
-
- ulen = XFastConvertUtf8ToUcs((unsigned char*)string,
- num_bytes, &ucs);
-
- if (ulen < 1) ulen = 1;
-
- no_spc = XUtf8IsNonSpacing(ucs);
- if (no_spc) {
- ucs = no_spc;
- }
-
- /*
- * find the first encoding which can be used to
- * draw the glyph
- */
- fnum = first;
- while (fnum < nb_font) {
- if (fonts[fnum] &&
- ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
- {
- if (encodings[fnum] != 0 ||
- (ucs >= ranges[fnum * 2] &&
- ucs <= ranges[fnum * 2 + 1]))
- {
- break;
- }
- }
- fnum++;
- }
- if (fnum == nb_font) {
- /** the char is not valid in all encodings ->
- * draw it using the first font :-( **/
- fnum = first;
- ucs2fontmap(glyph, '?', encodings[fnum]);
- }
-
- if (last_fnum != fnum || no_spc) {
- x += XTextWidth16(fonts[last_fnum], buf, i);
- i = 0;
- (*buf).byte1 = glyph[0];
- (*buf).byte2 = glyph[1];
- if (no_spc) {
- /* go back to draw the non-spacing char over
- * the previous char */
- x -= XTextWidth16(fonts[fnum], buf, 1);
- }
- } else {
- (*(buf + i)).byte1 = glyph[0];
- (*(buf + i)).byte2 = glyph[1];
- }
- last_fnum = fnum;
- i++;
- string += ulen;
- num_bytes -= ulen;
- }
-
- x += XTextWidth16(fonts[last_fnum], buf, i);
-
- return x;
+ }
+ fnum++;
+ }
+ if (fnum == nb_font) {
+ /* the char is not valid in all encodings ->
+ * draw it using the first font :-(
+ */
+ fnum = first;
+ ucs2fontmap(glyph, '?', encodings[fnum]);
+ }
+
+ if (last_fnum != fnum || no_spc) {
+ x += XTextWidth16(fonts[last_fnum], buf, i);
+ i = 0;
+ (*buf).byte1 = glyph[0];
+ (*buf).byte2 = glyph[1];
+ if (no_spc) {
+ /* go back to draw the non-spacing char over the previous char */
+ x -= XTextWidth16(fonts[fnum], buf, 1);
+ }
+ } else {
+ (*(buf + i)).byte1 = glyph[0];
+ (*(buf + i)).byte2 = glyph[1];
+ }
+ last_fnum = fnum;
+ i++;
+ string += ulen;
+ num_bytes -= ulen;
+ }
+
+ x += XTextWidth16(fonts[last_fnum], buf, i);
+
+ return x;
}
/*****************************************************************************/
/** get the X font and glyph ID of a UCS char **/
/*****************************************************************************/
int
-XGetUtf8FontAndGlyph(
- XUtf8FontStruct *font_set,
- unsigned int ucs,
- XFontStruct **fnt,
- unsigned short *id)
-{
- int x;
- int *encodings; /* encodings array */
- XFontStruct **fonts; /* fonts array */
- int fnum; /* index of the current font in the fonts array*/
- int i; /* current byte in the XChar2b buffer */
- int first; /* first valid font index */
- int last_fnum; /* font index of the previous char */
- int nb_font; /* quantity of fonts in the font array */
- char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
- int *ranges; /* sub range of iso10646 */
-
- nb_font = font_set->nb_font;
- x = 0;
-
- if (nb_font < 1) {
- /* there is no font in the font_set :-( */
- return -1;
- }
-
- ranges = font_set->ranges;
- fonts = font_set->fonts;
- encodings = font_set->encodings;
- i = 0;
- fnum = 0;
-
- while(fnum < nb_font && !fonts[fnum]) fnum++;
- if (fnum >= nb_font) {
- /* there is no valid font for the X server */
- return -1;
- }
-
- first = fnum;
- last_fnum = fnum;
-
- /*
- * find the first encoding which can be used to
- * draw the glyph
- */
- fnum = first;
- while (fnum < nb_font) {
- if (fonts[fnum] &&
- ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
- {
- if (encodings[fnum] != 0 || (ucs >= ranges[fnum * 2] &&
- ucs <= ranges[fnum * 2 + 1]))
- {
- break;
- }
- }
- fnum++;
- }
- if (fnum == nb_font) {
- /** the char is not valid in all encodings ->
- * draw it using the first font :-( **/
- fnum = first;
- ucs2fontmap(glyph, '?', encodings[fnum]);
- }
-
- *id = ((unsigned char)glyph[0] << 8) | (unsigned char)glyph[1] ;
- *fnt = fonts[fnum];
- return 0;
+XGetUtf8FontAndGlyph(XUtf8FontStruct *font_set,
+ unsigned int ucs,
+ XFontStruct **fnt,
+ unsigned short *id) {
+
+ int x;
+ int *encodings; /* encodings array */
+ XFontStruct **fonts; /* fonts array */
+ int fnum; /* index of the current font in the fonts array*/
+ int i; /* current byte in the XChar2b buffer */
+ int first; /* first valid font index */
+ int last_fnum; /* font index of the previous char */
+ int nb_font; /* quantity of fonts in the font array */
+ char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
+ int *ranges; /* sub range of iso10646 */
+
+ nb_font = font_set->nb_font;
+ x = 0;
+
+ if (nb_font < 1) {
+ /* there is no font in the font_set :-( */
+ return -1;
+ }
+
+ ranges = font_set->ranges;
+ fonts = font_set->fonts;
+ encodings = font_set->encodings;
+ i = 0;
+ fnum = 0;
+
+ while(fnum < nb_font && !fonts[fnum]) fnum++;
+ if (fnum >= nb_font) {
+ /* there is no valid font for the X server */
+ return -1;
+ }
+
+ first = fnum;
+ last_fnum = fnum;
+
+ /*
+ * find the first encoding which can be used to
+ * draw the glyph
+ */
+ fnum = first;
+ while (fnum < nb_font) {
+ if (fonts[fnum] && ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
+ if (encodings[fnum] != 0 ||
+ (ucs >= ranges[fnum * 2] &&
+ ucs <= ranges[fnum * 2 + 1])) {
+ break;
+ }
+ }
+ fnum++;
+ }
+ if (fnum == nb_font) {
+ /* the char is not valid in all encodings ->
+ * draw it using the first font :-(
+ */
+ fnum = first;
+ ucs2fontmap(glyph, '?', encodings[fnum]);
+ }
+
+ *id = ((unsigned char)glyph[0] << 8) | (unsigned char)glyph[1] ;
+ *fnt = fonts[fnum];
+ return 0;
}
/*****************************************************************************/
/** returns the pixel width of a UCS char **/
/*****************************************************************************/
int
-XUtf8UcsWidth(
- XUtf8FontStruct *font_set,
- unsigned int ucs)
-{
- int x;
- int *encodings; /* encodings array */
- XFontStruct **fonts; /* fonts array */
- XChar2b buf[8]; /* drawing buffer */
- int fnum; /* index of the current font in the fonts array*/
- int i; /* current byte in the XChar2b buffer */
- int first; /* first valid font index */
- int last_fnum; /* font index of the previous char */
- int nb_font; /* quantity of fonts in the font array */
- char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
- int *ranges; /* sub range of iso10646 */
-
- nb_font = font_set->nb_font;
- x = 0;
-
- if (nb_font < 1) {
- /* there is no font in the font_set :-( */
- return x;
- }
-
- ranges = font_set->ranges;
- fonts = font_set->fonts;
- encodings = font_set->encodings;
- i = 0;
- fnum = 0;
-
- while(fnum < nb_font && !fonts[fnum]) fnum++;
- if (fnum >= nb_font) {
- /* there is no valid font for the X server */
- return x;
- }
-
- first = fnum;
- last_fnum = fnum;
-
-
- ucs = XUtf8IsNonSpacing(ucs);
-
- /*
- * find the first encoding which can be used to
- * draw the glyph
- */
- fnum = first;
- while (fnum < nb_font) {
- if (fonts[fnum] &&
- ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
- {
- if (encodings[fnum] != 0 || (ucs >= ranges[fnum * 2] &&
- ucs <= ranges[fnum * 2 + 1]))
- {
- break;
- }
- }
- fnum++;
- }
- if (fnum == nb_font) {
- /** the char is not valid in all encodings ->
- * draw it using the first font :-( **/
- fnum = first;
- ucs2fontmap(glyph, '?', encodings[fnum]);
- }
-
- (*buf).byte1 = glyph[0];
- (*buf).byte2 = glyph[1];
-
- x += XTextWidth16(fonts[fnum], buf, 1);
-
- return x;
+XUtf8UcsWidth(XUtf8FontStruct *font_set,
+ unsigned int ucs) {
+
+ int x;
+ int *encodings; /* encodings array */
+ XFontStruct **fonts; /* fonts array */
+ XChar2b buf[8]; /* drawing buffer */
+ int fnum; /* index of the current font in the fonts array*/
+ int i; /* current byte in the XChar2b buffer */
+ int first; /* first valid font index */
+ int last_fnum; /* font index of the previous char */
+ int nb_font; /* quantity of fonts in the font array */
+ char glyph[2]; /* byte1 and byte1 value of the UTF-8 char */
+ int *ranges; /* sub range of iso10646 */
+
+ nb_font = font_set->nb_font;
+ x = 0;
+
+ if (nb_font < 1) {
+ /* there is no font in the font_set :-( */
+ return x;
+ }
+
+ ranges = font_set->ranges;
+ fonts = font_set->fonts;
+ encodings = font_set->encodings;
+ i = 0;
+ fnum = 0;
+
+ while(fnum < nb_font && !fonts[fnum]) fnum++;
+ if (fnum >= nb_font) {
+ /* there is no valid font for the X server */
+ return x;
+ }
+
+ first = fnum;
+ last_fnum = fnum;
+
+ ucs = XUtf8IsNonSpacing(ucs);
+
+ /*
+ * find the first encoding which can be used to
+ * draw the glyph
+ */
+ fnum = first;
+ while (fnum < nb_font) {
+ if (fonts[fnum] &&
+ ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
+ if (encodings[fnum] != 0 || (ucs >= ranges[fnum * 2] &&
+ ucs <= ranges[fnum * 2 + 1])) {
+ break;
+ }
+ }
+ fnum++;
+ }
+ if (fnum == nb_font) {
+ /* the char is not valid in all encodings ->
+ * draw it using the first font :-(
+ */
+ fnum = first;
+ ucs2fontmap(glyph, '?', encodings[fnum]);
+ }
+
+ (*buf).byte1 = glyph[0];
+ (*buf).byte2 = glyph[1];
+
+ x += XTextWidth16(fonts[fnum], buf, 1);
+
+ return x;
}
/*****************************************************************************/
/** draw an UTF-8 string and clear the background. **/
/*****************************************************************************/
void
-XUtf8DrawImageString(
- Display *display,
- Drawable d,
- XUtf8FontStruct *font_set,
- GC gc,
- int x,
- int y,
- const char *string,
- int num_bytes)
-{
- /* FIXME: must be improved ! */
- int w;
- int fill_style;
- unsigned long foreground;
- unsigned long background;
- int function;
- XGCValues xgcv;
-
- w = XUtf8TextWidth(font_set, string, num_bytes);
-
- XGetGCValues(display, gc,
- GCFunction|GCForeground|GCBackground|GCFillStyle, &xgcv);
-
- function = xgcv.function;
- fill_style = xgcv.fill_style;
- foreground = xgcv.foreground;
- background = xgcv.background;
-
- xgcv.function = GXcopy;
- xgcv.foreground = background;
- xgcv.background = foreground;
- xgcv.fill_style = FillSolid;
-
- XChangeGC(display, gc,
- GCFunction|GCForeground|GCBackground|GCFillStyle, &xgcv);
-
- XFillRectangle(display, d, gc, x, y - font_set->ascent,
- (unsigned)w, (unsigned)(font_set->ascent + font_set->descent));
-
- xgcv.function = function;
- xgcv.foreground = foreground;
- xgcv.background = background;
- xgcv.fill_style = fill_style;
-
- XChangeGC(display, gc,
- GCFunction|GCForeground|GCBackground|GCFillStyle, &xgcv);
-
- XUtf8DrawString(display, d, font_set, gc, x, y, string, num_bytes);
+XUtf8DrawImageString(Display *display,
+ Drawable d,
+ XUtf8FontStruct *font_set,
+ GC gc,
+ int x,
+ int y,
+ const char *string,
+ int num_bytes) {
+
+ /* FIXME: must be improved ! */
+ int w;
+ int fill_style;
+ unsigned long foreground;
+ unsigned long background;
+ int function;
+ XGCValues xgcv;
+
+ w = XUtf8TextWidth(font_set, string, num_bytes);
+
+ XGetGCValues(display, gc,
+ GCFunction|GCForeground|GCBackground|GCFillStyle, &xgcv);
+
+ function = xgcv.function;
+ fill_style = xgcv.fill_style;
+ foreground = xgcv.foreground;
+ background = xgcv.background;
+
+ xgcv.function = GXcopy;
+ xgcv.foreground = background;
+ xgcv.background = foreground;
+ xgcv.fill_style = FillSolid;
+
+ XChangeGC(display, gc,
+ GCFunction|GCForeground|GCBackground|GCFillStyle, &xgcv);
+
+ XFillRectangle(display, d, gc, x, y - font_set->ascent,
+ (unsigned)w, (unsigned)(font_set->ascent + font_set->descent));
+
+ xgcv.function = function;
+ xgcv.foreground = foreground;
+ xgcv.background = background;
+ xgcv.fill_style = fill_style;
+
+ XChangeGC(display, gc,
+ GCFunction|GCForeground|GCBackground|GCFillStyle, &xgcv);
+
+ XUtf8DrawString(display, d, font_set, gc, x, y, string, num_bytes);
}
/*****************************************************************************/
/** free the XFontSet and others things created by XCreateUtf8FontSet **/
/*****************************************************************************/
void
-XFreeUtf8FontStruct(
- Display *dpy,
- XUtf8FontStruct *font_set)
-{
- int i;
- i = 0;
- while (i < font_set->nb_font) {
- if (font_set->fonts[i]) {
- XFreeFont(dpy, font_set->fonts[i]);
- free(font_set->font_name_list[i]);
- }
- i++;
- }
- free(font_set->ranges);
- free(font_set->font_name_list);
- free(font_set->fonts);
- free(font_set->encodings);
- free(font_set);
+XFreeUtf8FontStruct(Display *dpy,
+ XUtf8FontStruct *font_set) {
+
+ int i;
+ i = 0;
+ while (i < font_set->nb_font) {
+ if (font_set->fonts[i]) {
+ XFreeFont(dpy, font_set->fonts[i]);
+ free(font_set->font_name_list[i]);
+ }
+ i++;
+ }
+ free(font_set->ranges);
+ free(font_set->font_name_list);
+ free(font_set->fonts);
+ free(font_set->encodings);
+ free(font_set);
}
#endif /* X11 only */
diff --git a/src/xutf8/utils/conv_gen.c b/src/xutf8/utils/conv_gen.c
index cd40a769b..c9790298d 100644
--- a/src/xutf8/utils/conv_gen.c
+++ b/src/xutf8/utils/conv_gen.c
@@ -30,147 +30,143 @@
#include <stdio.h>
char buffer[1000000];
-int main(int argc, char **argv)
-{
- char buf[80];
- int len;
- char *encode[256];
- int encode_number = 0;
- unsigned int i = 0;
- unsigned char *ptr;
- unsigned char *lst = "";
- size_t nb;
- int nbb = 0;
- len = fread(buffer, 1, 1000000, stdin);
+int main(int argc, char **argv) {
+ char buf[80];
+ int len;
+ char *encode[256];
+ int encode_number = 0;
+ unsigned int i = 0;
+ unsigned char *ptr;
+ unsigned char *lst = "";
+ size_t nb;
+ int nbb = 0;
+ len = fread(buffer, 1, 1000000, stdin);
- puts(" ");
- puts(" /*************** conv_gen.c ************/");
- buffer[len] = '\0';
- ptr = buffer;
-
- printf("const int ucs2fontmap"
- "(char *s, unsigned int ucs, int enc)\n");
- printf("{\n");
- printf(" switch(enc) {\n");
- printf(" case 0:\n");
- printf(" s[0] = (char) ((ucs & 0xFF00) >> 8);\n");
- printf(" s[1] = (char) (ucs & 0xFF);\n");
- printf(" return 0;");
- while (len > 0) {
- unsigned char *p = ptr;
- unsigned char *f, *t;
-
- while (*p != ']') {
- i++;
- p++;
- }
- *(p - 1) = '\0';
- *(p - 6) = '\0';
- f = p - 5;
- while (*p != '+') { i++; p++;}
- p++;
- t = p;
- *(p + 4) = '\0';
- if (strcmp(lst, ptr)) {
- encode_number++;
- encode[encode_number] = ptr;
- printf("\n break;");
- printf("\n case %d:\n", encode_number);
- printf(" ");
- } else {
- printf(" else ");
- }
- lst = ptr;
- printf("if (ucs <= 0x%s) {\n", t);
- printf(" if (ucs >= 0x%s) {\n", f);
- if (*(f - 3) == '2') {
- printf(" int i = (ucs - 0x%s) * 2;\n", f);
- printf(" s[0] = %s_%s[i++];\n", ptr, f, f);
- printf(" s[1] = %s_%s[i];\n", ptr, f, f);
- printf(" if (s[0] || s[1]) return %d;\n",
- encode_number);
- } else {
- printf(" s[0] = 0;\n");
- printf(" s[1] = %s_%s[ucs - 0x%s];\n",
- ptr, f, f);
- printf(" if (s[1]) return %d;\n", encode_number);
- }
- printf(" }\n");
- printf(" }");
- while (*ptr != '\n') {
- ptr++;
- len--;
- }
- ptr++;
- len--;
- }
- printf("\n break;\n");
- printf("\n default:\n");
- printf(" break;\n");
- printf(" };\n");
- printf(" return -1;\n");
- printf("};\n\n");
+ puts(" ");
+ puts(" /*************** conv_gen.c ************/");
+ buffer[len] = '\0';
+ ptr = buffer;
+
+ printf("const int ucs2fontmap"
+ "(char *s, unsigned int ucs, int enc)\n");
+ printf("{\n");
+ printf(" switch(enc) {\n");
+ printf(" case 0:\n");
+ printf(" s[0] = (char) ((ucs & 0xFF00) >> 8);\n");
+ printf(" s[1] = (char) (ucs & 0xFF);\n");
+ printf(" return 0;");
+ while (len > 0) {
+ unsigned char *p = ptr;
+ unsigned char *f, *t;
+
+ while (*p != ']') {
+ i++;
+ p++;
+ }
+ *(p - 1) = '\0';
+ *(p - 6) = '\0';
+ f = p - 5;
+ while (*p != '+') { i++; p++;}
+ p++;
+ t = p;
+ *(p + 4) = '\0';
+ if (strcmp(lst, ptr)) {
+ encode_number++;
+ encode[encode_number] = ptr;
+ printf("\n break;");
+ printf("\n case %d:\n", encode_number);
+ printf(" ");
+ } else {
+ printf(" else ");
+ }
+ lst = ptr;
+ printf("if (ucs <= 0x%s) {\n", t);
+ printf(" if (ucs >= 0x%s) {\n", f);
+ if (*(f - 3) == '2') {
+ printf(" int i = (ucs - 0x%s) * 2;\n", f);
+ printf(" s[0] = %s_%s[i++];\n", ptr, f, f);
+ printf(" s[1] = %s_%s[i];\n", ptr, f, f);
+ printf(" if (s[0] || s[1]) return %d;\n", encode_number);
+ } else {
+ printf(" s[0] = 0;\n");
+ printf(" s[1] = %s_%s[ucs - 0x%s];\n", ptr, f, f);
+ printf(" if (s[1]) return %d;\n", encode_number);
+ }
+ printf(" }\n");
+ printf(" }");
+ while (*ptr != '\n') {
+ ptr++;
+ len--;
+ }
+ ptr++;
+ len--;
+ }
+ printf("\n break;\n");
+ printf("\n default:\n");
+ printf(" break;\n");
+ printf(" };\n");
+ printf(" return -1;\n");
+ printf("};\n\n");
- printf("const int encoding_number(const char *enc)\n{\n");
- printf(" if (!enc || !strcmp(enc, \"iso10646-1\")) {\n");
- printf(" return 0;\n");
- i = 1;
- while (i <= encode_number) {
- int l;
- char *ptr;
- l = strlen(encode[i]) - 3;
- ptr = encode[i] + l;
- *(ptr) = '\0';
- ptr--;
- while (ptr != encode[i]) {
- if (*ptr == '_') {
- *ptr = '-';
- ptr--;
- break;
- }
- ptr--;
- }
- while (ptr != encode[i]) {
- if (*ptr == '_') {
- *ptr = '.';
- }
- ptr--;
- }
- printf(" } else if (!strcmp(enc, \"%s\")", encode[i] +11);
+ printf("const int encoding_number(const char *enc)\n{\n");
+ printf(" if (!enc || !strcmp(enc, \"iso10646-1\")) {\n");
+ printf(" return 0;\n");
+ i = 1;
+ while (i <= encode_number) {
+ int l;
+ char *ptr;
+ l = strlen(encode[i]) - 3;
+ ptr = encode[i] + l;
+ *(ptr) = '\0';
+ ptr--;
+ while (ptr != encode[i]) {
+ if (*ptr == '_') {
+ *ptr = '-';
+ ptr--;
+ break;
+ }
+ ptr--;
+ }
+ while (ptr != encode[i]) {
+ if (*ptr == '_') {
+ *ptr = '.';
+ }
+ ptr--;
+ }
+ printf(" } else if (!strcmp(enc, \"%s\")", encode[i] +11);
- if (!strcmp(encode[i] + 11, "big5-0")) {
- printf(" || !strcmp(enc, \"big5.eten-0\")");
- } else if (!strcmp(encode[i] + 11, "dingbats")) {
- printf(" || !strcmp(enc, \"zapfdingbats\")");
- printf(" || !strcmp(enc, \"zapf dingbats\")");
- printf(" || !strcmp(enc, \"itc zapf dingbats\")");
- } else if (!strcmp(encode[i] + 11, "jisx0208.1983-0")) {
- printf(" || !strcmp(enc, \"jisx0208.1990-0\")");
- }
+ if (!strcmp(encode[i] + 11, "big5-0")) {
+ printf(" || !strcmp(enc, \"big5.eten-0\")");
+ } else if (!strcmp(encode[i] + 11, "dingbats")) {
+ printf(" || !strcmp(enc, \"zapfdingbats\")");
+ printf(" || !strcmp(enc, \"zapf dingbats\")");
+ printf(" || !strcmp(enc, \"itc zapf dingbats\")");
+ } else if (!strcmp(encode[i] + 11, "jisx0208.1983-0")) {
+ printf(" || !strcmp(enc, \"jisx0208.1990-0\")");
+ }
- printf(") {\n");
- printf(" return %d;\n", i);
- i++;
- }
- printf(" };\n");
- printf(" return -1;\n");
- printf("};\n\n");
+ printf(") {\n");
+ printf(" return %d;\n", i);
+ i++;
+ }
+ printf(" };\n");
+ printf(" return -1;\n");
+ printf("};\n\n");
-
- printf("/*\n");
- printf("const char *encoding_name(int num)\n{\n");
- printf(" switch (num) {\n");
- i = 1;
- while (i <= encode_number) {
- printf(" case %d:\n", i);
- printf(" return \"%s\";\n", encode[i] + 11);
- i++;
- }
- printf(" };\n");
- printf(" return \"iso10646-1\";\n");
- printf("};\n\n");
- printf("*/\n");
- return 0;
+ printf("/*\n");
+ printf("const char *encoding_name(int num)\n{\n");
+ printf(" switch (num) {\n");
+ i = 1;
+ while (i <= encode_number) {
+ printf(" case %d:\n", i);
+ printf(" return \"%s\";\n", encode[i] + 11);
+ i++;
+ }
+ printf(" };\n");
+ printf(" return \"iso10646-1\";\n");
+ printf("};\n\n");
+ printf("*/\n");
+ return 0;
}
/*
diff --git a/src/xutf8/utils/convert_map.c b/src/xutf8/utils/convert_map.c
index 976c06db8..6e9c6492a 100644
--- a/src/xutf8/utils/convert_map.c
+++ b/src/xutf8/utils/convert_map.c
@@ -33,149 +33,145 @@
char buffer[1000000];
-int JIS0208(unsigned char * ptr)
-{
- int i = 0;
- unsigned int fmap;
- unsigned int ucs;
- while(*ptr != '\t') { ptr++; i++; }
- ptr++; i++; *(ptr+6) = '\0';
- fmap = (unsigned int)strtoul(ptr, NULL, 16);
- while(*ptr != '\0') { ptr++; i++; }
- i++; ptr++; *(ptr+6) = '\0';
- ucs = (unsigned int)strtoul(ptr, NULL, 16);
- if (ucs) printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
- (fmap & 0xFF00) >> 8, fmap & 0xFF);
- while(*ptr != '\0') { ptr++; i++; }
- i++; ptr++;
- while(*ptr != '\n') { ptr++; i++; }
- i++;
- return i;
+int JIS0208(unsigned char * ptr) {
+ int i = 0;
+ unsigned int fmap;
+ unsigned int ucs;
+ while(*ptr != '\t') { ptr++; i++; }
+ ptr++; i++; *(ptr+6) = '\0';
+ fmap = (unsigned int)strtoul(ptr, NULL, 16);
+ while(*ptr != '\0') { ptr++; i++; }
+ i++; ptr++; *(ptr+6) = '\0';
+ ucs = (unsigned int)strtoul(ptr, NULL, 16);
+ if (ucs)
+ printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
+ (fmap & 0xFF00) >> 8, fmap & 0xFF);
+ while(*ptr != '\0') { ptr++; i++; }
+ i++; ptr++;
+ while(*ptr != '\n') { ptr++; i++; }
+ i++;
+ return i;
}
-int JIS0201(unsigned char * ptr)
-{
- int i = 0;
- unsigned int fmap;
- unsigned int ucs;
- *(ptr+4) = '\0';
- fmap = (unsigned int)strtoul(ptr, NULL, 16);
- while(*ptr != '\0') { ptr++; i++; }
- i++; ptr++; *(ptr+6) = '\0';
- ucs = (unsigned int)strtoul(ptr, NULL, 16);
- if (*(ptr + 1) != 'x') {
- printf("/* EOF */\n");
- abort();
- }
- if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
- while(*ptr != '\0') { ptr++; i++; }
- i++; ptr++;
- while(*ptr != '\n') { ptr++; i++; }
- i++;
- return i;
+int JIS0201(unsigned char * ptr) {
+ int i = 0;
+ unsigned int fmap;
+ unsigned int ucs;
+ *(ptr+4) = '\0';
+ fmap = (unsigned int)strtoul(ptr, NULL, 16);
+ while(*ptr != '\0') { ptr++; i++; }
+ i++; ptr++; *(ptr+6) = '\0';
+ ucs = (unsigned int)strtoul(ptr, NULL, 16);
+ if (*(ptr + 1) != 'x') {
+ printf("/* EOF */\n");
+ abort();
+ }
+ if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
+ while(*ptr != '\0') { ptr++; i++; }
+ i++; ptr++;
+ while(*ptr != '\n') { ptr++; i++; }
+ i++;
+ return i;
}
-int ADOBE(unsigned char * ptr)
-{
- int i = 0;
- unsigned int fmap;
- unsigned int ucs;
- *(ptr+4) = '\0';
- ucs = (unsigned int)strtoul(ptr, NULL, 16);
- while(*ptr != '\0') { ptr++; i++; }
- i++; ptr++; *(ptr+2) = '\0';
- fmap = (unsigned int)strtoul(ptr, NULL, 16);
- if (fmap < 1) {
- printf("/* EOF */\n");
- abort();
- }
- if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
- while(*ptr != '\0') { ptr++; i++; }
- i++; ptr++;
- while(*ptr != '\n') { ptr++; i++; }
- i++;
- return i;
+int ADOBE(unsigned char * ptr) {
+ int i = 0;
+ unsigned int fmap;
+ unsigned int ucs;
+ *(ptr+4) = '\0';
+ ucs = (unsigned int)strtoul(ptr, NULL, 16);
+ while(*ptr != '\0') { ptr++; i++; }
+ i++; ptr++; *(ptr+2) = '\0';
+ fmap = (unsigned int)strtoul(ptr, NULL, 16);
+ if (fmap < 1) {
+ printf("/* EOF */\n");
+ abort();
+ }
+ if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
+ while(*ptr != '\0') { ptr++; i++; }
+ i++; ptr++;
+ while(*ptr != '\n') { ptr++; i++; }
+ i++;
+ return i;
}
-int JIS0212(unsigned char * ptr)
-{
- int i = 0;
- unsigned int fmap;
- unsigned int ucs;
- *(ptr+6) = '\0';
- fmap = (unsigned int)strtoul(ptr, NULL, 16);
- ptr += 7;
- i += 7;
- while(*ptr == ' ') { ptr++; i++; }
- //i++; ptr++;
- *(ptr+6) = '\0';
- ucs = (unsigned int)strtoul(ptr, NULL, 16);
- if (*(ptr + 1) != 'x') {
- printf("/* EOF */\n");
- abort();
- }
- if (ucs) printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
- (fmap & 0xFF00) >> 8, fmap & 0xFF);
- while(*ptr != '\0') { ptr++; i++; }
- i++; ptr++;
- while(*ptr != '\n') { ptr++; i++; }
- i++;
- return i;
+int JIS0212(unsigned char * ptr) {
+ int i = 0;
+ unsigned int fmap;
+ unsigned int ucs;
+ *(ptr+6) = '\0';
+ fmap = (unsigned int)strtoul(ptr, NULL, 16);
+ ptr += 7;
+ i += 7;
+ while(*ptr == ' ') { ptr++; i++; }
+ //i++; ptr++;
+ *(ptr+6) = '\0';
+ ucs = (unsigned int)strtoul(ptr, NULL, 16);
+ if (*(ptr + 1) != 'x') {
+ printf("/* EOF */\n");
+ abort();
+ }
+ if (ucs)
+ printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
+ (fmap & 0xFF00) >> 8, fmap & 0xFF);
+ while(*ptr != '\0') { ptr++; i++; }
+ i++; ptr++;
+ while(*ptr != '\n') { ptr++; i++; }
+ i++;
+ return i;
}
-int main(int argc, char **argv)
-{
- char buf[80];
- int len;
- int i;
- unsigned char *ptr;
- size_t nb;
- len = fread(buffer, 1, 1000000, stdin);
+int main(int argc, char **argv) {
+ char buf[80];
+ int len;
+ int i;
+ unsigned char *ptr;
+ size_t nb;
+ len = fread(buffer, 1, 1000000, stdin);
- buffer[len] = '\0';
- ptr = (unsigned char *)buffer;
- while (*ptr !='\n') {ptr++; len--;};
- ptr++; len--;
- while (*ptr == '#') {
- while (*ptr !='\n') {
- ptr++;
- len--;
- }
- ptr++;
- len--;
- }
+ buffer[len] = '\0';
+ ptr = (unsigned char *)buffer;
+ while (*ptr !='\n') {ptr++; len--;};
+ ptr++; len--;
+ while (*ptr == '#') {
+ while (*ptr !='\n') {
+ ptr++;
+ len--;
+ }
+ ptr++;
+ len--;
+ }
-
- while (len > 0) {
- nb = 0;
- if (!strcmp("jisx0208.1983-0", argv[1])) {
- nb = JIS0208(ptr);
- } else if (!strcmp("jisx0201.1976-0", argv[1])) {
- nb = JIS0201(ptr);
- } else if (!strcmp("jisx0212.1990-0", argv[1])) {
- nb = JIS0212(ptr);
- } else if (!strcmp("gb2312.1980-0", argv[1])) {
- nb = JIS0212(ptr);
- } else if (!strcmp("ksc5601.1987-0", argv[1])) {
- nb = JIS0212(ptr);
- } else if (!strcmp("big5-0", argv[1])) {
- nb = JIS0212(ptr);
- } else if (!strncmp("iso8859", argv[1], 7)) {
- nb = JIS0201(ptr);
- } else if (!strcmp("koi8-1", argv[1])) {
- nb = JIS0201(ptr);
- } else if (!strcmp("dingbats", argv[1]) ||
- !strcmp("symbol", argv[1]))
- {
- nb = ADOBE(ptr);
- } else {
- len = 0;
- }
- ptr += nb;
- len = len - nb;
- }
- return 0;
+ while (len > 0) {
+ nb = 0;
+ if (!strcmp("jisx0208.1983-0", argv[1])) {
+ nb = JIS0208(ptr);
+ } else if (!strcmp("jisx0201.1976-0", argv[1])) {
+ nb = JIS0201(ptr);
+ } else if (!strcmp("jisx0212.1990-0", argv[1])) {
+ nb = JIS0212(ptr);
+ } else if (!strcmp("gb2312.1980-0", argv[1])) {
+ nb = JIS0212(ptr);
+ } else if (!strcmp("ksc5601.1987-0", argv[1])) {
+ nb = JIS0212(ptr);
+ } else if (!strcmp("big5-0", argv[1])) {
+ nb = JIS0212(ptr);
+ } else if (!strncmp("iso8859", argv[1], 7)) {
+ nb = JIS0201(ptr);
+ } else if (!strcmp("koi8-1", argv[1])) {
+ nb = JIS0201(ptr);
+ } else if (!strcmp("dingbats", argv[1]) ||
+ !strcmp("symbol", argv[1]))
+ {
+ nb = ADOBE(ptr);
+ } else {
+ len = 0;
+ }
+ ptr += nb;
+ len = len - nb;
+ }
+ return 0;
}
/*
diff --git a/src/xutf8/utils/create_table.c b/src/xutf8/utils/create_table.c
index 5bc702952..cfee793d8 100644
--- a/src/xutf8/utils/create_table.c
+++ b/src/xutf8/utils/create_table.c
@@ -1,3 +1,28 @@
+/* "$Id: $"
+ *
+ * Author: Jean-Marc Lienher ( http://oksid.ch )
+ * Copyright 2000-2003 by O'ksi'D.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Please report all bugs and problems on the following page:
+ *
+ * http://www.fltk.org/str.php
+ */
+
#include <wchar.h>
#include <stdio.h>
char buffer[1000000];
@@ -5,85 +30,83 @@ char buffer[1000000];
/*** you can try to modifie this value to have better performences **/
#define MAX_DELTA 0x80
-int main(int argc, char **argv)
-{
- char buf[80];
- int len;
- unsigned int i = 0;
- unsigned char *ptr;
- size_t nb;
- int nbb = 0;
- len = fread(buffer, 1, 1000000, stdin);
+int main(int argc, char **argv) {
+ char buf[80];
+ int len;
+ unsigned int i = 0;
+ unsigned char *ptr;
+ size_t nb;
+ int nbb = 0;
+ len = fread(buffer, 1, 1000000, stdin);
- buffer[len] = '\0';
- ptr = (unsigned char *)buffer;
- while (*ptr != '\n') ptr++;
- ptr++;
- while (*ptr != '\n') {
- if (*ptr == ',') nbb++;
- ptr++;
+ buffer[len] = '\0';
+ ptr = (unsigned char *)buffer;
+ while (*ptr != '\n') ptr++;
+ ptr++;
+ while (*ptr != '\n') {
+ if (*ptr == ',') nbb++;
+ ptr++;
+ }
+ ptr = (unsigned char *)buffer;
+ printf("/* %s */\n", argv[1]);
+ while (len > 0) {
+ unsigned int ucs = 0;
+ char *p = ptr;
+ char pp[20];
+ nb = 0;
+ pp[0] = '\0';
+ while (*p != 'U') p++;
+ strncat(pp, p, 6);
+ *pp = '0';
+ *(pp+1) = 'x';
+ ucs = (unsigned int)strtoul(pp, NULL, 16);;
+ if (ucs < 1) {
+ printf("ERROR %d %d\n", len, ucs);
+ abort();
+ }
+ if (i != ucs - 1 || !i) {
+ if ((ucs - i) > MAX_DELTA || !i) {
+ if (i) {
+ printf("};\n");
+ fprintf(stderr, "\t/* end: U+%04X */\n", i);
}
- ptr = (unsigned char *)buffer;
- printf("/* %s */\n", argv[1]);
- while (len > 0) {
- unsigned int ucs = 0;
- char *p = ptr;
- char pp[20];
- nb = 0;
- pp[0] = '\0';
- while (*p != 'U') p++;
- strncat(pp, p, 6);
- *pp = '0';
- *(pp+1) = 'x';
- ucs = (unsigned int)strtoul(pp, NULL, 16);;
- if (ucs < 1) {
- printf("ERROR %d %d\n", len, ucs);
- abort();
- }
- if (i != ucs - 1 || !i) {
- if ((ucs - i) > MAX_DELTA || !i) {
- if (i) {
- printf("};\n");
- fprintf(stderr, "\t/* end: U+%04X */\n",
- i);
- }
- if (strcmp(argv[1], "spacing")) {
- printf("\nstatic const char"
- " unicode_to_%s_%db_%04X[]"
- " = {\n", argv[1], nbb, ucs);
- fprintf(stderr,
- "unicode_to_%s_%db_%04X[]; ",
- argv[1], nbb, ucs);
- } else {
- printf("\nstatic const unsigned short"
- " ucs_table_%04X[]"
- " = {\n", ucs);
- fprintf(stderr,
- "ucs_table_%04X[]; ",
- ucs);
- }
- } else {
- while (i < ucs - 1) {
- i++;
- if (nbb == 1) {
- printf("0x00,\n");
- } else {
- printf("0x00, 0x00,\n");
- }
- };
- }
- }
- i = ucs;
- while (*ptr != '\n') {
- printf("%c", *ptr);
- ptr++;
- len--;
- }
- printf("\n");
- ptr++;
- len--;
+ if (strcmp(argv[1], "spacing")) {
+ printf("\nstatic const char unicode_to_%s_%db_%04X[] = {\n",
+ argv[1], nbb, ucs);
+ fprintf(stderr, "unicode_to_%s_%db_%04X[]; ",
+ argv[1], nbb, ucs);
+ } else {
+ printf("\nstatic const unsigned short"
+ " ucs_table_%04X[]"
+ " = {\n", ucs);
+ fprintf(stderr, "ucs_table_%04X[]; ", ucs);
}
- printf("};\n");
- fprintf(stderr, "\t/* end: U+%04X */\n", i);
- return 0;
+ } else {
+ while (i < ucs - 1) {
+ i++;
+ if (nbb == 1) {
+ printf("0x00,\n");
+ } else {
+ printf("0x00, 0x00,\n");
+ }
+ };
+ }
+ }
+ i = ucs;
+ while (*ptr != '\n') {
+ printf("%c", *ptr);
+ ptr++;
+ len--;
+ }
+ printf("\n");
+ ptr++;
+ len--;
+ }
+ printf("};\n");
+ fprintf(stderr, "\t/* end: U+%04X */\n", i);
+ return 0;
}
+
+/*
+ * End of "$Id$".
+ */
diff --git a/src/xutf8/utils/euc_tw.c b/src/xutf8/utils/euc_tw.c
index 54da80b46..523266653 100644
--- a/src/xutf8/utils/euc_tw.c
+++ b/src/xutf8/utils/euc_tw.c
@@ -32,36 +32,34 @@
char uni[0x10000];
#include "../utf8Utils.c"
-int main(int argc, char **argv)
-{
+int main(int argc, char **argv) {
- iconv_t cd;
+ iconv_t cd;
- int i;
- cd = iconv_open("EUC-TW", "UTF16");
- for(i = 0; i < 0x10000; i++) uni[i] = 0;
- for(i = 0x00000000; i < 0xFFFFFFFF; i++) {
- char buf[4], ob[6];
- char *b = buf;
- int ucs = -1;
- int l1 = 4, l2 = 6;
- char *o = ob ;
- buf[0] = i & 0xff;
- buf[1] = (i >> 8) & 0xFF;
- buf[2] = (i >> 16) & 0xFF;
- buf[3] = (i >> 24) & 0xFF;
- iconv(cd, NULL, NULL, NULL, NULL);
- iconv(cd, &b, &l1, &o, &l2);
- if (l2 != 6) {
- ucs = (unsigned)ob[0];
- ucs += (unsigned) (ob[1] << 8);
- //XConvertUtf8ToUcs((unsigned char*)ob, 6 - l2, &ucs);
- printf ("%x --> %X\n", i, ucs & 0xFFFF);
- }
-
- }
- iconv_close(cd);
- return 0;
+ int i;
+ cd = iconv_open("EUC-TW", "UTF16");
+ for(i = 0; i < 0x10000; i++) uni[i] = 0;
+ for(i = 0x00000000; i < 0xFFFFFFFF; i++) {
+ char buf[4], ob[6];
+ char *b = buf;
+ int ucs = -1;
+ int l1 = 4, l2 = 6;
+ char *o = ob ;
+ buf[0] = i & 0xff;
+ buf[1] = (i >> 8) & 0xFF;
+ buf[2] = (i >> 16) & 0xFF;
+ buf[3] = (i >> 24) & 0xFF;
+ iconv(cd, NULL, NULL, NULL, NULL);
+ iconv(cd, &b, &l1, &o, &l2);
+ if (l2 != 6) {
+ ucs = (unsigned)ob[0];
+ ucs += (unsigned) (ob[1] << 8);
+ //XConvertUtf8ToUcs((unsigned char*)ob, 6 - l2, &ucs);
+ printf ("%x --> %X\n", i, ucs & 0xFFFF);
+ }
+ }
+ iconv_close(cd);
+ return 0;
}
/*