Browse Source

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
pull/49/head
Greg Ercolano 16 years ago
parent
commit
6cbde8909b
  1. 18
      src/xutf8/case.c
  2. 4
      src/xutf8/is_right2left.c
  3. 5
      src/xutf8/is_spacing.c
  4. 4
      src/xutf8/keysym2Ucs.c
  5. 59
      src/xutf8/test.c
  6. 37
      src/xutf8/test2.c
  7. 9
      src/xutf8/ucs2fontmap.c
  8. 63
      src/xutf8/utf8Input.c
  9. 47
      src/xutf8/utf8Utils.c
  10. 193
      src/xutf8/utf8Wrap.c
  11. 10
      src/xutf8/utils/conv_gen.c
  12. 22
      src/xutf8/utils/convert_map.c
  13. 47
      src/xutf8/utils/create_table.c
  14. 4
      src/xutf8/utils/euc_tw.c

18
src/xutf8/case.c

@ -30,13 +30,9 @@ @@ -30,13 +30,9 @@
#include "headers/case.h"
#include <stdlib.h>
int
XUtf8Tolower(
int ucs)
{
XUtf8Tolower(int ucs) {
int ret;
if (ucs <= 0x02B6) {
if (ucs >= 0x0041) {
ret = ucs_table_0041[ucs - 0x0041];
@ -105,15 +101,12 @@ XUtf8Tolower( @@ -105,15 +101,12 @@ XUtf8Tolower(
}
int
XUtf8Toupper(
int ucs)
{
XUtf8Toupper(int ucs) {
int i;
static unsigned short *table = NULL;
if (!table) {
table = (unsigned short*) malloc(
sizeof(unsigned short) * 0x10000);
table = (unsigned short*) malloc(sizeof(unsigned short) * 0x10000);
for (i = 0; i < 0x10000; i++) {
table[i] = (unsigned short) i;
}
@ -122,12 +115,11 @@ XUtf8Toupper( @@ -122,12 +115,11 @@ XUtf8Toupper(
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$".
*/

4
src/xutf8/is_right2left.c

@ -28,9 +28,7 @@ @@ -28,9 +28,7 @@
*/
unsigned short
XUtf8IsRightToLeft(
unsigned int ucs)
{
XUtf8IsRightToLeft(unsigned int ucs) {
#if 0
/* for debug only */

5
src/xutf8/is_spacing.c

@ -29,11 +29,8 @@ @@ -29,11 +29,8 @@
#include "headers/spacing.h"
unsigned short
XUtf8IsNonSpacing(
unsigned int ucs)
{
XUtf8IsNonSpacing(unsigned int ucs) {
if (ucs <= 0x0361) {
if (ucs >= 0x0300) return ucs_table_0300[ucs - 0x0300];

4
src/xutf8/keysym2Ucs.c

@ -30,9 +30,7 @@ @@ -30,9 +30,7 @@
#include "../../FL/Xutf8.h"
#include "imKStoUCS.c"
long XKeysymToUcs(KeySym keysym)
{
long XKeysymToUcs(KeySym keysym) {
return (long) KeySymToUcs4(keysym);
}

59
src/xutf8/test.c

@ -26,7 +26,9 @@ @@ -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" @@ -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,8 +82,7 @@ GC gc; @@ -80,8 +82,7 @@ GC gc;
int x = 2;
int y = 40;
int main(int argc, char**argv)
{
int main(int argc, char**argv) {
char **missing_charset_list;
int missing_charset_count;
XGCValues xgcv;
@ -124,7 +125,10 @@ int main(int argc, char**argv) @@ -124,7 +125,10 @@ int main(int argc, char**argv)
DefaultDepth(dpy, DefaultScreen(dpy)),
InputOutput, DefaultVisual(dpy, DefaultScreen(dpy)),
CWEventMask | CWBackPixel | CWBorderPixel, &set_attr);
if (!w) { puts("cannot creat window.\n"); exit(-1); }
if (!w) {
puts("cannot creat window.\n");
exit(-1);
}
class_hints.res_name = "test";
class_hints.res_class = "Test";
@ -140,12 +144,14 @@ int main(int argc, char**argv) @@ -140,12 +144,14 @@ int main(int argc, char**argv)
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); }
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++)
{
i < xim_styles->count_styles; i++, style++) {
if (i == 0 && *style == (XIMStatusNone|XIMPreeditNone)) {
printf("this is not a XIM server !!!\n");
no_xim = 1;
@ -159,16 +165,19 @@ int main(int argc, char**argv) @@ -159,16 +165,19 @@ int main(int argc, char**argv)
XNClientWindow, w,
XNFocusWindow, w,
NULL);
if (!xim_ic) { puts("cannot create Input Context.\n"); exit(-1);}
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
/***************************************************************
* 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. */
/***************************************************************/
* your language.
***************************************************************/
fontset = XCreateUtf8FontStruct(dpy,
"-*-*-*-*-*-*-*-*-*-*-*-*-iso8858-3," /* not valid */
"-*-*-medium-r-*-*-*-*-*-*-*-*-iso8859-1,"
@ -204,8 +213,10 @@ int main(int argc, char**argv) @@ -204,8 +213,10 @@ int main(int argc, char**argv)
xgcv.background = WhitePixel(dpy, DefaultScreen(dpy));
gc = XCreateGC(dpy, w, mask, &xgcv);
if (!gc) { puts("cannot create Graphic Context.\n"); exit(-1);}
if (!gc) {
puts("cannot create Graphic Context.\n");
exit(-1);
}
/***************************************************************/
while (1) {
@ -226,8 +237,7 @@ int main(int argc, char**argv) @@ -226,8 +237,7 @@ int main(int argc, char**argv)
xim_im = XOpenIM(dpy, NULL, "test", "Test");
if (xim_im) {
xim_ic = XCreateIC(xim_im,
XNInputStyle, (XIMPreeditNothing |
XIMStatusNothing),
XNInputStyle, (XIMPreeditNothing | XIMStatusNothing),
XNClientWindow, w,
XNFocusWindow, w,
NULL);
@ -258,23 +268,16 @@ int main(int argc, char**argv) @@ -258,23 +268,16 @@ int main(int argc, char**argv)
x = 0;
XCloseIM(xim_im);
} else {
XUtf8DrawImageString(dpy, w, fontset, gc,
x, y, buf, len);
XUtf8DrawImageString(dpy, w, fontset, gc, x, y, buf, len);
x += XUtf8TextWidth(fontset, 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));
XUtf8DrawRtlString(dpy, w, fontset, gc,
50, 90, rtl_txt, strlen(rtl_txt));
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");

37
src/xutf8/test2.c

@ -26,7 +26,9 @@ @@ -26,7 +26,9 @@
/*
* UTF-8 X test program
*
To test it do :
*****************
* To test it do :
*****************
kinput2 -canna
XMODIFIERS="@im=kinput2"; export XMODIFIERS
@ -82,8 +84,7 @@ GC gc; @@ -82,8 +84,7 @@ GC gc;
int x = 2;
int y = 40;
int main(int argc, char**argv)
{
int main(int argc, char**argv) {
char **missing_charset_list;
int missing_charset_count;
XGCValues xgcv;
@ -138,10 +139,9 @@ int main(int argc, char**argv) @@ -138,10 +139,9 @@ int main(int argc, char**argv)
XMapWindow(dpy, w);
xim_im = XOpenIM(dpy, NULL, "test", "Test");
XGetIMValues (xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
XGetIMValues(xim_im, XNQueryInputStyle, &xim_styles, NULL, NULL);
for (i = 0, style = xim_styles->supported_styles;
i < xim_styles->count_styles; i++, style++)
{
i < xim_styles->count_styles; i++, style++) {
if (*style == (XIMStatusNone|XIMPreeditNone)) {
printf("this is not a XIM server !!!\n");
no_xim = 1;
@ -157,10 +157,10 @@ int main(int argc, char**argv) @@ -157,10 +157,10 @@ int main(int argc, char**argv)
NULL);
XSetICFocus(xim_ic);
/***************************************************************/
/** I don't recommand to use a font base name list similar
* to the following one in a real application ;-) */
/***************************************************************/
/***************************************************************
* 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,"
@ -184,7 +184,6 @@ int main(int argc, char**argv) @@ -184,7 +184,6 @@ int main(int argc, char**argv)
gc = XCreateGC(dpy, w, mask, &xgcv);
/***************************************************************/
while (1) {
int filtered;
@ -202,18 +201,10 @@ int main(int argc, char**argv) @@ -202,18 +201,10 @@ int main(int argc, char**argv)
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));
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;

9
src/xutf8/ucs2fontmap.c

@ -62,10 +62,10 @@ typedef struct { @@ -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) @@ -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")) {

63
src/xutf8/utf8Input.c

@ -60,10 +60,7 @@ typedef struct { @@ -60,10 +60,7 @@ typedef struct {
#include "lcUniConv/ksc5601.h"
int
XConvertEucTwToUtf8(
char* buffer_return,
int len)
{
XConvertEucTwToUtf8(char* buffer_return, int len) {
/* FIXME */
#if HAVE_LIBC_ICONV
iconv_t cd;
@ -105,9 +102,7 @@ XConvertEucTwToUtf8( @@ -105,9 +102,7 @@ XConvertEucTwToUtf8(
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)
{
if (c2 >= 0xa1 && c2 < 0xff && c3 >= 0xa1 && c3 < 0xff) {
ucs = ' '; i += 4;
} else {
ucs = '?'; i++;
@ -127,10 +122,7 @@ XConvertEucTwToUtf8( @@ -127,10 +122,7 @@ XConvertEucTwToUtf8(
}
int
XConvertEucKrToUtf8(
char* buffer_return,
int len)
{
XConvertEucKrToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
@ -170,10 +162,7 @@ XConvertEucKrToUtf8( @@ -170,10 +162,7 @@ XConvertEucKrToUtf8(
}
int
XConvertBig5ToUtf8(
char* buffer_return,
int len)
{
XConvertBig5ToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
@ -202,10 +191,7 @@ XConvertBig5ToUtf8( @@ -202,10 +191,7 @@ XConvertBig5ToUtf8(
}
int
XConvertGb2312ToUtf8(
char* buffer_return,
int len)
{
XConvertGb2312ToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
@ -234,10 +220,7 @@ XConvertGb2312ToUtf8( @@ -234,10 +220,7 @@ XConvertGb2312ToUtf8(
}
int
XConvertEucCnToUtf8(
char* buffer_return,
int len)
{
XConvertEucCnToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
@ -276,10 +259,7 @@ XConvertEucCnToUtf8( @@ -276,10 +259,7 @@ XConvertEucCnToUtf8(
}
int
XConvertEucJpToUtf8(
char* buffer_return,
int len)
{
XConvertEucJpToUtf8(char* buffer_return, int len) {
int i = 0, l = 0;
char *buf;
@ -327,9 +307,7 @@ XConvertEucJpToUtf8( @@ -327,9 +307,7 @@ XConvertEucJpToUtf8(
unsigned char b[2];
b[0] = c - 0x80;
b[1] = c1 - 0x80;
if (jisx0212_mbtowc(NULL, &ucs, b, 2)
< 1)
{
if (jisx0212_mbtowc(NULL, &ucs, b, 2) < 1) {
ucs = '?';
}
} else {
@ -337,8 +315,7 @@ XConvertEucJpToUtf8( @@ -337,8 +315,7 @@ XConvertEucJpToUtf8(
}
} else {
if (c1 >= 0xa1 && c1 < 0xff) {
ucs = 0xe3ac + 94 * (c - 0xF5) +
(c1 - 0xA1);
ucs = 0xe3ac + 94 * (c - 0xF5) + (c1 - 0xA1);
} else {
ucs = '?';
}
@ -355,12 +332,11 @@ XConvertEucJpToUtf8( @@ -355,12 +332,11 @@ XConvertEucJpToUtf8(
}
int
XConvertEucToUtf8(
const char* locale,
XConvertEucToUtf8(const char* locale,
char* buffer_return,
int len,
int bytes_buffer)
{
int bytes_buffer) {
if (!locale/* || strstr(locale, "UTF") || strstr(locale, "utf")*/) {
return len;
}
@ -371,9 +347,7 @@ XConvertEucToUtf8( @@ -371,9 +347,7 @@ XConvertEucToUtf8(
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"))
{
if (strstr(locale, "EUC") || strstr(locale, "euc") || strstr(locale, "chinese-t")) {
return XConvertEucTwToUtf8(buffer_return, len);
}
return XConvertBig5ToUtf8(buffer_return, len);
@ -388,16 +362,14 @@ XConvertEucToUtf8( @@ -388,16 +362,14 @@ XConvertEucToUtf8(
return len;
}
int
XUtf8LookupString(
XIC ic,
XUtf8LookupString(XIC ic,
XKeyPressedEvent* event,
char* buffer_return,
int bytes_buffer,
KeySym* keysym,
Status* status_return)
{
Status* status_return) {
long ucs = -1;
int len;
len = XmbLookupString(ic, event, buffer_return, bytes_buffer / 5,
@ -426,8 +398,7 @@ XUtf8LookupString( @@ -426,8 +398,7 @@ XUtf8LookupString(
if (!ic) return 0;
im = XIMOfIC(ic);
if (!im) return 0;
len = XConvertEucToUtf8(XLocaleOfIM(im),
buffer_return, len, bytes_buffer);
len = XConvertEucToUtf8(XLocaleOfIM(im), buffer_return, len, bytes_buffer);
}
return len;
}

47
src/xutf8/utf8Utils.c

@ -39,11 +39,10 @@ @@ -39,11 +39,10 @@
* Returns -1 if the UTF-8 string is not valid
*/
int
XConvertUtf8ToUcs(
const unsigned char *buf,
XConvertUtf8ToUcs(const unsigned char *buf,
int len,
unsigned int *ucs)
{
unsigned int *ucs) {
if (buf[0] & 0x80) {
if (buf[0] & 0x40) {
if (buf[0] & 0x20) {
@ -59,8 +58,7 @@ XConvertUtf8ToUcs( @@ -59,8 +58,7 @@ XConvertUtf8ToUcs(
&& (buf[1] & 0xC0) == 0x80
&& (buf[2] & 0xC0) == 0x80
&& (buf[3] & 0xC0) == 0x80
&& (buf[4] & 0xC0) == 0x80)
{
&& (buf[4] & 0xC0) == 0x80) {
/* 0x00200000 - 0x03FFFFFF */
*ucs = ((buf[0] & ~0xF8) << 24) +
((buf[1] & ~0x80) << 18) +
@ -72,8 +70,7 @@ XConvertUtf8ToUcs( @@ -72,8 +70,7 @@ XConvertUtf8ToUcs(
} else if (len > 3
&& (buf[1] & 0xC0) == 0x80
&& (buf[2] & 0xC0) == 0x80
&& (buf[3] & 0xC0) == 0x80)
{
&& (buf[3] & 0xC0) == 0x80) {
/* 0x00010000 - 0x001FFFFF */
*ucs = ((buf[0] & ~0xF0) << 18) +
((buf[1] & ~0x80) << 12) +
@ -81,10 +78,9 @@ XConvertUtf8ToUcs( @@ -81,10 +78,9 @@ XConvertUtf8ToUcs(
(buf[3] & ~0x80);
if (*ucs > 0x0000FFFF) return 4;
}
} else if (len > 2 &&
(buf[1] & 0xC0) == 0x80 &&
(buf[2] & 0xC0) == 0x80)
{
} else if (len > 2
&& (buf[1] & 0xC0) == 0x80
&& (buf[2] & 0xC0) == 0x80) {
/* 0x00000800 - 0x0000FFFF */
*ucs = ((buf[0] & ~0xE0) << 12) +
((buf[1] & ~0x80) << 6) +
@ -113,10 +109,9 @@ XConvertUtf8ToUcs( @@ -113,10 +109,9 @@ XConvertUtf8ToUcs(
* NOTE : the buffer (buf) must be at least 5 bytes long !!!
*/
int
XConvertUcsToUtf8(
unsigned int ucs,
char *buf)
{
XConvertUcsToUtf8(unsigned int ucs,
char *buf) {
if (ucs < 0x000080) {
buf[0] = ucs;
return 1;
@ -152,10 +147,8 @@ XConvertUcsToUtf8( @@ -152,10 +147,8 @@ XConvertUcsToUtf8(
* (returns -1 if not valid)
*/
int
XUtf8CharByteLen(
const unsigned char *buf,
int len)
{
XUtf8CharByteLen(const unsigned char *buf,
int len) {
unsigned int ucs;
return XConvertUtf8ToUcs(buf, len, &ucs);
}
@ -164,10 +157,9 @@ XUtf8CharByteLen( @@ -164,10 +157,9 @@ XUtf8CharByteLen(
* returns the quantity of Unicode chars in the UTF-8 string
*/
int
XCountUtf8Char(
const unsigned char *buf,
int len)
{
XCountUtf8Char(const unsigned char *buf,
int len) {
int i = 0;
int nbc = 0;
while (i < len) {
@ -183,11 +175,10 @@ XCountUtf8Char( @@ -183,11 +175,10 @@ XCountUtf8Char(
* Same as XConvertUtf8ToUcs but no sanity check is done.
*/
int
XFastConvertUtf8ToUcs(
const unsigned char *buf,
XFastConvertUtf8ToUcs(const unsigned char *buf,
int len,
unsigned int *ucs)
{
unsigned int *ucs) {
if (buf[0] & 0x80) {
if (buf[0] & 0x40) {
if (buf[0] & 0x20) {

193
src/xutf8/utf8Wrap.c

@ -49,8 +49,7 @@ @@ -49,8 +49,7 @@
static int
get_font_list(
const char *base_font_name_list,
char ***flist)
{
char ***flist) {
const char *ptr;
const char *p;
int nb;
@ -95,9 +94,7 @@ get_font_list( @@ -95,9 +94,7 @@ get_font_list(
/** (mainly used for adobe-symbol and adobe-zapfdingbats) **/
/*********************************************************************/
static int
font_spec_enc(
char *font)
{
font_spec_enc(char *font) {
int ret;
char *enc;
char *end;
@ -122,11 +119,10 @@ font_spec_enc( @@ -122,11 +119,10 @@ font_spec_enc(
/** get the sub range of a iso10646-1 font **/
/*********************************************************************/
static void
get_range(
const char *enc,
get_range(const char *enc,
int *min,
int *max)
{
int *max) {
const char *ptr = enc;
const char *ptr1;
@ -153,11 +149,10 @@ get_range( @@ -153,11 +149,10 @@ get_range(
/** get the internal encoding number of each fonts **/
/*********************************************************************/
static int *
get_encodings(
char **font_name_list,
get_encodings(char **font_name_list,
int *ranges,
int nb_font)
{
int nb_font) {
int *font_encoding_list;
int i;
i = 0;
@ -180,8 +175,7 @@ get_encodings( @@ -180,8 +175,7 @@ get_encodings(
if (*ptr == '-') {
ec++;
if (ec == 13) {
font_encoding_list[i] =
encoding_number(ptr + 1);
font_encoding_list[i] = encoding_number(ptr + 1);
if (font_encoding_list[i] == 0) {
get_range(ptr + 1,
ranges + i * 2,
@ -202,10 +196,9 @@ get_encodings( @@ -202,10 +196,9 @@ get_encodings(
/** find the first font which matches the name and load it. **/
/*********************************************************************/
XFontStruct *
find_best_font(
Display *dpy,
char **name)
{
find_best_font(Display *dpy,
char **name) {
char **list;
int cnt;
XFontStruct *s;
@ -225,21 +218,20 @@ find_best_font( @@ -225,21 +218,20 @@ find_best_font(
/** load all fonts **/
/*********************************************************************/
static void
load_fonts(
Display *dpy,
XUtf8FontStruct *font_set)
{
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->fonts = (XFontStruct**) malloc(sizeof(XFontStruct*) *
font_set->nb_font);
font_set->ranges = (int*)
malloc(sizeof(int) * font_set->nb_font * 2);
font_set->ranges = (int*) malloc(sizeof(int) *
font_set->nb_font * 2);
font_set->descent = 0;
font_set->ascent = 0;
@ -280,8 +272,7 @@ load_fonts( @@ -280,8 +272,7 @@ load_fonts(
font_set->ranges[2*j] ==
font_set->ranges[2*i] &&
font_set->ranges[(2*j)+1] &&
font_set->ranges[(2*i)+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;
@ -297,14 +288,12 @@ load_fonts( @@ -297,14 +288,12 @@ load_fonts(
/** list of fonts. XLoad all fonts. **/
/*********************************************************************/
XUtf8FontStruct *
XCreateUtf8FontStruct (
Display *dpy,
const char *base_font_name_list)
{
XCreateUtf8FontStruct(Display *dpy,
const char *base_font_name_list) {
XUtf8FontStruct *font_set;
font_set = (XUtf8FontStruct*)
malloc(sizeof(XUtf8FontStruct));
font_set = (XUtf8FontStruct*)malloc(sizeof(XUtf8FontStruct));
if (!font_set) {
return NULL;
@ -328,16 +317,15 @@ XCreateUtf8FontStruct ( @@ -328,16 +317,15 @@ XCreateUtf8FontStruct (
/** draw a Right To Left UTF-8 string using multiple fonts as needed. **/
/*****************************************************************************/
void
XUtf8DrawRtlString(
Display *display,
XUtf8DrawRtlString(Display *display,
Drawable d,
XUtf8FontStruct *font_set,
GC gc,
int x,
int y,
const char *string,
int num_bytes)
{
int num_bytes) {
int *encodings; /* encodings array */
XFontStruct **fonts; /* fonts array */
XChar2b buf[128]; /* drawing buffer */
@ -376,8 +364,7 @@ XUtf8DrawRtlString( @@ -376,8 +364,7 @@ XUtf8DrawRtlString(
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 */
unsigned int no_spc; /* Spacing char equivalent of a non-spacing char */
if (i > 120) {
/*** draw the buffer **/
@ -388,8 +375,7 @@ XUtf8DrawRtlString( @@ -388,8 +375,7 @@ XUtf8DrawRtlString(
ptr = buf + 128;
}
ulen = XFastConvertUtf8ToUcs((unsigned char*)string,
num_bytes, &ucs);
ulen = XFastConvertUtf8ToUcs((unsigned char*)string, num_bytes, &ucs);
if (ulen < 1) ulen = 1;
@ -402,21 +388,18 @@ XUtf8DrawRtlString( @@ -402,21 +388,18 @@ XUtf8DrawRtlString(
*/
fnum = first;
while (fnum < nb_font) {
if (fonts[fnum] &&
ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
{
if (fonts[fnum] && ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
if (encodings[fnum] != 0 ||
(ucs >= ranges[fnum * 2] &&
ucs <= ranges[fnum * 2 + 1]))
{
(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 :-( **/
/* the char is not valid in all encodings ->
* draw it using the first font :-(
*/
fnum = first;
ucs2fontmap(glyph, '?', encodings[fnum]);
}
@ -455,16 +438,15 @@ XUtf8DrawRtlString( @@ -455,16 +438,15 @@ XUtf8DrawRtlString(
/** draw an UTF-8 string using multiple fonts as needed. **/
/*****************************************************************************/
void
XUtf8DrawString(
Display *display,
XUtf8DrawString(Display *display,
Drawable d,
XUtf8FontStruct *font_set,
GC gc,
int x,
int y,
const char *string,
int num_bytes)
{
int num_bytes) {
int *encodings; /* encodings array */
XFontStruct **fonts; /* fonts array */
XChar2b buf[128]; /* drawing buffer */
@ -500,8 +482,7 @@ XUtf8DrawString( @@ -500,8 +482,7 @@ XUtf8DrawString(
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 */
unsigned int no_spc; /* Spacing char equivalent of a non-spacing char */
if (i > 120) {
/*** draw the buffer **/
@ -511,8 +492,7 @@ XUtf8DrawString( @@ -511,8 +492,7 @@ XUtf8DrawString(
i = 0;
}
ulen = XFastConvertUtf8ToUcs((unsigned char*)string,
num_bytes, &ucs);
ulen = XFastConvertUtf8ToUcs((unsigned char*)string, num_bytes, &ucs);
if (ulen < 1) ulen = 1;
@ -525,21 +505,19 @@ XUtf8DrawString( @@ -525,21 +505,19 @@ XUtf8DrawString(
*/
fnum = first;
while (fnum < nb_font) {
if (fonts[fnum] &&
ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
{
if (fonts[fnum] && ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
if (encodings[fnum] != 0 ||
(ucs >= ranges[fnum * 2] &&
ucs <= ranges[fnum * 2 + 1]))
{
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 :-( **/
/* the char is not valid in all encodings ->
* draw it using the first font :-(
*/
fnum = first;
ucs2fontmap(glyph, '?', encodings[fnum]);
}
@ -574,11 +552,10 @@ XUtf8DrawString( @@ -574,11 +552,10 @@ XUtf8DrawString(
/** returns the pixel width of a UTF-8 string **/
/*****************************************************************************/
int
XUtf8TextWidth(
XUtf8FontStruct *font_set,
XUtf8TextWidth(XUtf8FontStruct *font_set,
const char *string,
int num_bytes)
{
int num_bytes) {
int x;
int *encodings; /* encodings array */
XFontStruct **fonts; /* fonts array */
@ -617,8 +594,7 @@ XUtf8TextWidth( @@ -617,8 +594,7 @@ XUtf8TextWidth(
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 */
unsigned int no_spc; /* Spacing char equivalent of a non-spacing char */
if (i > 120) {
/*** measure the buffer **/
@ -626,8 +602,7 @@ XUtf8TextWidth( @@ -626,8 +602,7 @@ XUtf8TextWidth(
i = 0;
}
ulen = XFastConvertUtf8ToUcs((unsigned char*)string,
num_bytes, &ucs);
ulen = XFastConvertUtf8ToUcs((unsigned char*)string, num_bytes, &ucs);
if (ulen < 1) ulen = 1;
@ -642,21 +617,19 @@ XUtf8TextWidth( @@ -642,21 +617,19 @@ XUtf8TextWidth(
*/
fnum = first;
while (fnum < nb_font) {
if (fonts[fnum] &&
ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
{
if (fonts[fnum] && ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
if (encodings[fnum] != 0 ||
(ucs >= ranges[fnum * 2] &&
ucs <= ranges[fnum * 2 + 1]))
{
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 :-( **/
/* the char is not valid in all encodings ->
* draw it using the first font :-(
*/
fnum = first;
ucs2fontmap(glyph, '?', encodings[fnum]);
}
@ -667,8 +640,7 @@ XUtf8TextWidth( @@ -667,8 +640,7 @@ XUtf8TextWidth(
(*buf).byte1 = glyph[0];
(*buf).byte2 = glyph[1];
if (no_spc) {
/* go back to draw the non-spacing char over
* the previous char */
/* go back to draw the non-spacing char over the previous char */
x -= XTextWidth16(fonts[fnum], buf, 1);
}
} else {
@ -690,12 +662,11 @@ XUtf8TextWidth( @@ -690,12 +662,11 @@ XUtf8TextWidth(
/** get the X font and glyph ID of a UCS char **/
/*****************************************************************************/
int
XGetUtf8FontAndGlyph(
XUtf8FontStruct *font_set,
XGetUtf8FontAndGlyph(XUtf8FontStruct *font_set,
unsigned int ucs,
XFontStruct **fnt,
unsigned short *id)
{
unsigned short *id) {
int x;
int *encodings; /* encodings array */
XFontStruct **fonts; /* fonts array */
@ -736,20 +707,19 @@ XGetUtf8FontAndGlyph( @@ -736,20 +707,19 @@ XGetUtf8FontAndGlyph(
*/
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]))
{
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 :-( **/
/* the char is not valid in all encodings ->
* draw it using the first font :-(
*/
fnum = first;
ucs2fontmap(glyph, '?', encodings[fnum]);
}
@ -763,10 +733,9 @@ XGetUtf8FontAndGlyph( @@ -763,10 +733,9 @@ XGetUtf8FontAndGlyph(
/** returns the pixel width of a UCS char **/
/*****************************************************************************/
int
XUtf8UcsWidth(
XUtf8FontStruct *font_set,
unsigned int ucs)
{
XUtf8UcsWidth(XUtf8FontStruct *font_set,
unsigned int ucs) {
int x;
int *encodings; /* encodings array */
XFontStruct **fonts; /* fonts array */
@ -802,7 +771,6 @@ XUtf8UcsWidth( @@ -802,7 +771,6 @@ XUtf8UcsWidth(
first = fnum;
last_fnum = fnum;
ucs = XUtf8IsNonSpacing(ucs);
/*
@ -812,19 +780,18 @@ XUtf8UcsWidth( @@ -812,19 +780,18 @@ XUtf8UcsWidth(
fnum = first;
while (fnum < nb_font) {
if (fonts[fnum] &&
ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0)
{
ucs2fontmap(glyph, ucs, encodings[fnum]) >= 0) {
if (encodings[fnum] != 0 || (ucs >= ranges[fnum * 2] &&
ucs <= ranges[fnum * 2 + 1]))
{
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 :-( **/
/* the char is not valid in all encodings ->
* draw it using the first font :-(
*/
fnum = first;
ucs2fontmap(glyph, '?', encodings[fnum]);
}
@ -841,16 +808,15 @@ XUtf8UcsWidth( @@ -841,16 +808,15 @@ XUtf8UcsWidth(
/** draw an UTF-8 string and clear the background. **/
/*****************************************************************************/
void
XUtf8DrawImageString(
Display *display,
XUtf8DrawImageString(Display *display,
Drawable d,
XUtf8FontStruct *font_set,
GC gc,
int x,
int y,
const char *string,
int num_bytes)
{
int num_bytes) {
/* FIXME: must be improved ! */
int w;
int fill_style;
@ -895,10 +861,9 @@ XUtf8DrawImageString( @@ -895,10 +861,9 @@ XUtf8DrawImageString(
/** free the XFontSet and others things created by XCreateUtf8FontSet **/
/*****************************************************************************/
void
XFreeUtf8FontStruct(
Display *dpy,
XUtf8FontStruct *font_set)
{
XFreeUtf8FontStruct(Display *dpy,
XUtf8FontStruct *font_set) {
int i;
i = 0;
while (i < font_set->nb_font) {

10
src/xutf8/utils/conv_gen.c

@ -30,8 +30,7 @@ @@ -30,8 +30,7 @@
#include <stdio.h>
char buffer[1000000];
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
char buf[80];
int len;
char *encode[256];
@ -87,12 +86,10 @@ int main(int argc, char **argv) @@ -87,12 +86,10 @@ int main(int argc, char **argv)
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);
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(" s[1] = %s_%s[ucs - 0x%s];\n", ptr, f, f);
printf(" if (s[1]) return %d;\n", encode_number);
}
printf(" }\n");
@ -156,7 +153,6 @@ int main(int argc, char **argv) @@ -156,7 +153,6 @@ int main(int argc, char **argv)
printf(" return -1;\n");
printf("};\n\n");
printf("/*\n");
printf("const char *encoding_name(int num)\n{\n");
printf(" switch (num) {\n");

22
src/xutf8/utils/convert_map.c

@ -33,8 +33,7 @@ @@ -33,8 +33,7 @@
char buffer[1000000];
int JIS0208(unsigned char * ptr)
{
int JIS0208(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
@ -44,7 +43,8 @@ int JIS0208(unsigned char * ptr) @@ -44,7 +43,8 @@ int JIS0208(unsigned char * ptr)
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,
if (ucs)
printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
(fmap & 0xFF00) >> 8, fmap & 0xFF);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
@ -53,8 +53,7 @@ int JIS0208(unsigned char * ptr) @@ -53,8 +53,7 @@ int JIS0208(unsigned char * ptr)
return i;
}
int JIS0201(unsigned char * ptr)
{
int JIS0201(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
@ -75,8 +74,7 @@ int JIS0201(unsigned char * ptr) @@ -75,8 +74,7 @@ int JIS0201(unsigned char * ptr)
return i;
}
int ADOBE(unsigned char * ptr)
{
int ADOBE(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
@ -98,8 +96,7 @@ int ADOBE(unsigned char * ptr) @@ -98,8 +96,7 @@ int ADOBE(unsigned char * ptr)
}
int JIS0212(unsigned char * ptr)
{
int JIS0212(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
@ -115,7 +112,8 @@ int JIS0212(unsigned char * ptr) @@ -115,7 +112,8 @@ int JIS0212(unsigned char * ptr)
printf("/* EOF */\n");
abort();
}
if (ucs) printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
if (ucs)
printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
(fmap & 0xFF00) >> 8, fmap & 0xFF);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
@ -124,8 +122,7 @@ int JIS0212(unsigned char * ptr) @@ -124,8 +122,7 @@ int JIS0212(unsigned char * ptr)
return i;
}
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
char buf[80];
int len;
int i;
@ -146,7 +143,6 @@ int main(int argc, char **argv) @@ -146,7 +143,6 @@ int main(int argc, char **argv)
len--;
}
while (len > 0) {
nb = 0;
if (!strcmp("jisx0208.1983-0", argv[1])) {

47
src/xutf8/utils/create_table.c

@ -1,3 +1,28 @@ @@ -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,8 +30,7 @@ char buffer[1000000]; @@ -5,8 +30,7 @@ char buffer[1000000];
/*** you can try to modifie this value to have better performences **/
#define MAX_DELTA 0x80
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
char buf[80];
int len;
unsigned int i = 0;
@ -44,23 +68,18 @@ int main(int argc, char **argv) @@ -44,23 +68,18 @@ int main(int argc, char **argv)
if ((ucs - i) > MAX_DELTA || !i) {
if (i) {
printf("};\n");
fprintf(stderr, "\t/* end: U+%04X */\n",
i);
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[]; ",
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);
fprintf(stderr, "ucs_table_%04X[]; ", ucs);
}
} else {
while (i < ucs - 1) {
@ -87,3 +106,7 @@ int main(int argc, char **argv) @@ -87,3 +106,7 @@ int main(int argc, char **argv)
fprintf(stderr, "\t/* end: U+%04X */\n", i);
return 0;
}
/*
* End of "$Id$".
*/

4
src/xutf8/utils/euc_tw.c

@ -32,8 +32,7 @@ @@ -32,8 +32,7 @@
char uni[0x10000];
#include "../utf8Utils.c"
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
iconv_t cd;
@ -58,7 +57,6 @@ int main(int argc, char **argv) @@ -58,7 +57,6 @@ int main(int argc, char **argv)
//XConvertUtf8ToUcs((unsigned char*)ob, 6 - l2, &ucs);
printf ("%x --> %X\n", i, ucs & 0xFFFF);
}
}
iconv_close(cd);
return 0;

Loading…
Cancel
Save