summaryrefslogtreecommitdiff
path: root/gs/doc/Xfonts.htm
blob: 1371f41be9282f756222ce6f0e46076085aa5761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Ghostscript's external font and text interface</title>
<!-- $Id$ -->
<!-- Originally: xfonts.txt -->
<link rel="stylesheet" type="text/css" href="gs.css" title="Ghostscript Style">
</head>

<body>
<!-- [1.0 begin visible header] ============================================ -->

<!-- [1.1 begin headline] ================================================== -->

<h1>Ghostscript's external font and text interface</h1>

<!-- [1.1 end headline] ==================================================== -->

<!-- [1.2 begin table of contents] ========================================= -->

<h2>Table of contents</h2>

<blockquote><ul>
<li><a href="#Introduction">Introduction</a>
<li><a href="#Types">Types</a>
<li><a href="#Implementation_procedures">Implementation procedures</a>
<li><a href="#Font_level_procedures">Font-level procedures</a>
<ul>
<li><a href="#lookup_font"><b><tt>lookup_font</tt></b></a>
<li><a href="#char_xglyph"><b><tt>char_xglyph</tt></b></a>
<li><a href="#char_metrics"><b><tt>char_metrics</tt></b></a>
<li><a href="#render_char"><b><tt>render_char</tt></b></a>
<li><a href="#release"><b><tt>release</tt></b></a>
</ul>
</ul></blockquote>

<!-- [1.2 end table of contents] =========================================== -->

<!-- [1.3 begin hint] ====================================================== -->

<p>For other information, see the <a href="Readme.htm">Ghostscript
overview</a>.

<!-- [1.3 end hint] ======================================================== -->

<hr>

<!-- [1.0 end visible header] ============================================== -->

<!-- [2.0 begin contents] ================================================== -->

<h2><a name="Introduction"></a>Introduction</h2>

<p>
Ghostscript can use the character rasterizer provided by the underlying
operating system and window system; specifically, Adobe Type Manager (ATM)
or a TrueType rasterizer under MS Windows, or the facilities provided by X
Windows.  This ability augments, but does not replace, Ghostscript's own
Type 1 rasterizer: Ghostscript may still use its own rasterizer for very
large characters, characters that are clipped or transformed in unusual
ways, and for output to devices other than the screen.

<p>
Ghostscript connects to these platform facilities through a driver-like
interface called the xfont (external font) interface.  Current xfont
implementations are associated directly with device drivers; in a future
release, Ghostscript may separate them, so that (for example) it will be
possible to use the platform rasterizer when writing to a file.

<p>
Please note that from this point, this file is likely to be useful only
to a small number of Ghostscript porters and implementors.

<hr>

<h2><a name="Types"></a>Types</h2>

<table cellpadding=0 cellspacing=0>
<tr>	<th valign=bottom align=left>Type
	<td>&nbsp;&nbsp;
	<th valign=bottom align=left>Declared /<br>defined in
	<td>&nbsp;
	<th valign=bottom align=left>Represents
<tr>	<td colspan=5><hr>
<tr>	<td valign=top><b><tt>gs_char</tt></b>
	<td>&nbsp;
	<td valign=top><b><tt>gsccode.h</tt></b>
	<td>&nbsp;
	<td valign=top>A character code that appears in a string. Currently
	    it is always a single byte, but composite fonts or Unicode may
	    require it to be wider in the future.
<tr>	<td valign=top><b><tt>gs_glyph</tt></b>
	<td>&nbsp;
	<td valign=top><b><tt>gsccode.h</tt></b>
	<td>&nbsp;
	<td valign=top>A character name like "period" or "epsilon". From
	    the xfont implementation's point of view, it is just a handle;
	    when necessary, Ghostscript provides a
	    <b><tt>gs_proc_glyph_name_t</tt></b> procedure to
	    convert it to a string name.
