1/*
2 * tkFont.h --
3 *
4 *	Declarations for interfaces between the generic and platform-specific
5 *	parts of the font package. This information is not visible outside of
6 *	the font package.
7 *
8 * Copyright (c) 1996-1997 Sun Microsystems, Inc.
9 *
10 * See the file "license.terms" for information on usage and redistribution of
11 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * RCS: @(#) $Id$
14 */
15
16#ifndef _TKFONT
17#define _TKFONT
18
19#ifdef BUILD_tk
20#undef TCL_STORAGE_CLASS
21#define TCL_STORAGE_CLASS DLLEXPORT
22#endif
23
24/*
25 * The following structure keeps track of the attributes of a font. It can be
26 * used to keep track of either the desired attributes or the actual
27 * attributes gotten when the font was instantiated.
28 */
29
30struct TkFontAttributes {
31    Tk_Uid family;		/* Font family, or NULL to represent plaform-
32				 * specific default system font. */
33    int size;			/* Pointsize of font, 0 for default size, or
34				 * negative number meaning pixel size. */
35    int weight;			/* Weight flag; see below for def'n. */
36    int slant;			/* Slant flag; see below for def'n. */
37    int underline;		/* Non-zero for underline font. */
38    int overstrike;		/* Non-zero for overstrike font. */
39};
40
41/*
42 * Possible values for the "weight" field in a TkFontAttributes structure.
43 * Weight is a subjective term and depends on what the company that created
44 * the font considers bold.
45 */
46
47#define TK_FW_NORMAL	0
48#define TK_FW_BOLD	1
49
50#define TK_FW_UNKNOWN	-1	/* Unknown weight. This value is used for
51				 * error checking and is never actually stored
52				 * in the weight field. */
53
54/*
55 * Possible values for the "slant" field in a TkFontAttributes structure.
56 */
57
58#define TK_FS_ROMAN	0
59#define TK_FS_ITALIC	1
60#define TK_FS_OBLIQUE	2	/* This value is only used when parsing X font
61				 * names to determine the closest match. It is
62				 * only stored in the XLFDAttributes
63				 * structure, never in the slant field of the
64				 * TkFontAttributes. */
65
66#define TK_FS_UNKNOWN	-1	/* Unknown slant. This value is used for error
67				 * checking and is never actually stored in
68				 * the slant field. */
69
70/*
71 * The following structure keeps track of the metrics for an instantiated
72 * font. The metrics are the physical properties of the font itself.
73 */
74
75typedef struct TkFontMetrics {
76    int	ascent;			/* From baseline to top of font. */
77    int	descent;		/* From baseline to bottom of font. */
78    int maxWidth;		/* Width of widest character in font. */
79    int fixed;			/* Non-zero if this is a fixed-width font,
80				 * 0 otherwise. */
81} TkFontMetrics;
82
83/*
84 * The following structure is used to keep track of the generic information
85 * about a font. Each platform-specific font is represented by a structure
86 * with the following structure at its beginning, plus any platform-specific
87 * stuff after that.
88 */
89
90typedef struct TkFont {
91    /*
92     * Fields used and maintained exclusively by generic code.
93     */
94
95    int resourceRefCount;	/* Number of active uses of this font (each
96				 * active use corresponds to a call to
97				 * Tk_AllocFontFromTable or Tk_GetFont). If
98				 * this count is 0, then this TkFont structure
99				 * is no longer valid and it isn't present in
100				 * a hash table: it is being kept around only
101				 * because there are objects referring to it.
102				 * The structure is freed when
103				 * resourceRefCount and objRefCount are both
104				 * 0. */
105    int objRefCount;		/* The number of Tcl objects that reference
106				 * this structure. */
107    Tcl_HashEntry *cacheHashPtr;/* Entry in font cache for this structure,
108				 * used when deleting it. */
109    Tcl_HashEntry *namedHashPtr;/* Pointer to hash table entry that
110				 * corresponds to the named font that the
111				 * tkfont was based on, or NULL if the tkfont
112				 * was not based on a named font. */
113    Screen *screen;		/* The screen where this font is valid. */
114    int tabWidth;		/* Width of tabs in this font (pixels). */
115    int	underlinePos;		/* Offset from baseline to origin of underline
116				 * bar (used for drawing underlines on a
117				 * non-underlined font). */
118    int underlineHeight;	/* Height of underline bar (used for drawing
119				 * underlines on a non-underlined font). */
120
121    /*
122     * Fields used in the generic code that are filled in by
123     * platform-specific code.
124     */
125
126    Font fid;			/* For backwards compatibility with XGCValues
127				 * structures. Remove when TkGCValues is
128				 * implemented. */
129    TkFontAttributes fa;	/* Actual font attributes obtained when the
130				 * the font was created, as opposed to the
131				 * desired attributes passed in to
132				 * TkpGetFontFromAttributes(). The desired
133				 * metrics can be determined from the string
134				 * that was used to create this font. */
135    TkFontMetrics fm;		/* Font metrics determined when font was
136				 * created. */
137    struct TkFont *nextPtr;	/* Points to the next TkFont structure with
138				 * the same name. All fonts with the same name
139				 * (but different displays) are chained
140				 * together off a single entry in a hash
141				 * table. */
142} TkFont;
143
144/*
145 * The following structure is used to return attributes when parsing an XLFD.
146 * The extra information is of interest to the Unix-specific code when
147 * attempting to find the closest matching font.
148 */
149
150typedef struct TkXLFDAttributes {
151    Tk_Uid foundry;		/* The foundry of the font. */
152    int slant;			/* The tristate value for the slant, which is
153				 * significant under X. */
154    int setwidth;		/* The proportionate width, see below for
155				 * definition. */
156    Tk_Uid charset;		/* The actual charset string. */
157} TkXLFDAttributes;
158
159/*
160 * Possible values for the "setwidth" field in a TkXLFDAttributes structure.
161 * The setwidth is whether characters are considered wider or narrower than
162 * normal.
163 */
164
165#define TK_SW_NORMAL	0
166#define TK_SW_CONDENSE	1
167#define TK_SW_EXPAND	2
168#define TK_SW_UNKNOWN	3	/* Unknown setwidth. This value may be stored
169				 * in the setwidth field. */
170
171/*
172 * The following defines specify the meaning of the fields in a fully
173 * qualified XLFD.
174 */
175
176#define XLFD_FOUNDRY	    0
177#define XLFD_FAMILY	    1
178#define XLFD_WEIGHT	    2
179#define XLFD_SLANT	    3
180#define XLFD_SETWIDTH	    4
181#define XLFD_ADD_STYLE	    5
182#define XLFD_PIXEL_SIZE	    6
183#define XLFD_POINT_SIZE	    7
184#define XLFD_RESOLUTION_X   8
185#define XLFD_RESOLUTION_Y   9
186#define XLFD_SPACING	    10
187#define XLFD_AVERAGE_WIDTH  11
188#define XLFD_CHARSET	    12
189#define XLFD_NUMFIELDS	    13	/* Number of fields in XLFD. */
190
191/*
192 * Low-level API exported by generic code to platform-specific code.
193 */
194
195#define TkInitFontAttributes(fa)   memset((fa), 0, sizeof(TkFontAttributes));
196#define TkInitXLFDAttributes(xa)   memset((xa), 0, sizeof(TkXLFDAttributes));
197
198MODULE_SCOPE int	TkFontParseXLFD(CONST char *string,
199			    TkFontAttributes *faPtr, TkXLFDAttributes *xaPtr);
200MODULE_SCOPE char **	TkFontGetAliasList(CONST char *faceName);
201MODULE_SCOPE char ***	TkFontGetFallbacks(void);
202MODULE_SCOPE int	TkFontGetPixels(Tk_Window tkwin, int size);
203MODULE_SCOPE int	TkFontGetPoints(Tk_Window tkwin, int size);
204MODULE_SCOPE char **	TkFontGetGlobalClass(void);
205MODULE_SCOPE char **	TkFontGetSymbolClass(void);
206MODULE_SCOPE int	TkCreateNamedFont(Tcl_Interp *interp, Tk_Window tkwin,
207			    CONST char *name, TkFontAttributes *faPtr);
208MODULE_SCOPE int	TkDeleteNamedFont(Tcl_Interp *interp,
209			    Tk_Window tkwin, CONST char *name);
210MODULE_SCOPE int	TkFontGetFirstTextLayout(Tk_TextLayout layout,
211			    Tk_Font *font, char *dst);
212
213/*
214 * Low-level API exported by platform-specific code to generic code.
215 */
216
217MODULE_SCOPE void	TkpDeleteFont(TkFont *tkFontPtr);
218MODULE_SCOPE void	TkpFontPkgInit(TkMainInfo *mainPtr);
219MODULE_SCOPE TkFont *	TkpGetFontFromAttributes(TkFont *tkFontPtr,
220			    Tk_Window tkwin, CONST TkFontAttributes *faPtr);
221MODULE_SCOPE void	TkpGetFontFamilies(Tcl_Interp *interp,
222			    Tk_Window tkwin);
223MODULE_SCOPE TkFont *	TkpGetNativeFont(Tk_Window tkwin, CONST char *name);
224
225#undef TCL_STORAGE_CLASS
226#define TCL_STORAGE_CLASS DLLIMPORT
227
228#endif	/* _TKFONT */
229