]> git.sesse.net Git - rdpsrv/blob - Xserver/include/fonts/fontstruct.h
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / include / fonts / fontstruct.h
1 /* $XConsortium: fontstruct.h /main/17 1996/08/09 16:23:54 kaleb $ */
2 /* $XFree86: xc/include/fonts/fontstruct.h,v 3.1 1996/12/23 05:58:39 dawes Exp $ */
3 /***********************************************************
4 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
5
6                         All Rights Reserved
7
8 Permission to use, copy, modify, and distribute this software and its
9 documentation for any purpose and without fee is hereby granted,
10 provided that the above copyright notice appear in all copies and that
11 both that copyright notice and this permission notice appear in
12 supporting documentation, and that the name of Digital not be
13 used in advertising or publicity pertaining to distribution of the
14 software without specific, written prior permission.
15
16 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
18 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
19 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
22 SOFTWARE.
23
24 ******************************************************************/
25
26 #ifndef FONTSTR_H
27 #define FONTSTR_H
28
29 #include <X11/Xproto.h>
30 #include "font.h"
31 #include <X11/Xfuncproto.h>
32
33 /*
34  * This version of the server font data strucutre is only for describing
35  * the in memory data structure. The file structure is not necessarily a
36  * copy of this. That is up to the compiler and the OS layer font loading
37  * machinery.
38  */
39
40 #define GLYPHPADOPTIONS 4       /* 1, 2, 4, or 8 */
41
42 typedef struct _FontProp {
43     long        name;
44     long        value;          /* assumes ATOM is not larger than INT32 */
45 }           FontPropRec;
46
47 typedef struct _FontResolution {
48     unsigned short x_resolution;
49     unsigned short y_resolution;
50     unsigned short point_size;
51 }           FontResolutionRec;
52
53 typedef struct _ExtentInfo {
54     DrawDirection drawDirection;
55     int         fontAscent;
56     int         fontDescent;
57     int         overallAscent;
58     int         overallDescent;
59     int         overallWidth;
60     int         overallLeft;
61     int         overallRight;
62 }           ExtentInfoRec;
63
64 typedef struct _CharInfo {
65     xCharInfo   metrics;        /* info preformatted for Queries */
66     char       *bits;           /* pointer to glyph image */
67 }           CharInfoRec;
68
69 /*
70  * Font is created at font load time. It is specific to a single encoding.
71  * e.g. not all of the glyphs in a font may be part of a single encoding.
72  */
73
74 typedef struct _FontInfo {
75     unsigned short firstCol;
76     unsigned short lastCol;
77     unsigned short firstRow;
78     unsigned short lastRow;
79     unsigned short defaultCh;
80     unsigned int noOverlap:1;
81     unsigned int terminalFont:1;
82     unsigned int constantMetrics:1;
83     unsigned int constantWidth:1;
84     unsigned int inkInside:1;
85     unsigned int inkMetrics:1;
86     unsigned int allExist:1;
87     unsigned int drawDirection:2;
88     unsigned int cachable:1;
89     unsigned int anamorphic:1;
90     short       maxOverlap;
91     short       pad;
92     xCharInfo   maxbounds;
93     xCharInfo   minbounds;
94     xCharInfo   ink_maxbounds;
95     xCharInfo   ink_minbounds;
96     short       fontAscent;
97     short       fontDescent;
98     int         nprops;
99     FontPropPtr props;
100     char       *isStringProp;
101 }           FontInfoRec;
102
103 typedef struct _Font {
104     int         refcnt;
105     FontInfoRec info;
106     char        bit;
107     char        byte;
108     char        glyph;
109     char        scan;
110     fsBitmapFormat format;
111     int         (*get_glyphs) (
112 #if NeedNestedPrototypes
113         FontPtr         /* font */,
114         unsigned long   /* count */,
115         unsigned char * /* chars */,
116         FontEncoding    /* encoding */,
117         unsigned long * /* count */,
118         CharInfoPtr *   /* glyphs */
119 #endif
120 );
121     int         (*get_metrics) ( 
122 #if NeedNestedPrototypes
123         FontPtr         /* font */,
124         unsigned long   /* count */,
125         unsigned char * /* chars */,
126         FontEncoding    /* encoding */,
127         unsigned long * /* count */,
128         xCharInfo **    /* glyphs */
129 #endif
130 );
131     void        (*unload_font) ( 
132 #if NeedNestedPrototypes
133         FontPtr         /* font */
134 #endif
135 );
136     void        (*unload_glyphs) ( 
137 #if NeedNestedPrototypes
138         FontPtr         /* font */
139 #endif
140 );
141     FontPathElementPtr fpe;
142     pointer     svrPrivate;
143     pointer     fontPrivate;
144     pointer     fpePrivate;
145     int         maxPrivate;
146     pointer     *devPrivates;
147 }           FontRec;
148
149 extern Bool     _FontSetNewPrivate (
150 #if NeedFunctionPrototypes
151                 FontPtr        /* pFont */,
152                 int            /* n */,
153                 pointer        /* ptr */
154 #endif
155                 );
156 extern int      AllocateFontPrivateIndex (
157 #if NeedFunctionPrototypes
158                 void
159 #endif
160                 );
161
162 #define FontGetPrivate(pFont,n) ((n) > (pFont)->maxPrivate ? (pointer) 0 : \
163                              (pFont)->devPrivates[n])
164
165 #define FontSetPrivate(pFont,n,ptr) ((n) > (pFont)->maxPrivate ? \
166                         _FontSetNewPrivate (pFont, n, ptr) : \
167                         ((((pFont)->devPrivates[n] = (ptr)) != 0) || TRUE))
168
169 typedef struct _FontNames {
170     int         nnames;
171     int         size;
172     int        *length;
173     char      **names;
174 }           FontNamesRec;
175
176 /* External view of font paths */
177 typedef struct _FontPathElement {
178     int         name_length;
179     char       *name;
180     int         type;
181     int         refcount;
182     pointer     private;
183 }           FontPathElementRec;
184
185 typedef struct _FPEFunctions {
186     int         (*name_check) (
187 #if NeedFunctionPrototypes
188                                char* /* name */
189 #endif
190                                );
191     int         (*init_fpe) (
192 #if NeedNestedPrototypes
193                              FontPathElementPtr /* fpe */
194 #endif
195                              );
196     int         (*reset_fpe) (
197 #if NeedNestedPrototypes
198                              FontPathElementPtr /* fpe */
199 #endif
200                              );
201     int         (*free_fpe) (
202 #if NeedNestedPrototypes
203                              FontPathElementPtr /* fpe */
204 #endif
205                              );
206     int         (*open_font) (
207 #if NeedNestedPrototypes
208                               pointer /* client */,
209                               FontPathElementPtr /* fpe */,
210                               int /* flags */,
211                               char* /* name */,
212                               int /* namelen */,
213                               fsBitmapFormat /* format */,
214                               fsBitmapFormatMask /* fmask */,
215                               unsigned long /* id (type XID or FSID) */,
216                               FontPtr* /* pFont */,
217                               char** /* aliasName */,
218                               FontPtr /* non_cachable_font */
219 #endif
220                               );
221
222     int         (*close_font) (
223 #if NeedNestedPrototypes
224                                FontPathElementPtr /* fpe */,
225                                FontPtr /* pFont */
226 #endif
227                                );
228     int         (*list_fonts) (
229 #if NeedNestedPrototypes
230                                pointer /* client */,
231                                FontPathElementPtr /* fpe */,
232                                char* /* pat */,
233                                int /* len */,
234                                int /* max */,
235                                FontNamesPtr /* names */
236 #endif
237                                );
238     int         (*start_list_fonts_and_aliases) (
239 #if NeedNestedPrototypes
240                                                  pointer /* client */,
241                                                  FontPathElementPtr /* fpe */,
242                                                  char* /* pat */,
243                                                  int /* len */,
244                                                  int /* max */,
245                                                  pointer* /* privatep */
246 #endif
247                                                  );
248     int         (*list_next_font_or_alias) (
249 #if NeedNestedPrototypes
250                                             pointer /* client */,
251                                             FontPathElementPtr /* fpe */,
252                                             char** /* namep */,
253                                             int* /* namelenp */,
254                                             char** /* resolvedp */,
255                                             int* /* resolvedlenp */,
256                                             pointer /* private */
257 #endif
258                                             );
259     int         (*start_list_fonts_with_info) (
260 #if NeedNestedPrototypes
261                                                pointer /* client */,
262                                                FontPathElementPtr /* fpe */,
263                                                char* /* pat */,
264                                                int /* patlen */,
265                                                int /* maxnames */,
266                                                pointer* /* privatep */
267 #endif
268                                                );
269     int         (*list_next_font_with_info) (   /* client, fpe, name, namelen,
270                                                  info, num, data */
271 #if NeedNestedPrototypes
272                                              pointer /* client */,
273                                              FontPathElementPtr /* fpe */,
274                                              char** /* name */,
275                                              int* /* namelen */,
276                                              FontInfoPtr* /* info */,
277                                              int* /* numFonts */,
278                                              pointer /* private */
279 #endif
280                                              );
281     int         (*wakeup_fpe) (
282 #if NeedNestedPrototypes
283                                FontPathElementPtr /* fpe */,
284                                unsigned long* /* LastSelectMask */
285 #endif
286                                );
287     int         (*client_died) (
288 #if NeedNestedPrototypes
289                                 pointer /* client */,
290                                 FontPathElementPtr /* fpe */
291 #endif
292                                 );
293                 /* for load_glyphs, range_flag = 0 ->
294                         nchars = # of characters in data
295                         item_size = bytes/char
296                         data = list of characters
297                    range_flag = 1 ->
298                         nchars = # of fsChar2b's in data
299                         item_size is ignored
300                         data = list of fsChar2b's */
301     int         (*load_glyphs) (
302 #if NeedNestedPrototypes
303                                 pointer /* client */,
304                                 FontPtr /* pfont */,
305                                 Bool /* range_flag */,
306                                 unsigned int /* nchars */,
307                                 int /* item_size */,
308                                 unsigned char* /* data */
309 #endif
310                                 );
311     void        (*set_path_hook)(
312 #if NeedFunctionPrototypes
313                                  void
314 #endif
315                                  );
316 }           FPEFunctionsRec, FPEFunctions;
317
318 #if 0   /* unused */
319 extern int  InitFPETypes();
320 #endif
321
322 /*
323  * Various macros for computing values based on contents of
324  * the above structures
325  */
326
327 #define GLYPHWIDTHPIXELS(pci) \
328         ((pci)->metrics.rightSideBearing - (pci)->metrics.leftSideBearing)
329
330 #define GLYPHHEIGHTPIXELS(pci) \
331         ((pci)->metrics.ascent + (pci)->metrics.descent)
332
333 #define GLYPHWIDTHBYTES(pci)    (((GLYPHWIDTHPIXELS(pci))+7) >> 3)
334
335 #define GLYPHWIDTHPADDED(bc)    (((bc)+7) & ~0x7)
336
337 #define BYTES_PER_ROW(bits, nbytes) \
338         ((nbytes) == 1 ? (((bits)+7)>>3)        /* pad to 1 byte */ \
339         :(nbytes) == 2 ? ((((bits)+15)>>3)&~1)  /* pad to 2 bytes */ \
340         :(nbytes) == 4 ? ((((bits)+31)>>3)&~3)  /* pad to 4 bytes */ \
341         :(nbytes) == 8 ? ((((bits)+63)>>3)&~7)  /* pad to 8 bytes */ \
342         : 0)
343
344 #define BYTES_FOR_GLYPH(ci,pad) (GLYPHHEIGHTPIXELS(ci) * \
345                                  BYTES_PER_ROW(GLYPHWIDTHPIXELS(ci),pad))
346 /*
347  * Macros for computing different bounding boxes for fonts; from
348  * the font protocol
349  */
350
351 #define FONT_MAX_ASCENT(pi)     ((pi)->fontAscent > (pi)->ink_maxbounds.ascent ? \
352                             (pi)->fontAscent : (pi)->ink_maxbounds.ascent)
353 #define FONT_MAX_DESCENT(pi)    ((pi)->fontDescent > (pi)->ink_maxbounds.descent ? \
354                             (pi)->fontDescent : (pi)->ink_maxbounds.descent)
355 #define FONT_MAX_HEIGHT(pi)     (FONT_MAX_ASCENT(pi) + FONT_MAX_DESCENT(pi))
356 #define FONT_MIN_LEFT(pi)       ((pi)->ink_minbounds.leftSideBearing < 0 ? \
357                             (pi)->ink_minbounds.leftSideBearing : 0)
358 #define FONT_MAX_RIGHT(pi)      ((pi)->ink_maxbounds.rightSideBearing > \
359                                 (pi)->ink_maxbounds.characterWidth ? \
360                             (pi)->ink_maxbounds.rightSideBearing : \
361                                 (pi)->ink_maxbounds.characterWidth)
362 #define FONT_MAX_WIDTH(pi)      (FONT_MAX_RIGHT(pi) - FONT_MIN_LEFT(pi))
363
364 #endif                          /* FONTSTR_H */