117ca54c3Smrg/***********************************************************
217ca54c3SmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
317ca54c3Smrg
417ca54c3Smrg                        All Rights Reserved
517ca54c3Smrg
617ca54c3SmrgPermission to use, copy, modify, and distribute this software and its
717ca54c3Smrgdocumentation for any purpose and without fee is hereby granted,
817ca54c3Smrgprovided that the above copyright notice appear in all copies and that
917ca54c3Smrgboth that copyright notice and this permission notice appear in
1017ca54c3Smrgsupporting documentation, and that the name of Digital not be
1117ca54c3Smrgused in advertising or publicity pertaining to distribution of the
1217ca54c3Smrgsoftware without specific, written prior permission.
1317ca54c3Smrg
1417ca54c3SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
1517ca54c3SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
1617ca54c3SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
1717ca54c3SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
1817ca54c3SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
1917ca54c3SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2017ca54c3SmrgSOFTWARE.
2117ca54c3Smrg
2217ca54c3Smrg******************************************************************/
2317ca54c3Smrg
2417ca54c3Smrg#ifndef FONTSTR_H
2517ca54c3Smrg#define FONTSTR_H
2617ca54c3Smrg
2717ca54c3Smrg#include <X11/Xproto.h>
2817ca54c3Smrg#include "font.h"
2917ca54c3Smrg#include <X11/Xfuncproto.h>
3017ca54c3Smrg#include <X11/Xdefs.h>
3117ca54c3Smrg
3217ca54c3Smrg/*
33ea1d6981Smrg * This version of the server font data structure is only for describing
3417ca54c3Smrg * the in memory data structure. The file structure is not necessarily a
3517ca54c3Smrg * copy of this. That is up to the compiler and the OS layer font loading
3617ca54c3Smrg * machinery.
3717ca54c3Smrg */
3817ca54c3Smrg
3917ca54c3Smrg#define GLYPHPADOPTIONS 4	/* 1, 2, 4, or 8 */
4017ca54c3Smrg
4117ca54c3Smrgtypedef struct _FontProp {
4217ca54c3Smrg    long        name;
4317ca54c3Smrg    long        value;		/* assumes ATOM is not larger than INT32 */
4417ca54c3Smrg}           FontPropRec;
4517ca54c3Smrg
4617ca54c3Smrgtypedef struct _FontResolution {
4717ca54c3Smrg    unsigned short x_resolution;
4817ca54c3Smrg    unsigned short y_resolution;
4917ca54c3Smrg    unsigned short point_size;
5017ca54c3Smrg}           FontResolutionRec;
5117ca54c3Smrg
5217ca54c3Smrgtypedef struct _ExtentInfo {
5317ca54c3Smrg    DrawDirection drawDirection;
5417ca54c3Smrg    int         fontAscent;
5517ca54c3Smrg    int         fontDescent;
5617ca54c3Smrg    int         overallAscent;
5717ca54c3Smrg    int         overallDescent;
5817ca54c3Smrg    int         overallWidth;
5917ca54c3Smrg    int         overallLeft;
6017ca54c3Smrg    int         overallRight;
6117ca54c3Smrg}           ExtentInfoRec;
6217ca54c3Smrg
6317ca54c3Smrgtypedef struct _CharInfo {
6417ca54c3Smrg    xCharInfo   metrics;	/* info preformatted for Queries */
6517ca54c3Smrg    char       *bits;		/* pointer to glyph image */
6617ca54c3Smrg}           CharInfoRec;
6717ca54c3Smrg
6817ca54c3Smrg/*
6917ca54c3Smrg * Font is created at font load time. It is specific to a single encoding.
7017ca54c3Smrg * e.g. not all of the glyphs in a font may be part of a single encoding.
7117ca54c3Smrg */
7217ca54c3Smrg
7317ca54c3Smrgtypedef struct _FontInfo {
7417ca54c3Smrg    unsigned short firstCol;
7517ca54c3Smrg    unsigned short lastCol;
7617ca54c3Smrg    unsigned short firstRow;
7717ca54c3Smrg    unsigned short lastRow;
7817ca54c3Smrg    unsigned short defaultCh;
7917ca54c3Smrg    unsigned int noOverlap:1;
8017ca54c3Smrg    unsigned int terminalFont:1;
8117ca54c3Smrg    unsigned int constantMetrics:1;
8217ca54c3Smrg    unsigned int constantWidth:1;
8317ca54c3Smrg    unsigned int inkInside:1;
8417ca54c3Smrg    unsigned int inkMetrics:1;
8517ca54c3Smrg    unsigned int allExist:1;
8617ca54c3Smrg    unsigned int drawDirection:2;
8717ca54c3Smrg    unsigned int cachable:1;
8817ca54c3Smrg    unsigned int anamorphic:1;
8917ca54c3Smrg    short       maxOverlap;
9017ca54c3Smrg    short       pad;
9117ca54c3Smrg    xCharInfo   maxbounds;
9217ca54c3Smrg    xCharInfo   minbounds;
9317ca54c3Smrg    xCharInfo   ink_maxbounds;
9417ca54c3Smrg    xCharInfo   ink_minbounds;
9517ca54c3Smrg    short       fontAscent;
9617ca54c3Smrg    short       fontDescent;
9717ca54c3Smrg    int         nprops;
9817ca54c3Smrg    FontPropPtr props;
9917ca54c3Smrg    char       *isStringProp;
10017ca54c3Smrg}           FontInfoRec;
10117ca54c3Smrg
10217ca54c3Smrgtypedef struct _Font {
10317ca54c3Smrg    int         refcnt;
10417ca54c3Smrg    FontInfoRec info;
10517ca54c3Smrg    char        bit;
10617ca54c3Smrg    char        byte;
10717ca54c3Smrg    char        glyph;
10817ca54c3Smrg    char        scan;
10917ca54c3Smrg    fsBitmapFormat format;
11017ca54c3Smrg    int         (*get_glyphs) (FontPtr         /* font */,
11117ca54c3Smrg			       unsigned long   /* count */,
11217ca54c3Smrg			       unsigned char * /* chars */,
11317ca54c3Smrg			       FontEncoding    /* encoding */,
11417ca54c3Smrg			       unsigned long * /* count */,
11517ca54c3Smrg			       CharInfoPtr *   /* glyphs */);
11617ca54c3Smrg    int         (*get_metrics) (FontPtr         /* font */,
11717ca54c3Smrg				unsigned long   /* count */,
11817ca54c3Smrg				unsigned char * /* chars */,
11917ca54c3Smrg				FontEncoding    /* encoding */,
12017ca54c3Smrg				unsigned long * /* count */,
12117ca54c3Smrg				xCharInfo **    /* glyphs */);
12217ca54c3Smrg    void        (*unload_font) (FontPtr         /* font */);
12317ca54c3Smrg    void        (*unload_glyphs) (FontPtr         /* font */);
12417ca54c3Smrg    FontPathElementPtr fpe;
12517ca54c3Smrg    void        *svrPrivate;
12617ca54c3Smrg    void        *fontPrivate;
12717ca54c3Smrg    void        *fpePrivate;
12817ca54c3Smrg    int		maxPrivate;
12917ca54c3Smrg    void        **devPrivates;
13017ca54c3Smrg}           FontRec;
13117ca54c3Smrg
13217ca54c3Smrg#define FontGetPrivate(pFont,n) ((n) > (pFont)->maxPrivate ? (void *) 0 : \
13317ca54c3Smrg			     (pFont)->devPrivates[n])
13417ca54c3Smrg
13517ca54c3Smrg#define FontSetPrivate(pFont,n,ptr) ((n) > (pFont)->maxPrivate ? \
13617ca54c3Smrg			_FontSetNewPrivate (pFont, n, ptr) : \
13717ca54c3Smrg			((((pFont)->devPrivates[n] = (ptr)) != 0) || TRUE))
13817ca54c3Smrg
13917ca54c3Smrgtypedef struct _FontNames {
14017ca54c3Smrg    int         nnames;
14117ca54c3Smrg    int         size;
14217ca54c3Smrg    int        *length;
14317ca54c3Smrg    char      **names;
14417ca54c3Smrg}           FontNamesRec;
14517ca54c3Smrg
14617ca54c3Smrg
14717ca54c3Smrg/* External view of font paths */
14817ca54c3Smrgtypedef struct _FontPathElement {
14917ca54c3Smrg    int         name_length;
15017ca54c3Smrg#if FONT_PATH_ELEMENT_NAME_CONST
15117ca54c3Smrg    const
15217ca54c3Smrg#endif
15317ca54c3Smrg    char        *name;
15417ca54c3Smrg    int         type;
15517ca54c3Smrg    int         refcount;
15617ca54c3Smrg    void        *private;
15717ca54c3Smrg}           FontPathElementRec;
15817ca54c3Smrg
15917ca54c3Smrgtypedef Bool (*NameCheckFunc) (const char *name);
16017ca54c3Smrgtypedef int (*InitFpeFunc) (FontPathElementPtr fpe);
16117ca54c3Smrgtypedef int (*FreeFpeFunc) (FontPathElementPtr fpe);
16217ca54c3Smrgtypedef int (*ResetFpeFunc) (FontPathElementPtr fpe);
16317ca54c3Smrgtypedef int (*OpenFontFunc) ( void *client,
16417ca54c3Smrg			      FontPathElementPtr fpe,
16517ca54c3Smrg			      Mask flags,
16617ca54c3Smrg			      const char* name,
16717ca54c3Smrg			      int namelen,
16817ca54c3Smrg			      fsBitmapFormat format,
16917ca54c3Smrg			      fsBitmapFormatMask fmask,
17017ca54c3Smrg			      XID id,
17117ca54c3Smrg			      FontPtr* pFont,
17217ca54c3Smrg			      char** aliasName,
17317ca54c3Smrg			      FontPtr non_cachable_font);
17417ca54c3Smrgtypedef void (*CloseFontFunc) (FontPathElementPtr fpe, FontPtr pFont);
17517ca54c3Smrgtypedef int (*ListFontsFunc) (void *client,
17617ca54c3Smrg			      FontPathElementPtr fpe,
17717ca54c3Smrg			      const char* pat,
17817ca54c3Smrg			      int len,
17917ca54c3Smrg			      int max,
18017ca54c3Smrg			      FontNamesPtr names);
18117ca54c3Smrg
18217ca54c3Smrgtypedef int (*StartLfwiFunc) (void *client,
18317ca54c3Smrg			      FontPathElementPtr fpe,
18417ca54c3Smrg			      const char* pat,
18517ca54c3Smrg			      int len,
18617ca54c3Smrg			      int max,
18717ca54c3Smrg			      void ** privatep);
18817ca54c3Smrg
18917ca54c3Smrgtypedef int (*NextLfwiFunc) (void *client,
19017ca54c3Smrg			     FontPathElementPtr fpe,
19117ca54c3Smrg			     char** name,
19217ca54c3Smrg			     int* namelen,
19317ca54c3Smrg			     FontInfoPtr* info,
19417ca54c3Smrg			     int* numFonts,
19517ca54c3Smrg			     void *private);
19617ca54c3Smrg
19717ca54c3Smrgtypedef int (*WakeupFpeFunc) (FontPathElementPtr fpe,
19817ca54c3Smrg			      unsigned long* LastSelectMask);
19917ca54c3Smrg
20017ca54c3Smrgtypedef void (*ClientDiedFunc) (void *client,
20117ca54c3Smrg			       FontPathElementPtr fpe);
20217ca54c3Smrg
20317ca54c3Smrgtypedef int (*LoadGlyphsFunc) (void *client,
20417ca54c3Smrg			       FontPtr pfont,
20517ca54c3Smrg			       Bool range_flag,
20617ca54c3Smrg			       unsigned int nchars,
20717ca54c3Smrg			       int item_size,
20817ca54c3Smrg			       unsigned char* data);
20917ca54c3Smrg
21017ca54c3Smrgtypedef int (*StartLaFunc) (void *client,
21117ca54c3Smrg			    FontPathElementPtr fpe,
21217ca54c3Smrg			    const char* pat,
21317ca54c3Smrg			    int len,
21417ca54c3Smrg			    int max,
21517ca54c3Smrg			    void ** privatep);
21617ca54c3Smrg
21717ca54c3Smrgtypedef int (*NextLaFunc) (void *client,
21817ca54c3Smrg			   FontPathElementPtr fpe,
21917ca54c3Smrg			   char** namep,
22017ca54c3Smrg			   int* namelenp,
22117ca54c3Smrg			   char** resolvedp,
22217ca54c3Smrg			   int* resolvedlenp,
22317ca54c3Smrg			   void *private);
22417ca54c3Smrg
22517ca54c3Smrgtypedef void (*SetPathFunc)(void);
22617ca54c3Smrg
22717ca54c3Smrgtypedef struct _FPEFunctions {
22817ca54c3Smrg    NameCheckFunc       name_check;
22917ca54c3Smrg    InitFpeFunc 	init_fpe;
23017ca54c3Smrg    ResetFpeFunc	reset_fpe;
23117ca54c3Smrg    FreeFpeFunc         free_fpe;
23217ca54c3Smrg    OpenFontFunc        open_font;
23317ca54c3Smrg    CloseFontFunc       close_font;
23417ca54c3Smrg    ListFontsFunc       list_fonts;
23517ca54c3Smrg    StartLaFunc         start_list_fonts_and_aliases;
23617ca54c3Smrg    NextLaFunc          list_next_font_or_alias;
23717ca54c3Smrg    StartLfwiFunc       start_list_fonts_with_info;
23817ca54c3Smrg    NextLfwiFunc        list_next_font_with_info;
23917ca54c3Smrg    WakeupFpeFunc       wakeup_fpe;
24017ca54c3Smrg    ClientDiedFunc 	client_died;
24117ca54c3Smrg		/* for load_glyphs, range_flag = 0 ->
24217ca54c3Smrg			nchars = # of characters in data
24317ca54c3Smrg			item_size = bytes/char
24417ca54c3Smrg			data = list of characters
24517ca54c3Smrg		   range_flag = 1 ->
24617ca54c3Smrg			nchars = # of fsChar2b's in data
24717ca54c3Smrg			item_size is ignored
24817ca54c3Smrg			data = list of fsChar2b's */
24917ca54c3Smrg    LoadGlyphsFunc	load_glyphs;
25017ca54c3Smrg    SetPathFunc		set_path_hook;
25117ca54c3Smrg} FPEFunctionsRec, FPEFunctions;
25217ca54c3Smrg
25317ca54c3Smrg/*
25417ca54c3Smrg * Various macros for computing values based on contents of
25517ca54c3Smrg * the above structures
25617ca54c3Smrg */
25717ca54c3Smrg
25817ca54c3Smrg#define	GLYPHWIDTHPIXELS(pci) \
25917ca54c3Smrg	((pci)->metrics.rightSideBearing - (pci)->metrics.leftSideBearing)
26017ca54c3Smrg
26117ca54c3Smrg#define	GLYPHHEIGHTPIXELS(pci) \
26217ca54c3Smrg 	((pci)->metrics.ascent + (pci)->metrics.descent)
26317ca54c3Smrg
26417ca54c3Smrg#define	GLYPHWIDTHBYTES(pci)	(((GLYPHWIDTHPIXELS(pci))+7) >> 3)
26517ca54c3Smrg
26617ca54c3Smrg#define GLYPHWIDTHPADDED(bc)	(((bc)+7) & ~0x7)
26717ca54c3Smrg
26817ca54c3Smrg#define BYTES_PER_ROW(bits, nbytes) \
26917ca54c3Smrg	((nbytes) == 1 ? (((bits)+7)>>3)	/* pad to 1 byte */ \
27017ca54c3Smrg	:(nbytes) == 2 ? ((((bits)+15)>>3)&~1)	/* pad to 2 bytes */ \
27117ca54c3Smrg	:(nbytes) == 4 ? ((((bits)+31)>>3)&~3)	/* pad to 4 bytes */ \
27217ca54c3Smrg	:(nbytes) == 8 ? ((((bits)+63)>>3)&~7)	/* pad to 8 bytes */ \
27317ca54c3Smrg	: 0)
27417ca54c3Smrg
27517ca54c3Smrg#define BYTES_FOR_GLYPH(ci,pad)	(GLYPHHEIGHTPIXELS(ci) * \
27617ca54c3Smrg				 BYTES_PER_ROW(GLYPHWIDTHPIXELS(ci),pad))
27717ca54c3Smrg/*
27817ca54c3Smrg * Macros for computing different bounding boxes for fonts; from
27917ca54c3Smrg * the font protocol
28017ca54c3Smrg */
28117ca54c3Smrg
28217ca54c3Smrg#define FONT_MAX_ASCENT(pi)	((pi)->fontAscent > (pi)->ink_maxbounds.ascent ? \
28317ca54c3Smrg			    (pi)->fontAscent : (pi)->ink_maxbounds.ascent)
28417ca54c3Smrg#define FONT_MAX_DESCENT(pi)	((pi)->fontDescent > (pi)->ink_maxbounds.descent ? \
28517ca54c3Smrg			    (pi)->fontDescent : (pi)->ink_maxbounds.descent)
28617ca54c3Smrg#define FONT_MAX_HEIGHT(pi)	(FONT_MAX_ASCENT(pi) + FONT_MAX_DESCENT(pi))
28717ca54c3Smrg#define FONT_MIN_LEFT(pi)	((pi)->ink_minbounds.leftSideBearing < 0 ? \
28817ca54c3Smrg			    (pi)->ink_minbounds.leftSideBearing : 0)
28917ca54c3Smrg#define FONT_MAX_RIGHT(pi)	((pi)->ink_maxbounds.rightSideBearing > \
29017ca54c3Smrg				(pi)->ink_maxbounds.characterWidth ? \
29117ca54c3Smrg			    (pi)->ink_maxbounds.rightSideBearing : \
29217ca54c3Smrg				(pi)->ink_maxbounds.characterWidth)
29317ca54c3Smrg#define FONT_MAX_WIDTH(pi)	(FONT_MAX_RIGHT(pi) - FONT_MIN_LEFT(pi))
29417ca54c3Smrg
29517ca54c3Smrg#include "fontproto.h"
29617ca54c3Smrg
29717ca54c3Smrg#endif				/* FONTSTR_H */
298