xref: /plan9-contrib/sys/src/cmd/gs/doc/Xfonts.htm (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
13ff48bf5SDavid du Colombier<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
27dd7cddfSDavid du Colombier<html>
37dd7cddfSDavid du Colombier<head>
47dd7cddfSDavid du Colombier<title>Ghostscript's external font and text interface</title>
5*593dc095SDavid du Colombier<!-- $Id: Xfonts.htm,v 1.39 2005/10/20 19:46:23 ray Exp $ -->
67dd7cddfSDavid du Colombier<!-- Originally: xfonts.txt -->
73ff48bf5SDavid du Colombier<link rel="stylesheet" type="text/css" href="gs.css" title="Ghostscript Style">
87dd7cddfSDavid du Colombier</head>
97dd7cddfSDavid du Colombier
107dd7cddfSDavid du Colombier<body>
117dd7cddfSDavid du Colombier<!-- [1.0 begin visible header] ============================================ -->
127dd7cddfSDavid du Colombier
137dd7cddfSDavid du Colombier<!-- [1.1 begin headline] ================================================== -->
147dd7cddfSDavid du Colombier
153ff48bf5SDavid du Colombier<h1>Ghostscript's external font and text interface</h1>
167dd7cddfSDavid du Colombier
177dd7cddfSDavid du Colombier<!-- [1.1 end headline] ==================================================== -->
187dd7cddfSDavid du Colombier
197dd7cddfSDavid du Colombier<!-- [1.2 begin table of contents] ========================================= -->
207dd7cddfSDavid du Colombier
217dd7cddfSDavid du Colombier<h2>Table of contents</h2>
227dd7cddfSDavid du Colombier
237dd7cddfSDavid du Colombier<blockquote><ul>
247dd7cddfSDavid du Colombier<li><a href="#Introduction">Introduction</a>
257dd7cddfSDavid du Colombier<li><a href="#Types">Types</a>
267dd7cddfSDavid du Colombier<li><a href="#Implementation_procedures">Implementation procedures</a>
277dd7cddfSDavid du Colombier<li><a href="#Font_level_procedures">Font-level procedures</a>
287dd7cddfSDavid du Colombier<ul>
297dd7cddfSDavid du Colombier<li><a href="#lookup_font"><b><tt>lookup_font</tt></b></a>
307dd7cddfSDavid du Colombier<li><a href="#char_xglyph"><b><tt>char_xglyph</tt></b></a>
317dd7cddfSDavid du Colombier<li><a href="#char_metrics"><b><tt>char_metrics</tt></b></a>
327dd7cddfSDavid du Colombier<li><a href="#render_char"><b><tt>render_char</tt></b></a>
337dd7cddfSDavid du Colombier<li><a href="#release"><b><tt>release</tt></b></a>
347dd7cddfSDavid du Colombier</ul>
357dd7cddfSDavid du Colombier</ul></blockquote>
367dd7cddfSDavid du Colombier
377dd7cddfSDavid du Colombier<!-- [1.2 end table of contents] =========================================== -->
387dd7cddfSDavid du Colombier
397dd7cddfSDavid du Colombier<!-- [1.3 begin hint] ====================================================== -->
407dd7cddfSDavid du Colombier
417dd7cddfSDavid du Colombier<p>For other information, see the <a href="Readme.htm">Ghostscript
427dd7cddfSDavid du Colombieroverview</a>.
437dd7cddfSDavid du Colombier
447dd7cddfSDavid du Colombier<!-- [1.3 end hint] ======================================================== -->
457dd7cddfSDavid du Colombier
467dd7cddfSDavid du Colombier<hr>
477dd7cddfSDavid du Colombier
487dd7cddfSDavid du Colombier<!-- [1.0 end visible header] ============================================== -->
497dd7cddfSDavid du Colombier
507dd7cddfSDavid du Colombier<!-- [2.0 begin contents] ================================================== -->
517dd7cddfSDavid du Colombier
523ff48bf5SDavid du Colombier<h2><a name="Introduction"></a>Introduction</h2>
537dd7cddfSDavid du Colombier
547dd7cddfSDavid du Colombier<p>
557dd7cddfSDavid du ColombierGhostscript can use the character rasterizer provided by the underlying
567dd7cddfSDavid du Colombieroperating system and window system; specifically, Adobe Type Manager (ATM)
577dd7cddfSDavid du Colombieror a TrueType rasterizer under MS Windows, or the facilities provided by X
587dd7cddfSDavid du ColombierWindows.  This ability augments, but does not replace, Ghostscript's own
597dd7cddfSDavid du ColombierType 1 rasterizer: Ghostscript may still use its own rasterizer for very
607dd7cddfSDavid du Colombierlarge characters, characters that are clipped or transformed in unusual
617dd7cddfSDavid du Colombierways, and for output to devices other than the screen.
627dd7cddfSDavid du Colombier
637dd7cddfSDavid du Colombier<p>
647dd7cddfSDavid du ColombierGhostscript connects to these platform facilities through a driver-like
657dd7cddfSDavid du Colombierinterface called the xfont (external font) interface.  Current xfont
667dd7cddfSDavid du Colombierimplementations are associated directly with device drivers; in a future
677dd7cddfSDavid du Colombierrelease, Ghostscript may separate them, so that (for example) it will be
687dd7cddfSDavid du Colombierpossible to use the platform rasterizer when writing to a file.
697dd7cddfSDavid du Colombier
707dd7cddfSDavid du Colombier<p>
717dd7cddfSDavid du ColombierPlease note that from this point, this file is likely to be useful only
727dd7cddfSDavid du Colombierto a small number of Ghostscript porters and implementors.
737dd7cddfSDavid du Colombier
747dd7cddfSDavid du Colombier<hr>
757dd7cddfSDavid du Colombier
763ff48bf5SDavid du Colombier<h2><a name="Types"></a>Types</h2>
777dd7cddfSDavid du Colombier
787dd7cddfSDavid du Colombier<table cellpadding=0 cellspacing=0>
797dd7cddfSDavid du Colombier<tr>	<th valign=bottom align=left>Type
807dd7cddfSDavid du Colombier	<td>&nbsp;&nbsp;
817dd7cddfSDavid du Colombier	<th valign=bottom align=left>Declared /<br>defined in
827dd7cddfSDavid du Colombier	<td>&nbsp;
837dd7cddfSDavid du Colombier	<th valign=bottom align=left>Represents
847dd7cddfSDavid du Colombier<tr>	<td colspan=5><hr>
857dd7cddfSDavid du Colombier<tr>	<td valign=top><b><tt>gs_char</tt></b>
867dd7cddfSDavid du Colombier	<td>&nbsp;
877dd7cddfSDavid du Colombier	<td valign=top><b><tt>gsccode.h</tt></b>
887dd7cddfSDavid du Colombier	<td>&nbsp;
897dd7cddfSDavid du Colombier	<td valign=top>A character code that appears in a string. Currently
907dd7cddfSDavid du Colombier	    it is always a single byte, but composite fonts or Unicode may
917dd7cddfSDavid du Colombier	    require it to be wider in the future.
927dd7cddfSDavid du Colombier<tr>	<td valign=top><b><tt>gs_glyph</tt></b>
937dd7cddfSDavid du Colombier	<td>&nbsp;
947dd7cddfSDavid du Colombier	<td valign=top><b><tt>gsccode.h</tt></b>
957dd7cddfSDavid du Colombier	<td>&nbsp;
967dd7cddfSDavid du Colombier	<td valign=top>A character name like "period" or "epsilon". From
977dd7cddfSDavid du Colombier	    the xfont implementation's point of view, it is just a handle;
987dd7cddfSDavid du Colombier	    when necessary, Ghostscript provides a
997dd7cddfSDavid du Colombier	    <b><tt>gs_proc_glyph_name_t</tt></b> procedure to
1007dd7cddfSDavid du Colombier	    convert it to a string name.
1017dd7cddfSDavid du Colombier<tr>	<td valign=top><b><tt>gs_proc_glyph_name_t</tt></b>
1027dd7cddfSDavid du Colombier	<td>&nbsp;
1037dd7cddfSDavid du Colombier	<td valign=top><b><tt>gsccode.h</tt></b>
1047dd7cddfSDavid du Colombier	<td>&nbsp;
1057dd7cddfSDavid du Colombier	<td valign=top>A procedure that maps a <b><tt>gs_glyph</tt></b> to
1067dd7cddfSDavid du Colombier	    its string name; see the <b><tt>char_xglyph</tt></b> procedure.
1077dd7cddfSDavid du Colombier<tr>	<td valign=top><b><tt>gx_xglyph</tt></b>
1087dd7cddfSDavid du Colombier	<td>&nbsp;
1097dd7cddfSDavid du Colombier	<td valign=top><b><tt>gsxfont.h</tt></b>
1107dd7cddfSDavid du Colombier	<td>&nbsp;
1117dd7cddfSDavid du Colombier	<td valign=top>A character or glyph code that can be used with a
1127dd7cddfSDavid du Colombier	    specific platform font.  Normally it will be a character code
1137dd7cddfSDavid du Colombier	    that the implementation of <b><tt>render_char</tt></b> will
1147dd7cddfSDavid du Colombier	    turn into a 1-character string and give to the platform's
1157dd7cddfSDavid du Colombier	    "display string" operation.
1167dd7cddfSDavid du Colombier<tr>	<td valign=top><b><tt>gx_xfont_procs</tt></b>
1177dd7cddfSDavid du Colombier	<td>&nbsp;
1187dd7cddfSDavid du Colombier	<td valign=top><b><tt>gsxfont.h</tt></b>, <b><tt>gxxfont.h</tt></b>
1197dd7cddfSDavid du Colombier	<td>&nbsp;
1207dd7cddfSDavid du Colombier	<td valign=top>The xfont analogue of
1217dd7cddfSDavid du Colombier	    <b><tt>gx_device_procs</tt></b>, the type of the
1227dd7cddfSDavid du Colombier	    procedure record that defines an xfont implementation.
1237dd7cddfSDavid du Colombier<tr>	<td valign=top><b><tt>gx_xfont</tt></b>
1247dd7cddfSDavid du Colombier	<td>&nbsp;
1257dd7cddfSDavid du Colombier	<td valign=top><b><tt>gsxfont.h</tt></b>, <b><tt>gxxfont.h</tt></b>
1267dd7cddfSDavid du Colombier	<td>&nbsp;
1277dd7cddfSDavid du Colombier	<td valign=top>The gxfont analogue of <b><tt>gx_device</tt></b>,
1287dd7cddfSDavid du Colombier	    the type of the basic structure for an xfont.
1297dd7cddfSDavid du Colombier<tr>	<td valign=top>(<b><tt>encoding_index</tt></b>)
1307dd7cddfSDavid du Colombier	<td>&nbsp;
1317dd7cddfSDavid du Colombier	<td>&nbsp;
1327dd7cddfSDavid du Colombier	<td>&nbsp;
1337dd7cddfSDavid du Colombier	<td valign=top>Not really a type, although it probably should be:
1347dd7cddfSDavid du Colombier	    an <b><tt>int</tt></b> used to indicate the
1357dd7cddfSDavid du Colombier	    <b><tt>Encoding</tt></b> used by a font.  Defined values are
1367dd7cddfSDavid du Colombier		<dl compact>
1377dd7cddfSDavid du Colombier		<dt>0<dd><b><tt>StandardEncoding</tt></b>
1387dd7cddfSDavid du Colombier		<dt>1<dd><b><tt>ISOLatin1Encoding</tt></b>
1397dd7cddfSDavid du Colombier		<dt>2<dd><b><tt>SymbolEncoding</tt></b>
1407dd7cddfSDavid du Colombier		<dt>3<dd><b><tt>DingbatsEncoding</tt></b>
1417dd7cddfSDavid du Colombier		<dt>-1<dd>Other encoding
1427dd7cddfSDavid du Colombier		</dl>
1437dd7cddfSDavid du Colombier</table>
1447dd7cddfSDavid du Colombier
1457dd7cddfSDavid du Colombier<hr>
1467dd7cddfSDavid du Colombier
1473ff48bf5SDavid du Colombier<h2><a name="Implementation_procedures"></a>Implementation
1483ff48bf5SDavid du Colombierprocedures</h2>
1497dd7cddfSDavid du Colombier
1507dd7cddfSDavid du Colombier<p>
1517dd7cddfSDavid du ColombierAll the procedures that return <b><tt>int</tt></b> results return 0 on
1527dd7cddfSDavid du Colombiersuccess, or an appropriate negative error code for error conditions; these
1537dd7cddfSDavid du Colombiererror codes are defined in <b><tt>gserrors.h</tt></b>.  The relevant ones
1547dd7cddfSDavid du Colombierare the same as for <a href="Drivers.htm">drivers</a>, and as with drivers,
1557dd7cddfSDavid du Colombierif an implementation procedure returns an error, it should use the
1567dd7cddfSDavid du Colombier<b><tt>return_error</tt></b> macro -- defined in <b><tt>gx.h</tt></b>,
1577dd7cddfSDavid du Colombierwhich is automatically included by <b><tt>gdevprn.h</tt></b> but not by
1587dd7cddfSDavid du Colombier<b><tt>gserrors.h</tt></b> -- rather than a simple <b><tt>return</tt></b>
1597dd7cddfSDavid du Colombierstatement, for instance
1607dd7cddfSDavid du Colombier
1617dd7cddfSDavid du Colombier<blockquote>
1627dd7cddfSDavid du Colombier<b><tt>return_error(gs_error_VMerror);</tt></b>
1637dd7cddfSDavid du Colombier</blockquote>
1647dd7cddfSDavid du Colombier
1657dd7cddfSDavid du Colombier<h2><a name="Font_level_procedures"></a>Font-level procedures</h2>
1667dd7cddfSDavid du Colombier
1677dd7cddfSDavid du Colombier<h3><a name="lookup_font"></a><b><tt>lookup_font</tt></b></h3>
1687dd7cddfSDavid du Colombier
1697dd7cddfSDavid du Colombier<dl>
1707dd7cddfSDavid du Colombier<dt><b><tt>gx_xfont *(*lookup_font)(P7(gx_device&nbsp;*dev,
1717dd7cddfSDavid du Colombierconst&nbsp;byte&nbsp;*fname, uint&nbsp;len, int&nbsp;encoding_index,
1727dd7cddfSDavid du Colombierconst&nbsp;gs_uid&nbsp;*puid, const&nbsp;gs_matrix&nbsp;*pmat,
1737dd7cddfSDavid du Colombierconst&nbsp;gs_memory_procs&nbsp;*mprocs))</tt></b>
1747dd7cddfSDavid du Colombier<dd>Look up a font name, <b><tt>UniqueID</tt></b>, and matrix, and return
1757dd7cddfSDavid du Colombieran xfont, or <b><tt>NULL</tt></b> if no suitable xfont exists.  Use
1767dd7cddfSDavid du Colombier<b><tt>mprocs</tt></b> to allocate the xfont and any subsidiary data
1777dd7cddfSDavid du Colombierstructures.  The matrix is the <b><tt>FontMatrix</tt></b> concatenated with
1787dd7cddfSDavid du Colombierthe CTM, so (roughly speaking) the font size in pixels is
1797dd7cddfSDavid du Colombier<b><tt>pmat&nbsp;-&gt;&nbsp;yy</tt></b>&nbsp;&times;&nbsp;1000 for a normal
1807dd7cddfSDavid du ColombierType 1 font.
1817dd7cddfSDavid du Colombier
1827dd7cddfSDavid du Colombier<p>
1837dd7cddfSDavid du ColombierNote that this is the only implementation procedure that does not take an
1847dd7cddfSDavid du Colombierxfont * as its first argument.  In fact, callers of
1857dd7cddfSDavid du Colombier<b><tt>lookup_font</tt></b> must use the <b><tt>get_xfont_device</tt></b>
1867dd7cddfSDavid du Colombierdriver procedure to get the correct device to pass as the first argument to
1877dd7cddfSDavid du Colombier<b><tt>lookup_font</tt></b>.
1887dd7cddfSDavid du Colombier</dl>
1897dd7cddfSDavid du Colombier
1907dd7cddfSDavid du Colombier<h3><a name="char_xglyph"></a><b><tt>char_xglyph</tt></b></h3>
1917dd7cddfSDavid du Colombier
1927dd7cddfSDavid du Colombier<dl>
1937dd7cddfSDavid du Colombier<dt><b><tt>gx_xglyph (*char_xglyph)(P5(gx_xfont&nbsp;*xf, gs_char&nbsp;chr,
1947dd7cddfSDavid du Colombierint&nbsp;encoding_index, gs_glyph&nbsp;glyph,
1957dd7cddfSDavid du Colombiergs_proc_glyph_name_t&nbsp;glyph_name))</tt></b>
1967dd7cddfSDavid du Colombier<dd>Convert a character name to an xglyph code.  In the case of
1977dd7cddfSDavid du Colombier<b><tt>glyphshow</tt></b>, <b><tt>chr</tt></b> may be
1987dd7cddfSDavid du Colombier<b><tt>gs_no_char</tt></b>; for an ordinary <b><tt>show</tt></b> operation,
1997dd7cddfSDavid du Colombierif the character code is invalid, <b><tt>glyph</tt></b> may be
2007dd7cddfSDavid du Colombier<b><tt>gs_no_glyph</tt></b>.
2017dd7cddfSDavid du Colombier</dl>
2027dd7cddfSDavid du Colombier
2037dd7cddfSDavid du Colombier<h3><a name="char_metrics"></a><b><tt>char_metrics</tt></b></h3>
2047dd7cddfSDavid du Colombier
2057dd7cddfSDavid du Colombier<dl>
2067dd7cddfSDavid du Colombier<dt><b><tt>int (*char_metrics)(P5(gx_xfont&nbsp;*xf, gx_xglyph&nbsp;xg,
2077dd7cddfSDavid du Colombierint&nbsp;wmode, gs_int_point&nbsp;*pwidth,
2087dd7cddfSDavid du Colombiergs_int_rect&nbsp;*pbbox))</tt></b>
2097dd7cddfSDavid du Colombier<dd>Get the metrics for a character.  If the metrics are unavailable,
2107dd7cddfSDavid du Colombierreturn 1.
2117dd7cddfSDavid du Colombier</dl>
2127dd7cddfSDavid du Colombier
2137dd7cddfSDavid du Colombier<h3><a name="render_char"></a><b><tt>render_char</tt></b></h3>
2147dd7cddfSDavid du Colombier
2157dd7cddfSDavid du Colombier<dl>
2167dd7cddfSDavid du Colombier<dt><b><tt>int (*render_char)(P7(gx_xfont&nbsp;*xf, gx_xglyph&nbsp;xg,
2177dd7cddfSDavid du Colombiergx_device&nbsp;*target, int&nbsp;x, int&nbsp;y, gx_color_index&nbsp;color,
2187dd7cddfSDavid du Colombierint&nbsp;required))</tt></b>
2197dd7cddfSDavid du Colombier<dd>Render a character.  <em>(x,y)</em> corresponds to the character
2207dd7cddfSDavid du Colombierorigin.  The target may be any Ghostscript device.  A good implementation
2217dd7cddfSDavid du Colombierwill check whether the target can handle this type of xfont directly (for
2227dd7cddfSDavid du Colombierinstance by checking the target name), and if so, will render the character
2237dd7cddfSDavid du Colombierdirectly; otherwise, it will do what has to be done in the general case,
2247dd7cddfSDavid du Colombiernamely, get a bitmap for the character and use the target's
2257dd7cddfSDavid du Colombier<b><tt>copy_mono</tt></b> operation.  If <b><tt>required</tt></b> is false,
2267dd7cddfSDavid du Colombierthe procedure should return an error if the rendering operation would be
2277dd7cddfSDavid du Colombierexpensive, since in this case Ghostscript has already cached the bitmap and
2287dd7cddfSDavid du Colombiermetrics from a previous call with <b><tt>required</tt></b>=true.  If the
2297dd7cddfSDavid du Colombieroperation cannot be done, return 1.
2307dd7cddfSDavid du Colombier</dl>
2317dd7cddfSDavid du Colombier
2327dd7cddfSDavid du Colombier<h3><a name="release"></a><b><tt>release</tt></b></h3>
2337dd7cddfSDavid du Colombier
2347dd7cddfSDavid du Colombier<dl>
2357dd7cddfSDavid du Colombier<dt><b><tt>int (*release)(P2(gx_xfont&nbsp;*xf,
2367dd7cddfSDavid du Colombierconst&nbsp;gs_memory_procs&nbsp;*mprocs))</tt></b>
2377dd7cddfSDavid du Colombier<dd>Release any external resources associated with an xfont.  If
2387dd7cddfSDavid du Colombier<b><tt>mprocs</tt></b> is not <b><tt>NULL</tt></b>, also free any storage
2397dd7cddfSDavid du Colombierallocated by <b><tt>lookup_font</tt></b> (including the xfont itself).
2407dd7cddfSDavid du Colombier</dl>
2417dd7cddfSDavid du Colombier
2427dd7cddfSDavid du Colombier<!-- [2.0 end contents] ==================================================== -->
2437dd7cddfSDavid du Colombier
2447dd7cddfSDavid du Colombier<!-- [3.0 begin visible trailer] =========================================== -->
2457dd7cddfSDavid du Colombier<hr>
2467dd7cddfSDavid du Colombier
2473ff48bf5SDavid du Colombier<p>
2483ff48bf5SDavid du Colombier<small>Copyright &copy; 1996, 1997, 1998 Aladdin Enterprises.  All
2493ff48bf5SDavid du Colombierrights reserved.</small>
2507dd7cddfSDavid du Colombier
2517dd7cddfSDavid du Colombier<p>
252*593dc095SDavid du ColombierThis software is provided AS-IS with no warranty, either express or
253*593dc095SDavid du Colombierimplied.
254*593dc095SDavid du Colombier
255*593dc095SDavid du ColombierThis software is distributed under license and may not be copied,
256*593dc095SDavid du Colombiermodified or distributed except as expressly authorized under the terms
257*593dc095SDavid du Colombierof the license contained in the file LICENSE in this distribution.
258*593dc095SDavid du Colombier
259*593dc095SDavid du ColombierFor more information about licensing, please refer to
260*593dc095SDavid du Colombierhttp://www.ghostscript.com/licensing/. For information on
261*593dc095SDavid du Colombiercommercial licensing, go to http://www.artifex.com/licensing/ or
262*593dc095SDavid du Colombiercontact Artifex Software, Inc., 101 Lucas Valley Road #110,
263*593dc095SDavid du ColombierSan Rafael, CA  94903, U.S.A., +1(415)492-9861.
2647dd7cddfSDavid du Colombier
2653ff48bf5SDavid du Colombier<p>
266*593dc095SDavid du Colombier<small>Ghostscript version 8.53, 20 October 2005
2677dd7cddfSDavid du Colombier
2687dd7cddfSDavid du Colombier<!-- [3.0 end visible trailer] ============================================= -->
2697dd7cddfSDavid du Colombier
2707dd7cddfSDavid du Colombier</body>
2717dd7cddfSDavid du Colombier</html>
272