Xfonts.htm 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Ghostscript's external font and text interface</title>
  5. <!-- $Id: Xfonts.htm,v 1.13.2.2 2002/02/01 05:31:25 raph Exp $ -->
  6. <!-- Originally: xfonts.txt -->
  7. <link rel="stylesheet" type="text/css" href="gs.css" title="Ghostscript Style">
  8. </head>
  9. <body>
  10. <!-- [1.0 begin visible header] ============================================ -->
  11. <!-- [1.1 begin headline] ================================================== -->
  12. <h1>Ghostscript's external font and text interface</h1>
  13. <!-- [1.1 end headline] ==================================================== -->
  14. <!-- [1.2 begin table of contents] ========================================= -->
  15. <h2>Table of contents</h2>
  16. <blockquote><ul>
  17. <li><a href="#Introduction">Introduction</a>
  18. <li><a href="#Types">Types</a>
  19. <li><a href="#Implementation_procedures">Implementation procedures</a>
  20. <li><a href="#Font_level_procedures">Font-level procedures</a>
  21. <ul>
  22. <li><a href="#lookup_font"><b><tt>lookup_font</tt></b></a>
  23. <li><a href="#char_xglyph"><b><tt>char_xglyph</tt></b></a>
  24. <li><a href="#char_metrics"><b><tt>char_metrics</tt></b></a>
  25. <li><a href="#render_char"><b><tt>render_char</tt></b></a>
  26. <li><a href="#release"><b><tt>release</tt></b></a>
  27. </ul>
  28. </ul></blockquote>
  29. <!-- [1.2 end table of contents] =========================================== -->
  30. <!-- [1.3 begin hint] ====================================================== -->
  31. <p>For other information, see the <a href="Readme.htm">Ghostscript
  32. overview</a>.
  33. <!-- [1.3 end hint] ======================================================== -->
  34. <hr>
  35. <!-- [1.0 end visible header] ============================================== -->
  36. <!-- [2.0 begin contents] ================================================== -->
  37. <h2><a name="Introduction"></a>Introduction</h2>
  38. <p>
  39. Ghostscript can use the character rasterizer provided by the underlying
  40. operating system and window system; specifically, Adobe Type Manager (ATM)
  41. or a TrueType rasterizer under MS Windows, or the facilities provided by X
  42. Windows. This ability augments, but does not replace, Ghostscript's own
  43. Type 1 rasterizer: Ghostscript may still use its own rasterizer for very
  44. large characters, characters that are clipped or transformed in unusual
  45. ways, and for output to devices other than the screen.
  46. <p>
  47. Ghostscript connects to these platform facilities through a driver-like
  48. interface called the xfont (external font) interface. Current xfont
  49. implementations are associated directly with device drivers; in a future
  50. release, Ghostscript may separate them, so that (for example) it will be
  51. possible to use the platform rasterizer when writing to a file.
  52. <p>
  53. Please note that from this point, this file is likely to be useful only
  54. to a small number of Ghostscript porters and implementors.
  55. <hr>
  56. <h2><a name="Types"></a>Types</h2>
  57. <table cellpadding=0 cellspacing=0>
  58. <tr> <th valign=bottom align=left>Type
  59. <td>&nbsp;&nbsp;
  60. <th valign=bottom align=left>Declared /<br>defined in
  61. <td>&nbsp;
  62. <th valign=bottom align=left>Represents
  63. <tr> <td colspan=5><hr>
  64. <tr> <td valign=top><b><tt>gs_char</tt></b>
  65. <td>&nbsp;
  66. <td valign=top><b><tt>gsccode.h</tt></b>
  67. <td>&nbsp;
  68. <td valign=top>A character code that appears in a string. Currently
  69. it is always a single byte, but composite fonts or Unicode may
  70. require it to be wider in the future.
  71. <tr> <td valign=top><b><tt>gs_glyph</tt></b>
  72. <td>&nbsp;
  73. <td valign=top><b><tt>gsccode.h</tt></b>
  74. <td>&nbsp;
  75. <td valign=top>A character name like "period" or "epsilon". From
  76. the xfont implementation's point of view, it is just a handle;
  77. when necessary, Ghostscript provides a
  78. <b><tt>gs_proc_glyph_name_t</tt></b> procedure to
  79. convert it to a string name.
  80. <tr> <td valign=top><b><tt>gs_proc_glyph_name_t</tt></b>
  81. <td>&nbsp;
  82. <td valign=top><b><tt>gsccode.h</tt></b>
  83. <td>&nbsp;
  84. <td valign=top>A procedure that maps a <b><tt>gs_glyph</tt></b> to
  85. its string name; see the <b><tt>char_xglyph</tt></b> procedure.
  86. <tr> <td valign=top><b><tt>gx_xglyph</tt></b>
  87. <td>&nbsp;
  88. <td valign=top><b><tt>gsxfont.h</tt></b>
  89. <td>&nbsp;
  90. <td valign=top>A character or glyph code that can be used with a
  91. specific platform font. Normally it will be a character code
  92. that the implementation of <b><tt>render_char</tt></b> will
  93. turn into a 1-character string and give to the platform's
  94. "display string" operation.
  95. <tr> <td valign=top><b><tt>gx_xfont_procs</tt></b>
  96. <td>&nbsp;
  97. <td valign=top><b><tt>gsxfont.h</tt></b>, <b><tt>gxxfont.h</tt></b>
  98. <td>&nbsp;
  99. <td valign=top>The xfont analogue of
  100. <b><tt>gx_device_procs</tt></b>, the type of the
  101. procedure record that defines an xfont implementation.
  102. <tr> <td valign=top><b><tt>gx_xfont</tt></b>
  103. <td>&nbsp;
  104. <td valign=top><b><tt>gsxfont.h</tt></b>, <b><tt>gxxfont.h</tt></b>
  105. <td>&nbsp;
  106. <td valign=top>The gxfont analogue of <b><tt>gx_device</tt></b>,
  107. the type of the basic structure for an xfont.
  108. <tr> <td valign=top>(<b><tt>encoding_index</tt></b>)
  109. <td>&nbsp;
  110. <td>&nbsp;
  111. <td>&nbsp;
  112. <td valign=top>Not really a type, although it probably should be:
  113. an <b><tt>int</tt></b> used to indicate the
  114. <b><tt>Encoding</tt></b> used by a font. Defined values are
  115. <dl compact>
  116. <dt>0<dd><b><tt>StandardEncoding</tt></b>
  117. <dt>1<dd><b><tt>ISOLatin1Encoding</tt></b>
  118. <dt>2<dd><b><tt>SymbolEncoding</tt></b>
  119. <dt>3<dd><b><tt>DingbatsEncoding</tt></b>
  120. <dt>-1<dd>Other encoding
  121. </dl>
  122. </table>
  123. <hr>
  124. <h2><a name="Implementation_procedures"></a>Implementation
  125. procedures</h2>
  126. <p>
  127. All the procedures that return <b><tt>int</tt></b> results return 0 on
  128. success, or an appropriate negative error code for error conditions; these
  129. error codes are defined in <b><tt>gserrors.h</tt></b>. The relevant ones
  130. are the same as for <a href="Drivers.htm">drivers</a>, and as with drivers,
  131. if an implementation procedure returns an error, it should use the
  132. <b><tt>return_error</tt></b> macro -- defined in <b><tt>gx.h</tt></b>,
  133. which is automatically included by <b><tt>gdevprn.h</tt></b> but not by
  134. <b><tt>gserrors.h</tt></b> -- rather than a simple <b><tt>return</tt></b>
  135. statement, for instance
  136. <blockquote>
  137. <b><tt>return_error(gs_error_VMerror);</tt></b>
  138. </blockquote>
  139. <h2><a name="Font_level_procedures"></a>Font-level procedures</h2>
  140. <h3><a name="lookup_font"></a><b><tt>lookup_font</tt></b></h3>
  141. <dl>
  142. <dt><b><tt>gx_xfont *(*lookup_font)(P7(gx_device&nbsp;*dev,
  143. const&nbsp;byte&nbsp;*fname, uint&nbsp;len, int&nbsp;encoding_index,
  144. const&nbsp;gs_uid&nbsp;*puid, const&nbsp;gs_matrix&nbsp;*pmat,
  145. const&nbsp;gs_memory_procs&nbsp;*mprocs))</tt></b>
  146. <dd>Look up a font name, <b><tt>UniqueID</tt></b>, and matrix, and return
  147. an xfont, or <b><tt>NULL</tt></b> if no suitable xfont exists. Use
  148. <b><tt>mprocs</tt></b> to allocate the xfont and any subsidiary data
  149. structures. The matrix is the <b><tt>FontMatrix</tt></b> concatenated with
  150. the CTM, so (roughly speaking) the font size in pixels is
  151. <b><tt>pmat&nbsp;-&gt;&nbsp;yy</tt></b>&nbsp;&times;&nbsp;1000 for a normal
  152. Type 1 font.
  153. <p>
  154. Note that this is the only implementation procedure that does not take an
  155. xfont * as its first argument. In fact, callers of
  156. <b><tt>lookup_font</tt></b> must use the <b><tt>get_xfont_device</tt></b>
  157. driver procedure to get the correct device to pass as the first argument to
  158. <b><tt>lookup_font</tt></b>.
  159. </dl>
  160. <h3><a name="char_xglyph"></a><b><tt>char_xglyph</tt></b></h3>
  161. <dl>
  162. <dt><b><tt>gx_xglyph (*char_xglyph)(P5(gx_xfont&nbsp;*xf, gs_char&nbsp;chr,
  163. int&nbsp;encoding_index, gs_glyph&nbsp;glyph,
  164. gs_proc_glyph_name_t&nbsp;glyph_name))</tt></b>
  165. <dd>Convert a character name to an xglyph code. In the case of
  166. <b><tt>glyphshow</tt></b>, <b><tt>chr</tt></b> may be
  167. <b><tt>gs_no_char</tt></b>; for an ordinary <b><tt>show</tt></b> operation,
  168. if the character code is invalid, <b><tt>glyph</tt></b> may be
  169. <b><tt>gs_no_glyph</tt></b>.
  170. </dl>
  171. <h3><a name="char_metrics"></a><b><tt>char_metrics</tt></b></h3>
  172. <dl>
  173. <dt><b><tt>int (*char_metrics)(P5(gx_xfont&nbsp;*xf, gx_xglyph&nbsp;xg,
  174. int&nbsp;wmode, gs_int_point&nbsp;*pwidth,
  175. gs_int_rect&nbsp;*pbbox))</tt></b>
  176. <dd>Get the metrics for a character. If the metrics are unavailable,
  177. return 1.
  178. </dl>
  179. <h3><a name="render_char"></a><b><tt>render_char</tt></b></h3>
  180. <dl>
  181. <dt><b><tt>int (*render_char)(P7(gx_xfont&nbsp;*xf, gx_xglyph&nbsp;xg,
  182. gx_device&nbsp;*target, int&nbsp;x, int&nbsp;y, gx_color_index&nbsp;color,
  183. int&nbsp;required))</tt></b>
  184. <dd>Render a character. <em>(x,y)</em> corresponds to the character
  185. origin. The target may be any Ghostscript device. A good implementation
  186. will check whether the target can handle this type of xfont directly (for
  187. instance by checking the target name), and if so, will render the character
  188. directly; otherwise, it will do what has to be done in the general case,
  189. namely, get a bitmap for the character and use the target's
  190. <b><tt>copy_mono</tt></b> operation. If <b><tt>required</tt></b> is false,
  191. the procedure should return an error if the rendering operation would be
  192. expensive, since in this case Ghostscript has already cached the bitmap and
  193. metrics from a previous call with <b><tt>required</tt></b>=true. If the
  194. operation cannot be done, return 1.
  195. </dl>
  196. <h3><a name="release"></a><b><tt>release</tt></b></h3>
  197. <dl>
  198. <dt><b><tt>int (*release)(P2(gx_xfont&nbsp;*xf,
  199. const&nbsp;gs_memory_procs&nbsp;*mprocs))</tt></b>
  200. <dd>Release any external resources associated with an xfont. If
  201. <b><tt>mprocs</tt></b> is not <b><tt>NULL</tt></b>, also free any storage
  202. allocated by <b><tt>lookup_font</tt></b> (including the xfont itself).
  203. </dl>
  204. <!-- [2.0 end contents] ==================================================== -->
  205. <!-- [3.0 begin visible trailer] =========================================== -->
  206. <hr>
  207. <p>
  208. <small>Copyright &copy; 1996, 1997, 1998 Aladdin Enterprises. All
  209. rights reserved.</small>
  210. <p>
  211. <small>This file is part of AFPL Ghostscript. See the
  212. <a href="Public.htm">Aladdin Free Public License</a> (the "License") for
  213. full details of the terms of using, copying, modifying, and redistributing
  214. AFPL Ghostscript.</small>
  215. <p>
  216. <small>Ghostscript version 7.04, 31 January 2002
  217. <!-- [3.0 end visible trailer] ============================================= -->
  218. </body>
  219. </html>