From http://www.jwz.org/xscreensaver/xscreensaver-5.31.tar.gz
[xscreensaver] / utils / xft.h
1 /* xscreensaver, Copyright (c) 2014 Jamie Zawinski <jwz@jwz.org>
2  *
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 
9  * implied warranty.
10  */
11
12 /* Compatibility layer using XDrawString, XDrawString16() or Xutf8DrawString().
13    This layer is used by X11 systems without Xft, and by MacOS / iOS.
14  */
15
16 #ifndef __XSCREENSAVER_XFT_H__
17 #define __XSCREENSAVER_XFT_H__
18
19 # ifdef HAVE_XFT
20
21 #  include <X11/Xft/Xft.h>
22
23 # else  /* !HAVE_XFT -- whole file */
24
25 # ifdef HAVE_COCOA
26 #  include "jwxyz.h"
27 #elif defined(HAVE_ANDROID)
28 #  include "jwxyz.h"
29 # else
30 #  include <X11/Xlib.h>
31 # endif
32
33 /* This doesn't seem to work right.  See comment in xft.c. */
34 # undef HAVE_XUTF8DRAWSTRING
35
36
37 # ifndef _Xconst
38 #  define _Xconst const
39 # endif
40
41 typedef struct _XGlyphInfo {
42   unsigned short width, height;     /* bounding box of the ink */
43   short x, y;           /* distance from upper left of bbox to glyph origin. */
44   short xOff, yOff;     /* distance from glyph origin to next origin. */
45
46   /* These field names and values are, of course, arbitrarily different
47      from XCharStruct for no sensible reason.  Here's a translation key
48      between the two:
49
50      XGlyphInfo from XCharStruct:
51
52        g.x         =  -c.lbearing;
53        g.y         =   c.ascent;
54        g.xOff      =   c.width;
55        g.yOff      =   0;
56        g.width     =   c.rbearing - c.lbearing;
57        g.height    =   c.ascent   + c.descent;
58      
59      XCharStruct from XGlyphInfo:
60
61        c.lbearing  =  -g.x;
62        c.rbearing  =   g.width - g.x;
63        c.ascent    =   g.y;
64        c.descent   =   g.height - g.y;
65        c.width     =   g.xOff;
66    */
67
68 } XGlyphInfo;
69
70
71 typedef struct _XftFont {
72   XFontStruct *xfont;
73 # ifdef HAVE_XUTF8DRAWSTRING
74   XFontSet fontset;
75 # endif
76   char *name;
77   int ascent;
78   int descent;
79   int height;
80 } XftFont;
81
82 typedef struct {
83   unsigned short   red;
84   unsigned short   green;
85   unsigned short   blue;
86   unsigned short   alpha;
87 } XRenderColor;
88
89 typedef struct _XftColor {
90   unsigned long pixel;
91   XRenderColor color;
92 } XftColor;
93
94 typedef struct _XftDraw XftDraw;
95
96 typedef unsigned char FcChar8;
97
98
99 XftFont *XftFontOpenXlfd (Display *dpy, int screen, _Xconst char *xlfd);
100
101 void XftFontClose (Display *dpy, XftFont *font);
102
103 Bool XftColorAllocName (Display  *dpy,
104                         _Xconst Visual *visual,
105                         Colormap cmap,
106                         _Xconst char *name,
107                         XftColor *result);
108
109 Bool XftColorAllocValue (Display *dpy,
110                          _Xconst Visual *visual,
111                          Colormap cmap,
112                          _Xconst XRenderColor *color,
113                          XftColor *result);
114
115 void XftColorFree (Display *dpy,
116                    Visual *visual,
117                    Colormap cmap,
118                    XftColor *color);
119
120 XftDraw *XftDrawCreate (Display   *dpy,
121                         Drawable  drawable,
122                         Visual    *visual,
123                         Colormap  colormap);
124
125 void XftDrawDestroy (XftDraw *draw);
126
127 void
128 XftTextExtentsUtf8 (Display         *dpy,
129                     XftFont         *pub,
130                     _Xconst FcChar8 *string,
131                     int             len,
132                     XGlyphInfo      *extents);
133
134 void
135 XftDrawStringUtf8 (XftDraw          *draw,
136                    _Xconst XftColor *color,
137                    XftFont          *pub,
138                    int              x,
139                    int              y,
140                    _Xconst FcChar8  *string,
141                    int              len);
142
143 # endif /* !HAVE_XFT */
144
145 #endif /* __XSCREENSAVER_XFT_H__ */