<tr>	<td valign=top><b><tt>gs_proc_glyph_name_t</tt></b>
	<td>&nbsp;
	<td valign=top><b><tt>gsccode.h</tt></b>
	<td>&nbsp;
	<td valign=top>A procedure that maps a <b><tt>gs_glyph</tt></b> to
	    its string name; see the <b><tt>char_xglyph</tt></b> procedure.
<tr>	<td valign=top><b><tt>gx_xglyph</tt></b>
	<td>&nbsp;
	<td valign=top><b><tt>gsxfont.h</tt></b>
	<td>&nbsp;
	<td valign=top>A character or glyph code that can be used with a
	    specific platform font.  Normally it will be a character code
	    that the implementation of <b><tt>render_char</tt></b> will
	    turn into a 1-character string and give to the platform's
	    "display string" operation.
<tr>	<td valign=top><b><tt>gx_xfont_procs</tt></b>
	<td>&nbsp;
	<td valign=top><b><tt>gsxfont.h</tt></b>, <b><tt>gxxfont.h</tt></b>
	<td>&nbsp;
	<td valign=top>The xfont analogue of
	    <b><tt>gx_device_procs</tt></b>, the type of the
	    procedure record that defines an xfont implementation.
<tr>	<td valign=top><b><tt>gx_xfont</tt></b>
	<td>&nbsp;
	<td valign=top><b><tt>gsxfont.h</tt></b>, <b><tt>gxxfont.h</tt></b>
	<td>&nbsp;
	<td valign=top>The gxfont analogue of <b><tt>gx_device</tt></b>,
	    the type of the basic structure for an xfont.
<tr>	<td valign=top>(<b><tt>encoding_index</tt></b>)
	<td>&nbsp;
	<td>&nbsp;
	<td>&nbsp;
	<td valign=top>Not really a type, although it probably should be:
	    an <b><tt>int</tt></b> used to indicate the
	    <b><tt>Encoding</tt></b> used by a font.  Defined values are
		<dl compact>
		<dt>0<dd><b><tt>StandardEncoding</tt></b>
		<dt>1<dd><b><tt>ISOLatin1Encoding</tt></b>
		<dt>2<dd><b><tt>SymbolEncoding</tt></b>
		<dt>3<dd><b><tt>DingbatsEncoding</tt></b>
		<dt>-1<dd>Other encoding
		</dl>
</table>

<hr>

<h2><a name="Implementation_procedures"></a>Implementation
procedures</h2>

<p>
All the procedures that return <b><tt>int</tt></b> results return 0 on
success, or an appropriate negative error code for error conditions; these
error codes are defined in <b><tt>gserrors.h</tt></b>.  The relevant ones
are the same as for <a href="Drivers.htm">drivers</a>, and as with drivers,
if an implementation procedure returns an error, it should use the
<b><tt>return_error</tt></b> macro -- defined in <b><tt>gx.h</tt></b>,
which is automatically included by <b><tt>gdevprn.h</tt></b> but not by
<b><tt>gserrors.h</tt></b> -- rather than a simple <b><tt>return</tt></b>
statement, for instance

<blockquote>
<b><tt>return_error(gs_error_VMerror);</tt></b>
</blockquote>

<h2><a name="Font_level_procedures"></a>Font-level procedures</h2>

<h3><a name="lookup_font"></a><b><tt>lookup_font</tt></b></h3>

<dl>
<dt><b><tt>gx_xfont *(*lookup_font)(P7(gx_device&nbsp;*dev,
const&nbsp;byte&nbsp;*fname, uint&nbsp;len, int&nbsp;encoding_index,
const&nbsp;gs_uid&nbsp;*puid, const&nbsp;gs_matrix&nbsp;*pmat,
const&nbsp;gs_memory_procs&nbsp;*mprocs))</tt></b>
<dd>Look up a font name, <b><tt>UniqueID</tt></b>, and matrix, and return
an xfont, or <b><tt>NULL</tt></b> if no suitable xfont exists.  Use
<b><tt>mprocs</tt></b> to allocate the xfont and any subsidiary data
structures.  The matrix is the <b><tt>FontMatrix</tt></b> concatenated with
the CTM, so (roughly speaking) the font size in pixels is
<b><tt>pmat&nbsp;-&gt;&nbsp;yy</tt></b>&nbsp;&times;&nbsp;1000 for a normal
Type 1 font.

