OSDN Git Service

[Fix] #37285 ティボルトのUNIQUE属性付加忘れを修正。
[hengband/hengband.git] / src / main-x11.c
index 1073be3..15d8db3 100644 (file)
@@ -1,4 +1,4 @@
-/* File: main-x11.c */
+/* File: main-x11.c */
 
 /*
  * Copyright (c) 1997 Ben Harrison, and others
 
 #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
 /*
@@ -126,7 +126,7 @@ char *XSetIMValues(XIM, ...); /* Hack for XFree86 4.0 */
 #include <X11/Xatom.h>
 #endif /* __MAKEDEPEND__ */
 
-
+#include <iconv.h>
 /*
  * Include some helpful X11 code.
  */
@@ -346,7 +346,7 @@ struct infofnt
        XFontStruct *info;
 #endif
 
-       cptr name;
+       concptr name;
 
        s16b wid;
        s16b twid;
@@ -487,7 +487,7 @@ static infofnt *Infofnt = (infofnt*)(NULL);
  *
  * Return -1 if no Display given, and none can be opened.
  */
-static errr Metadpy_init_2(Display *dpy, cptr name)
+static errr Metadpy_init_2(Display *dpy, concptr name)
 {
        metadpy *m = Metadpy;
 
@@ -621,7 +621,7 @@ static errr Metadpy_do_beep(void)
 /*
  * Set the name (in the title bar) of Infowin
  */
-static errr Infowin_set_name(cptr name)
+static errr Infowin_set_name(concptr name)
 {
        Status st;
        XTextProperty tp;
@@ -639,7 +639,7 @@ static errr Infowin_set_name(cptr name)
 /*
  * Set the icon name of Infowin
  */
-static errr Infowin_set_icon_name(cptr name)
+static errr Infowin_set_icon_name(concptr name)
 {
        Status st;
        XTextProperty tp;
@@ -951,7 +951,7 @@ static errr Infowin_fill(void)
  * Pairs of values, first is texttual name, second is the string
  * holding the decimal value that the operation corresponds to.
  */
-static cptr opcode_pairs[] =
+static concptr opcode_pairs[] =
 {
        "cpy", "3",
        "xor", "6",
@@ -987,7 +987,7 @@ static cptr opcode_pairs[] =
  *     0-15: if 'str' is a valid Operation
  *     -1:   if 'str' could not be parsed
  */
-static int Infoclr_Opcode(cptr str)
+static int Infoclr_Opcode(concptr str)
 {
        register int i;
 
@@ -1022,7 +1022,7 @@ static int Infoclr_Opcode(cptr str)
  * Valid forms for 'name':
  *     'fg', 'bg', 'zg', '<name>' and '#<code>'
  */
-static Pixell Infoclr_Pixell(cptr name)
+static Pixell Infoclr_Pixell(concptr name)
 {
        XColor scrn;
 
@@ -1310,7 +1310,7 @@ static errr Infofnt_prepare(XFontStruct *info)
                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;
@@ -1409,9 +1409,9 @@ static errr Infofnt_init_real(XFontStruct *info)
  *     name: The name of the requested Font
  */
 #ifdef USE_JP_FONTSTRUCT
-static void Infofnt_init_data(cptr name, cptr kname)
+static void Infofnt_init_data(concptr name, concptr kname)
 #else
-static void Infofnt_init_data(cptr name)
+static void Infofnt_init_data(concptr name)
 #endif
 
 {
@@ -1507,7 +1507,7 @@ static void Infofnt_init_data(cptr name)
 
 #ifdef USE_JP_FONTSTRUCT
 /*
- * EUCÆüËܸ쥳¡¼¥É¤ò´Þ¤àʸ»úÎó¤òɽ¼¨¤¹¤ë (Xlib)
+ * EUC日本語コードを含む文字列を表示する (Xlib)
  */
 static void
 XDrawMultiString(display,d,gc, x, y, string, len, afont, 
@@ -1536,48 +1536,48 @@ 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) ) {
@@ -1588,11 +1588,11 @@ XDrawMultiString(display,d,gc, x, y, string, len, afont,
              slen++;
          }
          
-         /* ÉÁ²è */
+         /* 描画 */
          XSetFont( display, gc, afont->fid );
          XDrawImageString( display, d, gc, x, y, p, slen );
          
-         /* ¥Ý¥¤¥ó¥¿¤ò¿Ê¤á¤ë */
+         /* ポインタを進める */
          x += afont_width * slen;
       }
     }
@@ -1602,7 +1602,7 @@ XDrawMultiString(display,d,gc, x, y, string, len, afont,
 /*
  * Standard Text
  */
-static errr Infofnt_text_std(int x, int y, cptr str, int len)
+static errr Infofnt_text_std(int x, int y, concptr str, int len)
 {
        int i;
 
@@ -1657,7 +1657,7 @@ static errr Infofnt_text_std(int x, int y, cptr str, int len)
        {
                /* Note that the Infoclr is set up to contain the Infofnt */
 #ifdef USE_JP_FONTSTRUCT
-               /* ´Á»ú¥Õ¥©¥ó¥È¤Îɽ¼¨Éý¤Ï ASCII¥Õ¥©¥ó¥È¤Î2Çܤ˸ÇÄê */
+               /* 漢字フォントの表示幅は ASCIIフォントの2倍に固定 */
                XDrawMultiString(Metadpy->dpy, Infowin->win, Infoclr->gc,
                                 x, y, str, len,
                                 Infofnt->info, Infofnt->wid, Infofnt->hgt,
@@ -1665,8 +1665,21 @@ static errr Infofnt_text_std(int x, int y, cptr str, int len)
                                 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; char *kp = kanji;
+               char sbuf[1024];
+               my_strcpy(sbuf, str, sizeof(sbuf));
+               sp = sbuf;
+               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);
@@ -1684,7 +1697,7 @@ static errr Infofnt_text_std(int x, int y, cptr str, int len)
 /*
  * Painting where text would be
  */
-static errr Infofnt_text_non(int x, int y, cptr str, int len)
+static errr Infofnt_text_non(int x, int y, concptr str, int len)
 {
        int w, h;
 
@@ -2290,8 +2303,9 @@ static bool paste_x11_send_text(XSelectionRequestEvent *rq)
        char buf[1024];
        char *list[1000];
        co_ord max, min;
-       int x,y,l,n;
-       byte a;
+       TERM_LEN x,y;
+       int l,n;
+       TERM_COLOR a;
        char c;
 
        /* Too old, or incorrect call. */
@@ -2816,12 +2830,12 @@ static errr CheckEvent(bool wait)
 /*
  * An array of sound file names
  */
-static cptr sound_file[SOUND_MAX];
+static concptr sound_file[SOUND_MAX];
 
 /*
  * Check for existance of a file
  */
-static bool check_file(cptr s)
+static bool check_file(concptr s)
 {
        FILE *fff;
 
@@ -3082,7 +3096,7 @@ static errr Term_wipe_x11(int x, int y, int n)
 /*
  * Draw some textual characters.
  */
-static errr Term_text_x11(int x, int y, int n, byte a, cptr s)
+static errr Term_text_x11(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s)
 {
        /* Draw the text */
        Infoclr_set(clr[a]);
@@ -3103,14 +3117,14 @@ static errr Term_text_x11(int x, int y, int n, byte a, cptr s)
 /*
  * Draw some graphical characters.
  */
-static errr Term_pict_x11(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp)
+static errr Term_pict_x11(TERM_LEN x, TERM_LEN y, int n, const TERM_COLOR *ap, const char *cp, const TERM_COLOR *tap, const char *tcp)
 {
        int i, x1, y1;
 
-       byte a;
+       TERM_COLOR a;
        char c;
 
-       byte ta;
+       TERM_COLOR ta;
        char tc;
 
        int x2, y2;
@@ -3305,11 +3319,11 @@ static errr term_data_init(term_data *td, int i)
 {
        term *t = &td->t;
 
-       cptr name = angband_term_name[i];
+       concptr name = angband_term_name[i];
 
-       cptr font;
+       concptr font;
 #ifdef USE_JP_FONTSTRUCT
-       cptr kfont;
+       concptr kfont;
 #endif
 
 
@@ -3326,7 +3340,7 @@ static errr term_data_init(term_data *td, int i)
 
        char buf[80];
 
-       cptr str;
+       concptr str;
 
        int val;
 
@@ -3653,7 +3667,7 @@ errr init_x11(int argc, char *argv[])
 {
        int i;
 
-       cptr dpy_name = "";
+       concptr dpy_name = "";
 
        int num_term = 3;