xftint.h revision 2836776b
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
71typedef struct _XftMatcher {
72    char    *object;
73    double  (*compare) (char *object, FcValue value1, FcValue value2);
74} XftMatcher;
75
76typedef struct _XftSymbolic {
77    const char	*name;
78    int		value;
79} XftSymbolic;
80
81/*
82 * Glyphs are stored in this structure
83 */
84typedef struct _XftGlyph {
85    XGlyphInfo	    metrics;
86    void	    *bitmap;
87    unsigned long   glyph_memory;
88} XftGlyph;
89
90/*
91 * A hash table translates Unicode values into glyph indicies
92 */
93typedef struct _XftUcsHash {
94    FcChar32	    ucs4;
95    FT_UInt	    glyph;
96} XftUcsHash;
97
98/*
99 * Many fonts can share the same underlying face data; this
100 * structure references that.  Note that many faces may in fact
101 * live in the same font file; that is irrelevant to this structure
102 * which is concerned only with the individual faces themselves
103 */
104
105typedef struct _XftFtFile {
106    struct _XftFtFile	*next;
107    int			ref;	    /* number of font infos using this file */
108
109    char		*file;	    /* file name */
110    int			id;	    /* font index within that file */
111
112    FT_F26Dot6		xsize;	    /* current xsize setting */
113    FT_F26Dot6		ysize;	    /* current ysize setting */
114    FT_Matrix		matrix;	    /* current matrix setting */
115
116    int			lock;	    /* lock count; can't unload unless 0 */
117    FT_Face		face;	    /* pointer to face; only valid when lock */
118} XftFtFile;
119
120/*
121 * This structure holds the data extracted from a pattern
122 * needed to create a unique font object.
123 */
124
125struct _XftFontInfo {
126    /*
127     * Hash value (not include in hash value computation)
128     */
129    FcChar32		hash;
130    XftFtFile		*file;		/* face source */
131    /*
132     * Rendering options
133     */
134    FT_F26Dot6		xsize, ysize;	/* pixel size */
135    FcBool		antialias;	/* doing antialiasing */
136    FcBool		embolden;	/* force emboldening */
137    int			rgba;		/* subpixel order */
138    int			lcd_filter;	/* lcd filter */
139    FT_Matrix		matrix;		/* glyph transformation matrix */
140    FcBool		transform;	/* non-identify matrix? */
141    FT_Int		load_flags;	/* glyph load flags */
142    FcBool		render;		/* whether to use the Render extension */
143    /*
144     * Internal fields
145     */
146    int			spacing;
147    FcBool		minspace;
148    int			char_width;
149};
150
151/*
152 * Internal version of the font with private data
153 */
154
155typedef struct _XftFontInt {
156    XftFont		public;		/* public fields */
157    XftFont		*next;		/* all fonts on display */
158    XftFont		*hash_next;	/* fonts in this hash chain */
159    XftFontInfo		info;		/* Data from pattern */
160    int			ref;		/* reference count */
161    /*
162     * Per-glyph information, indexed by glyph ID
163     * This array follows the font in memory
164     */
165    XftGlyph		**glyphs;
166    int			num_glyphs;	/* size of glyphs/bitmaps arrays */
167    /*
168     * Hash table to get from Unicode value to glyph ID
169     * This array follows the glyphs in memory
170     */
171    XftUcsHash		*hash_table;
172    int			hash_value;
173    int			rehash_value;
174    /*
175     * X specific fields
176     */
177    GlyphSet		glyphset;	/* Render glyphset */
178    XRenderPictFormat	*format;	/* Render format for glyphs */
179    /*
180     * Glyph memory management fields
181     */
182    unsigned long	glyph_memory;
183    unsigned long	max_glyph_memory;
184    FcBool		use_free_glyphs;   /* Use XRenderFreeGlyphs */
185} XftFontInt;
186
187typedef enum _XftClipType {
188    XftClipTypeNone, XftClipTypeRegion, XftClipTypeRectangles
189} XftClipType;
190
191typedef struct _XftClipRect {
192    int			xOrigin;
193    int			yOrigin;
194    int			n;
195} XftClipRect;
196
197#define XftClipRects(cr)    ((XRectangle *) ((cr) + 1))
198
199typedef union _XftClip {
200    XftClipRect	    *rect;
201    Region	    region;
202} XftClip;
203
204struct _XftDraw {
205    Display	    *dpy;
206    int		    screen;
207    unsigned int    bits_per_pixel;
208    unsigned int    depth;
209    Drawable	    drawable;
210    Visual	    *visual;	/* NULL for bitmaps */
211    Colormap	    colormap;
212    XftClipType	    clip_type;
213    XftClip	    clip;
214    int		    subwindow_mode;
215    struct {
216	Picture		pict;
217    } render;
218    struct {
219	GC		gc;
220	int		use_pixmap;
221    } core;
222};
223
224/*
225 * Instead of taking two round trips for each blending request,
226 * assume that if a particular drawable fails GetImage that it will
227 * fail for a "while"; use temporary pixmaps to avoid the errors
228 */
229
230#define XFT_ASSUME_PIXMAP	20
231
232typedef struct _XftSolidColor {
233    XRenderColor    color;
234    int		    screen;
235    Picture	    pict;
236} XftSolidColor;
237
238#define XFT_NUM_SOLID_COLOR	16
239
240#define XFT_NUM_FONT_HASH	127
241
242typedef struct _XftDisplayInfo {
243    struct _XftDisplayInfo  *next;
244    Display		    *display;
245    XExtCodes		    *codes;
246    FcPattern		    *defaults;
247    FcBool		    hasRender;
248    XftFont		    *fonts;
249    XRenderPictFormat	    *solidFormat;
250    unsigned long	    glyph_memory;
251    unsigned long	    max_glyph_memory;
252    FcBool		    use_free_glyphs;
253    int			    num_unref_fonts;
254    int			    max_unref_fonts;
255    XftSolidColor	    colors[XFT_NUM_SOLID_COLOR];
256    XftFont		    *fontHash[XFT_NUM_FONT_HASH];
257} XftDisplayInfo;
258
259/*
260 * By default, use no more than 4 meg of server memory total, and no
261 * more than 1 meg for any one font
262 */
263#define XFT_DPY_MAX_GLYPH_MEMORY    (4 * 1024 * 1024)
264#define XFT_FONT_MAX_GLYPH_MEMORY   (1024 * 1024)
265
266/*
267 * By default, keep the last 16 unreferenced fonts around to
268 * speed reopening them.  Note that the glyph caching code
269 * will keep the global memory usage reasonably limited
270 */
271#define XFT_DPY_MAX_UNREF_FONTS	    16
272
273extern XftDisplayInfo	*_XftDisplayInfo;
274
275#define XFT_DBG_OPEN	1
276#define XFT_DBG_OPENV	2
277#define XFT_DBG_RENDER	4
278#define XFT_DBG_DRAW	8
279#define XFT_DBG_REF	16
280#define XFT_DBG_GLYPH	32
281#define XFT_DBG_GLYPHV	64
282#define XFT_DBG_CACHE	128
283#define XFT_DBG_CACHEV	256
284#define XFT_DBG_MEMORY	512
285
286#define XFT_MEM_DRAW	0
287#define XFT_MEM_FONT	1
288#define XFT_MEM_FILE	2
289#define XFT_MEM_GLYPH	3
290#define XFT_MEM_NUM	4
291
292/* xftcompat.c */
293void XftFontSetDestroy (FcFontSet *s);
294FcBool XftMatrixEqual (_Xconst FcMatrix *mat1, _Xconst FcMatrix *mat2);
295void XftMatrixMultiply (FcMatrix *result, FcMatrix *a, FcMatrix *b);
296void XftMatrixRotate (FcMatrix *m, double c, double s);
297void XftMatrixScale (FcMatrix *m, double sx, double sy);
298void XftMatrixShear (FcMatrix *m, double sh, double sv);
299FcPattern *XftPatternCreate (void);
300void XftValueDestroy (FcValue v);
301void XftPatternDestroy (FcPattern *p);
302FcBool XftPatternAdd (FcPattern *p, _Xconst char *object, FcValue value, FcBool append);
303FcBool XftPatternDel (FcPattern *p, _Xconst char *object);
304FcBool XftPatternAddInteger (FcPattern *p, _Xconst char *object, int i);
305FcBool XftPatternAddDouble (FcPattern *p, _Xconst char *object, double i);
306FcBool XftPatternAddMatrix (FcPattern *p, _Xconst char *object, FcMatrix *i);
307FcBool XftPatternAddString (FcPattern *p, _Xconst char *object, char *i);
308FcBool XftPatternAddBool (FcPattern *p, _Xconst char *object, FcBool i);
309FcResult XftPatternGet (FcPattern *p, _Xconst char *object, int id, FcValue *v);
310FcResult XftPatternGetInteger (FcPattern *p, _Xconst char *object, int id, int *i);
311FcResult XftPatternGetDouble (FcPattern *p, _Xconst char *object, int id, double *i);
312FcResult XftPatternGetString (FcPattern *p, _Xconst char *object, int id, char **i);
313FcResult XftPatternGetMatrix (FcPattern *p, _Xconst char *object, int id, FcMatrix **i);
314FcResult XftPatternGetBool (FcPattern *p, _Xconst char *object, int id, FcBool *i);
315FcPattern *XftPatternDuplicate (FcPattern *orig);
316FcPattern *XftPatternVaBuild (FcPattern *orig, va_list va);
317FcPattern *XftPatternBuild (FcPattern *orig, ...);
318FcBool XftNameUnparse (FcPattern *pat, char *dest, int len);
319FcBool XftGlyphExists (Display *dpy, XftFont *font, FcChar32 ucs4);
320FcObjectSet *XftObjectSetCreate (void);
321Bool XftObjectSetAdd (FcObjectSet *os, _Xconst char *object);
322void XftObjectSetDestroy (FcObjectSet *os);
323FcObjectSet *XftObjectSetVaBuild (_Xconst char *first, va_list va);
324FcObjectSet *XftObjectSetBuild (_Xconst char *first, ...);
325FcFontSet *XftListFontSets (FcFontSet **sets, int nsets, FcPattern *p, FcObjectSet *os);
326
327/* xftcore.c */
328void
329XftRectCore (XftDraw		*draw,
330	     _Xconst XftColor	*color,
331	     int		x,
332	     int		y,
333	     unsigned int	width,
334	     unsigned int	height);
335
336void
337XftGlyphCore (XftDraw		*draw,
338	      _Xconst XftColor	*color,
339	      XftFont		*public,
340	      int		x,
341	      int		y,
342	      _Xconst FT_UInt	*glyphs,
343	      int		nglyphs);
344
345void
346XftGlyphSpecCore (XftDraw		*draw,
347		  _Xconst XftColor	*color,
348		  XftFont		*public,
349		  _Xconst XftGlyphSpec	*glyphs,
350		  int			nglyphs);
351
352void
353XftGlyphFontSpecCore (XftDraw			*draw,
354		      _Xconst XftColor		*color,
355		      _Xconst XftGlyphFontSpec	*glyphs,
356		      int			nglyphs);
357
358/* xftdbg.c */
359int
360XftDebug (void);
361
362/* xftdpy.c */
363XftDisplayInfo *
364_XftDisplayInfoGet (Display *dpy, FcBool createIfNecessary);
365
366void
367_XftDisplayManageMemory (Display *dpy);
368
369int
370XftDefaultParseBool (const char *v);
371
372FcBool
373XftDefaultGetBool (Display *dpy, const char *object, int screen, FcBool def);
374
375int
376XftDefaultGetInteger (Display *dpy, const char *object, int screen, int def);
377
378double
379XftDefaultGetDouble (Display *dpy, const char *object, int screen, double def);
380
381FcFontSet *
382XftDisplayGetFontSet (Display *dpy);
383
384/* xftdraw.c */
385unsigned int
386XftDrawDepth (XftDraw *draw);
387
388unsigned int
389XftDrawBitsPerPixel (XftDraw *draw);
390
391FcBool
392XftDrawRenderPrepare (XftDraw	*draw);
393
394/* xftextent.c */
395
396/* xftfont.c */
397
398/* xftfreetype.c */
399FcBool
400_XftSetFace (XftFtFile *f, FT_F26Dot6 xsize, FT_F26Dot6 ysize, FT_Matrix *matrix);
401
402void
403XftFontManageMemory (Display *dpy);
404
405/* xftglyph.c */
406void
407_XftFontUncacheGlyph (Display *dpy, XftFont *public);
408
409void
410_XftFontManageMemory (Display *dpy, XftFont *public);
411
412/* xftinit.c */
413void
414XftMemReport (void);
415
416void
417XftMemAlloc (int kind, int size);
418
419void
420XftMemFree (int kind, int size);
421
422/* xftlist.c */
423FcFontSet *
424XftListFontsPatternObjects (Display	    *dpy,
425			    int		    screen,
426			    FcPattern	    *pattern,
427			    FcObjectSet    *os);
428
429/* xftname.c */
430void
431_XftNameInit (void);
432
433/* xftrender.c */
434
435/* xftstr.c */
436int
437_XftMatchSymbolic (XftSymbolic *s, int n, const char *name, int def);
438
439/* xftswap.c */
440int
441XftNativeByteOrder (void);
442
443void
444XftSwapCARD32 (CARD32 *data, int n);
445
446void
447XftSwapCARD24 (CARD8 *data, int width, int height);
448
449void
450XftSwapCARD16 (CARD16 *data, int n);
451
452void
453XftSwapImage (XImage *image);
454
455/* xftxlfd.c */
456#endif /* _XFT_INT_H_ */
457