tkFont.h 7.8 KB

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