xftint.h revision 0d590c07
1/*
2 * Copyright © 2000 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission.  Keith Packard makes no
11 * representations about the suitability of this software for any purpose.  It
12 * is provided "as is" without express or implied warranty.
13 *
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23/*
24 * These definitions are solely for use by the implementation of Xft
25 * and constitute no kind of standard.  If you need any of these functions,
26 * please drop me a note.  Either the library needs new functionality,
27 * or there's a way to do what you need using the existing published
28 * interfaces. keithp@freedesktop.org
29 */
30
31#ifndef _XFTINT_H_
32#define _XFTINT_H_
33
34#ifdef HAVE_CONFIG_H
35#include "config.h"
36#else /* X monolithic tree */
37#define HAVE_STDLIB_H 1  /* assumed since all ANSI C platforms require it */
38#include <X11/Xosdefs.h> /* get string.h or strings.h as appropriate */
39#endif
40
41#include <stdio.h>
42#if HAVE_STDLIB_H
43#include <stdlib.h>
44#endif
45#if HAVE_STRING_H
46#include <string.h>
47#else
48#if HAVE_STRINGS_H
49#include <strings.h>
50#endif
51#endif
52#include <ctype.h>
53
54#include <X11/Xlib.h>
55#include <X11/Xutil.h>
56#include <X11/Xmd.h>
57#include <X11/Xlibint.h>
58#define _XFT_NO_COMPAT_
59#include "Xft.h"
60#include <fontconfig/fcprivate.h>
61#include <fontconfig/fcfreetype.h>
62
63/* Added to <X11/Xfuncproto.h> in X11R6.9 and later */
64#ifndef _X_HIDDEN
65# define _X_HIDDEN /**/
66#endif
67#ifndef _X_EXPORT
68# define _X_EXPORT /**/
69#endif
70
71#ifndef HAVE_CONFIG_H
72# if (FREETYPE_MAJOR > 2 ||						    \
73      (FREETYPE_MAJOR == 2 && (FREETYPE_MINOR > 1 ||			    \
74			       (FREETYPE_MINOR == 1 && FREETYPE_PATCH >= 5))))
75#  define HAVE_FT_BITMAP_SIZE_Y_PPEM 1
76# else
77#  define HAVE_FT_BITMAP_SIZE_Y_PPEM 0
78# endif
79#endif
80
81typedef struct _XftMatcher {
82    char    *object;
83    double  (*compare) (char *object, FcValue value1, FcValue value2);
84} XftMatcher;
85
86typedef struct _XftSymbolic {
87    const char	*name;
88    int		value;
89} XftSymbolic;
90
91/*
92 * Glyphs are stored in this structure
93 */
94typedef struct _XftGlyph {
95    XGlyphInfo	    metrics;
96    void	    *bitmap;
97    unsigned long   glyph_memory;
98} XftGlyph;
99
100/*
101 * A hash table translates Unicode values into glyph indicies
102 */
103typedef struct _XftUcsHash {
104    FcChar32	    ucs4;
105    FT_UInt	    glyph;
106} XftUcsHash;
107
108/*
109 * Many fonts can share the same underlying face data; this
110 * structure references that.  Note that many faces may in fact
111 * live in the same font file; that is irrelevant to this structure
112 * which is concerned only with the individual faces themselves
113 */
114
115typedef struct _XftFtFile {
116    struct _XftFtFile	*next;
117    int			ref;	    /* number of font infos using this file */
118
119    char		*file;	    /* file name */
120    int			id;	    /* font index within that file */
121
122    FT_F26Dot6		xsize;	    /* current xsize setting */
123    FT_F26Dot6		ysize;	    /* current ysize setting */
124    FT_Matrix		matrix;	    /* current matrix setting */
125
126    int			lock;	    /* lock count; can't unload unless 0 */
127    FT_Face		face;	    /* pointer to face; only valid when lock */
128} XftFtFile;
129
130/*
131 * This structure holds the data extracted from a pattern
132 * needed to create a unique font object.
133 */
134
135struct _XftFontInfo {
136    /*
137     * Hash value (not include in hash value computation)
138     */
139    FcChar32		hash;
140    XftFtFile		*file;		/* face source */
141    /*
142     * Rendering options
143     */
144    FT_F26Dot6		xsize, ysize;	/* pixel size */
145    FcBool		antialias;	/* doing antialiasing */
146    FcBool		embolden;	/* force emboldening */
147    int			rgba;		/* subpixel order */
148    FT_Matrix		matrix;		/* glyph transformation matrix */
149    FcBool		transform;	/* non-identify matrix? */
150    FT_Int		load_flags;	/* glyph load flags */
151    FcBool		render;		/* whether to use the Render extension */
152    /*
153     * Internal fields
154     */
155    int			spacing;
156    FcBool		minspace;
157    int			char_width;
158};
159
160/*
161 * Internal version of the font with private data
162 */
163
164typedef struct _XftFontInt {
165    XftFont		public;		/* public fields */
166    XftFont		*next;		/* all fonts on display */
167    XftFont		*hash_next;	/* fonts in this hash chain */
168    XftFontInfo		info;		/* Data from pattern */
169    int			ref;		/* reference count */
170    /*
171     * Per-glyph information, indexed by glyph ID
172     * This array follows the font in memory
173     */
174    XftGlyph		**glyphs;
175    int			num_glyphs;	/* size of glyphs/bitmaps arrays */
176    /*
177     * Hash table to get from Unicode value to glyph ID
178     * This array follows the glyphs in memory
179     */
180    XftUcsHash		*hash_table;
181    int			hash_value;
182    int			rehash_value;
183    /*
184     * X specific fields
185     */
186    GlyphSet		glyphset;	/* Render glyphset */
187    XRenderPictFormat	*format;	/* Render format for glyphs */
188    /*
189     * Glyph memory management fields
190     */
191    unsigned long	glyph_memory;
192    unsigned long	max_glyph_memory;
193    FcBool		use_free_glyphs;   /* Use XRenderFreeGlyphs */
194} XftFontInt;
195
196typedef enum _XftClipType {
197    XftClipTypeNone, XftClipTypeRegion, XftClipTypeRectangles
198} XftClipType;
199
200typedef struct _XftClipRect {
201    int			xOrigin;
202    int			yOrigin;
203    int			n;
204} XftClipRect;
205
206#define XftClipRects(cr)    ((XRectangle *) ((cr) + 1))
207
208typedef union _XftClip {
209    XftClipRect	    *rect;
210    Region	    region;
211} XftClip;
212
213struct _XftDraw {
214    Display	    *dpy;
215    int		    screen;
216    unsigned int    bits_per_pixel;
217    unsigned int    depth;
218    Drawable	    drawable;
219    Visual	    *visual;	/* NULL for bitmaps */
220    Colormap	    colormap;
221    XftClipType	    clip_type;
222    XftClip	    clip;
223    int		    subwindow_mode;
224    struct {
225	Picture		pict;
226    } render;
227    struct {
228	GC		gc;
229	int		use_pixmap;
230    } core;
231};
232
233/*
234 * Instead of taking two round trips for each blending request,
235 * assume that if a particular drawable fails GetImage that it will
236 * fail for a "while"; use temporary pixmaps to avoid the errors
237 */
238
239#define XFT_ASSUME_PIXMAP	20
240
241typedef struct _XftSolidColor {
242    XRenderColor    color;
243    int		    screen;
244    Picture	    pict;
245} XftSolidColor;
246
247#define XFT_NUM_SOLID_COLOR	16
248
249#define XFT_NUM_FONT_HASH	127
250
251typedef struct _XftDisplayInfo {
252    struct _XftDisplayInfo  *next;
253    Display		    *display;
254    XExtCodes		    *codes;
255    FcPattern		    *defaults;
256    FcBool		    hasRender;
257    XftFont		    *fonts;
258    XRenderPictFormat	    *solidFormat;
259    unsigned long	    glyph_memory;
260    unsigned long	    max_glyph_memory;
261    FcBool		    use_free_glyphs;
262    int			    num_unref_fonts;
263    int			    max_unref_fonts;
264    XftSolidColor	    colors[XFT_NUM_SOLID_COLOR];
265    XftFont		    *fontHash[XFT_NUM_FONT_HASH];
266} XftDisplayInfo;
267
268/*
269 * By default, use no more than 4 meg of server memory total, and no
270 * more than 1 meg for any one font
271 */
272#define XFT_DPY_MAX_GLYPH_MEMORY    (4 * 1024 * 1024)
273#define XFT_FONT_MAX_GLYPH_MEMORY   (1024 * 1024)
274
275/*
276 * By default, keep the last 16 unreferenced fonts around to
277 * speed reopening them.  Note that the glyph caching code
278 * will keep the global memory usage reasonably limited
279 */
280#define XFT_DPY_MAX_UNREF_FONTS	    16
281
282extern XftDisplayInfo	*_XftDisplayInfo;
283
284#define XFT_DBG_OPEN	1
285#define XFT_DBG_OPENV	2
286#define XFT_DBG_RENDER	4
287#define XFT_DBG_DRAW	8
288#define XFT_DBG_REF	16
289#define XFT_DBG_GLYPH	32
290#define XFT_DBG_GLYPHV	64
291#define XFT_DBG_CACHE	128
292#define XFT_DBG_CACHEV	256
293#define XFT_DBG_MEMORY	512
294
295#define XFT_MEM_DRAW	0
296#define XFT_MEM_FONT	1
297#define XFT_MEM_FILE	2
298#define XFT_MEM_GLYPH	3
299#define XFT_MEM_NUM	4
300
301/* xftcompat.c */
302void XftFontSetDestroy (FcFontSet *s);
303FcBool XftMatrixEqual (_Xconst FcMatrix *mat1, _Xconst FcMatrix *mat2);
304void XftMatrixMultiply (FcMatrix *result, FcMatrix *a, FcMatrix *b);
305void XftMatrixRotate (FcMatrix *m, double c, double s);
306void XftMatrixScale (FcMatrix *m, double sx, double sy);
307void XftMatrixShear (FcMatrix *m, double sh, double sv);
308FcPattern *XftPatternCreate (void);
309void XftValueDestroy (FcValue v);
310void XftPatternDestroy (FcPattern *p);
311FcBool XftPatternAdd (FcPattern *p, _Xconst char *object, FcValue value, FcBool append);
312FcBool XftPatternDel (FcPattern *p, _Xconst char *object);
313FcBool XftPatternAddInteger (FcPattern *p, _Xconst char *object, int i);
314FcBool XftPatternAddDouble (FcPattern *p, _Xconst char *object, double i);
315FcBool XftPatternAddMatrix (FcPattern *p, _Xconst char *object, FcMatrix *i);
316FcBool XftPatternAddString (FcPattern *p, _Xconst char *object, char *i);
317FcBool XftPatternAddBool (FcPattern *p, _Xconst char *object, FcBool i);
318FcResult XftPatternGet (FcPattern *p, _Xconst char *object, int id, FcValue *v);
319FcResult XftPatternGetInteger (FcPattern *p, _Xconst char *object, int id, int *i);
320FcResult XftPatternGetDouble (FcPattern *p, _Xconst char *object, int id, double *i);
321FcResult XftPatternGetString (FcPattern *p, _Xconst char *object, int id, char **i);
322FcResult XftPatternGetMatrix (FcPattern *p, _Xconst char *object, int id, FcMatrix **i);
323FcResult XftPatternGetBool (FcPattern *p, _Xconst char *object, int id, FcBool *i);
324FcPattern *XftPatternDuplicate (FcPattern *orig);
325FcPattern *XftPatternVaBuild (FcPattern *orig, va_list va);
326FcPattern *XftPatternBuild (FcPattern *orig, ...);
327FcBool XftNameUnparse (FcPattern *pat, char *dest, int len);
328FcBool XftGlyphExists (Display *dpy, XftFont *font, FcChar32 ucs4);
329FcObjectSet *XftObjectSetCreate (void);
330Bool XftObjectSetAdd (FcObjectSet *os, _Xconst char *object);
331void XftObjectSetDestroy (FcObjectSet *os);
332FcObjectSet *XftObjectSetVaBuild (_Xconst char *first, va_list va);
333FcObjectSet *XftObjectSetBuild (_Xconst char *first, ...);
334FcFontSet *XftListFontSets (FcFontSet **sets, int nsets, FcPattern *p, FcObjectSet *os);
335
336/* xftcore.c */
337void
338XftRectCore (XftDraw		*draw,
339	     _Xconst XftColor	*color,
340	     int		x,
341	     int		y,
342	     unsigned int	width,
343	     unsigned int	height);
344
345void
346XftGlyphCore (XftDraw		*draw,
347	      _Xconst XftColor	*color,
348	      XftFont		*public,
349	      int		x,
350	      int		y,
351	      _Xconst FT_UInt	*glyphs,
352	      int		nglyphs);
353
354void
355XftGlyphSpecCore (XftDraw		*draw,
356		  _Xconst XftColor	*color,
357		  XftFont		*public,
358		  _Xconst XftGlyphSpec	*glyphs,
359		  int			nglyphs);
360
361void
362XftGlyphFontSpecCore (XftDraw			*draw,
363		      _Xconst XftColor		*color,
364		      _Xconst XftGlyphFontSpec	*glyphs,
365		      int			nglyphs);
366
367/* xftdbg.c */
368int
369XftDebug (void);
370
371/* xftdpy.c */
372XftDisplayInfo *
373_XftDisplayInfoGet (Display *dpy, FcBool createIfNecessary);
374
375void
376_XftDisplayManageMemory (Display *dpy);
377
378int
379XftDefaultParseBool (char *v);
380
381FcBool
382XftDefaultGetBool (Display *dpy, const char *object, int screen, FcBool def);
383
384int
385XftDefaultGetInteger (Display *dpy, const char *object, int screen, int def);
386
387double
388XftDefaultGetDouble (Display *dpy, const char *object, int screen, double def);
389
390FcFontSet *
391XftDisplayGetFontSet (Display *dpy);
392
393/* xftdraw.c */
394unsigned int
395XftDrawDepth (XftDraw *draw);
396
397unsigned int
398XftDrawBitsPerPixel (XftDraw *draw);
399
400FcBool
401XftDrawRenderPrepare (XftDraw	*draw);
402
403/* xftextent.c */
404
405/* xftfont.c */
406
407/* xftfreetype.c */
408FcBool
409_XftSetFace (XftFtFile *f, FT_F26Dot6 xsize, FT_F26Dot6 ysize, FT_Matrix *matrix);
410
411void
412XftFontManageMemory (Display *dpy);
413
414/* xftglyph.c */
415void
416_XftFontUncacheGlyph (Display *dpy, XftFont *public);
417
418void
419_XftFontManageMemory (Display *dpy, XftFont *public);
420
421/* xftinit.c */
422void
423XftMemReport (void);
424
425void
426XftMemAlloc (int kind, int size);
427
428void
429XftMemFree (int kind, int size);
430
431/* xftlist.c */
432FcFontSet *
433XftListFontsPatternObjects (Display	    *dpy,
434			    int		    screen,
435			    FcPattern	    *pattern,
436			    FcObjectSet    *os);
437
438/* xftname.c */
439void
440_XftNameInit (void);
441
442/* xftrender.c */
443
444/* xftstr.c */
445int
446_XftMatchSymbolic (XftSymbolic *s, int n, const char *name, int def);
447
448/* xftswap.c */
449int
450XftNativeByteOrder (void);
451
452void
453XftSwapCARD32 (CARD32 *data, int n);
454
455void
456XftSwapCARD24 (CARD8 *data, int width, int height);
457
458void
459XftSwapCARD16 (CARD16 *data, int n);
460
461void
462XftSwapImage (XImage *image);
463
464/* xftxlfd.c */
465#endif /* _XFT_INT_H_ */
466