1 /* xscreensaver, Copyright (c) 2014-2015 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
12 /* Compatibility layer using XDrawString, XDrawString16() or Xutf8DrawString().
13 This layer is used by X11 systems without Xft, and by MacOS / iOS.
16 #ifndef __XSCREENSAVER_XFT_H__
17 #define __XSCREENSAVER_XFT_H__
19 /* The XGlyphInfo field names and values are, of course, arbitrarily
20 different from XCharStruct for no sensible reason. These macros
21 translate between them.
24 # define XGlyphInfo_to_XCharStruct(G,C) do { \
25 (C).lbearing = -(G).x; \
26 (C).rbearing = (G).width - (G).x; \
28 (C).descent = (G).height - (G).y; \
29 (C).width = (G).xOff; \
32 # define XCharStruct_to_XGlyphInfo(C,G) do { \
33 (G).x = -(C).lbearing; \
35 (G).xOff = (C).width; \
37 (G).width = (C).rbearing - (C).lbearing; \
38 (G).height = (C).ascent + (C).descent; \
41 /* Xutf8TextExtents returns a bounding box in an XRectangle, which
42 conveniently interprets everything in the opposite direction
45 # define XCharStruct_to_XmbRectangle(C,R) do { \
46 (R).x = (C).lbearing; \
47 (R).y = -(C).ascent; \
48 (R).width = (C).rbearing - (C).lbearing; \
49 (R).height = (C).ascent + (C).descent; \
52 # define XmbRectangle_to_XCharStruct(R,C,ADV) do { \
53 (C).lbearing = (R).x; \
54 (C).rbearing = (R).width + (R).x; \
55 (C).ascent = -(R).y; \
56 (C).descent = (R).height + (R).y; \
63 # include <X11/Xft/Xft.h>
65 # else /* !HAVE_XFT -- the rest of the file */
69 #elif defined(HAVE_ANDROID)
72 # include <X11/Xlib.h>
75 /* This doesn't seem to work right under X11. See comment in xft.c. */
77 # undef HAVE_XUTF8DRAWSTRING
82 # define _Xconst const
85 typedef struct _XGlyphInfo {
86 unsigned short width, height; /* bounding box of the ink */
87 short x, y; /* distance from upper left of bbox to glyph origin. */
88 short xOff, yOff; /* distance from glyph origin to next origin. */
92 typedef struct _XftFont {
94 # ifdef HAVE_XUTF8DRAWSTRING
105 unsigned short green;
107 unsigned short alpha;
110 typedef struct _XftColor {
115 typedef struct _XftDraw XftDraw;
117 typedef unsigned char FcChar8;
120 XftFont *XftFontOpenXlfd (Display *dpy, int screen, _Xconst char *xlfd);
121 #define XftFontOpenName XftFontOpenXlfd
123 void XftFontClose (Display *dpy, XftFont *font);
125 Bool XftColorAllocName (Display *dpy,
126 _Xconst Visual *visual,
131 Bool XftColorAllocValue (Display *dpy,
132 _Xconst Visual *visual,
134 _Xconst XRenderColor *color,
137 void XftColorFree (Display *dpy,
142 XftDraw *XftDrawCreate (Display *dpy,
147 void XftDrawDestroy (XftDraw *draw);
150 XftTextExtentsUtf8 (Display *dpy,
152 _Xconst FcChar8 *string,
154 XGlyphInfo *extents);
157 XftDrawStringUtf8 (XftDraw *draw,
158 _Xconst XftColor *color,
162 _Xconst FcChar8 *string,
165 # endif /* !HAVE_XFT */
167 #endif /* __XSCREENSAVER_XFT_H__ */