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