jpayne@69: /* jpayne@69: * tkFont.h -- jpayne@69: * jpayne@69: * Declarations for interfaces between the generic and platform-specific jpayne@69: * parts of the font package. This information is not visible outside of jpayne@69: * the font package. jpayne@69: * jpayne@69: * Copyright (c) 1996-1997 Sun Microsystems, Inc. jpayne@69: * jpayne@69: * See the file "license.terms" for information on usage and redistribution of jpayne@69: * this file, and for a DISCLAIMER OF ALL WARRANTIES. jpayne@69: */ jpayne@69: jpayne@69: #ifndef _TKFONT jpayne@69: #define _TKFONT jpayne@69: jpayne@69: /* jpayne@69: * The following structure keeps track of the attributes of a font. It can be jpayne@69: * used to keep track of either the desired attributes or the actual jpayne@69: * attributes gotten when the font was instantiated. jpayne@69: */ jpayne@69: jpayne@69: struct TkFontAttributes { jpayne@69: Tk_Uid family; /* Font family, or NULL to represent plaform- jpayne@69: * specific default system font. */ jpayne@69: double size; /* Pointsize of font, 0.0 for default size, or jpayne@69: * negative number meaning pixel size. */ jpayne@69: int weight; /* Weight flag; see below for def'n. */ jpayne@69: int slant; /* Slant flag; see below for def'n. */ jpayne@69: int underline; /* Non-zero for underline font. */ jpayne@69: int overstrike; /* Non-zero for overstrike font. */ jpayne@69: }; jpayne@69: jpayne@69: /* jpayne@69: * Possible values for the "weight" field in a TkFontAttributes structure. jpayne@69: * Weight is a subjective term and depends on what the company that created jpayne@69: * the font considers bold. jpayne@69: */ jpayne@69: jpayne@69: #define TK_FW_NORMAL 0 jpayne@69: #define TK_FW_BOLD 1 jpayne@69: jpayne@69: #define TK_FW_UNKNOWN -1 /* Unknown weight. This value is used for jpayne@69: * error checking and is never actually stored jpayne@69: * in the weight field. */ jpayne@69: jpayne@69: /* jpayne@69: * Possible values for the "slant" field in a TkFontAttributes structure. jpayne@69: */ jpayne@69: jpayne@69: #define TK_FS_ROMAN 0 jpayne@69: #define TK_FS_ITALIC 1 jpayne@69: #define TK_FS_OBLIQUE 2 /* This value is only used when parsing X font jpayne@69: * names to determine the closest match. It is jpayne@69: * only stored in the XLFDAttributes jpayne@69: * structure, never in the slant field of the jpayne@69: * TkFontAttributes. */ jpayne@69: jpayne@69: #define TK_FS_UNKNOWN -1 /* Unknown slant. This value is used for error jpayne@69: * checking and is never actually stored in jpayne@69: * the slant field. */ jpayne@69: jpayne@69: /* jpayne@69: * The following structure keeps track of the metrics for an instantiated jpayne@69: * font. The metrics are the physical properties of the font itself. jpayne@69: */ jpayne@69: jpayne@69: typedef struct TkFontMetrics { jpayne@69: int ascent; /* From baseline to top of font. */ jpayne@69: int descent; /* From baseline to bottom of font. */ jpayne@69: int maxWidth; /* Width of widest character in font. */ jpayne@69: int fixed; /* Non-zero if this is a fixed-width font, jpayne@69: * 0 otherwise. */ jpayne@69: } TkFontMetrics; jpayne@69: jpayne@69: /* jpayne@69: * The following structure is used to keep track of the generic information jpayne@69: * about a font. Each platform-specific font is represented by a structure jpayne@69: * with the following structure at its beginning, plus any platform-specific jpayne@69: * stuff after that. jpayne@69: */ jpayne@69: jpayne@69: typedef struct TkFont { jpayne@69: /* jpayne@69: * Fields used and maintained exclusively by generic code. jpayne@69: */ jpayne@69: jpayne@69: int resourceRefCount; /* Number of active uses of this font (each jpayne@69: * active use corresponds to a call to jpayne@69: * Tk_AllocFontFromTable or Tk_GetFont). If jpayne@69: * this count is 0, then this TkFont structure jpayne@69: * is no longer valid and it isn't present in jpayne@69: * a hash table: it is being kept around only jpayne@69: * because there are objects referring to it. jpayne@69: * The structure is freed when jpayne@69: * resourceRefCount and objRefCount are both jpayne@69: * 0. */ jpayne@69: int objRefCount; /* The number of Tcl objects that reference jpayne@69: * this structure. */ jpayne@69: Tcl_HashEntry *cacheHashPtr;/* Entry in font cache for this structure, jpayne@69: * used when deleting it. */ jpayne@69: Tcl_HashEntry *namedHashPtr;/* Pointer to hash table entry that jpayne@69: * corresponds to the named font that the jpayne@69: * tkfont was based on, or NULL if the tkfont jpayne@69: * was not based on a named font. */ jpayne@69: Screen *screen; /* The screen where this font is valid. */ jpayne@69: int tabWidth; /* Width of tabs in this font (pixels). */ jpayne@69: int underlinePos; /* Offset from baseline to origin of underline jpayne@69: * bar (used for drawing underlines on a jpayne@69: * non-underlined font). */ jpayne@69: int underlineHeight; /* Height of underline bar (used for drawing jpayne@69: * underlines on a non-underlined font). */ jpayne@69: jpayne@69: /* jpayne@69: * Fields used in the generic code that are filled in by jpayne@69: * platform-specific code. jpayne@69: */ jpayne@69: jpayne@69: Font fid; /* For backwards compatibility with XGCValues jpayne@69: * structures. Remove when TkGCValues is jpayne@69: * implemented. */ jpayne@69: TkFontAttributes fa; /* Actual font attributes obtained when the jpayne@69: * the font was created, as opposed to the jpayne@69: * desired attributes passed in to jpayne@69: * TkpGetFontFromAttributes(). The desired jpayne@69: * metrics can be determined from the string jpayne@69: * that was used to create this font. */ jpayne@69: TkFontMetrics fm; /* Font metrics determined when font was jpayne@69: * created. */ jpayne@69: struct TkFont *nextPtr; /* Points to the next TkFont structure with jpayne@69: * the same name. All fonts with the same name jpayne@69: * (but different displays) are chained jpayne@69: * together off a single entry in a hash jpayne@69: * table. */ jpayne@69: } TkFont; jpayne@69: jpayne@69: /* jpayne@69: * The following structure is used to return attributes when parsing an XLFD. jpayne@69: * The extra information is of interest to the Unix-specific code when jpayne@69: * attempting to find the closest matching font. jpayne@69: */ jpayne@69: jpayne@69: typedef struct TkXLFDAttributes { jpayne@69: Tk_Uid foundry; /* The foundry of the font. */ jpayne@69: int slant; /* The tristate value for the slant, which is jpayne@69: * significant under X. */ jpayne@69: int setwidth; /* The proportionate width, see below for jpayne@69: * definition. */ jpayne@69: Tk_Uid charset; /* The actual charset string. */ jpayne@69: } TkXLFDAttributes; jpayne@69: jpayne@69: /* jpayne@69: * Possible values for the "setwidth" field in a TkXLFDAttributes structure. jpayne@69: * The setwidth is whether characters are considered wider or narrower than jpayne@69: * normal. jpayne@69: */ jpayne@69: jpayne@69: #define TK_SW_NORMAL 0 jpayne@69: #define TK_SW_CONDENSE 1 jpayne@69: #define TK_SW_EXPAND 2 jpayne@69: #define TK_SW_UNKNOWN 3 /* Unknown setwidth. This value may be stored jpayne@69: * in the setwidth field. */ jpayne@69: jpayne@69: /* jpayne@69: * The following defines specify the meaning of the fields in a fully jpayne@69: * qualified XLFD. jpayne@69: */ jpayne@69: jpayne@69: #define XLFD_FOUNDRY 0 jpayne@69: #define XLFD_FAMILY 1 jpayne@69: #define XLFD_WEIGHT 2 jpayne@69: #define XLFD_SLANT 3 jpayne@69: #define XLFD_SETWIDTH 4 jpayne@69: #define XLFD_ADD_STYLE 5 jpayne@69: #define XLFD_PIXEL_SIZE 6 jpayne@69: #define XLFD_POINT_SIZE 7 jpayne@69: #define XLFD_RESOLUTION_X 8 jpayne@69: #define XLFD_RESOLUTION_Y 9 jpayne@69: #define XLFD_SPACING 10 jpayne@69: #define XLFD_AVERAGE_WIDTH 11 jpayne@69: #define XLFD_CHARSET 12 jpayne@69: #define XLFD_NUMFIELDS 13 /* Number of fields in XLFD. */ jpayne@69: jpayne@69: /* jpayne@69: * Helper macro. How to correctly round a double to a short. jpayne@69: */ jpayne@69: jpayne@69: #define ROUND16(x) ((short) floor((x) + 0.5)) jpayne@69: jpayne@69: /* jpayne@69: * Low-level API exported by generic code to platform-specific code. jpayne@69: */ jpayne@69: jpayne@69: #define TkInitFontAttributes(fa) memset((fa), 0, sizeof(TkFontAttributes)); jpayne@69: #define TkInitXLFDAttributes(xa) memset((xa), 0, sizeof(TkXLFDAttributes)); jpayne@69: jpayne@69: MODULE_SCOPE int TkFontParseXLFD(const char *string, jpayne@69: TkFontAttributes *faPtr, TkXLFDAttributes *xaPtr); jpayne@69: MODULE_SCOPE const char *const * TkFontGetAliasList(const char *faceName); jpayne@69: MODULE_SCOPE const char *const *const * TkFontGetFallbacks(void); jpayne@69: MODULE_SCOPE double TkFontGetPixels(Tk_Window tkwin, double size); jpayne@69: MODULE_SCOPE double TkFontGetPoints(Tk_Window tkwin, double size); jpayne@69: MODULE_SCOPE const char *const * TkFontGetGlobalClass(void); jpayne@69: MODULE_SCOPE const char *const * TkFontGetSymbolClass(void); jpayne@69: MODULE_SCOPE int TkCreateNamedFont(Tcl_Interp *interp, Tk_Window tkwin, jpayne@69: const char *name, TkFontAttributes *faPtr); jpayne@69: MODULE_SCOPE int TkDeleteNamedFont(Tcl_Interp *interp, jpayne@69: Tk_Window tkwin, const char *name); jpayne@69: MODULE_SCOPE int TkFontGetFirstTextLayout(Tk_TextLayout layout, jpayne@69: Tk_Font *font, char *dst); jpayne@69: jpayne@69: /* jpayne@69: * Low-level API exported by platform-specific code to generic code. jpayne@69: */ jpayne@69: jpayne@69: MODULE_SCOPE void TkpDeleteFont(TkFont *tkFontPtr); jpayne@69: MODULE_SCOPE void TkpFontPkgInit(TkMainInfo *mainPtr); jpayne@69: MODULE_SCOPE TkFont * TkpGetFontFromAttributes(TkFont *tkFontPtr, jpayne@69: Tk_Window tkwin, const TkFontAttributes *faPtr); jpayne@69: MODULE_SCOPE void TkpGetFontFamilies(Tcl_Interp *interp, jpayne@69: Tk_Window tkwin); jpayne@69: MODULE_SCOPE TkFont * TkpGetNativeFont(Tk_Window tkwin, const char *name); jpayne@69: jpayne@69: #endif /* _TKFONT */