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