home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / doc / Server / fontlib.ms < prev    next >
Encoding:
Text File  |  1991-07-31  |  15.3 KB  |  358 lines

  1. .ps 12
  2. .nr PS 12
  3. .de Cs
  4. .IP
  5. .nf
  6. .ft C
  7. ..
  8. .de Ce
  9. .ft P
  10. .fi
  11. ..
  12. .\" $XConsortium $
  13. .EF 'Font Library Interface'- % -'July 27, 1991'
  14. .OF 'Font Library Interface'- % -'July 27, 1991'
  15. .EH ''''
  16. .OH ''''
  17. .TL
  18. The X Font Library
  19. .AU
  20. Keith Packard
  21. .AI
  22. MIT X Consortium
  23. .AU
  24. David Lemke
  25. .AI
  26. Network Computing Devices
  27. .LP
  28. This document describes the data structures and interfaces for using the X
  29. Font library.  It is intended as a reference for programmers building X
  30. and Font servers.  You may want to refer to the following documents:
  31. .IP \(bu 5
  32. "Definition of the Porting Layer for the X v11 Sample Server" for a
  33. discussion on how this library interacts with the X server
  34. .IP \(bu 5
  35. "Font Server Implementation Overview" which discusses the design of the font
  36. server.
  37. .IP \(bu 5
  38. "Bitmap Distribution Format" which covers the contents of the bitmap font
  39. files which this library reads; although the library is capable of reading
  40. other formats as well, including non-bitmap fonts.
  41. .IP \(bu 5
  42. "The X Font Service Protocol" for a description of the constraints placed on
  43. the design by including support for this font service mechanism.
  44. .LP
  45. This document assumes the reader is familiar with the X server design, the
  46. X protocol as it relates to fonts and the C programming language.  As with
  47. most MIT produced documentation, this relies heavily on the source code, so
  48. have a listing handy.
  49. .NH 1
  50. Requirements for the Font library
  51. .LP
  52. To avoid miles of duplicate code in the X server, the font server and the
  53. various font manipulation tools, the font library should provide interfaces
  54. appropriate for all of these tasks.  In particular, the X server and font
  55. server should be able to both use the library to access disk based fonts,
  56. and to communicate with a font server.  By providing a general library, we
  57. hoped to avoid duplicating code between the X server and font server.
  58. .LP
  59. Another requirement is that the X server (or even a font server) be able to
  60. continue servicing requests from other clients while awaiting a response
  61. from the font server on behalf of one client.  This is the strongest
  62. requirement placed on the font library, and has warped the design in curious
  63. ways.  Because both the X server and font server are single threaded, the
  64. font library must not suspend internally, rather it returns an indication of
  65. suspension to the application which continues processing other things, until
  66. the font data is ready, at which time it restarts the suspended request.
  67. .LP
  68. Because the code for reading and manipulating bitmap font data is used by
  69. the font applications "mkfontdir" and "bdftopcf", the font library includes
  70. bitmap-font specific interfaces which those applications use, instead of the
  71. more general interfaces used by the X and font servers, which are unaware of
  72. the source of the font data.  These routines will be refered to as the
  73. bitmap font access methods.
  74. .NH 1
  75. General Font Library Interface details.
  76. .LP
  77. To avoid collision between the #define name space for errors, the Font
  78. library defines a new set of return values:
  79. .Cs
  80. #define AllocError      80
  81. #define StillWorking    81
  82. #define FontNameAlias   82
  83. #define BadFontName     83
  84. #define Suspended       84
  85. #define Successful      85
  86. #define BadFontPath     86
  87. #define BadCharRange    87
  88. #define BadFontFormat   88
  89. #define FPEResetFailed  89
  90. .Ce
  91. .LP
  92. Whenever a routine returns \fBSuspended\fP, the font library will notify the
  93. caller (via the ClientSignal interface described below) who should then
  94. reinvoke the same routine again with the same arguments.
  95. .NH 1
  96. Font Path Elements
  97. .LP
  98. At the center of the general font access methods used by X and fs is the
  99. Font Path Element data structure.  Like most structures in the X server,
  100. this contains a collection of data and some function pointers for
  101. manipulating this data:
  102. .Cs
  103. /* External view of font paths */
  104. typedef struct _FontPathElement {
  105.     int         name_length;
  106.     char       *name;
  107.     int         type;
  108.     int         refcount;
  109.     pointer     private;
  110. } FontPathElementRec, *FontPathElementPtr;
  111.  
  112. typedef struct _FPEFunctions {
  113.     int         (*name_check) ( /* name */ );
  114.     int         (*init_fpe) ( /* fpe */ );
  115.     int         (*reset_fpe) ( /* fpe */ );
  116.     int         (*free_fpe) ( /* fpe */ );
  117.     int         (*open_font) (  /* client, fpe, flags,
  118.                         name, namelen, format,
  119.                         fid,  ppfont, alias */ );
  120.     int         (*close_font) ( /* pfont */ );
  121.     int         (*list_fonts) ( /* client, fpe, pattern,
  122.                         patlen, maxnames, paths */ );
  123.     int         (*start_list_fonts_with_info) (
  124.                         /* client, fpe, name, namelen,
  125.                            maxnames, data */ );
  126.     int         (*list_next_font_with_info) (
  127.                         /* client, fpe, name, namelen,
  128.                            info, num, data */ );
  129.     int         (*wakeup_fpe) ( /* fpe, mask */ );
  130.     int         (*client_died) ( /* client, fpe */ );
  131. } FPEFunctionsRec, FPEFunctions;
  132. .Ce
  133. .LP
  134. The function pointers are split out from the data structure to save memory;
  135. additionally, this avoids any complications when initializing the data
  136. structure as there would not be any way to discover the appropriate function
  137. to call (a chicken and egg problem).
  138. .LP
  139. When a font path type is initialized, it passes the function pointers to the
  140. server which are then stored in an FPEFunctionsRec.  Each function is
  141. described below in turn.
  142. .NH 2
  143. (*name_check)
  144. .LP
  145. Each new font path member is passed to this function; if the return value
  146. is Successful, then the FPE recognises the format of the string.  This does
  147. not guarantee that the FPE will be able to successfully use this member.
  148. For example, the disk-based font directory file "fonts.dir" may be
  149. corrupted, this will not be detected until the font path is initialized.
  150. This routine never returns \fBSuspended\fP.
  151. .NH 2
  152. (*init_fpe)
  153. .LP
  154. Initialize a new font path element.  This function prepares a new font path
  155. element for other requests:  the disk font routine reads the "fonts.dir" and
  156. "fonts.alias" files into the internal format, while the font server routine
  157. connects to the requested font server and prepares for using it.  This
  158. routine returns Successful if everything went OK, otherwise the return value
  159. indicates the source of the problem.  This routine never returns \fBSuspended\fP.
  160. .NH 2
  161. (*reset_fpe)
  162. .LP
  163. When the X font path is reset, and some of the new members are also in the
  164. old font path, this function is called to reinitialize those FPEs.  This
  165. routine returns Successful if everything went OK.  It returns FPEResetFailed
  166. if (for some reason) the reset failed, and the caller should remove the old
  167. FPE and simply create a new one in its place.  This is used by the
  168. disk-based fonts routine as resetting the internal directory structures
  169. would be more complicated than simply having destroying the old and creating
  170. a new.
  171. .NH 2
  172. (*free_fpe)
  173. .LP
  174. When the server is finished with an FPE, this function is called to dispose
  175. of any internal state.  It should return Successful, unless something
  176. terrible happens.
  177. .NH 2
  178. (*open_font)
  179. .LP
  180. This routine requests that a font be opened.  The client argument is used
  181. by the font library only in connection with suspending/restarting the
  182. request.  The flags argument specifies some behaviour for the library and can
  183. be any of:
  184. .Cs
  185. /* OpenFont flags */
  186. #define FontLoadInfo    0x0001
  187. #define FontLoadProps   0x0002
  188. #define FontLoadMetrics 0x0004
  189. #define FontLoadBitmaps 0x0008
  190. #define FontLoadAll     0x000f
  191. #define FontOpenSync    0x0010
  192. .Ce
  193. .LP
  194. The various fields specify which portions of the font should be loaded at
  195. this time.  When FontOpenSync is specified, this routine will not return
  196. until all of the requested portions are loaded.  Otherwise, this routine may
  197. return \fBSuspended\fP.  When the presented font name is actually an alias
  198. for some other font name, FontName Alias is returned, and the actual font
  199. name is stored in the location pointed to by the \fIalias\fP argument as a
  200. null-terminated string.
  201. .NH 2
  202. (*close_font)
  203. .LP
  204. When the server is finished with a font, this routine disposes of any
  205. internal state and frees the font data structure.
  206. .NH 2
  207. (*list_fonts)
  208. .LP
  209. The \fIpaths\fP argument is a data structure which will be filled with all
  210. of the font names from this directory which match the specified pattern.  At
  211. most \fImaxnames\fP will be added.  This routine may return \fBSuspended\fP.
  212. .NH 2
  213. (*start_list_fonts_with_info)
  214. .LP
  215. This routine sets any internal state for a verbose listing of all fonts
  216. matching the specified pattern.  This routine may return \fBSuspended\fP.
  217. .NH 2
  218. (*list_next_font_with_info)
  219. .LP
  220. To avoid storing huge amounts of data, the interface for ListFontsWithInfo
  221. allows the server to get one reply at a time and forward that to the
  222. client.  When the font name returned is actually an alias for some other
  223. font, \fBFontNameAlias\fP will be returned.  The actual font name is return
  224. instead, and the font alias which matched the pattern is returned in the
  225. location pointed to by data as a null-terminated string.  The caller can
  226. then get the information by recursively listing that font name with a
  227. maxnames of 1.  When \fBSuccessful\fP is returned, the matching font name is
  228. returned, and a FontInfoPtr is stored in the location pointed to by
  229. \fIdata\fP.  \fIData\fP must be initialized with a pointer to a FontInfoRec
  230. allocated by the caller.  When the pointer pointed to by \fIdata\fP is not
  231. left pointing at that storage, the caller mustn't free the associated
  232. property data.  This routine may return \fBSuspended\fP.
  233. .NH 2
  234. (*wakeup_fpe)
  235. .LP
  236. Whenever an FPE function has returned Suspended, this routine is called
  237. whenever the application wakes up from waiting for input (from select(2)).
  238. This mask argument should be the value returned from select(2).
  239. .NH 2
  240. (*client_died)
  241. .LP
  242. When an FPE function has returned \fBSuspended\fP and the associated client
  243. is being destroyed, this function allows the font library to dispose of any
  244. state associated with that client.
  245. .NH 1
  246. Fonts
  247. .LP
  248. The data structure which actually contains the font information has changed
  249. significantly since previous releases; it now attempts to hide the actual
  250. storage format for the data from the application, providing accessor
  251. functions to get at the data.  This allows a range of internal details for
  252. different font sources.  The structure is split into two pieces, so that
  253. ListFontsWithInfo can share information from the font when it has been
  254. loaded.  The FontInfo structure, then, contains only information germane to
  255. LFWI.
  256. .Cs
  257. typedef struct _FontInfo {
  258.     unsigned short firstCol;            /* range of glyphs for this font */
  259.     unsigned short lastCol;
  260.     unsigned short firstRow;
  261.     unsigned short lastRow;
  262.     unsigned short defaultCh;           /* default character index */
  263.     unsigned int noOverlap:1;           /* no combination of glyphs overlap */
  264.     unsigned int terminalFont:1;        /* Character cell font */
  265.     unsigned int constantMetrics:1;     /* all metrics are the same */
  266.     unsigned int constantWidth:1;       /* all character widths are the same*/
  267.     unsigned int inkInside:1;           /* all ink inside character cell */
  268.     unsigned int inkMetrics:1;          /* font has ink metrics */
  269.     unsigned int allExist:1;            /* no missing chars in range */
  270.     unsigned int drawDirection:2;       /* left-to-right/right-to-left*/
  271.     unsigned int cachable:1;            /* font needn't be opened each time*/
  272.     unsigned int anamorphic:1;          /* font is strangely scaled */
  273.     short       maxOverlap;             /* maximum overlap amount */
  274.     short       pad;                    /* unused */
  275.     xCharInfo   maxbounds;              /* glyph metrics maximums */
  276.     xCharInfo   minbounds;              /* glyph metrics minimums */
  277.     xCharInfo   ink_maxbounds;          /* ink metrics maximums */
  278.     xCharInfo   ink_minbounds;          /* ink metrics minimums */
  279.     short       fontAscent;             /* font ascent amount */
  280.     short       fontDescent;            /* font descent amount */
  281.     int         nprops;                 /* number of font properties */
  282.     FontPropPtr props;                  /* font properties */
  283.     char       *isStringProp;           /* boolean array */
  284. }           FontInfoRec, *FontInfoPtr;
  285. .Ce
  286. .LP
  287. The font structure, then, contains a font info record, the format of the
  288. bits in each bitmap and the functions which access the font records (which
  289. are stored in an opaque format hung off of fontPrivate).
  290. .Cs
  291. typedef struct _Font {
  292.     int         refcnt;
  293.     FontInfoRec info;
  294.     char        bit;                    /* bit order: LSBFirst/MSBFirst */
  295.     char        byte;                   /* byte order: LSBFirst/MSBFirst */
  296.     char        glyph;                  /* glyph pad: 1, 2, 4 or 8 */
  297.     char        scan;                   /* glyph scan unit: 1, 2 or 4 */
  298.     fsBitmapFormat format;              /* FS-style format (packed) */
  299.     int         (*get_glyphs) ( /* font, count, chars, encoding, count, glyphs */ );
  300.     int         (*get_metrics) ( /* font, count, chars, encoding, count, glyphs */ );
  301.     int         (*get_bitmaps) (/* client, font, flags, format,
  302.                                    flags, nranges, ranges, data_sizep,
  303.                                    num_glyphsp, offsetsp, glyph_datap,
  304.                                    free_datap */ );
  305.     int         (*get_extents) (/* client, font, flags, nranges,
  306.                                     ranges, nextentsp, extentsp */);
  307.     void        (*unload_font) ( /* font */ );
  308.     FontPathElementPtr fpe;             /* FPE associated with this font */
  309.     pointer     svrPrivate;             /* X/FS private data */
  310.     pointer     fontPrivate;            /* private to font */
  311.     pointer     fpePrivate;             /* private to FPE */
  312.     int         maxPrivate;             /* devPrivates (see below) */
  313.     pointer     *devPrivates;           /*  ... */
  314. }           FontRec, *FontPtr;
  315. .Ce
  316. .LP
  317. Yes, there are several different private pointers in the Font structure; they
  318. were added haphazardly until the devPrivate pointers were added.  Future
  319. releases may remove some (or all) of the specific pointers, leaving only the
  320. devPrivates mechanism.
  321. .LP
  322. There are two similar interfaces implemented - get_glyphs/get_metrics and
  323. get_bitmaps/get_extents.  Too little time caused the font-server specific
  324. interfaces to be placed in the font library (and portions duplicated in each
  325. renderer) instead of having them integrated into the font server itself.
  326. This may change.  The X server uses only get_glyphs/get_metrics, and those
  327. will not change dramatically.  Each of the routines is described below
  328. .NH 2
  329. (*get_glyphs)
  330. .LP
  331. This routine returns CharInfoPtrs for each of the requested characters in
  332. the font.  If the character does not exist in the font, the default
  333. character will be returned, unless no default character exists in which case
  334. that character is skipped.  Thus, the number of glyphs returned will not
  335. always be the same as the number of characters passed in.
  336. .NH 2
  337. (*get_metrics)
  338. .LP
  339. This is similar to (*get_glyphs) except that pointers to xCharInfo
  340. structures are returned, and, if the font has ink metrics, those are
  341. returned instead of the bitmap metrics.
  342. .NH 2
  343. (*get-bitmaps)
  344. .LP
  345. This packs the glyph image data in the requested format and returns it.  The
  346. ranges/nranges argument specify the set of glyphs from the font to pack
  347. together.
  348. .NH 2
  349. (*get_extents)
  350. .LP
  351. This returns the metrics for the specified font from the specified ranges.
  352. .LP
  353. .NH 2
  354. (*unload_font)
  355. .LP
  356. This is called from the FPE routine (*close_font), and so should not ever be
  357. called from the application.
  358.