home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / g / gs241j11.zip / INCLUDE.PCF / FONTSTRU.H < prev    next >
C/C++ Source or Header  |  1992-04-02  |  8KB  |  220 lines

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