xftint.h revision 8292847c
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 FcBool hasSolid; 249 XftFont *fonts; 250 XRenderPictFormat *solidFormat; 251 unsigned long glyph_memory; 252 unsigned long max_glyph_memory; 253 FcBool use_free_glyphs; 254 int num_unref_fonts; 255 int max_unref_fonts; 256 XftSolidColor colors[XFT_NUM_SOLID_COLOR]; 257 XftFont *fontHash[XFT_NUM_FONT_HASH]; 258} XftDisplayInfo; 259 260/* 261 * By default, use no more than 4 meg of server memory total, and no 262 * more than 1 meg for any one font 263 */ 264#define XFT_DPY_MAX_GLYPH_MEMORY (4 * 1024 * 1024) 265#define XFT_FONT_MAX_GLYPH_MEMORY (1024 * 1024) 266 267/* 268 * By default, keep the last 16 unreferenced fonts around to 269 * speed reopening them. Note that the glyph caching code 270 * will keep the global memory usage reasonably limited 271 */ 272#define XFT_DPY_MAX_UNREF_FONTS 16 273 274extern XftDisplayInfo *_XftDisplayInfo; 275 276#define XFT_DBG_OPEN 1 277#define XFT_DBG_OPENV 2 278#define XFT_DBG_RENDER 4 279#define XFT_DBG_DRAW 8 280#define XFT_DBG_REF 16 281#define XFT_DBG_GLYPH 32 282#define XFT_DBG_GLYPHV 64 283#define XFT_DBG_CACHE 128 284#define XFT_DBG_CACHEV 256 285#define XFT_DBG_MEMORY 512 286 287#define XFT_MEM_DRAW 0 288#define XFT_MEM_FONT 1 289#define XFT_MEM_FILE 2 290#define XFT_MEM_GLYPH 3 291#define XFT_MEM_NUM 4 292 293/* xftcompat.c */ 294void XftFontSetDestroy (FcFontSet *s); 295FcBool XftMatrixEqual (_Xconst FcMatrix *mat1, _Xconst FcMatrix *mat2); 296void XftMatrixMultiply (FcMatrix *result, FcMatrix *a, FcMatrix *b); 297void XftMatrixRotate (FcMatrix *m, double c, double s); 298void XftMatrixScale (FcMatrix *m, double sx, double sy); 299void XftMatrixShear (FcMatrix *m, double sh, double sv); 300FcPattern *XftPatternCreate (void); 301void XftValueDestroy (FcValue v); 302void XftPatternDestroy (FcPattern *p); 303FcBool XftPatternAdd (FcPattern *p, _Xconst char *object, FcValue value, FcBool append); 304FcBool XftPatternDel (FcPattern *p, _Xconst char *object); 305FcBool XftPatternAddInteger (FcPattern *p, _Xconst char *object, int i); 306FcBool XftPatternAddDouble (FcPattern *p, _Xconst char *object, double i); 307FcBool XftPatternAddMatrix (FcPattern *p, _Xconst char *object, FcMatrix *i); 308FcBool XftPatternAddString (FcPattern *p, _Xconst char *object, char *i); 309FcBool XftPatternAddBool (FcPattern *p, _Xconst char *object, FcBool i); 310FcResult XftPatternGet (FcPattern *p, _Xconst char *object, int id, FcValue *v); 311FcResult XftPatternGetInteger (FcPattern *p, _Xconst char *object, int id, int *i); 312FcResult XftPatternGetDouble (FcPattern *p, _Xconst char *object, int id, double *i); 313FcResult XftPatternGetString (FcPattern *p, _Xconst char *object, int id, char **i); 314FcResult XftPatternGetMatrix (FcPattern *p, _Xconst char *object, int id, FcMatrix **i); 315FcResult XftPatternGetBool (FcPattern *p, _Xconst char *object, int id, FcBool *i); 316FcPattern *XftPatternDuplicate (FcPattern *orig); 317FcPattern *XftPatternVaBuild (FcPattern *orig, va_list va); 318FcPattern *XftPatternBuild (FcPattern *orig, ...); 319FcBool XftNameUnparse (FcPattern *pat, char *dest, int len); 320FcBool XftGlyphExists (Display *dpy, XftFont *font, FcChar32 ucs4); 321FcObjectSet *XftObjectSetCreate (void); 322Bool XftObjectSetAdd (FcObjectSet *os, _Xconst char *object); 323void XftObjectSetDestroy (FcObjectSet *os); 324FcObjectSet *XftObjectSetVaBuild (_Xconst char *first, va_list va); 325FcObjectSet *XftObjectSetBuild (_Xconst char *first, ...); 326FcFontSet *XftListFontSets (FcFontSet **sets, int nsets, FcPattern *p, FcObjectSet *os); 327 328/* xftcore.c */ 329void 330XftRectCore (XftDraw *draw, 331 _Xconst XftColor *color, 332 int x, 333 int y, 334 unsigned int width, 335 unsigned int height); 336 337void 338XftGlyphCore (XftDraw *draw, 339 _Xconst XftColor *color, 340 XftFont *public, 341 int x, 342 int y, 343 _Xconst FT_UInt *glyphs, 344 int nglyphs); 345 346void 347XftGlyphSpecCore (XftDraw *draw, 348 _Xconst XftColor *color, 349 XftFont *public, 350 _Xconst XftGlyphSpec *glyphs, 351 int nglyphs); 352 353void 354XftGlyphFontSpecCore (XftDraw *draw, 355 _Xconst XftColor *color, 356 _Xconst XftGlyphFontSpec *glyphs, 357 int nglyphs); 358 359/* xftdbg.c */ 360int 361XftDebug (void); 362 363/* xftdpy.c */ 364XftDisplayInfo * 365_XftDisplayInfoGet (Display *dpy, FcBool createIfNecessary); 366 367void 368_XftDisplayManageMemory (Display *dpy); 369 370int 371XftDefaultParseBool (const char *v); 372 373FcBool 374XftDefaultGetBool (Display *dpy, const char *object, int screen, FcBool def); 375 376int 377XftDefaultGetInteger (Display *dpy, const char *object, int screen, int def); 378 379double 380XftDefaultGetDouble (Display *dpy, const char *object, int screen, double def); 381 382FcFontSet * 383XftDisplayGetFontSet (Display *dpy); 384 385/* xftdraw.c */ 386unsigned int 387XftDrawDepth (XftDraw *draw); 388 389unsigned int 390XftDrawBitsPerPixel (XftDraw *draw); 391 392FcBool 393XftDrawRenderPrepare (XftDraw *draw); 394 395/* xftextent.c */ 396 397/* xftfont.c */ 398 399/* xftfreetype.c */ 400FcBool 401_XftSetFace (XftFtFile *f, FT_F26Dot6 xsize, FT_F26Dot6 ysize, FT_Matrix *matrix); 402 403void 404XftFontManageMemory (Display *dpy); 405 406/* xftglyph.c */ 407void 408_XftFontUncacheGlyph (Display *dpy, XftFont *public); 409 410void 411_XftFontManageMemory (Display *dpy, XftFont *public); 412 413/* xftinit.c */ 414void 415XftMemReport (void); 416 417void 418XftMemAlloc (int kind, int size); 419 420void 421XftMemFree (int kind, int size); 422 423/* xftlist.c */ 424FcFontSet * 425XftListFontsPatternObjects (Display *dpy, 426 int screen, 427 FcPattern *pattern, 428 FcObjectSet *os); 429 430/* xftname.c */ 431void 432_XftNameInit (void); 433 434/* xftrender.c */ 435 436/* xftstr.c */ 437int 438_XftMatchSymbolic (XftSymbolic *s, int n, const char *name, int def); 439 440/* xftswap.c */ 441int 442XftNativeByteOrder (void); 443 444void 445XftSwapCARD32 (CARD32 *data, int n); 446 447void 448XftSwapCARD24 (CARD8 *data, int width, int height); 449 450void 451XftSwapCARD16 (CARD16 *data, int n); 452 453void 454XftSwapImage (XImage *image); 455 456/* xftxlfd.c */ 457#endif /* _XFT_INT_H_ */ 458