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