#endif /* __MAKEDEPEND__ */
#include <iconv.h>
+#ifdef USE_XFT
+#include <X11/Xft/Xft.h>
+#endif
+
/*
* Include some helpful X11 code.
*/
/*
* An X11 pixell specifier
*/
+#ifdef USE_XFT
+typedef XftColor Pixell;
+#else
typedef unsigned long Pixell;
+#endif
/*
* The structures defined below
Pixell bg;
Pixell fg;
+#ifndef USE_XFT
Pixell zg;
+#endif
uint mono:1;
uint color:1;
XIC xic;
long xic_mask;
#endif
+#ifdef USE_XFT
+ XftDraw *draw;
+#endif
long mask;
*/
struct infoclr
{
+#ifndef USE_XFT
GC gc;
+#endif
Pixell fg;
Pixell bg;
*/
struct infofnt
{
+#ifdef USE_XFT
+ XftFont *info;
+#else
XFontSet info;
+#endif
concptr name;
s16b wid;
m->depth = DefaultDepthOfScreen(m->screen);
/* Save the Standard Colors */
+#ifdef USE_XFT
+ Visual *vis = DefaultVisual(dpy, 0);
+ XftColorAllocName(dpy, vis, m->cmap, "black", &m->black);
+ XftColorAllocName(dpy, vis, m->cmap, "white", &m->white);
+#else
m->black = BlackPixelOfScreen(m->screen);
m->white = WhitePixelOfScreen(m->screen);
+#endif
/*** Make some clever Guesses ***/
m->bg = m->black;
m->fg = m->white;
+#ifndef USE_XFT
/* Calculate the Maximum allowed Pixel value. */
m->zg = (1 << m->depth) - 1;
+#endif
/* Save various default Flag Settings */
m->color = ((m->depth > 1) ? 1 : 0);
/* Check For Error XXX Extract some ACTUAL data from 'xid' */
XGetGeometry(Metadpy->dpy, xid, &tmp_win, &x, &y, &w, &h, &b, &d);
+#ifdef USE_XFT
+ Visual *vis = DefaultVisual(Metadpy->dpy, 0);
+ if (vis->class != TrueColor) {
+ quit_fmt("Display does not support truecolor.\n");
+ }
+ iwin->draw = XftDrawCreate(Metadpy->dpy, iwin->win, vis, Metadpy->cmap);
+#endif
+
/* Apply the above info */
iwin->x = x;
iwin->y = y;
if (dad == None) dad = Metadpy->root;
/* Create the Window XXX Error Check */
+#ifdef USE_XFT
+ xid = XCreateSimpleWindow(Metadpy->dpy, dad, x, y, w, h, b, fg.pixel, bg.pixel);
+#else
xid = XCreateSimpleWindow(Metadpy->dpy, dad, x, y, w, h, b, fg, bg);
+#endif
/* Start out selecting No events */
XSelectInput(Metadpy->dpy, xid, 0L);
{
infoclr *iclr = Infoclr;
+#ifndef USE_XFT
GC gc;
XGCValues gcv;
unsigned long gc_mask;
+#endif
/*** Simple error checking of opr and clr ***/
/* Check the 'Pixells' for realism */
+#ifndef USE_XFT
if (bg > Metadpy->zg) return (-1);
if (fg > Metadpy->zg) return (-1);
/* Create the GC detailed above */
gc = XCreateGC(Metadpy->dpy, Metadpy->root, gc_mask, &gcv);
+#endif
/*** Initialize ***/
/* Wipe the iclr clean */
(void)WIPE(iclr, infoclr);
+#ifndef USE_XFT
/* Assign the GC */
iclr->gc = gc;
+#endif
/* Nuke it when done */
iclr->nuke = 1;
infoclr *iclr = Infoclr;
+#ifdef USE_XFT
+ iclr->fg = fg;
+#else
/*** Simple error checking of opr and clr ***/
/* Check the 'Pixells' for realism */
/* Change */
XSetForeground(Metadpy->dpy, iclr->gc, fg);
+#endif
/* Success */
return (0);
/*
* Prepare a new 'infofnt'
*/
+#ifdef USE_XFT
+static errr Infofnt_prepare(XftFont *info)
+#else
static errr Infofnt_prepare(XFontSet info)
+#endif
{
infofnt *ifnt = Infofnt;
+#ifndef USE_XFT
XCharStruct *cs;
XFontStruct **fontinfo;
char **fontname;
int n_fonts;
int ascent, descent, width;
+#endif
/* Assign the struct */
ifnt->info = info;
+
+#ifdef USE_XFT
+ ifnt->asc = info->ascent;
+ ifnt->hgt = info->ascent + info->descent;
+ const char *text = "A";
+ XGlyphInfo extent;
+ XftTextExtentsUtf8(Metadpy->dpy, info, (FcChar8*)text, strlen(text), &extent);
+ ifnt->wid = extent.xOff;
+#else
n_fonts = XFontsOfFontSet(info, &fontinfo, &fontname);
ascent = descent = width = 0;
ifnt->asc = ascent;
ifnt->hgt = ascent + descent;
ifnt->wid = width;
+#endif
if (use_bigtile)
ifnt->twid = 2 * ifnt->wid;
static void Infofnt_init_data(concptr name)
{
+#ifdef USE_XFT
+ XftFont *info;
+#else
XFontSet info;
char **missing_list;
int missing_count;
char *default_font;
+#endif
/*** Load the info Fresh, using the name ***/
if (!name || !*name) quit("Missing font!");
/* Attempt to load the font */
+#ifdef USE_XFT
+ info = XftFontOpenName(Metadpy->dpy, 0, name);
+ /* TODO: error handling */
+#else
info = XCreateFontSet(Metadpy->dpy, name, &missing_list, &missing_count, &default_font);
if(missing_count > 0){
printf("missing font(s): \n");
}
XFreeStringList(missing_list);
}
+#endif
/* The load failed, try to recover */
if (!info) quit_fmt("Failed to find font:\"%s\"", name);
if (Infofnt_prepare(info))
{
/* Free the font */
+#ifdef USE_XFT
+ XftFontClose(Metadpy->dpy, info);
+#else
XFreeFontSet(Metadpy->dpy, info);
+#endif
/* Fail */
quit_fmt("Failed to prepare font:\"%s\"", name);
*/
static errr Infofnt_text_std(int x, int y, concptr str, int len)
{
- int i;
-
-
/*** Do a brief info analysis ***/
/* Do nothing if the string is null */
/* Monotize the font */
if (Infofnt->mono)
{
+#ifndef USE_XFT
+ int i;
+
/* Do each character */
for (i = 0; i < len; ++i)
{
XDrawImageString(Metadpy->dpy, Infowin->win, Infoclr->gc,
x + i * Infofnt->wid + Infofnt->off, y, str + i, 1);
}
+#endif
}
/* Assume monoospaced font */
iconv(cd, &sp, &inlen, &kp, &outlen);
iconv_close(cd);
+#ifdef USE_XFT
+ XftDraw* draw = Infowin->draw;
+
+ XRectangle r;
+ r.x = 0;
+ r.y = 0;
+ r.width = Infofnt->wid*len;
+ r.height = Infofnt->hgt;
+ XftDrawSetClipRectangles(draw, x, y-Infofnt->asc, &r, 1);
+ XftDrawRect(draw, &Infoclr->bg, x, y-Infofnt->asc, Infofnt->wid*len, Infofnt->hgt);
+ XftDrawStringUtf8(draw, &Infoclr->fg, Infofnt->info, x, y,
+ (FcChar8*)kanji, kp - kanji);
+ XftDrawSetClip(draw, 0);
+#else
XmbDrawImageString(Metadpy->dpy, Infowin->win, Infofnt->info,
Infoclr->gc, x, y, kanji, kp-kanji);
+#endif
free(kanji);
}
/*** Actually 'paint' the area ***/
/* Just do a Fill Rectangle */
+#ifdef USE_XFT
+ XftDrawRect(Infowin->draw, &Infoclr->fg, x, y, w, h);
+#else
XFillRectangle(Metadpy->dpy, Infowin->win, Infoclr->gc, x, y, w, h);
+#endif
/* Success */
return (0);
infofnt *fnt;
infowin *win;
+#ifndef USE_XFT
XImage *tiles;
/* Tempory storage for overlaying tiles. */
XImage *TmpImage;
+#endif
};
{
square_to_pixel(&x1, &y1, x1, y1);
square_to_pixel(&x2, &y2, x2, y2);
+#ifdef USE_XFT
+ XftDrawRect(Infowin->draw, &clr[2]->fg, x1, y1, x2-x1+Infofnt->wid - 1, y2-y1+Infofnt->hgt - 1);
+#else
XDrawRectangle(Metadpy->dpy, Infowin->win, clr[2]->gc, x1, y1,
x2-x1+Infofnt->wid - 1, y2-y1+Infofnt->hgt - 1);
+#endif
}
/*
case TERM_XTRA_SOUND: return (Term_xtra_x11_sound(v));
/* Flush the output XXX XXX */
+#ifdef USE_XFT
+ case TERM_XTRA_FRESH: Metadpy_update(1, 1, 0); return (0);
+#else
case TERM_XTRA_FRESH: Metadpy_update(1, 0, 0); return (0);
+#endif
/* Process random events XXX */
case TERM_XTRA_BORED: return (CheckEvent(0));
{
if (use_graphics)
{
+#ifdef USE_XFT
+ XftDrawRect(Infowin->draw, &xor->fg,
+ x * Infofnt->wid + Infowin->ox,
+ y * Infofnt->hgt + Infowin->oy,
+ Infofnt->wid - 1, Infofnt->hgt - 1);
+ XftDrawRect(Infowin->draw, &xor->fg,
+ x * Infofnt->wid + Infowin->ox + 1,
+ y * Infofnt->hgt + Infowin->oy + 1,
+ Infofnt->wid - 3, Infofnt->hgt - 3);
+#else
XDrawRectangle(Metadpy->dpy, Infowin->win, xor->gc,
x * Infofnt->wid + Infowin->ox,
y * Infofnt->hgt + Infowin->oy,
x * Infofnt->wid + Infowin->ox + 1,
y * Infofnt->hgt + Infowin->oy + 1,
Infofnt->wid - 3, Infofnt->hgt - 3);
+#endif
}
else
{
{
if (use_graphics)
{
+#ifdef USE_XFT
+ XftDrawRect(Infowin->draw, &xor->fg,
+ x * Infofnt->wid + Infowin->ox,
+ y * Infofnt->hgt + Infowin->oy,
+ Infofnt->twid - 1, Infofnt->hgt - 1);
+ XftDrawRect(Infowin->draw, &xor->fg,
+ x * Infofnt->wid + Infowin->ox + 1,
+ y * Infofnt->hgt + Infowin->oy + 1,
+ Infofnt->twid - 3, Infofnt->hgt - 3);
+#else
XDrawRectangle(Metadpy->dpy, Infowin->win, xor->gc,
x * Infofnt->wid + Infowin->ox,
y * Infofnt->hgt + Infowin->oy,
x * Infofnt->wid + Infowin->ox + 1,
y * Infofnt->hgt + Infowin->oy + 1,
Infofnt->twid - 3, Infofnt->hgt - 3);
+#endif
}
else
{
}
+#ifndef USE_XFT
/*
* Draw some graphical characters.
*/
/* Success */
return (0);
}
+#endif
#ifdef USE_XIM
static void IMDestroyCallback(XIM, XPointer, XPointer);
int num_term = 3;
+#ifndef USE_XFT
char filename[1024];
int pict_wid = 0;
int pict_hgt = 0;
char *TmpData;
+#endif
/* Parse args */
for (i = 1; i < argc; i++)
continue;
}
+#ifndef USE_XFT
if (prefix(argv[i], "-s"))
{
smoothRescaling = FALSE;
arg_graphics = GRAPHICS_ORIGINAL;
continue;
}
+#endif
if (prefix(argv[i], "-b"))
{
/* initialize sound */
if (arg_sound) init_sound();
+#ifndef USE_XFT
/* Try graphics */
switch (arg_graphics)
{
/* Free tiles_raw? XXX XXX */
}
+#endif /* ! USE_XFT */
/* Success */
return (0);