1
/* This file contains the internal _set_font method, which is called when
2
the font_name, font_size, and textangle fields of the current drawing
3
state have been filled in. It retrieves the specified font, and fills
4
in the true_font_name, true_font_size, font_type, typeface_index,
1
/* This file is part of the GNU plotutils package. Copyright (C) 1995,
2
1996, 1997, 1998, 1999, 2000, 2005, Free Software Foundation, Inc.
4
The GNU plotutils package is free software. You may redistribute it
5
and/or modify it under the terms of the GNU General Public License as
6
published by the Free Software foundation; either version 2, or (at your
7
option) any later version.
9
The GNU plotutils package is distributed in the hope that it will be
10
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU General Public License along
15
with the GNU plotutils package; see the file COPYING. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
17
Boston, MA 02110-1301, USA. */
19
/* This file contains the internal _pl_g_set_font method, which is called
20
when the font_name, font_size, and textangle fields of the current
21
drawing state have been filled in. It retrieves the specified font, and
22
fills in the true_font_name, true_font_size, font_type, typeface_index,
5
23
font_index, font_is_iso8858_1, font_ascent, font_descent, and
6
24
font_cap_height fields of the drawing state.
8
_set_font is invoked by _API_alabel() and _API_flabelwidth(), and also
9
by _API_fontname(), _API_fontsize(), and _API_textangle() (only because
10
those three functions in the API must return a font size).
26
_pl_g_set_font is invoked by _API_alabel() and _API_flabelwidth(), and
27
also by _API_fontname(), _API_fontsize(), and _API_textangle() (only
28
because those three functions in the API must return a font size).
12
_set_font does the following, in order:
30
_pl_g_set_font does the following, in order:
14
32
1. If font_name is the name of a supported Hershey font, i.e., one in
15
33
libplot's database, it fills in the fields itself.
17
35
2. If the font name is the name of a supported font of a non-Hershey
18
36
type (i.e. PS/PCL/Stick), it _tentatively_ fills in the fields. If the
19
37
font name doesn't appear in libplot's internal database, it simply sets
20
the font_type to `F_OTHER'.
38
the font_type to `PL_F_OTHER'.
22
40
3a. If the font name isn't the name of a supported Hershey font, it
23
41
invokes the Plotter-specific `retrieve_font' method. In most Plotters
24
this simply returns true, but in principle it may modify the fields
25
arbitrarily, perhaps consult an external database, etc.
42
this simply returns true. (See the stub _pl_g_retrieve_font() below.)
43
But in principle it may modify the fields arbitrarily, perhaps consult
44
an external database, etc.
27
46
3b. If retrieve_font returns false, a default Hershey font is
28
47
substituted, and the fields are filled in. This feature is used e.g. by
40
59
((size)*(drawstate->true_font_size)/(HERSHEY_EM))
42
61
/* forward references */
43
static bool _match_hershey_font ____P((plDrawState *drawstate));
44
static bool _match_ps_font ____P((plDrawState *drawstate));
45
static bool _match_pcl_font ____P((plDrawState *drawstate));
46
static bool _match_stick_font ____P((plDrawState *drawstate, bool have_extra_stick_fonts));
62
static bool _match_hershey_font (plDrawState *drawstate);
63
static bool _match_ps_font (plDrawState *drawstate);
64
static bool _match_pcl_font (plDrawState *drawstate);
65
static bool _match_stick_font (plDrawState *drawstate, bool have_extra_stick_fonts);
50
_set_font (S___(Plotter *_plotter))
52
_set_font (S___(_plotter))
53
S___(Plotter *_plotter;)
68
_pl_g_set_font (S___(Plotter *_plotter))
56
70
plDrawState *drawstate = _plotter->drawstate;
57
71
plPlotterData *data = _plotter->data;
106
120
free ((char *)drawstate->true_font_name);
107
121
drawstate->true_font_name =
108
(const char *)_plot_xmalloc (strlen (drawstate->font_name) + 1);
122
(const char *)_pl_xmalloc (strlen (drawstate->font_name) + 1);
109
123
strcpy ((char *)drawstate->true_font_name, drawstate->font_name);
110
124
drawstate->true_font_size = drawstate->font_size;
112
drawstate->font_type = F_OTHER;
126
drawstate->font_type = PL_F_OTHER;
113
127
drawstate->typeface_index = 0;
114
128
drawstate->font_index = 1;
141
155
/* Via a recursive call, try to retrieve default font for this Plotter
142
156
type (if it's different from the one we just failed to retrieve;
143
otherwise retrieve the default Hershey font). */
157
otherwise retrieve the default Hershey font). */
145
159
switch (data->default_font_type)
148
default_font_name = DEFAULT_POSTSCRIPT_FONT;
151
default_font_name = DEFAULT_PCL_FONT;
154
default_font_name = DEFAULT_STICK_FONT;
156
case F_HERSHEY: /* Hershey shouldn't happen */
161
case PL_F_POSTSCRIPT:
162
default_font_name = PL_DEFAULT_POSTSCRIPT_FONT;
165
default_font_name = PL_DEFAULT_PCL_FONT;
168
default_font_name = PL_DEFAULT_STICK_FONT;
170
case PL_F_HERSHEY: /* Hershey shouldn't happen */
158
default_font_name = DEFAULT_HERSHEY_FONT;
172
default_font_name = PL_DEFAULT_HERSHEY_FONT;
161
175
/* N.B. No support yet for a Plotter-specific default font that is of
162
F_OTHER type, i.e., isn't listed in the libplot font database. */
176
PL_F_OTHER type, i.e., isn't listed in the libplot font database. */
165
if (strcmp (drawstate->font_name, default_font_name) == 0)
166
/* default font is the one we just failed to retrieve: so use Hershey */
167
default_font_name = DEFAULT_HERSHEY_FONT;
179
if (strcmp (drawstate->font_name, default_font_name) == 0
180
|| strcmp (drawstate->true_font_name, default_font_name) == 0)
181
/* default font is the one we just failed to retrieve: so use Hershey:
182
internal and guaranteed to be available */
183
default_font_name = PL_DEFAULT_HERSHEY_FONT;
169
185
/* stash fontname we failed to retrieve; then do recursive call, turning
170
186
off font warnings for the duration; restore fontname field */
200
215
_match_hershey_font (plDrawState *drawstate)
202
_match_hershey_font (drawstate)
203
plDrawState *drawstate;
208
219
/* is font a Hershey font? */
210
while (_hershey_font_info[++i].name)
221
while (_pl_g_hershey_font_info[++i].name)
212
if (_hershey_font_info[i].visible) /* i.e. font not internal-only */
213
if (strcasecmp (_hershey_font_info[i].name,
223
if (_pl_g_hershey_font_info[i].visible) /* i.e. font not internal-only */
224
if (strcasecmp (_pl_g_hershey_font_info[i].name,
214
225
drawstate->font_name) == 0
215
|| (_hershey_font_info[i].othername
216
&& strcasecmp (_hershey_font_info[i].othername,
226
|| (_pl_g_hershey_font_info[i].othername
227
&& strcasecmp (_pl_g_hershey_font_info[i].othername,
217
228
drawstate->font_name) == 0))
218
229
/* fill in fields */
220
231
free ((char *)drawstate->true_font_name);
221
232
drawstate->true_font_name =
222
(const char *)_plot_xmalloc (strlen (_hershey_font_info[i].name) + 1);
223
strcpy ((char *)drawstate->true_font_name, _hershey_font_info[i].name);
233
(const char *)_pl_xmalloc (strlen (_pl_g_hershey_font_info[i].name) + 1);
234
strcpy ((char *)drawstate->true_font_name, _pl_g_hershey_font_info[i].name);
224
235
drawstate->true_font_size = drawstate->font_size;
226
drawstate->font_type = F_HERSHEY;
227
drawstate->typeface_index = _hershey_font_info[i].typeface_index;
228
drawstate->font_index = _hershey_font_info[i].font_index;
229
drawstate->font_is_iso8859_1 = _hershey_font_info[i].iso8859_1;
237
drawstate->font_type = PL_F_HERSHEY;
238
drawstate->typeface_index = _pl_g_hershey_font_info[i].typeface_index;
239
drawstate->font_index = _pl_g_hershey_font_info[i].font_index;
240
drawstate->font_is_iso8859_1 = _pl_g_hershey_font_info[i].iso8859_1;
231
242
/* N.B. this macro uses true_font_size */
232
243
drawstate->font_cap_height =
247
257
_match_pcl_font (plDrawState *drawstate)
249
_match_pcl_font (drawstate)
250
plDrawState *drawstate;
255
261
/* is font a PCL font in libplot's database? */
256
while (_pcl_font_info[++i].ps_name)
262
while (_pl_g_pcl_font_info[++i].ps_name)
258
if (strcasecmp (_pcl_font_info[i].ps_name,
264
if (strcasecmp (_pl_g_pcl_font_info[i].ps_name,
259
265
drawstate->font_name) == 0
260
266
/* try alternative PS font name if any */
261
|| (_pcl_font_info[i].ps_name_alt != NULL
262
&& strcasecmp (_pcl_font_info[i].ps_name_alt,
267
|| (_pl_g_pcl_font_info[i].ps_name_alt != NULL
268
&& strcasecmp (_pl_g_pcl_font_info[i].ps_name_alt,
263
269
drawstate->font_name) == 0)
264
270
/* try X font name too */
265
|| strcasecmp (_pcl_font_info[i].x_name,
271
|| strcasecmp (_pl_g_pcl_font_info[i].x_name,
266
272
drawstate->font_name) == 0)
268
274
free ((char *)drawstate->true_font_name);
269
275
drawstate->true_font_name =
270
(const char *)_plot_xmalloc (strlen (_pcl_font_info[i].ps_name) + 1);
271
strcpy ((char *)drawstate->true_font_name, _pcl_font_info[i].ps_name);
276
(const char *)_pl_xmalloc (strlen (_pl_g_pcl_font_info[i].ps_name) + 1);
277
strcpy ((char *)drawstate->true_font_name, _pl_g_pcl_font_info[i].ps_name);
272
278
drawstate->true_font_size = drawstate->font_size;
274
drawstate->font_type = F_PCL;
275
drawstate->typeface_index = _pcl_font_info[i].typeface_index;
276
drawstate->font_index = _pcl_font_info[i].font_index;
277
drawstate->font_is_iso8859_1 = _pcl_font_info[i].iso8859_1;
280
drawstate->font_type = PL_F_PCL;
281
drawstate->typeface_index = _pl_g_pcl_font_info[i].typeface_index;
282
drawstate->font_index = _pl_g_pcl_font_info[i].font_index;
283
drawstate->font_is_iso8859_1 = _pl_g_pcl_font_info[i].iso8859_1;
279
285
drawstate->font_ascent
280
286
= drawstate->true_font_size
281
* (double)(_pcl_font_info[i].font_ascent)/1000.0;
287
* (double)(_pl_g_pcl_font_info[i].font_ascent)/1000.0;
282
288
drawstate->font_descent
283
289
= drawstate->true_font_size
284
* (double)(_pcl_font_info[i].font_descent)/1000.0;
290
* (double)(_pl_g_pcl_font_info[i].font_descent)/1000.0;
285
291
drawstate->font_cap_height
286
292
= drawstate->true_font_size
287
* (double)(_pcl_font_info[i].font_cap_height)/1000.0;
293
* (double)(_pl_g_pcl_font_info[i].font_cap_height)/1000.0;
296
301
_match_ps_font (plDrawState *drawstate)
298
_match_ps_font (drawstate)
299
plDrawState *drawstate;
304
305
/* is font a PS font in libplot's database ? */
305
while (_ps_font_info[++i].ps_name)
306
while (_pl_g_ps_font_info[++i].ps_name)
307
if (strcasecmp (_ps_font_info[i].ps_name,
308
if (strcasecmp (_pl_g_ps_font_info[i].ps_name,
308
309
drawstate->font_name) == 0
309
310
/* try alternative PS font name if any */
310
|| (_ps_font_info[i].ps_name_alt != NULL
311
&& strcasecmp (_ps_font_info[i].ps_name_alt,
311
|| (_pl_g_ps_font_info[i].ps_name_alt != NULL
312
&& strcasecmp (_pl_g_ps_font_info[i].ps_name_alt,
312
313
drawstate->font_name) == 0)
313
314
/* try 2nd alternative PS font name if any */
314
|| (_ps_font_info[i].ps_name_alt2 != NULL
315
&& strcasecmp (_ps_font_info[i].ps_name_alt2,
315
|| (_pl_g_ps_font_info[i].ps_name_alt2 != NULL
316
&& strcasecmp (_pl_g_ps_font_info[i].ps_name_alt2,
316
317
drawstate->font_name) == 0)
317
318
/* try X font name too */
318
|| strcasecmp (_ps_font_info[i].x_name,
319
|| strcasecmp (_pl_g_ps_font_info[i].x_name,
319
320
drawstate->font_name) == 0
320
321
/* try alternative X font name if any */
321
|| (_ps_font_info[i].x_name_alt != NULL
322
&& strcasecmp (_ps_font_info[i].x_name_alt,
322
|| (_pl_g_ps_font_info[i].x_name_alt != NULL
323
&& strcasecmp (_pl_g_ps_font_info[i].x_name_alt,
323
324
drawstate->font_name) == 0))
325
326
free ((char *)drawstate->true_font_name);
326
327
drawstate->true_font_name =
327
(const char *)_plot_xmalloc (strlen (_ps_font_info[i].ps_name) + 1);
328
strcpy ((char *)drawstate->true_font_name, _ps_font_info[i].ps_name);
329
drawstate->true_font_size = drawstate->font_size;
330
drawstate->true_font_size = drawstate->font_size;
332
drawstate->font_type = F_POSTSCRIPT;
333
drawstate->typeface_index = _ps_font_info[i].typeface_index;
334
drawstate->font_index = _ps_font_info[i].font_index;
335
drawstate->font_is_iso8859_1 = _ps_font_info[i].iso8859_1;
328
(const char *)_pl_xmalloc (strlen (_pl_g_ps_font_info[i].ps_name) + 1);
329
strcpy ((char *)drawstate->true_font_name, _pl_g_ps_font_info[i].ps_name);
331
drawstate->true_font_size = drawstate->font_size;
333
drawstate->font_type = PL_F_POSTSCRIPT;
334
drawstate->typeface_index = _pl_g_ps_font_info[i].typeface_index;
335
drawstate->font_index = _pl_g_ps_font_info[i].font_index;
336
drawstate->font_is_iso8859_1 = _pl_g_ps_font_info[i].iso8859_1;
337
338
drawstate->font_ascent
338
339
= drawstate->true_font_size
339
* (double)(_ps_font_info[i].font_ascent)/1000.0;
340
* (double)(_pl_g_ps_font_info[i].font_ascent)/1000.0;
340
341
drawstate->font_descent
341
342
= drawstate->true_font_size
342
* (double)(_ps_font_info[i].font_descent)/1000.0;
343
* (double)(_pl_g_ps_font_info[i].font_descent)/1000.0;
343
344
drawstate->font_cap_height
344
345
= drawstate->true_font_size
345
* (double)(_ps_font_info[i].font_cap_height)/1000.0;
346
* (double)(_pl_g_ps_font_info[i].font_cap_height)/1000.0;
354
354
_match_stick_font (plDrawState *drawstate, bool have_extra_stick_fonts)
356
_match_stick_font (drawstate, have_extra_stick_fonts)
357
plDrawState *drawstate;
358
bool have_extra_stick_fonts;
363
358
/* is font a PCL font in libplot's database? */
364
while (_stick_font_info[++i].ps_name)
359
while (_pl_g_stick_font_info[++i].ps_name)
366
if (_stick_font_info[i].basic == false
361
if (_pl_g_stick_font_info[i].basic == false
367
362
&& !have_extra_stick_fonts)
368
363
/* not a basic Stick font, and this Plotter supports only the basic
372
if (strcasecmp (_stick_font_info[i].ps_name,
367
if (strcasecmp (_pl_g_stick_font_info[i].ps_name,
373
368
drawstate->font_name) == 0)
374
369
/* fill in fields */
376
371
free ((char *)drawstate->true_font_name);
377
372
drawstate->true_font_name =
378
(const char *)_plot_xmalloc (strlen (_stick_font_info[i].ps_name) + 1);
379
strcpy ((char *)drawstate->true_font_name, _stick_font_info[i].ps_name);
373
(const char *)_pl_xmalloc (strlen (_pl_g_stick_font_info[i].ps_name) + 1);
374
strcpy ((char *)drawstate->true_font_name, _pl_g_stick_font_info[i].ps_name);
380
375
drawstate->true_font_size = drawstate->font_size;
381
376
drawstate->true_font_size = drawstate->font_size;
382
377
drawstate->true_font_size = drawstate->font_size;
384
drawstate->font_type = F_STICK;
385
drawstate->typeface_index = _stick_font_info[i].typeface_index;
386
drawstate->font_index = _stick_font_info[i].font_index;
387
drawstate->font_is_iso8859_1 = _stick_font_info[i].iso8859_1;
379
drawstate->font_type = PL_F_STICK;
380
drawstate->typeface_index = _pl_g_stick_font_info[i].typeface_index;
381
drawstate->font_index = _pl_g_stick_font_info[i].font_index;
382
drawstate->font_is_iso8859_1 = _pl_g_stick_font_info[i].iso8859_1;
389
384
drawstate->font_ascent
390
385
= drawstate->true_font_size
391
* (double)(_stick_font_info[i].font_ascent)/1000.0;
386
* (double)(_pl_g_stick_font_info[i].font_ascent)/1000.0;
392
387
drawstate->font_descent
393
388
= drawstate->true_font_size
394
* (double)(_stick_font_info[i].font_descent)/1000.0;
389
* (double)(_pl_g_stick_font_info[i].font_descent)/1000.0;
395
390
drawstate->font_cap_height
396
391
/* The `0.7' is undocumented HP magic; see comments in
397
392
h_font.c and g_fontd2.c */