-/* File: main-x11.c */
+/* File: main-x11.c */
/*
* Copyright (c) 1997 Ben Harrison, and others
*/
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
/*
- * ÆüËܸì(EUC-JAPAN)Âбþ (-DJP)
- * ¡¦´Á»ú¥Õ¥©¥ó¥È¤Î°·¤¤¤òÄɲÃ
- * ¡¦ÆüËܸì¤ò´Þ¤àʸ»úÎó¤Îɽ¼¨¥ë¡¼¥Á¥ó XDrawMultiString() ¤ÎÄɲÃ
- * ¡¦ÆüËܸì¤Îɽ¼¨Éý¤Ï¡¤¥Õ¥©¥ó¥È¤Î¾ðÊó¤Ë¤è¤é¤¹ASCII¥Õ¥©¥ó¥È¤Î2Çܤ˸ÇÄê
+ * 日本語(EUC-JAPAN)対応 (-DJP)
+ * ・漢字フォントの扱いを追加
+ * ・日本語を含む文字列の表示ルーチン XDrawMultiString() の追加
+ * ・日本語の表示幅は,フォントの情報によらすASCIIフォントの2倍に固定
*
- * ̤Âбþ
- * EUCȾ³Ñ¤Î°·¤¤
+ * 未対応
+ * EUC半角の扱い
*
- * 1996/6/7 Íû ¹¸¿ (ri@kuis.kyoto-u.ac.jp)
+ * 1996/6/7 李 晃伸 (ri@kuis.kyoto-u.ac.jp)
*/
#endif
/*
#include <X11/Xatom.h>
#endif /* __MAKEDEPEND__ */
-
+#include <iconv.h>
/*
* Include some helpful X11 code.
*/
static infowin *Focuswin = (infowin*)(NULL);
#endif
static infoclr *Infoclr = (infoclr*)(NULL);
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
static infofnt *Infofnt = (infofnt*)(NULL);
static infofnt *Infokfnt = (infofnt*)(NULL);
#else
/**** Generic code ****/
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
#define Infokfnt_set(I) \
(Infokfnt = (I))
#endif
{
infofnt *ifnt = Infofnt;
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
infofnt *ikfnt = Infokfnt;
#endif
/* Deal with 'name' */
string_free(ifnt->name);
}
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
if (ikfnt->name)
{
/* Free the name */
string_free(ikfnt->name);
}
#endif
+
/* Nuke info if needed */
if (ifnt->nuke)
{
/* Free the font */
+#ifdef USE_FONTSET
+ XFreeFontSet(Metadpy->dpy, ifnt->info);
+#else
XFreeFont(Metadpy->dpy, ifnt->info);
+#endif
}
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
if (ikfnt->nuke)
{
/* Free the font */
/*
* Prepare a new 'infofnt'
*/
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
static errr Infofnt_prepare(XFontStruct *info, XFontStruct *kinfo)
#else
#ifdef USE_FONTSET
{
infofnt *ifnt = Infofnt;
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
infofnt *ikfnt = Infokfnt;
#endif
XCharStruct *cs;
if(ascent < (*fontinfo)->ascent) ascent = (*fontinfo)->ascent;
if(descent < (*fontinfo)->descent) descent = (*fontinfo)->descent;
if(((*fontinfo)->max_byte1) > 0){
- /* ¿¥Ð¥¤¥Èʸ»ú¤Î¾ì¹ç¤ÏÉýȾʬ(ü¿ôÀÚ¤ê¾å¤²)¤Çɾ²Á¤¹¤ë */
+ /* 多バイト文字の場合は幅半分(端数切り上げ)で評価する */
if(width < (cs->width+1)/2) width = (cs->width+1)/2;
}else{
if(width < cs->width) width = cs->width;
else
ifnt->twid = ifnt->wid;
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
/* Assign the struct */
ikfnt->info = kinfo;
/*
* Initialize a new 'infofnt'.
*/
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
static errr Infofnt_init_real(XFontStruct *info, XFontStruct *kinfo)
#else
#ifdef USE_FONTSET
/* Wipe the thing */
(void)WIPE(Infofnt, infofnt);
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
WIPE(Infokfnt, infofnt);
#endif
/* No nuking */
Infofnt->nuke = 0;
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
Infokfnt->nuke = 0;
#endif
/* Attempt to prepare it */
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
return (Infofnt_prepare (info, kinfo));
#else
return (Infofnt_prepare(info));
* Inputs:
* name: The name of the requested Font
*/
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
static void Infofnt_init_data(cptr name, cptr kname)
#else
static void Infofnt_init_data(cptr name)
#endif
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
XFontStruct *kinfo;
#endif
/*** Load the info Fresh, using the name ***/
/* If the name is not given, report an error */
if (!name || !*name) quit("Missing font!");
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
if (!kname || !*kname) quit("Missing kanji font!");
#endif
/* Attempt to load the font */
}
#else
info = XLoadQueryFont(Metadpy->dpy, name);
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
kinfo = XLoadQueryFont(Metadpy->dpy, kname);
#endif
#endif
/* The load failed, try to recover */
if (!info) quit_fmt("Failed to find font:\"%s\"", name);
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
if (!kinfo) quit_fmt("Failed to find font:\"%s\"", kname);
#endif
/* Wipe the thing */
(void)WIPE(Infofnt, infofnt);
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
WIPE(Infokfnt, infofnt);
#endif
/* Attempt to prepare it */
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
if (Infofnt_prepare(info, kinfo))
#else
if (Infofnt_prepare(info))
XFreeFontSet(Metadpy->dpy, info);
#else
XFreeFont(Metadpy->dpy, info);
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
XFreeFont(Metadpy->dpy, kinfo);
#endif
#endif
/* Save a copy of the font name */
Infofnt->name = string_make(name);
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
Infokfnt->name = string_make(kname);
#endif
/* Mark it as nukable */
Infofnt->nuke = 1;
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
Infokfnt->nuke = 1;
#endif
}
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
/*
- * EUCÆüËܸ쥳¡¼¥É¤ò´Þ¤àʸ»úÎó¤òɽ¼¨¤¹¤ë (Xlib)
+ * EUC日本語コードを含む文字列を表示する (Xlib)
*/
static void
XDrawMultiString(display,d,gc, x, y, string, len, afont,
#ifdef TOFU
if ( (*str) == 0x7f ) {
- /* 0x7F¤Ï¢£¤Ç·è¤áÂǤÁ */
+ /* 0x7Fは■で決め打ち */
- /* Ϣ³¤¹¤ë0x7F¤ÎŤµ¤ò¸¡½Ð */
+ /* 連続する0x7Fの長さを検出 */
slen = 0;
while ( str < endp && (*str) == 0x7f ) {
slen++;
str++;
}
- /* ÉÁ²è */
+ /* 描画 */
XFillRectangle( display, d, gc, x, y-afont_ascent,
slen * afont_width, afont_height);
- /* ¥Ý¥¤¥ó¥¿¤ò¿Ê¤á¤ë */
+ /* ポインタを進める */
x += afont_width * slen;
}
else
#endif
if ( iskanji(*str) ) {
- /* UJIS¤Î»Ï¤Þ¤ê */
+ /* UJISの始まり */
- /* Ϣ³¤¹¤ëUJISʸ»ú¤ÎŤµ¤ò¸¡½Ð */
+ /* 連続するUJIS文字の長さを検出 */
slen = 0;
while ( str < endp && *str && iskanji(*str) ) {
kanji[slen].byte1 = *str++ & 0x7f;
kanji[slen++].byte2 = *str++ & 0x7f;
}
- /* ÉÁ²è */
+ /* 描画 */
XSetFont( display, gc, kfont->fid );
XDrawImageString16( display, d, gc, x, y, kanji, slen );
- /* ¥Ý¥¤¥ó¥¿¤ò¿Ê¤á¤ë */
+ /* ポインタを進める */
x += kfont_width * slen;
} else {
- /* Èó´Á»ú(=ASCII¤È²¾Äê)¤Î»Ï¤Þ¤ê */
+ /* 非漢字(=ASCIIと仮定)の始まり */
- /* Ϣ³¤¹¤ëASCIIʸ»ú¤ò¸¡½Ð */
+ /* 連続するASCII文字を検出 */
p = str;
slen = 0;
while ( str < endp && *str && !iskanji(*str) ) {
slen++;
}
- /* ÉÁ²è */
+ /* 描画 */
XSetFont( display, gc, afont->fid );
XDrawImageString( display, d, gc, x, y, p, slen );
- /* ¥Ý¥¤¥ó¥¿¤ò¿Ê¤á¤ë */
+ /* ポインタを進める */
x += afont_width * slen;
}
}
/*** Actually draw 'str' onto the infowin ***/
-#if 1
-#ifndef JP
+#ifndef USE_FONTSET
/* Be sure the correct font is ready */
XSetFont(Metadpy->dpy, Infoclr->gc, Infofnt->info->fid);
#endif
-#endif
/*** Handle the fake mono we can enforce on fonts ***/
/* Monotize the font */
if (Infofnt->mono)
{
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
/* Be sure the correct font is ready */
XSetFont(Metadpy->dpy, Infoclr->gc, Infofnt->info->fid);
#endif
else
{
/* Note that the Infoclr is set up to contain the Infofnt */
-#ifdef _JP
- /* ´Á»ú¥Õ¥©¥ó¥È¤Îɽ¼¨Éý¤Ï ASCII¥Õ¥©¥ó¥È¤Î2Çܤ˸ÇÄê */
+#ifdef USE_JP_FONTSTRUCT
+ /* 漢字フォントの表示幅は ASCIIフォントの2倍に固定 */
XDrawMultiString(Metadpy->dpy, Infowin->win, Infoclr->gc,
x, y, str, len,
Infofnt->info, Infofnt->wid, Infofnt->hgt,
Infokfnt->info, Infofnt->wid * 2);
#else
#ifdef USE_FONTSET
+
+ iconv_t cd = iconv_open("UTF-8", "EUC-JP");
+ size_t inlen = len;
+ size_t outlen = len * 2;
+ char *kanji = malloc(outlen);
+ char *sp = str; char *kp = kanji;
+ size_t n = iconv(cd, &sp, &inlen, &kp, &outlen);
+ iconv_close(cd);
+
XmbDrawImageString(Metadpy->dpy, Infowin->win, Infofnt->info,
- Infoclr->gc, x, y, str, len);
+ Infoclr->gc, x, y, kanji, kp-kanji);
+ free(kanji);
#else
XDrawImageString(Metadpy->dpy, Infowin->win, Infoclr->gc,
x, y, str, len);
term t;
infofnt *fnt;
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
infofnt *kfnt;
#endif
XImage *tiles;
-#ifdef USE_TRANSPARENCY
-
/* Tempory storage for overlaying tiles. */
XImage *TmpImage;
#endif
-#endif
-
};
for (n = 0, y = 0; y < Term->hgt; y++)
{
+#ifdef JP
int kanji = 0;
-
+#endif
if (y < min.y) continue;
if (y > max.y) break;
for (l = 0, x = 0; x < Term->wid; x++)
{
+#ifdef JP
if (x > max.x) break;
/* Find the character. */
if ((2 == kanji && x == min.x) ||
(1 == kanji && x == max.x))
c = ' ';
+#else
+ if (x > max.x) break;
+ if (x < min.x) continue;
+
+ /* Find the character. */
+ Term_what(x, y, &a, &c);
+#endif
/* Add it. */
buf[l] = c;
l++;
}
+ /* Ignore trailing spaces */
+ while (buf[l-1] == ' ') l--;
+
/* Terminate all line unless it's single line. */
if (min.y != max.y)
{
if (!sound_file[v]) return (1);
sprintf(buf,"./playwave.sh %s\n", sound_file[v]);
- system(buf);
- return (0);
+ return (system(buf) < 0);
}
#endif /* USE_SOUND */
/* Activate the font */
Infofnt_set(td->fnt);
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
Infokfnt_set(td->kfnt);
#endif
}
/*
* Draw some graphical characters.
*/
-# ifdef USE_TRANSPARENCY
static errr Term_pict_x11(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
-# else /* USE_TRANSPARENCY */
-static errr Term_pict_x11(int x, int y, int n, const byte *ap, const char *cp)
-# endif /* USE_TRANSPARENCY */
{
int i, x1, y1;
byte a;
char c;
-#ifdef USE_TRANSPARENCY
byte ta;
char tc;
int k,l;
unsigned long pixel, blank;
-#endif /* USE_TRANSPARENCY */
term_data *td = (term_data*)(Term->data);
continue;
}
-#ifdef USE_TRANSPARENCY
-
ta = *tap++;
tc = *tcp++;
0, 0, x, y,
td->fnt->twid, td->fnt->hgt);
}
-
-#else /* USE_TRANSPARENCY */
-
- /* Draw object / terrain */
- XPutImage(Metadpy->dpy, td->win->win,
- clr[0]->gc,
- td->tiles,
- x1, y1,
- x, y,
- td->fnt->twid, td->fnt->hgt);
-
-#endif /* USE_TRANSPARENCY */
}
/* Redraw the selection if any, as it may have been obscured. (later) */
cptr name = angband_term_name[i];
cptr font;
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
cptr kfont;
#endif
}
}
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
/* Window specific font name */
sprintf(buf, "ANGBAND_X11_KFONT_%d", i);
/* Prepare the standard font */
-#ifdef _JP
+#ifdef USE_JP_FONTSTRUCT
MAKE(td->fnt, infofnt);
Infofnt_set(td->fnt);
MAKE(td->kfnt, infofnt);
int pict_wid = 0;
int pict_hgt = 0;
-#ifdef USE_TRANSPARENCY
-
char *TmpData;
-#endif /* USE_TRANSPARENCY */
-
#endif /* USE_GRAPHICS */
}
#ifdef USE_LOCALE
+
+#ifdef JP
+ /* Get locale information from environment variables */
setlocale(LC_ALL, "");
+
#ifdef DEFAULT_LOCALE
if(!strcmp(setlocale(LC_ALL, NULL), "C")){
printf("try default locale \"%s\"\n", DEFAULT_LOCALE);
setlocale(LC_ALL, DEFAULT_LOCALE);
}
#endif
+
+ if(!strcmp(setlocale(LC_ALL, NULL), "C"))
{
- char *current_locale = setlocale(LC_ALL, NULL);
-/* printf("set locale to \"%s\"\n", current_locale); */
- if(!strcmp(current_locale, "C")){
- printf("WARNING: Locale is not supported. Non-english font may be displayed incorrectly.\n");
- }
+ printf("WARNING: Locale is not supported. Non-english font may be displayed incorrectly.\n");
}
if(!XSupportsLocale()){
printf("can't support locale in X\n");
setlocale(LC_ALL, "C");
}
+#else
+ /* Set locale to "C" without using environment variables */
+ setlocale(LC_ALL, "C");
+#endif /* JP */
+
#endif /* USE_LOCALE */
td->fnt->twid, td->fnt->hgt);
}
-#ifdef USE_TRANSPARENCY
/* Initialize the transparency masks */
for (i = 0; i < num_term; i++)
{
td->fnt->twid, td->fnt->hgt, 8, 0);
}
-#endif /* USE_TRANSPARENCY */
-
/* Free tiles_raw? XXX XXX */
}