<p>
Note that this is the only implementation procedure that does not take an
xfont * as its first argument.  In fact, callers of
<b><tt>lookup_font</tt></b> must use the <b><tt>get_xfont_device</tt></b>
driver procedure to get the correct device to pass as the first argument to
<b><tt>lookup_font</tt></b>.
</dl>

<h3><a name="char_xglyph"></a><b><tt>char_xglyph</tt></b></h3>

<dl>
<dt><b><tt>gx_xglyph (*char_xglyph)(P5(gx_xfont&nbsp;*xf, gs_char&nbsp;chr,
int&nbsp;encoding_index, gs_glyph&nbsp;glyph,
gs_proc_glyph_name_t&nbsp;glyph_name))</tt></b>
<dd>Convert a character name to an xglyph code.  In the case of
<b><tt>glyphshow</tt></b>, <b><tt>chr</tt></b> may be
<b><tt>gs_no_char</tt></b>; for an ordinary <b><tt>show</tt></b> operation,
if the character code is invalid, <b><tt>glyph</tt></b> may be
<b><tt>gs_no_glyph</tt></b>.
</dl>

<h3><a name="char_metrics"></a><b><tt>char_metrics</tt></b></h3>

<dl>
<dt><b><tt>int (*char_metrics)(P5(gx_xfont&nbsp;*xf, gx_xglyph&nbsp;xg,
int&nbsp;wmode, gs_int_point&nbsp;*pwidth,
gs_int_rect&nbsp;*pbbox))</tt></b>
<dd>Get the metrics for a character.  If the metrics are unavailable,
return 1.
</dl>

<h3><a name="render_char"></a><b><tt>render_char</tt></b></h3>

<dl>
<dt><b><tt>int (*render_char)(P7(gx_xfont&nbsp;*xf, gx_xglyph&nbsp;xg,
gx_device&nbsp;*target, int&nbsp;x, int&nbsp;y, gx_color_index&nbsp;color,
int&nbsp;required))</tt></b>
<dd>Render a character.  <em>(x,y)</em> corresponds to the character
origin.  The target may be any Ghostscript device.  A good implementation
will check whether the target can handle this type of xfont directly (for
instance by checking the target name), and if so, will render the character
directly; otherwise, it will do what has to be done in the general case,
namely, get a bitmap for the character and use the target's
<b><tt>copy_mono</tt></b> operation.  If <b><tt>required</tt></b> is false,
the procedure should return an error if the rendering operation would be
expensive, since in this case Ghostscript has already cached the bitmap and
metrics from a previous call with <b><tt>required</tt></b>=true.  If the
operation cannot be done, return 1.
</dl>

<h3><a name="release"></a><b><tt>release</tt></b></h3>

<dl>
<dt><b><tt>int (*release)(P2(gx_xfont&nbsp;*xf,
const&nbsp;gs_memory_procs&nbsp;*mprocs))</tt></b>
<dd>Release any external resources associated with an xfont.  If
<b><tt>mprocs</tt></b> is not <b><tt>NULL</tt></b>, also free any storage
allocated by <b><tt>lookup_font</tt></b> (including the xfont itself).
</dl>

<!-- [2.0 end contents] ==================================================== -->

<!-- [3.0 begin visible trailer] =========================================== -->
<hr>

<p>
<small>Copyright &copy; 1996, 1997, 1998 Aladdin Enterprises.  All
rights reserved.</small>

<p>
<small>This file is part of AFPL Ghostscript.  See the
<a href="Public.htm">Aladdin Free Public License</a> (the "License") for
full details of the terms of using, copying, modifying, and redistributing
AFPL Ghostscript.</small>

<p>
<small>Ghostscript version 7.03, 20 October 2001

<!-- [3.0 end visible trailer] ============================================= -->

</body>
</html>