X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=utils%2Fxft.h;fp=utils%2Fxft.h;h=e09c7b3aa9c23bef59d2b442e02556aa0edd5c90;hp=0000000000000000000000000000000000000000;hb=d5186197bc394e10a4402f7f6d23fbb14103bc50;hpb=6afd6db0ae9396cd7ff897ade597cd5483f49b0e diff --git a/utils/xft.h b/utils/xft.h new file mode 100644 index 00000000..e09c7b3a --- /dev/null +++ b/utils/xft.h @@ -0,0 +1,145 @@ +/* xscreensaver, Copyright (c) 2014 Jamie Zawinski + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + */ + +/* Compatibility layer using XDrawString, XDrawString16() or Xutf8DrawString(). + This layer is used by X11 systems without Xft, and by MacOS / iOS. + */ + +#ifndef __XSCREENSAVER_XFT_H__ +#define __XSCREENSAVER_XFT_H__ + +# ifdef HAVE_XFT + +# include + +# else /* !HAVE_XFT -- whole file */ + +# ifdef HAVE_COCOA +# include "jwxyz.h" +#elif defined(HAVE_ANDROID) +# include "jwxyz.h" +# else +# include +# endif + +/* This doesn't seem to work right. See comment in xft.c. */ +# undef HAVE_XUTF8DRAWSTRING + + +# ifndef _Xconst +# define _Xconst const +# endif + +typedef struct _XGlyphInfo { + unsigned short width, height; /* bounding box of the ink */ + short x, y; /* distance from upper left of bbox to glyph origin. */ + short xOff, yOff; /* distance from glyph origin to next origin. */ + + /* These field names and values are, of course, arbitrarily different + from XCharStruct for no sensible reason. Here's a translation key + between the two: + + XGlyphInfo from XCharStruct: + + g.x = -c.lbearing; + g.y = c.ascent; + g.xOff = c.width; + g.yOff = 0; + g.width = c.rbearing - c.lbearing; + g.height = c.ascent + c.descent; + + XCharStruct from XGlyphInfo: + + c.lbearing = -g.x; + c.rbearing = g.width - g.x; + c.ascent = g.y; + c.descent = g.height - g.y; + c.width = g.xOff; + */ + +} XGlyphInfo; + + +typedef struct _XftFont { + XFontStruct *xfont; +# ifdef HAVE_XUTF8DRAWSTRING + XFontSet fontset; +# endif + char *name; + int ascent; + int descent; + int height; +} XftFont; + +typedef struct { + unsigned short red; + unsigned short green; + unsigned short blue; + unsigned short alpha; +} XRenderColor; + +typedef struct _XftColor { + unsigned long pixel; + XRenderColor color; +} XftColor; + +typedef struct _XftDraw XftDraw; + +typedef unsigned char FcChar8; + + +XftFont *XftFontOpenXlfd (Display *dpy, int screen, _Xconst char *xlfd); + +void XftFontClose (Display *dpy, XftFont *font); + +Bool XftColorAllocName (Display *dpy, + _Xconst Visual *visual, + Colormap cmap, + _Xconst char *name, + XftColor *result); + +Bool XftColorAllocValue (Display *dpy, + _Xconst Visual *visual, + Colormap cmap, + _Xconst XRenderColor *color, + XftColor *result); + +void XftColorFree (Display *dpy, + Visual *visual, + Colormap cmap, + XftColor *color); + +XftDraw *XftDrawCreate (Display *dpy, + Drawable drawable, + Visual *visual, + Colormap colormap); + +void XftDrawDestroy (XftDraw *draw); + +void +XftTextExtentsUtf8 (Display *dpy, + XftFont *pub, + _Xconst FcChar8 *string, + int len, + XGlyphInfo *extents); + +void +XftDrawStringUtf8 (XftDraw *draw, + _Xconst XftColor *color, + XftFont *pub, + int x, + int y, + _Xconst FcChar8 *string, + int len); + +# endif /* !HAVE_XFT */ + +#endif /* __XSCREENSAVER_XFT_H__ */