1 /* $Header: fontstruct.h,v 1.10 91/07/22 15:37:41 keith Exp $ */ 2 /*********************************************************** 3 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, 4 and the Massachusetts Institute of Technology, Cambridge, 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 names of Digital or MIT 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 @(#)fontstruct.h 3.2 91/04/15 25 26 ******************************************************************/ 27 28 #ifndef FONTSTR_H 29 #define FONTSTR_H 30 31 #ifdef XSERVER 32 #include <X11/Xproto.h> 33 #else 34 #include "Xstuff.h" 35 #endif 36 37 #include "font.h" 38 39 /* 40 * This version of the server font data strucutre is only for describing 41 * the in memory data structure. The file structure is not necessarily a 42 * copy of this. That is up to the compiler and the OS layer font loading 43 * machinery. 44 */ 45 46 #define GLYPHPADOPTIONS 4 /* 1, 2, 4, or 8 */ 47 48 typedef enum { 49 Linear8Bit, TwoD8Bit, Linear16Bit, TwoD16Bit 50 } FontEncoding; 51 52 typedef struct _FontProp { 53 long name; 54 intptr_t value; /* large enough to hole an 'int' or 'void *' */ 55 } FontPropRec; 56 57 typedef struct _FontResolution { 58 unsigned short x_resolution; 59 unsigned short y_resolution; 60 unsigned short point_size; 61 } FontResolutionRec; 62 63 typedef struct _ExtentInfo { 64 DrawDirection drawDirection; 65 int fontAscent; 66 int fontDescent; 67 int overallAscent; 68 int overallDescent; 69 int overallWidth; 70 int overallLeft; 71 int overallRight; 72 } ExtentInfoRec; 73 74 typedef struct _CharInfo { 75 xCharInfo metrics; /* info preformatted for Queries */ 76 char *bits; /* pointer to glyph image */ 77 } CharInfoRec; 78 79 /* 80 * Font is created at font load time. It is specific to a single encoding. 81 * e.g. not all of the glyphs in a font may be part of a single encoding. 82 */ 83 84 typedef struct _FontInfo { 85 unsigned short firstCol; 86 unsigned short lastCol; 87 unsigned short firstRow; 88 unsigned short lastRow; 89 unsigned short defaultCh; 90 unsigned int noOverlap:1; 91 unsigned int terminalFont:1; 92 unsigned int constantMetrics:1; 93 unsigned int constantWidth:1; 94 unsigned int inkInside:1; 95 unsigned int inkMetrics:1; 96 unsigned int allExist:1; 97 unsigned int drawDirection:2; 98 unsigned int cachable:1; 99 unsigned int anamorphic:1; 100 short maxOverlap; 101 short pad; 102 xCharInfo maxbounds; 103 xCharInfo minbounds; 104 xCharInfo ink_maxbounds; 105 xCharInfo ink_minbounds; 106 short fontAscent; 107 short fontDescent; 108 int nprops; 109 FontPropPtr props; 110 char *isStringProp; 111 } FontInfoRec; 112 113 typedef struct _Font { 114 int refcnt; 115 FontInfoRec info; 116 char bit; 117 char byte; 118 char glyph; 119 char scan; 120 fsBitmapFormat format; 121 int (*get_glyphs) ( /* font, count, chars, encoding, count, glyphs */ ); 122 int (*get_metrics) ( /* font, count, chars, encoding, count, glyphs */ ); 123 int (*get_bitmaps) (/* client, font, flags, ranges, nranges, 124 nextents, extents */ ); 125 int (*get_extents) (/* client, font, format, flags, ranges, 126 nranges, nglyphs, offsets, glyphs */ ); 127 void (*unload_font) ( /* font */ ); 128 FontPathElementPtr fpe; 129 pointer svrPrivate; 130 pointer fontPrivate; 131 pointer fpePrivate; 132 int maxPrivate; 133 pointer *devPrivates; 134 } FontRec; 135 136 extern Bool _FontSetNewPrivate (/* pFont, n, ptr */); 137 extern int AllocateFontPrivateIndex (); 138 139 #define FontGetPrivate(pFont,n) ((n) > (pFont)->maxPrivate ? (pointer) 0 : \ 140 (pFont)->devPrivates[n]) 141 142 #define FontSetPrivate(pFont,n,ptr) ((n) > (pFont)->maxPrivate ? \ 143 _FontSetNewPrivate (pFont, n, ptr) : \ 144 ((((pFont)->devPrivates[n] = (ptr)) != 0) || TRUE)) 145 146 typedef struct _FontNames { 147 int nnames; 148 int size; 149 int *length; 150 char **names; 151 } FontNamesRec; 152 153 /* External view of font paths */ 154 typedef struct _FontPathElement { 155 int name_length; 156 char *name; 157 int type; 158 int refcount; 159 pointer private; 160 } FontPathElementRec; 161 162 typedef struct _FPEFunctions { 163 int (*name_check) ( /* name */ ); 164 int (*init_fpe) ( /* fpe */ ); 165 int (*reset_fpe) ( /* fpe */ ); 166 int (*free_fpe) ( /* fpe */ ); 167 int (*open_font) ( /* client, fpe, flags, name, namelen, format, 168 fid, ppfont, alias */ ); 169 int (*close_font) ( /* pfont */ ); 170 int (*list_fonts) ( /* client, fpe, pattern, patlen, maxnames, 171 paths */ ); 172 int (*start_list_fonts_with_info) ( /* client, fpe, name, namelen, 173 maxnames, data */ ); 174 int (*list_next_font_with_info) ( /* client, fpe, name, namelen, 175 info, num, data */ ); 176 int (*wakeup_fpe) ( /* fpe, mask */ ); 177 int (*client_died) ( /* client, fpe */ ); 178 } FPEFunctionsRec, FPEFunctions; 179 180 extern int InitFPETypes(); 181 182 /* 183 * Various macros for computing values based on contents of 184 * the above structures 185 */ 186 187 #define GLYPHWIDTHPIXELS(pci) \ 188 ((pci)->metrics.rightSideBearing - (pci)->metrics.leftSideBearing) 189 190 #define GLYPHHEIGHTPIXELS(pci) \ 191 ((pci)->metrics.ascent + (pci)->metrics.descent) 192 193 #define GLYPHWIDTHBYTES(pci) (((GLYPHWIDTHPIXELS(pci))+7) >> 3) 194 195 #define GLYPHWIDTHPADDED(bc) (((bc)+7) & ~0x7) 196 197 #define BYTES_PER_ROW(bits, nbytes) \ 198 ((nbytes) == 1 ? (((bits)+7)>>3) /* pad to 1 byte */ \ 199 :(nbytes) == 2 ? ((((bits)+15)>>3)&~1) /* pad to 2 bytes */ \ 200 :(nbytes) == 4 ? ((((bits)+31)>>3)&~3) /* pad to 4 bytes */ \ 201 :(nbytes) == 8 ? ((((bits)+63)>>3)&~7) /* pad to 8 bytes */ \ 202 : 0) 203 204 #define BYTES_FOR_GLYPH(ci,pad) (GLYPHHEIGHTPIXELS(ci) * \ 205 BYTES_PER_ROW(GLYPHWIDTHPIXELS(ci),pad)) 206 /* 207 * Macros for computing different bounding boxes for fonts; from 208 * the font protocol 209 */ 210 211 #define FONT_MAX_ASCENT(pi) ((pi)->fontAscent > (pi)->ink_maxbounds.ascent ? \ 212 (pi)->fontAscent : (pi)->ink_maxbounds.ascent) 213 #define FONT_MAX_DESCENT(pi) ((pi)->fontDescent > (pi)->ink_maxbounds.descent ? \ 214 (pi)->fontDescent : (pi)->ink_maxbounds.descent) 215 #define FONT_MAX_HEIGHT(pi) (FONT_MAX_ASCENT(pi) + FONT_MAX_DESCENT(pi)) 216 #define FONT_MIN_LEFT(pi) ((pi)->ink_minbounds.leftSideBearing < 0 ? \ 217 (pi)->ink_minbounds.leftSideBearing : 0) 218 #define FONT_MAX_RIGHT(pi) ((pi)->ink_maxbounds.rightSideBearing > \ 219 (pi)->ink_maxbounds.characterWidth ? \ 220 (pi)->ink_maxbounds.rightSideBearing : \ 221 (pi)->ink_maxbounds.characterWidth) 222 #define FONT_MAX_WIDTH(pi) (FONT_MAX_RIGHT(pi) - FONT_MIN_LEFT(pi)) 223 224 #endif /* FONTSTR_H */ 225