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