Back to index

tetex-bin  3.0
fontstruct.h
Go to the documentation of this file.
00001 /***********************************************************
00002 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
00003 and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
00004 
00005                         All Rights Reserved
00006 
00007 Permission to use, copy, modify, and distribute this software and its
00008 documentation for any purpose and without fee is hereby granted,
00009 provided that the above copyright notice appear in all copies and that
00010 both that copyright notice and this permission notice appear in
00011 supporting documentation, and that the names of Digital or MIT not be
00012 used in advertising or publicity pertaining to distribution of the
00013 software without specific, written prior permission.
00014 
00015 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00016 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00017 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00018 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00019 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00020 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00021 SOFTWARE.
00022 
00023        @(#)fontstruct.h     3.2    91/04/15
00024 
00025 ******************************************************************/
00026 
00027 #ifndef FONTSTR_H
00028 #define FONTSTR_H
00029 
00030 #ifdef XSERVER
00031 #include <X11/Xproto.h>
00032 #else
00033 #include "Xstuff.h"
00034 #endif
00035 
00036 #include "font.h"
00037 
00038 /*
00039  * This version of the server font data strucutre is only for describing
00040  * the in memory data structure. The file structure is not necessarily a
00041  * copy of this. That is up to the compiler and the OS layer font loading
00042  * machinery.
00043  */
00044 
00045 #define GLYPHPADOPTIONS 4   /* 1, 2, 4, or 8 */
00046 
00047 typedef enum {
00048     Linear8Bit, TwoD8Bit, Linear16Bit, TwoD16Bit
00049 }           FontEncoding;
00050 
00051 typedef struct _FontProp {
00052     long        name;
00053     long        value;             /* assumes ATOM is not larger than INT32 */
00054 }           FontPropRec;
00055 
00056 typedef struct _FontResolution {
00057     unsigned short x_resolution;
00058     unsigned short y_resolution;
00059     unsigned short point_size;
00060 }           FontResolutionRec;
00061 
00062 typedef struct _ExtentInfo {
00063     DrawDirection drawDirection;
00064     int         fontAscent;
00065     int         fontDescent;
00066     int         overallAscent;
00067     int         overallDescent;
00068     int         overallWidth;
00069     int         overallLeft;
00070     int         overallRight;
00071 }           ExtentInfoRec;
00072 
00073 typedef struct _CharInfo {
00074     xCharInfo   metrics;    /* info preformatted for Queries */
00075     char       *bits;              /* pointer to glyph image */
00076 }           CharInfoRec;
00077 
00078 /*
00079  * Font is created at font load time. It is specific to a single encoding.
00080  * e.g. not all of the glyphs in a font may be part of a single encoding.
00081  */
00082 
00083 typedef struct _FontInfo {
00084     unsigned short firstCol;
00085     unsigned short lastCol;
00086     unsigned short firstRow;
00087     unsigned short lastRow;
00088     unsigned short defaultCh;
00089     unsigned int noOverlap:1;
00090     unsigned int terminalFont:1;
00091     unsigned int constantMetrics:1;
00092     unsigned int constantWidth:1;
00093     unsigned int inkInside:1;
00094     unsigned int inkMetrics:1;
00095     unsigned int allExist:1;
00096     unsigned int drawDirection:2;
00097     unsigned int cachable:1;
00098     unsigned int anamorphic:1;
00099     short       maxOverlap;
00100     short       pad;
00101     xCharInfo   maxbounds;
00102     xCharInfo   minbounds;
00103     xCharInfo   ink_maxbounds;
00104     xCharInfo   ink_minbounds;
00105     short       fontAscent;
00106     short       fontDescent;
00107     int         nprops;
00108     FontPropPtr props;
00109     char       *isStringProp;
00110 }           FontInfoRec;
00111 
00112 typedef struct _Font {
00113     int         refcnt;
00114     FontInfoRec info;
00115     char        bit;
00116     char        byte;
00117     char        glyph;
00118     char        scan;
00119     fsBitmapFormat format;
00120     int         (*get_glyphs) ( /* font, count, chars, encoding, count, glyphs */ );
00121     int         (*get_metrics) ( /* font, count, chars, encoding, count, glyphs */ );
00122     int         (*get_bitmaps) (/* client, font, flags, ranges, nranges,
00123                                 nextents, extents */ );
00124     int         (*get_extents) (/* client, font, format, flags, ranges,
00125                                 nranges, nglyphs, offsets, glyphs */ );
00126     void        (*unload_font) ( /* font */ );
00127     FontPathElementPtr fpe;
00128     pointer     svrPrivate;
00129     pointer     fontPrivate;
00130     pointer     fpePrivate;
00131     int              maxPrivate;
00132     pointer   *devPrivates;
00133 }           FontRec;
00134 
00135 extern Bool   _FontSetNewPrivate (/* pFont, n, ptr */);
00136 extern int    AllocateFontPrivateIndex ();
00137 
00138 #define FontGetPrivate(pFont,n) ((n) > (pFont)->maxPrivate ? (pointer) 0 : \
00139                           (pFont)->devPrivates[n])
00140 
00141 #define FontSetPrivate(pFont,n,ptr) ((n) > (pFont)->maxPrivate ? \
00142                      _FontSetNewPrivate (pFont, n, ptr) : \
00143                      ((((pFont)->devPrivates[n] = (ptr)) != 0) || TRUE))
00144 
00145 typedef struct _FontNames {
00146     int         nnames;
00147     int         size;
00148     int        *length;
00149     char      **names;
00150 }           FontNamesRec;
00151 
00152 /* External view of font paths */
00153 typedef struct _FontPathElement {
00154     int         name_length;
00155     char       *name;
00156     int         type;
00157     int         refcount;
00158     pointer     private;
00159 }           FontPathElementRec;
00160 
00161 typedef struct _FPEFunctions {
00162     int         (*name_check) ( /* name */ );
00163     int         (*init_fpe) ( /* fpe */ );
00164     int         (*reset_fpe) ( /* fpe */ );
00165     int         (*free_fpe) ( /* fpe */ );
00166     int         (*open_font) (     /* client, fpe, flags, name, namelen, format,
00167                                fid,  ppfont, alias */ );
00168     int         (*close_font) ( /* pfont */ );
00169     int         (*list_fonts) (    /* client, fpe, pattern, patlen, maxnames,
00170                                 paths */ );
00171     int         (*start_list_fonts_with_info) (  /* client, fpe, name, namelen,
00172                                               maxnames, data */ );
00173     int         (*list_next_font_with_info) (    /* client, fpe, name, namelen,
00174                                             info, num, data */ );
00175     int         (*wakeup_fpe) ( /* fpe, mask */ );
00176     int              (*client_died) ( /* client, fpe */ );
00177 }           FPEFunctionsRec, FPEFunctions;
00178 
00179 extern int  InitFPETypes();
00180 
00181 /*
00182  * Various macros for computing values based on contents of
00183  * the above structures
00184  */
00185 
00186 #define       GLYPHWIDTHPIXELS(pci) \
00187        ((pci)->metrics.rightSideBearing - (pci)->metrics.leftSideBearing)
00188 
00189 #define       GLYPHHEIGHTPIXELS(pci) \
00190        ((pci)->metrics.ascent + (pci)->metrics.descent)
00191 
00192 #define       GLYPHWIDTHBYTES(pci) (((GLYPHWIDTHPIXELS(pci))+7) >> 3)
00193 
00194 #define GLYPHWIDTHPADDED(bc)       (((bc)+7) & ~0x7)
00195 
00196 #define BYTES_PER_ROW(bits, nbytes) \
00197        ((nbytes) == 1 ? (((bits)+7)>>3)   /* pad to 1 byte */ \
00198        :(nbytes) == 2 ? ((((bits)+15)>>3)&~1)    /* pad to 2 bytes */ \
00199        :(nbytes) == 4 ? ((((bits)+31)>>3)&~3)    /* pad to 4 bytes */ \
00200        :(nbytes) == 8 ? ((((bits)+63)>>3)&~7)    /* pad to 8 bytes */ \
00201        : 0)
00202 
00203 #define BYTES_FOR_GLYPH(ci,pad)    (GLYPHHEIGHTPIXELS(ci) * \
00204                              BYTES_PER_ROW(GLYPHWIDTHPIXELS(ci),pad))
00205 /*
00206  * Macros for computing different bounding boxes for fonts; from
00207  * the font protocol
00208  */
00209 
00210 #define FONT_MAX_ASCENT(pi) ((pi)->fontAscent > (pi)->ink_maxbounds.ascent ? \
00211                          (pi)->fontAscent : (pi)->ink_maxbounds.ascent)
00212 #define FONT_MAX_DESCENT(pi)       ((pi)->fontDescent > (pi)->ink_maxbounds.descent ? \
00213                          (pi)->fontDescent : (pi)->ink_maxbounds.descent)
00214 #define FONT_MAX_HEIGHT(pi) (FONT_MAX_ASCENT(pi) + FONT_MAX_DESCENT(pi))
00215 #define FONT_MIN_LEFT(pi)   ((pi)->ink_minbounds.leftSideBearing < 0 ? \
00216                          (pi)->ink_minbounds.leftSideBearing : 0)
00217 #define FONT_MAX_RIGHT(pi)  ((pi)->ink_maxbounds.rightSideBearing > \
00218                             (pi)->ink_maxbounds.characterWidth ? \
00219                          (pi)->ink_maxbounds.rightSideBearing : \
00220                             (pi)->ink_maxbounds.characterWidth)
00221 #define FONT_MAX_WIDTH(pi)  (FONT_MAX_RIGHT(pi) - FONT_MIN_LEFT(pi))
00222 
00223 #endif                      /* FONTSTR_H */