1b3062210Smrg<?xml version="1.0" encoding="UTF-8" ?>
241c30155Smrg<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
341c30155Smrg            "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
441c30155Smrg[
541c30155Smrg<!ENTITY % defs SYSTEM "defs.ent"> %defs;
641c30155Smrg]>
7b3062210Smrg<!-- lifted from troff+ms by doclifter -->
8b3062210Smrg<!-- previous version was in xorg-docs/specs/Xserver/fontlib.ms -->
9b3062210Smrg
1041c30155Smrg  <article id='fontlib'>
11b3062210Smrg<!-- .ps 12 -->
12b3062210Smrg<!-- .EF 'Font Library Interface'\- % \-'July 27, 1991' -->
13b3062210Smrg<!-- .OF 'Font Library Interface'\- % \-'July 27, 1991' -->
14b3062210Smrg<!-- .EH '''' -->
15b3062210Smrg<!-- .OH '''' -->
16b3062210Smrg<!-- body begins here -->
17b3062210Smrg    <articleinfo>
18b3062210Smrg      <title>
19b3062210Smrg	The X Font Library
20b3062210Smrg      </title>
21b3062210Smrg      <authorgroup>
22b3062210Smrg	<author>
23b3062210Smrg	  <firstname>Keith</firstname>
24b3062210Smrg	  <surname>Packard</surname>
25b3062210Smrg	  <affiliation>
26b3062210Smrg	    <orgname>MIT X Consortium</orgname>
27b3062210Smrg	  </affiliation>
28b3062210Smrg	</author>
29b3062210Smrg	<author>
30b3062210Smrg	  <firstname>David</firstname>
31b3062210Smrg	  <surname>Lemke</surname>
32b3062210Smrg	  <affiliation>
33b3062210Smrg	    <orgname>Network Computing Devices</orgname>
34b3062210Smrg	  </affiliation>
35b3062210Smrg	</author>
36b3062210Smrg      </authorgroup>
3741c30155Smrg      <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo>
3841c30155Smrg      <copyright><year>1993</year><holder>Network Computing Devices</holder></copyright>
3941c30155Smrg
40b3062210Smrg      <legalnotice>
41b3062210Smrg	<para>
42b3062210Smrg	  Permission to use, copy, modify, distribute, and sell this
43b3062210Smrg	  software and its documentation for any purpose is hereby
44b3062210Smrg	  granted without fee, provided that the above copyright
45b3062210Smrg	  notice appear in all copies and that both that copyright
46b3062210Smrg	  notice and this permission notice appear in supporting
47b3062210Smrg	  documentation, and that the name of Network Computing
48b3062210Smrg	  Devices not be used in advertising or publicity pertaining
49b3062210Smrg	  to distribution of the software without specific, written
50b3062210Smrg	  prior permission.  Network Computing Devices makes no
51b3062210Smrg	  representations about the suitability of this software for
52b3062210Smrg	  any purpose.  It is provided &ldquo;as is&rdquo; without
53b3062210Smrg	  express or implied warranty.
54b3062210Smrg	</para>
5541c30155Smrg	<para role="multiLicensing">
5641c30155Smrg	  Copyright &copy; 1993, 1994 X Consortium
57b3062210Smrg	</para>
58b3062210Smrg	<para>
59b3062210Smrg	  Permission is hereby granted, free of charge, to any person
60b3062210Smrg	  obtaining a copy of this software and associated
61b3062210Smrg	  documentation files (the &ldquo;Software&rdquo;), to deal in the
62b3062210Smrg	  Software without restriction, including without limitation
63b3062210Smrg	  the rights to use, copy, modify, merge, publish, distribute,
64b3062210Smrg	  sublicense, and/or sell copies of the Software, and to
65b3062210Smrg	  permit persons to whom the Software is furnished to do so,
66b3062210Smrg	  subject to the following conditions:
67b3062210Smrg	</para><para>
68b3062210Smrg	  The above copyright notice and this permission notice shall be
69b3062210Smrg	  included in all copies or substantial portions of the Software.
70b3062210Smrg	</para><para>
71b3062210Smrg	  THE SOFTWARE IS PROVIDED &ldquo;AS IS&rdquo;, WITHOUT WARRANTY
72b3062210Smrg	  OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
73b3062210Smrg	  THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
74b3062210Smrg	  PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE X
75b3062210Smrg	  CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
76b3062210Smrg	  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
77b3062210Smrg	  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
78b3062210Smrg	  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
79b3062210Smrg	</para><para>
80b3062210Smrg	  Except as contained in this notice, the name of the X
81b3062210Smrg	  Consortium shall not be used in advertising or otherwise to
82b3062210Smrg	  promote the sale, use or other dealings in this Software
83b3062210Smrg	  without prior written authorization from the X Consortium.
84b3062210Smrg	</para>
8541c30155Smrg        <para>X Window System is a trademark of The Open Group.</para>
86b3062210Smrg      </legalnotice>
8741c30155Smrg      <pubdate>July 27, 1991</pubdate>
88b3062210Smrg    </articleinfo>
89b3062210Smrg
90b3062210Smrg    <warning>
91b3062210Smrg      <para>
92b3062210Smrg	This document has not been updated since X11R6, and is likely
93b3062210Smrg	to be somewhat out of date for the current libXfont.
94b3062210Smrg      </para>
95b3062210Smrg    </warning>
96b3062210Smrg
97b3062210Smrg    <para>
98b3062210Smrg      This document describes the data structures and interfaces for
99b3062210Smrg      using the X Font library.  It is intended as a reference for
100b3062210Smrg      programmers building X and Font servers.  You may want to refer
101b3062210Smrg      to the following documents:
102b3062210Smrg    </para>
103b3062210Smrg
104b3062210Smrg    <itemizedlist>
105b3062210Smrg      <listitem>
106b3062210Smrg	<para>
107b3062210Smrg	  <citetitle pubwork="article">Definition of the Porting Layer for
108b3062210Smrg	    the X v11 Sample Server</citetitle> for a discussion on how this
109b3062210Smrg	  library interacts with the X server
110b3062210Smrg	</para>
111b3062210Smrg      </listitem>
112b3062210Smrg      <listitem>
113b3062210Smrg	<para>
114b43acbb4Smrg	  <olink targetdoc='xfs-design' targetptr='xfs-design'>
115b3062210Smrg	  <citetitle pubwork="article">Font Server Implementation
116b43acbb4Smrg	    Overview</citetitle></olink> which discusses the design of the font
117b3062210Smrg	  server.
118b3062210Smrg	</para>
119b3062210Smrg      </listitem>
120b3062210Smrg      <listitem>
121b3062210Smrg	<para>
122b3062210Smrg	  <citetitle pubwork="article">Bitmap Distribution Format</citetitle>
123b3062210Smrg	  which covers the contents of the bitmap font files which this
124b3062210Smrg	  library reads; although the library is capable of reading other
125b3062210Smrg	  formats as well, including non-bitmap fonts.
126b3062210Smrg	</para>
127b3062210Smrg      </listitem>
128b3062210Smrg      <listitem>
129b3062210Smrg	<para>
130b43acbb4Smrg	  <olink targetdoc='fsproto' targetptr='fsproto'>
131b3062210Smrg	  <citetitle pubwork="article">The X Font Service Protocol</citetitle>
132b43acbb4Smrg	  </olink>
133b3062210Smrg	  for a description of the constraints placed  on the design by
134b3062210Smrg	  including support for this font service mechanism.
135b3062210Smrg	</para>
136b3062210Smrg      </listitem>
137b3062210Smrg    </itemizedlist>
138b3062210Smrg
139b3062210Smrg    <para>
140b3062210Smrg      This document assumes the reader is familiar with the X server design,
141b3062210Smrg      the X protocol as it relates to fonts and the C programming language.
142b3062210Smrg      As with most MIT produced documentation, this relies heavily on the
143b3062210Smrg      source code, so have a listing handy.
144b3062210Smrg    </para>
145b3062210Smrg
14641c30155Smrg    <sect1 id='Requirements_for_the_Font_library'>
14741c30155Smrg<title>Requirements for the Font library</title>
148b3062210Smrg
149b3062210Smrg      <para>
150b3062210Smrg	To avoid miles of duplicate code in the X server, the font server
151b3062210Smrg	and the various font manipulation tools, the font library should
152b3062210Smrg	provide interfaces appropriate for all of these	tasks.  In
153b3062210Smrg	particular, the X server and font server should be able to both
154b3062210Smrg	use the library to access disk based fonts, and	to communicate
155b3062210Smrg	with a font server.  By providing a general library, we hoped to
156b3062210Smrg	avoid duplicating code between the X server and font server.
157b3062210Smrg      </para>
158b3062210Smrg
159b3062210Smrg      <para>
160b3062210Smrg	Another requirement is that the X server (or even a font server)
161b3062210Smrg	be able to continue servicing requests from other clients while
162b3062210Smrg	awaiting a response from the font server on behalf of one client.
163b3062210Smrg	This is the strongest requirement placed on the	font library, and
164b3062210Smrg	has warped the design in curious ways.	Because both the X server
165b3062210Smrg	and font server are single threaded, the font library must not
166b3062210Smrg	suspend internally, rather it returns an indication of suspension
167b3062210Smrg	to the application which continues processing other things, until
168b3062210Smrg	the font data is ready, at which time it restarts the suspended
169b3062210Smrg	request.
170b3062210Smrg      </para>
171b3062210Smrg
172b3062210Smrg      <para>
173b3062210Smrg	Because the code for reading and manipulating bitmap font data is
174b3062210Smrg	used by the font applications <command>mkfontdir</command> and
175b3062210Smrg	<command>bdftopcf</command>, the font library includes
176b3062210Smrg	bitmap-font specific interfaces which those applications use,
177b3062210Smrg	instead of the more general interfaces used by the X and font
178b3062210Smrg	servers, which are unaware of the source of the font data.
179b3062210Smrg	These routines will be refered to as the bitmap font access
180b3062210Smrg	methods.
181b3062210Smrg      </para>
182b3062210Smrg
183b3062210Smrg    </sect1>
184b3062210Smrg
18541c30155Smrg    <sect1 id='General_Font_Library_Interface_details'>
18641c30155Smrg<title>General Font Library Interface details.</title>
187b3062210Smrg
188b3062210Smrg      <para>
189b3062210Smrg	To avoid collision between the #define name space for errors, the Font
190b3062210Smrg	library defines a new set of return values:
191b3062210Smrg      </para>
192b3062210Smrg
193b3062210Smrg      <programlisting remap='.nf'>
194b3062210Smrg#define AllocError      80
195b3062210Smrg#define StillWorking    81
196b3062210Smrg#define FontNameAlias   82
197b3062210Smrg#define BadFontName     83
198b3062210Smrg#define Suspended       84
199b3062210Smrg#define Successful      85
200b3062210Smrg#define BadFontPath     86
201b3062210Smrg#define BadCharRange    87
202b3062210Smrg#define BadFontFormat   88
203b3062210Smrg#define FPEResetFailed  89
204b3062210Smrg      </programlisting> <!-- .fi -->
205b3062210Smrg
206b3062210Smrg      <para>
207b3062210Smrg	Whenever a routine returns <errorname>Suspended</errorname>,
208b3062210Smrg	the font library will notify the caller (via the ClientSignal
209b3062210Smrg	interface described below) who should then reinvoke the same routine
210b3062210Smrg	again with the same arguments.
211b3062210Smrg      </para>
212b3062210Smrg
213b3062210Smrg    </sect1>
214b3062210Smrg
21541c30155Smrg    <sect1 id='Font_Path_Elements'>
21641c30155Smrg<title>Font Path Elements</title>
217b3062210Smrg
218b3062210Smrg      <para>
219b3062210Smrg	At the center of the general font access methods used by X and
220b3062210Smrg	<command>xfs</command> is the Font Path Element data structure.
221b3062210Smrg	Like most structures in the X server, this contains a collection
222b3062210Smrg	of data and some function pointers for manipulating this data:
223b3062210Smrg      </para>
224b3062210Smrg
225b3062210Smrg      <programlisting remap='.nf'>
226b3062210Smrg/* External view of font paths */
227b3062210Smrgtypedef struct _FontPathElement {
228b3062210Smrg    int         name_length;
229b3062210Smrg    char       *name;
230b3062210Smrg    int         type;
231b3062210Smrg    int         refcount;
232b3062210Smrg    pointer     private;
233b3062210Smrg} FontPathElementRec, *FontPathElementPtr;
234b3062210Smrg
235b3062210Smrgtypedef struct _FPEFunctions {
236b3062210Smrg    int         (*name_check) ( /* name */ );
237b3062210Smrg    int         (*init_fpe) ( /* fpe */ );
238b3062210Smrg    int         (*reset_fpe) ( /* fpe */ );
239b3062210Smrg    int         (*free_fpe) ( /* fpe */ );
240b3062210Smrg    int         (*open_font) (  /* client, fpe, flags,
241b3062210Smrg                        name, namelen, format,
242b3062210Smrg                        fid,  ppfont, alias */ );
243b3062210Smrg    int         (*close_font) ( /* pfont */ );
244b3062210Smrg    int         (*list_fonts) ( /* client, fpe, pattern,
245b3062210Smrg                        patlen, maxnames, paths */ );
246b3062210Smrg    int         (*start_list_fonts_with_info) (
247b3062210Smrg                        /* client, fpe, name, namelen,
248b3062210Smrg                           maxnames, data */ );
249b3062210Smrg    int         (*list_next_font_with_info) (
250b3062210Smrg                        /* client, fpe, name, namelen,
251b3062210Smrg                           info, num, data */ );
252b3062210Smrg    int         (*wakeup_fpe) ( /* fpe, mask */ );
253b3062210Smrg    int         (*client_died) ( /* client, fpe */ );
254b3062210Smrg} FPEFunctionsRec, FPEFunctions;
255b3062210Smrg      </programlisting> <!-- .fi -->
256b3062210Smrg
257b3062210Smrg      <para>
258b3062210Smrg	The function pointers are split out from the data structure to
259b3062210Smrg	save memory; additionally, this avoids any complications when
260b3062210Smrg	initializing the data structure as there would not be any way
261b3062210Smrg	to discover the appropriate function to	call (a chicken and
262b3062210Smrg	egg problem).
263b3062210Smrg      </para>
264b3062210Smrg
265b3062210Smrg      <para>
266b3062210Smrg	When a font path type is initialized, it passes the function
267b3062210Smrg	pointers to the server which are then stored in an
268b3062210Smrg	<structname>FPEFunctionsRec</structname>. Each function is
269b3062210Smrg	described below in turn.
270b3062210Smrg      </para>
271b3062210Smrg
272b3062210Smrg      <sect2 id='name_check'>
27341c30155Smrg	<title>(*name_check)</title>
274b3062210Smrg
275b3062210Smrg	<para>
276b3062210Smrg	  Each new font path member is passed to this function; if
277b3062210Smrg	  the return value is <errorname>Successful</errorname>, then
278b3062210Smrg	  the FPE recognises the format of the string.  This does not
279b3062210Smrg	  guarantee that the FPE will be able to successfully use this
280b3062210Smrg	  member.  For example, the disk-based font directory file
281b3062210Smrg	  <filename>fonts.dir</filename> may be corrupted, this will
282b3062210Smrg	  not be detected until the font path is initialized.  This
283b3062210Smrg	  routine never returns <errorname>Suspended</errorname>.
284b3062210Smrg	</para>
285b3062210Smrg      </sect2>
286b3062210Smrg
287b3062210Smrg      <sect2 id='init_fpe'>
28841c30155Smrg	<title>(*init_fpe)</title>
289b3062210Smrg
290b3062210Smrg	<para>
291b3062210Smrg	  Initialize a new font path element.  This function prepares
292b3062210Smrg	  a new font path element for other requests: the disk font
293b3062210Smrg	  routine reads the <filename>fonts.dir</filename> and
294b3062210Smrg	  <filename>fonts.alias</filename> files into the internal
295b3062210Smrg	  format, while the font server routine connects to the
296b3062210Smrg	  requested font server and prepares for using it.  This
297b3062210Smrg	  routine returns <errorname>Successful</errorname> if
298b3062210Smrg	  everything went OK, otherwise the return value indicates the
299b3062210Smrg	  source of the problem.  This routine never returns
300b3062210Smrg	  <errorname>Suspended</errorname>.
301b3062210Smrg	</para>
302b3062210Smrg      </sect2>
303b3062210Smrg
304b3062210Smrg      <sect2 id='reset_fpe'>
30541c30155Smrg	<title>(*reset_fpe)</title>
306b3062210Smrg
307b3062210Smrg	<para>
308b3062210Smrg	  When the X font path is reset, and some of the new members
309b3062210Smrg	  are also in the old font path, this function is called to
310b3062210Smrg	  reinitialize those FPEs.  This routine returns
311b3062210Smrg	  <errorname>Successful</errorname> if everything went OK.  It
312b3062210Smrg	  returns <errorname>FPEResetFailed</errorname> if (for some
313b3062210Smrg	  reason) the reset failed, and the caller should remove the
314b3062210Smrg	  old FPE and simply create a new one in its place.  This is
315b3062210Smrg	  used by the disk-based fonts routine as resetting the
316b3062210Smrg	  internal directory structures would be more complicated than
317b3062210Smrg	  simply having destroying the old and creating a new.
318b3062210Smrg	</para>
319b3062210Smrg      </sect2>
320b3062210Smrg
321b3062210Smrg      <sect2 id='free_fpe'>
32241c30155Smrg	<title>(*free_fpe)</title>
323b3062210Smrg
324b3062210Smrg	<para>
325b3062210Smrg	  When the server is finished with an FPE, this function is
326b3062210Smrg	  called to dispose of any internal state.  It should return
327b3062210Smrg	  <errorname>Successful</errorname>, unless something terrible
328b3062210Smrg	  happens.
329b3062210Smrg	</para>
330b3062210Smrg      </sect2>
331b3062210Smrg
332b3062210Smrg      <sect2 id='open_font'>
33341c30155Smrg	<title>(*open_font)</title>
334b3062210Smrg
335b3062210Smrg	<para>
336b3062210Smrg	  This routine requests that a font be opened.  The <parameter
337b3062210Smrg	  class='function'>client</parameter> argument is used by the
338b3062210Smrg	  font library only in connection with suspending/restarting
339b3062210Smrg	  the request.  The <parameter class='function'>flags</parameter>
340b3062210Smrg	  argument specifies some behaviour for the library and can be
341b3062210Smrg	  any of:
342b3062210Smrg	</para>
343b3062210Smrg
344b3062210Smrg	<programlisting remap='.nf'>
345b3062210Smrg/* OpenFont flags */
346b3062210Smrg#define FontLoadInfo    0x0001
347b3062210Smrg#define FontLoadProps   0x0002
348b3062210Smrg#define FontLoadMetrics 0x0004
349b3062210Smrg#define FontLoadBitmaps 0x0008
350b3062210Smrg#define FontLoadAll     0x000f
351b3062210Smrg#define FontOpenSync    0x0010
352b3062210Smrg	</programlisting> <!-- .fi -->
353b3062210Smrg
354b3062210Smrg	<para>
355b3062210Smrg	  The various fields specify which portions of the font should
356b3062210Smrg	  be loaded at this time.  When <constant>FontOpenSync</constant>
357b3062210Smrg	  is specified, this routine will not return until all of the
358b3062210Smrg	  requested portions are loaded.  Otherwise, this routine may
359b3062210Smrg	  return <errorname>Suspended</errorname>.  When the presented
360b3062210Smrg	  font name is actually an alias for some other font name,
361b3062210Smrg	  <errorname>FontNameAlias</errorname> is returned, and the
362b3062210Smrg	  actual font name is stored in the location pointed to by the
363b3062210Smrg	  <parameter class='function'>alias</parameter> argument as a
364b3062210Smrg	  null-terminated string.
365b3062210Smrg	</para>
366b3062210Smrg      </sect2>
367b3062210Smrg
368b3062210Smrg      <sect2 id='close_font'>
36941c30155Smrg	<title>(*close_font)</title>
370b3062210Smrg
371b3062210Smrg	<para>
372b3062210Smrg	  When the server is finished with a font, this routine
373b3062210Smrg	  disposes of any internal state and frees the font data
374b3062210Smrg	  structure.
375b3062210Smrg	</para>
376b3062210Smrg      </sect2>
377b3062210Smrg
378b3062210Smrg      <sect2 id='list_fonts'>
37941c30155Smrg	<title>(*list_fonts)</title>
380b3062210Smrg
381b3062210Smrg	<para>
382b3062210Smrg	  The <parameter class='function'>paths</parameter> argument is
383b3062210Smrg	  a data structure which will be filled with all of the font names
384b3062210Smrg	  from this directory which match the specified
385b3062210Smrg	  <parameter class='function'>pattern</parameter>.  At
386b3062210Smrg	  most <parameter class='function'>maxnames</parameter> will be added.
387b3062210Smrg	  This routine may return <errorname>Suspended</errorname>.
388b3062210Smrg	</para>
389b3062210Smrg      </sect2>
390b3062210Smrg
391b3062210Smrg      <sect2 id='start_list_fonts_with_info'>
39241c30155Smrg	<title>(*start_list_fonts_with_info)</title>
393b3062210Smrg
394b3062210Smrg	<para>
395b3062210Smrg	  This routine sets any internal state for a verbose listing of
396b3062210Smrg	  all fonts matching the specified pattern.  This routine may
397b3062210Smrg	  return <errorname>Suspended</errorname>.
398b3062210Smrg	</para>
399b3062210Smrg      </sect2>
400b3062210Smrg
401b3062210Smrg      <sect2 id='list_next_font_with_info'>
40241c30155Smrg	<title>(*list_next_font_with_info)</title>
403b3062210Smrg
404b3062210Smrg	<para>
405b3062210Smrg	  To avoid storing huge amounts of data, the interface for
406b3062210Smrg	  ListFontsWithInfo allows the server to get one reply at a time
407b3062210Smrg	  and forward that to the client.  When the font name returned
408b3062210Smrg	  is actually an alias for some other font,
409b3062210Smrg	  <errorname>FontNameAlias</errorname> will be returned.  The
410b3062210Smrg	  actual font name is return instead, and the font alias which
411b3062210Smrg	  matched the pattern is returned in the location pointed to by
412b3062210Smrg	  data as a null-terminated string.  The caller can then get the
413b3062210Smrg	  information by recursively listing that font name with a
414b3062210Smrg	  maxnames of 1.  When <errorname>Successful</errorname> is
415b3062210Smrg	  returned, the matching font name is returned, and a
416b3062210Smrg	  FontInfoPtr is stored in the location pointed to by
417b3062210Smrg	  <parameter class='function'>data</parameter>.
418b3062210Smrg	  <parameter class='function'>Data</parameter> must be initialized
419b3062210Smrg	  with a pointer to a FontInfoRec allocated by the caller.  When the
420b3062210Smrg	  pointer pointed to by <parameter class='function'>data</parameter>
421b3062210Smrg	  is not left pointing at that storage, the caller mustn't free the
422b3062210Smrg	  associated property data. This routine may return
423b3062210Smrg	  <errorname>Suspended</errorname>.
424b3062210Smrg	</para>
425b3062210Smrg      </sect2>
426b3062210Smrg
427b3062210Smrg      <sect2 id='wakeup_fpe'>
42841c30155Smrg	<title>(*wakeup_fpe)</title>
429b3062210Smrg
430b3062210Smrg	<para>
431b3062210Smrg	  Whenever an FPE function has returned
432b3062210Smrg	  <errorname>Suspended</errorname>, this routine is called
433b3062210Smrg	  whenever the application wakes up from waiting for input
434b3062210Smrg	  (from <citerefentry><refentrytitle>select</refentrytitle>
435b3062210Smrg	    <manvolnum>2</manvolnum></citerefentry>).  This
436b3062210Smrg	    <parameter class='function'>mask</parameter> argument should be
437b3062210Smrg	    the value returned from <function>select(2)</function>.
438b3062210Smrg	</para>
439b3062210Smrg      </sect2>
440b3062210Smrg
441b3062210Smrg      <sect2 id='client_died'>
44241c30155Smrg	<title>(*client_died)</title>
443b3062210Smrg
444b3062210Smrg	<para>
445b3062210Smrg	  When an FPE function has returned <errorname>Suspended</errorname>
446b3062210Smrg	  and the associated client is being destroyed, this function
447b3062210Smrg	  allows the font library to dispose of any state associated
448b3062210Smrg	  with that client.
449b3062210Smrg	</para>
450b3062210Smrg      </sect2>
451b3062210Smrg    </sect1>
452b3062210Smrg
45341c30155Smrg    <sect1 id='Fonts'>
45441c30155Smrg<title>Fonts</title>
455b3062210Smrg
456b3062210Smrg      <para>
457b3062210Smrg	The data structure which actually contains the font information has
458b3062210Smrg	changed significantly since previous releases; it now attempts to
459b3062210Smrg	hide the actual storage format for the data from the application,
460b3062210Smrg	providing accessor functions to get at the data.  This allows a
461b3062210Smrg	range of internal details for different font sources.  The structure
462b3062210Smrg	is split into two pieces, so that ListFontsWithInfo can share
463b3062210Smrg	information from the font when it has been loaded.  The
464b3062210Smrg	<structname>FontInfo</structname> structure, then, contains only
465b3062210Smrg	information germane to LFWI.
466b3062210Smrg      </para>
467b3062210Smrg
468b3062210Smrg      <programlisting remap='.nf'>
469b3062210Smrgtypedef struct _FontInfo {
470b3062210Smrg    unsigned short firstCol;            /* range of glyphs for this font */
471b3062210Smrg    unsigned short lastCol;
472b3062210Smrg    unsigned short firstRow;
473b3062210Smrg    unsigned short lastRow;
474b3062210Smrg    unsigned short defaultCh;           /* default character index */
475b3062210Smrg    unsigned int noOverlap:1;           /* no combination of glyphs overlap */
476b3062210Smrg    unsigned int terminalFont:1;        /* Character cell font */
477b3062210Smrg    unsigned int constantMetrics:1;     /* all metrics are the same */
478b3062210Smrg    unsigned int constantWidth:1;       /* all character widths are the same*/
479b3062210Smrg    unsigned int inkInside:1;           /* all ink inside character cell */
480b3062210Smrg    unsigned int inkMetrics:1;          /* font has ink metrics */
481b3062210Smrg    unsigned int allExist:1;            /* no missing chars in range */
482b3062210Smrg    unsigned int drawDirection:2;       /* left-to-right/right-to-left*/
483b3062210Smrg    unsigned int cachable:1;            /* font needn't be opened each time*/
484b3062210Smrg    unsigned int anamorphic:1;          /* font is strangely scaled */
485b3062210Smrg    short       maxOverlap;             /* maximum overlap amount */
486b3062210Smrg    short       pad;                    /* unused */
487b3062210Smrg    xCharInfo   maxbounds;              /* glyph metrics maximums */
488b3062210Smrg    xCharInfo   minbounds;              /* glyph metrics minimums */
489b3062210Smrg    xCharInfo   ink_maxbounds;          /* ink metrics maximums */
490b3062210Smrg    xCharInfo   ink_minbounds;          /* ink metrics minimums */
491b3062210Smrg    short       fontAscent;             /* font ascent amount */
492b3062210Smrg    short       fontDescent;            /* font descent amount */
493b3062210Smrg    int         nprops;                 /* number of font properties */
494b3062210Smrg    FontPropPtr props;                  /* font properties */
495b3062210Smrg    char       *isStringProp;           /* boolean array */
496b3062210Smrg}           FontInfoRec, *FontInfoPtr;
497b3062210Smrg      </programlisting> <!-- .fi -->
498b3062210Smrg
499b3062210Smrg      <para>
500b3062210Smrg	The font structure, then, contains a font info record, the format of
501b3062210Smrg	the bits in each bitmap and the functions which access the font
502b3062210Smrg	records (which are stored in an opaque format hung off of
503b3062210Smrg	<structfield>fontPrivate</structfield>).
504b3062210Smrg      </para>
505b3062210Smrg
506b3062210Smrg      <programlisting remap='.nf'>
507b3062210Smrgtypedef struct _Font {
508b3062210Smrg    int         refcnt;
509b3062210Smrg    FontInfoRec info;
510b3062210Smrg    char        bit;                    /* bit order: LSBFirst/MSBFirst */
511b3062210Smrg    char        byte;                   /* byte order: LSBFirst/MSBFirst */
512b3062210Smrg    char        glyph;                  /* glyph pad: 1, 2, 4 or 8 */
513b3062210Smrg    char        scan;                   /* glyph scan unit: 1, 2 or 4 */
514b3062210Smrg    fsBitmapFormat format;              /* FS-style format (packed) */
515b3062210Smrg    int         (*get_glyphs)  ( /* font, count, chars, encoding, count, glyphs */ );
516b3062210Smrg    int         (*get_metrics) ( /* font, count, chars, encoding, count, glyphs */ );
517b3062210Smrg    int         (*get_bitmaps) ( /* client, font, flags, format,
518b3062210Smrg                                    flags, nranges, ranges, data_sizep,
519b3062210Smrg                                    num_glyphsp, offsetsp, glyph_datap,
520b3062210Smrg                                    free_datap */ );
521b3062210Smrg    int         (*get_extents) ( /* client, font, flags, nranges,
522b3062210Smrg                                    ranges, nextentsp, extentsp */);
523b3062210Smrg    void        (*unload_font) ( /* font */ );
524b3062210Smrg    FontPathElementPtr fpe;             /* FPE associated with this font */
525b3062210Smrg    pointer     svrPrivate;             /* X/FS private data */
526b3062210Smrg    pointer     fontPrivate;            /* private to font */
527b3062210Smrg    pointer     fpePrivate;             /* private to FPE */
528b3062210Smrg    int         maxPrivate;             /* devPrivates (see below) */
529b3062210Smrg    pointer     *devPrivates;           /*  ... */
530b3062210Smrg}           FontRec, *FontPtr;
531b3062210Smrg      </programlisting> <!-- .fi -->
532b3062210Smrg
533b3062210Smrg      <para>
534b3062210Smrg	Yes, there are several different private pointers in the
535b3062210Smrg	<structfield>Font</structfield> structure; they were added
536b3062210Smrg	haphazardly until the devPrivate pointers were added.  Future
537b3062210Smrg	releases may remove some (or all) of the specific pointers,
538b3062210Smrg	leaving only the <structfield>devPrivates</structfield>mechanism.
539b3062210Smrg      </para>
540b3062210Smrg
541b3062210Smrg      <para>
542b3062210Smrg	There are two similar interfaces implemented -
543b3062210Smrg	<structfield>get_glyphs</structfield>/<structfield>get_metrics</structfield>
544b3062210Smrg	and
545b3062210Smrg	<structfield>get_bitmaps</structfield>/<structfield>get_extents</structfield>.
546b3062210Smrg	Too little time caused the font-server specific interfaces to
547b3062210Smrg	be placed in the font library (and portions duplicated in each
548b3062210Smrg	renderer) instead of having them integrated into the font server
549b3062210Smrg	itself.  This may change.  The X server uses only
550b3062210Smrg	<structfield>get_glyphs</structfield>/<structfield>get_metrics</structfield>,
551b3062210Smrg	and those will not change dramatically.  Each of the routines
552b3062210Smrg	is described below.
553b3062210Smrg      </para>
554b3062210Smrg
555b3062210Smrg      <sect2 id='get_glyphs'>
55641c30155Smrg	<title>(*get_glyphs)</title>
557b3062210Smrg
558b3062210Smrg	<para>
559b3062210Smrg	  This routine returns <structname>CharInfoPtrs</structname>
560b3062210Smrg	  for each of the requested characters in the font.  If the
561b3062210Smrg	  character does not exist in the font, the default character
562b3062210Smrg	  will be returned, unless no default character exists in
563b3062210Smrg	  which case that character is skipped.  Thus, the number of
564b3062210Smrg	  glyphs returned will not always be the same as the number of
565b3062210Smrg	  characters passed in.
566b3062210Smrg	</para>
567b3062210Smrg      </sect2>
568b3062210Smrg
569b3062210Smrg      <sect2 id='get_metrics'>
57041c30155Smrg	<title>(*get_metrics)</title>
571b3062210Smrg
572b3062210Smrg	<para>
573b3062210Smrg	  This is similar to <structfield>(*get_glyphs)</structfield>
574b3062210Smrg	  except that pointers to <structname>xCharInfo</structname>
575b3062210Smrg	  structures are returned, and, if the font has ink metrics,
576b3062210Smrg	  those are returned instead of the bitmap metrics.
577b3062210Smrg	</para>
578b3062210Smrg      </sect2>
579b3062210Smrg
58041c30155Smrg      <sect2 id='get_bitmaps'>
58141c30155Smrg<title>(*get_bitmaps)</title>
582b3062210Smrg
583b3062210Smrg	<para>
584b3062210Smrg	  This packs the glyph image data in the requested
585b3062210Smrg	  <parameter class='function'>format</parameter> and returns it.  The
586b3062210Smrg	  <parameter class='function'>ranges</parameter>/<parameter class='function'>nranges</parameter>
587b3062210Smrg	  argument specify the set of glyphs from the font to pack together.
588b3062210Smrg	</para>
589b3062210Smrg      </sect2>
590b3062210Smrg
591b3062210Smrg      <sect2 id='get_extents'>
59241c30155Smrg	<title>(*get_extents)</title>
593b3062210Smrg
594b3062210Smrg	<para>
595b3062210Smrg	  This returns the metrics for the specified font from the
596b3062210Smrg	  specified <parameter class='function'>ranges</parameter>.
597b3062210Smrg	</para>
598b3062210Smrg
599b3062210Smrg      </sect2>
600b3062210Smrg
601b3062210Smrg      <sect2 id='unload_font'>
60241c30155Smrg	<title>(*unload_font)</title>
603b3062210Smrg
604b3062210Smrg	<para>
605b3062210Smrg	  This is called from the FPE routine
606b3062210Smrg	  <function>(*close_font)</function>, and so should not ever be
607b3062210Smrg	  called from the application.
608b3062210Smrg	</para>
609b3062210Smrg      </sect2>
610b3062210Smrg
61141c30155Smrg      <sect2 id='maxPrivate'>
61241c30155Smrg<title>maxPrivate</title>
613b3062210Smrg
614b3062210Smrg	<para>
615b3062210Smrg	  When initializing a new font structure,
616b3062210Smrg	  <structfield>maxPrivate</structfield> should be set to -1 so
617b3062210Smrg	  that the <function>FontSetPrivate()</function> macro works
618b3062210Smrg	  properly with an index of 0.  Initializing
619b3062210Smrg	  <structfield>maxPrivate</structfield> to 0 can cause
620b3062210Smrg	  problems if the server tries to set something at index 0.
621b3062210Smrg	</para>
622b3062210Smrg      </sect2>
623b3062210Smrg    </sect1>
624b3062210Smrg  </article>
625