Added missing newline in NEDsim error message.
[screensavers] / screenhack / xft.h
CommitLineData
3144ee8a
AT
1/* xscreensaver, Copyright (c) 2014-2015 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/* The XGlyphInfo field names and values are, of course, arbitrarily
20 different from XCharStruct for no sensible reason. These macros
21 translate between them.
22 */
23
24# define XGlyphInfo_to_XCharStruct(G,C) do { \
25 (C).lbearing = -(G).x; \
26 (C).rbearing = (G).width - (G).x; \
27 (C).ascent = (G).y; \
28 (C).descent = (G).height - (G).y; \
29 (C).width = (G).xOff; \
30} while (0)
31
32# define XCharStruct_to_XGlyphInfo(C,G) do { \
33 (G).x = -(C).lbearing; \
34 (G).y = (C).ascent; \
35 (G).xOff = (C).width; \
36 (G).yOff = 0; \
37 (G).width = (C).rbearing - (C).lbearing; \
38 (G).height = (C).ascent + (C).descent; \
39} while (0)
40
41/* Xutf8TextExtents returns a bounding box in an XRectangle, which
42 conveniently interprets everything in the opposite direction
43 from XGlyphInfo!
44 */
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; \
50} while (0)
51
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; \
57 (C).width = (ADV); \
58} while (0)
59
60
61# ifdef HAVE_XFT
62
63# include <X11/Xft/Xft.h>
64
65# else /* !HAVE_XFT -- the rest of the file */
66
67# ifdef HAVE_COCOA
68# include "jwxyz.h"
69#elif defined(HAVE_ANDROID)
70# include "jwxyz.h"
71# else
72# include <X11/Xlib.h>
73# endif
74
75/* This doesn't seem to work right under X11. See comment in xft.c. */
76# ifndef HAVE_COCOA
77# undef HAVE_XUTF8DRAWSTRING
78# endif
79
80
81# ifndef _Xconst
82# define _Xconst const
83# endif
84
85typedef 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. */
89} XGlyphInfo;
90
91
92typedef struct _XftFont {
93 XFontStruct *xfont;
94# ifdef HAVE_XUTF8DRAWSTRING
95 XFontSet fontset;
96# endif
97 char *name;
98 int ascent;
99 int descent;
100 int height;
101} XftFont;
102
103typedef struct {
104 unsigned short red;
105 unsigned short green;
106 unsigned short blue;
107 unsigned short alpha;
108} XRenderColor;
109
110typedef struct _XftColor {
111 unsigned long pixel;
112 XRenderColor color;
113} XftColor;
114
115typedef struct _XftDraw XftDraw;
116
117typedef unsigned char FcChar8;
118
119
120XftFont *XftFontOpenXlfd (Display *dpy, int screen, _Xconst char *xlfd);
121#define XftFontOpenName XftFontOpenXlfd
122
123void XftFontClose (Display *dpy, XftFont *font);
124
125Bool XftColorAllocName (Display *dpy,
126 _Xconst Visual *visual,
127 Colormap cmap,
128 _Xconst char *name,
129 XftColor *result);
130
131Bool XftColorAllocValue (Display *dpy,
132 _Xconst Visual *visual,
133 Colormap cmap,
134 _Xconst XRenderColor *color,
135 XftColor *result);
136
137void XftColorFree (Display *dpy,
138 Visual *visual,
139 Colormap cmap,
140 XftColor *color);
141
142XftDraw *XftDrawCreate (Display *dpy,
143 Drawable drawable,
144 Visual *visual,
145 Colormap colormap);
146
147void XftDrawDestroy (XftDraw *draw);
148
149void
150XftTextExtentsUtf8 (Display *dpy,
151 XftFont *pub,
152 _Xconst FcChar8 *string,
153 int len,
154 XGlyphInfo *extents);
155
156void
157XftDrawStringUtf8 (XftDraw *draw,
158 _Xconst XftColor *color,
159 XftFont *pub,
160 int x,
161 int y,
162 _Xconst FcChar8 *string,
163 int len);
164
165# endif /* !HAVE_XFT */
166
167#endif /* __XSCREENSAVER_XFT_H__ */