• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: Commit

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revisão11c8e9c02b610cf3ca800047fa6ecc236725ba46 (tree)
Hora2020-02-24 21:25:02
AutorHabu <habu@user...>
CommiterHabu

Mensagem de Log

[feature] libxft(TrueTypeフォント表示)のサポート

以下のフォークを参考にさせてもらい、libxftによるTrueTypeフォントの表示をサポート。
https://github.com/naota/hengband/tree/xft

configureに --enable-xft を指定することでTrueTypeフォントによる表示になる。

Mudança Sumário

Diff

--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,8 @@ AC_ARG_ENABLE(xim,
4444 [ --disable-xim disable xim support], use_xim=no, use_xim=yes)
4545 AC_ARG_ENABLE(fontset,
4646 [ --disable-fontset disable fontset support], use_fontset=no, use_fontset=yes)
47+AC_ARG_ENABLE([xft],
48+ AS_HELP_STRING([--enable-xft], [Enable xft support]))
4749 AC_ARG_ENABLE(worldscore,
4850 [ --disable-worldscore disable worldscore support], ,AC_DEFINE(WORLD_SCORE, 1, [Allow the game to send scores to the score server]))
4951 AC_ARG_ENABLE(chuukei,
@@ -94,6 +96,11 @@ if test "$have_x" = yes; then
9496 AC_CHECK_LIB(X11, _Xsetlocale, AC_DEFINE(X_LOCALE, 1, [Use XLocale]))
9597 AC_CHECK_LIB(xpg4, setlocale, LIBS="$LIBS -lxpg4")
9698 fi
99+
100+ AS_IF([test "x$enable_xft" = "xyes"], [
101+ PKG_CHECK_MODULES(XFT, [xft],
102+ [AC_DEFINE([USE_XFT], [1], [Use XFT])])
103+ ])
97104 fi
98105
99106 if test "$use_japanese" != no; then
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -111,6 +111,8 @@ EXTRA_hengband_SOURCES = \
111111 EXTRA_DIST = \
112112 gcc-wrap
113113
114+CFLAGS += $(XFT_CFLAGS)
115+LIBS += $(XFT_LIBS)
114116 COMPILE = $(srcdir)/gcc-wrap $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
115117 $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -Icmd -Icombat
116118
--- a/src/h-config.h
+++ b/src/h-config.h
@@ -224,6 +224,10 @@
224224 #define MAINTAINER "echizen@users.sourceforge.jp"
225225
226226 #ifdef JP
227+#ifdef USE_XFT
228+#define DEFAULT_X11_FONT "monospace-24:lang=ja:spacing=90"
229+#define DEFAULT_X11_FONT_SUB "sans-serif-16:lang=ja"
230+#else
227231 /*
228232 * OPTION: Default font (when using X11).
229233 */
@@ -235,6 +239,7 @@
235239 #define DEFAULT_X11_FONT_SUB \
236240 "-*-*-medium-r-normal--16-*-*-*-*-*-iso8859-1" \
237241 ",-*-*-medium-r-normal--16-*-*-*-*-*-jisx0208.1983-0"
242+#endif
238243 /* "8x16" \
239244 ",kanji16"*/
240245
--- a/src/maid-x11.c
+++ b/src/maid-x11.c
@@ -75,7 +75,11 @@ static int gamma_val = 0;
7575 /*
7676 * Hack -- Convert an RGB value to an X11 Pixel, or die.
7777 */
78+#ifdef USE_XFT
79+static XftColor create_pixel(Display *dpy, byte red, byte green, byte blue)
80+#else
7881 static unsigned long create_pixel(Display *dpy, byte red, byte green, byte blue)
82+#endif
7983 {
8084 Colormap cmap = DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy));
8185 XColor xcolour;
@@ -105,6 +109,20 @@ static unsigned long create_pixel(Display *dpy, byte red, byte green, byte blue)
105109 xcolour.blue = blue * 255;
106110 xcolour.flags = DoRed | DoGreen | DoBlue;
107111
112+#ifdef USE_XFT
113+ XftColor color;
114+ XRenderColor xcol;
115+ xcol.red = xcolour.red;
116+ xcol.green = xcolour.green;
117+ xcol.blue = xcolour.blue;
118+ if (!XftColorAllocValue(dpy, DefaultVisual(dpy, 0), cmap, &xcol, &color))
119+ {
120+ quit_fmt("Couldn't allocate bitmap color '#%02x%02x%02x'\n",
121+ red, green, blue);
122+ }
123+
124+ return color;
125+#else
108126 /* Attempt to Allocate the Parsed color */
109127 if (!(XAllocColor(dpy, cmap, &xcolour)))
110128 {
@@ -113,9 +131,11 @@ static unsigned long create_pixel(Display *dpy, byte red, byte green, byte blue)
113131 }
114132
115133 return (xcolour.pixel);
134+#endif
116135 }
117136
118137
138+#ifndef USE_XFT
119139
120140 /*
121141 * The Win32 "BITMAPFILEHEADER" type.
@@ -870,4 +890,6 @@ static XImage *ResizeImage(Display *dpy, XImage *Im,
870890 return Tmp;
871891 }
872892
893+#endif /* !USE_XFT */
894+
873895 #endif /* USE_X11 */
--- a/src/main-x11.c
+++ b/src/main-x11.c
@@ -121,6 +121,10 @@
121121 #endif /* __MAKEDEPEND__ */
122122
123123 #include <iconv.h>
124+#ifdef USE_XFT
125+#include <X11/Xft/Xft.h>
126+#endif
127+
124128 /*
125129 * Include some helpful X11 code.
126130 */
@@ -150,7 +154,11 @@
150154 /*
151155 * An X11 pixell specifier
152156 */
157+#ifdef USE_XFT
158+typedef XftColor Pixell;
159+#else
153160 typedef unsigned long Pixell;
161+#endif
154162
155163 /*
156164 * The structures defined below
@@ -211,7 +219,9 @@ struct metadpy
211219
212220 Pixell bg;
213221 Pixell fg;
222+#ifndef USE_XFT
214223 Pixell zg;
224+#endif
215225
216226 uint mono:1;
217227 uint color:1;
@@ -253,6 +263,9 @@ struct infowin
253263 XIC xic;
254264 long xic_mask;
255265 #endif
266+#ifdef USE_XFT
267+ XftDraw *draw;
268+#endif
256269
257270 long mask;
258271
@@ -295,7 +308,9 @@ struct infowin
295308 */
296309 struct infoclr
297310 {
311+#ifndef USE_XFT
298312 GC gc;
313+#endif
299314
300315 Pixell fg;
301316 Pixell bg;
@@ -325,7 +340,11 @@ struct infoclr
325340 */
326341 struct infofnt
327342 {
343+#ifdef USE_XFT
344+ XftFont *info;
345+#else
328346 XFontSet info;
347+#endif
329348 concptr name;
330349
331350 s16b wid;
@@ -505,8 +524,14 @@ static errr Metadpy_init_2(Display *dpy, concptr name)
505524 m->depth = DefaultDepthOfScreen(m->screen);
506525
507526 /* Save the Standard Colors */
527+#ifdef USE_XFT
528+ Visual *vis = DefaultVisual(dpy, 0);
529+ XftColorAllocName(dpy, vis, m->cmap, "black", &m->black);
530+ XftColorAllocName(dpy, vis, m->cmap, "white", &m->white);
531+#else
508532 m->black = BlackPixelOfScreen(m->screen);
509533 m->white = WhitePixelOfScreen(m->screen);
534+#endif
510535
511536 /*** Make some clever Guesses ***/
512537
@@ -514,8 +539,10 @@ static errr Metadpy_init_2(Display *dpy, concptr name)
514539 m->bg = m->black;
515540 m->fg = m->white;
516541
542+#ifndef USE_XFT
517543 /* Calculate the Maximum allowed Pixel value. */
518544 m->zg = (1 << m->depth) - 1;
545+#endif
519546
520547 /* Save various default Flag Settings */
521548 m->color = ((m->depth > 1) ? 1 : 0);
@@ -589,6 +616,14 @@ static errr Infowin_prepare(Window xid)
589616 /* Check For Error XXX Extract some ACTUAL data from 'xid' */
590617 XGetGeometry(Metadpy->dpy, xid, &tmp_win, &x, &y, &w, &h, &b, &d);
591618
619+#ifdef USE_XFT
620+ Visual *vis = DefaultVisual(Metadpy->dpy, 0);
621+ if (vis->class != TrueColor) {
622+ quit_fmt("Display does not support truecolor.\n");
623+ }
624+ iwin->draw = XftDrawCreate(Metadpy->dpy, iwin->win, vis, Metadpy->cmap);
625+#endif
626+
592627 /* Apply the above info */
593628 iwin->x = x;
594629 iwin->y = y;
@@ -643,7 +678,11 @@ static errr Infowin_init_data(Window dad, int x, int y, int w, int h,
643678 if (dad == None) dad = Metadpy->root;
644679
645680 /* Create the Window XXX Error Check */
681+#ifdef USE_XFT
682+ xid = XCreateSimpleWindow(Metadpy->dpy, dad, x, y, w, h, b, fg.pixel, bg.pixel);
683+#else
646684 xid = XCreateSimpleWindow(Metadpy->dpy, dad, x, y, w, h, b, fg, bg);
685+#endif
647686
648687 /* Start out selecting No events */
649688 XSelectInput(Metadpy->dpy, xid, 0L);
@@ -816,15 +855,18 @@ static errr Infoclr_init_data(Pixell fg, Pixell bg, int op, int stip)
816855 {
817856 infoclr *iclr = Infoclr;
818857
858+#ifndef USE_XFT
819859 GC gc;
820860 XGCValues gcv;
821861 unsigned long gc_mask;
862+#endif
822863
823864
824865
825866 /*** Simple error checking of opr and clr ***/
826867
827868 /* Check the 'Pixells' for realism */
869+#ifndef USE_XFT
828870 if (bg > Metadpy->zg) return (-1);
829871 if (fg > Metadpy->zg) return (-1);
830872
@@ -859,6 +901,7 @@ static errr Infoclr_init_data(Pixell fg, Pixell bg, int op, int stip)
859901
860902 /* Create the GC detailed above */
861903 gc = XCreateGC(Metadpy->dpy, Metadpy->root, gc_mask, &gcv);
904+#endif
862905
863906
864907 /*** Initialize ***/
@@ -866,8 +909,10 @@ static errr Infoclr_init_data(Pixell fg, Pixell bg, int op, int stip)
866909 /* Wipe the iclr clean */
867910 (void)WIPE(iclr, infoclr);
868911
912+#ifndef USE_XFT
869913 /* Assign the GC */
870914 iclr->gc = gc;
915+#endif
871916
872917 /* Nuke it when done */
873918 iclr->nuke = 1;
@@ -895,6 +940,9 @@ static errr Infoclr_change_fg(Pixell fg)
895940 infoclr *iclr = Infoclr;
896941
897942
943+#ifdef USE_XFT
944+ iclr->fg = fg;
945+#else
898946 /*** Simple error checking of opr and clr ***/
899947
900948 /* Check the 'Pixells' for realism */
@@ -905,6 +953,7 @@ static errr Infoclr_change_fg(Pixell fg)
905953
906954 /* Change */
907955 XSetForeground(Metadpy->dpy, iclr->gc, fg);
956+#endif
908957
909958 /* Success */
910959 return (0);
@@ -914,19 +963,34 @@ static errr Infoclr_change_fg(Pixell fg)
914963 /*
915964 * Prepare a new 'infofnt'
916965 */
966+#ifdef USE_XFT
967+static errr Infofnt_prepare(XftFont *info)
968+#else
917969 static errr Infofnt_prepare(XFontSet info)
970+#endif
918971 {
919972 infofnt *ifnt = Infofnt;
920973
974+#ifndef USE_XFT
921975 XCharStruct *cs;
922976 XFontStruct **fontinfo;
923977 char **fontname;
924978 int n_fonts;
925979 int ascent, descent, width;
980+#endif
926981
927982 /* Assign the struct */
928983 ifnt->info = info;
929984
985+
986+#ifdef USE_XFT
987+ ifnt->asc = info->ascent;
988+ ifnt->hgt = info->ascent + info->descent;
989+ const char *text = "A";
990+ XGlyphInfo extent;
991+ XftTextExtentsUtf8(Metadpy->dpy, info, (FcChar8*)text, strlen(text), &extent);
992+ ifnt->wid = extent.xOff;
993+#else
930994 n_fonts = XFontsOfFontSet(info, &fontinfo, &fontname);
931995
932996 ascent = descent = width = 0;
@@ -946,6 +1010,7 @@ static errr Infofnt_prepare(XFontSet info)
9461010 ifnt->asc = ascent;
9471011 ifnt->hgt = ascent + descent;
9481012 ifnt->wid = width;
1013+#endif
9491014
9501015 if (use_bigtile)
9511016 ifnt->twid = 2 * ifnt->wid;
@@ -965,10 +1030,14 @@ static errr Infofnt_prepare(XFontSet info)
9651030 static void Infofnt_init_data(concptr name)
9661031
9671032 {
1033+#ifdef USE_XFT
1034+ XftFont *info;
1035+#else
9681036 XFontSet info;
9691037 char **missing_list;
9701038 int missing_count;
9711039 char *default_font;
1040+#endif
9721041
9731042 /*** Load the info Fresh, using the name ***/
9741043
@@ -976,6 +1045,10 @@ static void Infofnt_init_data(concptr name)
9761045 if (!name || !*name) quit("Missing font!");
9771046
9781047 /* Attempt to load the font */
1048+#ifdef USE_XFT
1049+ info = XftFontOpenName(Metadpy->dpy, 0, name);
1050+ /* TODO: error handling */
1051+#else
9791052 info = XCreateFontSet(Metadpy->dpy, name, &missing_list, &missing_count, &default_font);
9801053 if(missing_count > 0){
9811054 printf("missing font(s): \n");
@@ -984,6 +1057,7 @@ static void Infofnt_init_data(concptr name)
9841057 }
9851058 XFreeStringList(missing_list);
9861059 }
1060+#endif
9871061
9881062 /* The load failed, try to recover */
9891063 if (!info) quit_fmt("Failed to find font:\"%s\"", name);
@@ -997,7 +1071,11 @@ static void Infofnt_init_data(concptr name)
9971071 if (Infofnt_prepare(info))
9981072 {
9991073 /* Free the font */
1074+#ifdef USE_XFT
1075+ XftFontClose(Metadpy->dpy, info);
1076+#else
10001077 XFreeFontSet(Metadpy->dpy, info);
1078+#endif
10011079
10021080 /* Fail */
10031081 quit_fmt("Failed to prepare font:\"%s\"", name);
@@ -1016,9 +1094,6 @@ static void Infofnt_init_data(concptr name)
10161094 */
10171095 static errr Infofnt_text_std(int x, int y, concptr str, int len)
10181096 {
1019- int i;
1020-
1021-
10221097 /*** Do a brief info analysis ***/
10231098
10241099 /* Do nothing if the string is null */
@@ -1046,6 +1121,9 @@ static errr Infofnt_text_std(int x, int y, concptr str, int len)
10461121 /* Monotize the font */
10471122 if (Infofnt->mono)
10481123 {
1124+#ifndef USE_XFT
1125+ int i;
1126+
10491127 /* Do each character */
10501128 for (i = 0; i < len; ++i)
10511129 {
@@ -1053,6 +1131,7 @@ static errr Infofnt_text_std(int x, int y, concptr str, int len)
10531131 XDrawImageString(Metadpy->dpy, Infowin->win, Infoclr->gc,
10541132 x + i * Infofnt->wid + Infofnt->off, y, str + i, 1);
10551133 }
1134+#endif
10561135 }
10571136
10581137 /* Assume monoospaced font */
@@ -1070,8 +1149,23 @@ static errr Infofnt_text_std(int x, int y, concptr str, int len)
10701149 iconv(cd, &sp, &inlen, &kp, &outlen);
10711150 iconv_close(cd);
10721151
1152+#ifdef USE_XFT
1153+ XftDraw* draw = Infowin->draw;
1154+
1155+ XRectangle r;
1156+ r.x = 0;
1157+ r.y = 0;
1158+ r.width = Infofnt->wid*len;
1159+ r.height = Infofnt->hgt;
1160+ XftDrawSetClipRectangles(draw, x, y-Infofnt->asc, &r, 1);
1161+ XftDrawRect(draw, &Infoclr->bg, x, y-Infofnt->asc, Infofnt->wid*len, Infofnt->hgt);
1162+ XftDrawStringUtf8(draw, &Infoclr->fg, Infofnt->info, x, y,
1163+ (FcChar8*)kanji, kp - kanji);
1164+ XftDrawSetClip(draw, 0);
1165+#else
10731166 XmbDrawImageString(Metadpy->dpy, Infowin->win, Infofnt->info,
10741167 Infoclr->gc, x, y, kanji, kp-kanji);
1168+#endif
10751169 free(kanji);
10761170 }
10771171
@@ -1115,7 +1209,11 @@ static errr Infofnt_text_non(int x, int y, concptr str, int len)
11151209 /*** Actually 'paint' the area ***/
11161210
11171211 /* Just do a Fill Rectangle */
1212+#ifdef USE_XFT
1213+ XftDrawRect(Infowin->draw, &Infoclr->fg, x, y, w, h);
1214+#else
11181215 XFillRectangle(Metadpy->dpy, Infowin->win, Infoclr->gc, x, y, w, h);
1216+#endif
11191217
11201218 /* Success */
11211219 return (0);
@@ -1161,10 +1259,12 @@ struct term_data
11611259 infofnt *fnt;
11621260 infowin *win;
11631261
1262+#ifndef USE_XFT
11641263 XImage *tiles;
11651264
11661265 /* Tempory storage for overlaying tiles. */
11671266 XImage *TmpImage;
1267+#endif
11681268 };
11691269
11701270
@@ -1405,8 +1505,12 @@ static void mark_selection_mark(int x1, int y1, int x2, int y2)
14051505 {
14061506 square_to_pixel(&x1, &y1, x1, y1);
14071507 square_to_pixel(&x2, &y2, x2, y2);
1508+#ifdef USE_XFT
1509+ XftDrawRect(Infowin->draw, &clr[2]->fg, x1, y1, x2-x1+Infofnt->wid - 1, y2-y1+Infofnt->hgt - 1);
1510+#else
14081511 XDrawRectangle(Metadpy->dpy, Infowin->win, clr[2]->gc, x1, y1,
14091512 x2-x1+Infofnt->wid - 1, y2-y1+Infofnt->hgt - 1);
1513+#endif
14101514 }
14111515
14121516 /*
@@ -2385,7 +2489,11 @@ static errr Term_xtra_x11(int n, int v)
23852489 case TERM_XTRA_SOUND: return (Term_xtra_x11_sound(v));
23862490
23872491 /* Flush the output XXX XXX */
2492+#ifdef USE_XFT
2493+ case TERM_XTRA_FRESH: Metadpy_update(1, 1, 0); return (0);
2494+#else
23882495 case TERM_XTRA_FRESH: Metadpy_update(1, 0, 0); return (0);
2496+#endif
23892497
23902498 /* Process random events XXX */
23912499 case TERM_XTRA_BORED: return (CheckEvent(0));
@@ -2423,6 +2531,16 @@ static errr Term_curs_x11(int x, int y)
24232531 {
24242532 if (use_graphics)
24252533 {
2534+#ifdef USE_XFT
2535+ XftDrawRect(Infowin->draw, &xor->fg,
2536+ x * Infofnt->wid + Infowin->ox,
2537+ y * Infofnt->hgt + Infowin->oy,
2538+ Infofnt->wid - 1, Infofnt->hgt - 1);
2539+ XftDrawRect(Infowin->draw, &xor->fg,
2540+ x * Infofnt->wid + Infowin->ox + 1,
2541+ y * Infofnt->hgt + Infowin->oy + 1,
2542+ Infofnt->wid - 3, Infofnt->hgt - 3);
2543+#else
24262544 XDrawRectangle(Metadpy->dpy, Infowin->win, xor->gc,
24272545 x * Infofnt->wid + Infowin->ox,
24282546 y * Infofnt->hgt + Infowin->oy,
@@ -2431,6 +2549,7 @@ static errr Term_curs_x11(int x, int y)
24312549 x * Infofnt->wid + Infowin->ox + 1,
24322550 y * Infofnt->hgt + Infowin->oy + 1,
24332551 Infofnt->wid - 3, Infofnt->hgt - 3);
2552+#endif
24342553 }
24352554 else
24362555 {
@@ -2453,6 +2572,16 @@ static errr Term_bigcurs_x11(int x, int y)
24532572 {
24542573 if (use_graphics)
24552574 {
2575+#ifdef USE_XFT
2576+ XftDrawRect(Infowin->draw, &xor->fg,
2577+ x * Infofnt->wid + Infowin->ox,
2578+ y * Infofnt->hgt + Infowin->oy,
2579+ Infofnt->twid - 1, Infofnt->hgt - 1);
2580+ XftDrawRect(Infowin->draw, &xor->fg,
2581+ x * Infofnt->wid + Infowin->ox + 1,
2582+ y * Infofnt->hgt + Infowin->oy + 1,
2583+ Infofnt->twid - 3, Infofnt->hgt - 3);
2584+#else
24562585 XDrawRectangle(Metadpy->dpy, Infowin->win, xor->gc,
24572586 x * Infofnt->wid + Infowin->ox,
24582587 y * Infofnt->hgt + Infowin->oy,
@@ -2461,6 +2590,7 @@ static errr Term_bigcurs_x11(int x, int y)
24612590 x * Infofnt->wid + Infowin->ox + 1,
24622591 y * Infofnt->hgt + Infowin->oy + 1,
24632592 Infofnt->twid - 3, Infofnt->hgt - 3);
2593+#endif
24642594 }
24652595 else
24662596 {
@@ -2513,6 +2643,7 @@ static errr Term_text_x11(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s
25132643 }
25142644
25152645
2646+#ifndef USE_XFT
25162647 /*
25172648 * Draw some graphical characters.
25182649 */
@@ -2622,6 +2753,7 @@ static errr Term_pict_x11(TERM_LEN x, TERM_LEN y, int n, const TERM_COLOR *ap, c
26222753 /* Success */
26232754 return (0);
26242755 }
2756+#endif
26252757
26262758 #ifdef USE_XIM
26272759 static void IMDestroyCallback(XIM, XPointer, XPointer);
@@ -2992,12 +3124,14 @@ errr init_x11(int argc, char *argv[])
29923124
29933125 int num_term = 3;
29943126
3127+#ifndef USE_XFT
29953128 char filename[1024];
29963129
29973130 int pict_wid = 0;
29983131 int pict_hgt = 0;
29993132
30003133 char *TmpData;
3134+#endif
30013135
30023136 /* Parse args */
30033137 for (i = 1; i < argc; i++)
@@ -3008,6 +3142,7 @@ errr init_x11(int argc, char *argv[])
30083142 continue;
30093143 }
30103144
3145+#ifndef USE_XFT
30113146 if (prefix(argv[i], "-s"))
30123147 {
30133148 smoothRescaling = FALSE;
@@ -3025,6 +3160,7 @@ errr init_x11(int argc, char *argv[])
30253160 arg_graphics = GRAPHICS_ORIGINAL;
30263161 continue;
30273162 }
3163+#endif
30283164
30293165 if (prefix(argv[i], "-b"))
30303166 {
@@ -3160,6 +3296,7 @@ errr init_x11(int argc, char *argv[])
31603296 /* initialize sound */
31613297 if (arg_sound) init_sound();
31623298
3299+#ifndef USE_XFT
31633300 /* Try graphics */
31643301 switch (arg_graphics)
31653302 {
@@ -3255,6 +3392,7 @@ errr init_x11(int argc, char *argv[])
32553392
32563393 /* Free tiles_raw? XXX XXX */
32573394 }
3395+#endif /* ! USE_XFT */
32583396
32593397 /* Success */
32603398 return (0);
Show on old repository browser