~ubuntu-branches/ubuntu/gutsy/plotutils/gutsy

« back to all changes in this revision

Viewing changes to libplot/g_retrieve.c

  • Committer: Bazaar Package Importer
  • Author(s): Floris Bruynooghe
  • Date: 2007-05-10 19:48:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070510194854-mrr3lgwzpxd8hovo
Tags: 2.5-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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. */
 
18
 
 
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.
7
25
 
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).
11
29
 
12
 
   _set_font does the following, in order:
 
30
   _pl_g_set_font does the following, in order:
13
31
 
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'.
21
39
 
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.
26
45
 
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
30
49
   database, except when the user frame -> device frame map is anisotropic
31
50
   (i.e. non-uniform).  It is also used by X Drawable Plotters, which may
32
51
   or may not have a PS font available, and in fact may or may not have any
33
 
   given font of type `F_OTHER' (see above) available. */
 
52
   given font of type `PL_F_OTHER' (see above) available. */
34
53
 
35
54
#include "sys-defines.h"
36
55
#include "extern.h"
40
59
        ((size)*(drawstate->true_font_size)/(HERSHEY_EM))
41
60
 
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);
47
66
 
48
67
void
49
 
#ifdef _HAVE_PROTOS
50
 
_set_font (S___(Plotter *_plotter))
51
 
#else
52
 
_set_font (S___(_plotter))
53
 
     S___(Plotter *_plotter;)
54
 
#endif
 
68
_pl_g_set_font (S___(Plotter *_plotter))
55
69
{
56
70
  plDrawState *drawstate = _plotter->drawstate;
57
71
  plPlotterData *data = _plotter->data;
105
119
    {
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;
111
125
 
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;
115
129
 
140
154
 
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).  */
144
158
 
145
159
  switch (data->default_font_type)
146
160
    {
147
 
    case F_POSTSCRIPT:
148
 
      default_font_name = DEFAULT_POSTSCRIPT_FONT;
149
 
      break;
150
 
    case F_PCL:
151
 
      default_font_name = DEFAULT_PCL_FONT;
152
 
      break;
153
 
    case F_STICK:
154
 
      default_font_name = DEFAULT_STICK_FONT;
155
 
      break;
156
 
    case F_HERSHEY:             /* Hershey shouldn't happen */
 
161
    case PL_F_POSTSCRIPT:
 
162
      default_font_name = PL_DEFAULT_POSTSCRIPT_FONT;
 
163
      break;
 
164
    case PL_F_PCL:
 
165
      default_font_name = PL_DEFAULT_PCL_FONT;
 
166
      break;
 
167
    case PL_F_STICK:
 
168
      default_font_name = PL_DEFAULT_STICK_FONT;
 
169
      break;
 
170
    case PL_F_HERSHEY:          /* Hershey shouldn't happen */
157
171
    default:
158
 
      default_font_name = DEFAULT_HERSHEY_FONT;
 
172
      default_font_name = PL_DEFAULT_HERSHEY_FONT;
159
173
      break;
160
174
 
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. */
163
177
    }
164
178
 
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;
168
184
  
169
185
  /* stash fontname we failed to retrieve; then do recursive call, turning
170
186
     off font warnings for the duration; restore fontname field */
176
192
    drawstate->font_name = default_font_name;
177
193
    saved_font_warning_issued = _plotter->data->font_warning_issued;
178
194
    _plotter->data->font_warning_issued = true; /* turn off warnings */
179
 
    _set_font (S___(_plotter));
 
195
    _pl_g_set_font (S___(_plotter));
180
196
    _plotter->data->font_warning_issued = saved_font_warning_issued;
181
197
    drawstate->font_name = saved_font_name;
182
198
  }
186
202
    {
187
203
      char *buf;
188
204
      
189
 
      buf = (char *)_plot_xmalloc (strlen (drawstate->font_name) + strlen (drawstate->true_font_name) + 100);
 
205
      buf = (char *)_pl_xmalloc (strlen (drawstate->font_name) + strlen (drawstate->true_font_name) + 100);
190
206
      sprintf (buf, "cannot retrieve font \"%s\", using default \"%s\"", 
191
207
               drawstate->font_name, drawstate->true_font_name);
192
208
      _plotter->warning (R___(_plotter) buf);
196
212
}
197
213
 
198
214
static bool
199
 
#ifdef _HAVE_PROTOS
200
215
_match_hershey_font (plDrawState *drawstate)
201
 
#else
202
 
_match_hershey_font (drawstate)
203
 
     plDrawState *drawstate;
204
 
#endif
205
216
{
206
217
  int i;
207
218
 
208
219
  /* is font a Hershey font? */
209
220
  i = -1;
210
 
  while (_hershey_font_info[++i].name)
 
221
  while (_pl_g_hershey_font_info[++i].name)
211
222
    {
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 */
219
230
          {
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;
225
236
 
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;
230
241
 
231
242
            /* N.B. this macro uses true_font_size */
232
243
            drawstate->font_cap_height = 
243
254
}
244
255
 
245
256
static bool
246
 
#ifdef _HAVE_PROTOS
247
257
_match_pcl_font (plDrawState *drawstate)
248
 
#else
249
 
_match_pcl_font (drawstate)
250
 
     plDrawState *drawstate;
251
 
#endif
252
258
{
253
259
  int i = -1;
254
260
 
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)
257
263
    {
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)
267
273
        {
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;
273
279
 
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;
278
284
 
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;
288
294
          return true;
289
295
        }
290
296
    }
292
298
}
293
299
 
294
300
static bool
295
 
#ifdef _HAVE_PROTOS
296
301
_match_ps_font (plDrawState *drawstate)
297
 
#else
298
 
_match_ps_font (drawstate)
299
 
     plDrawState *drawstate;
300
 
#endif
301
302
{
302
303
  int i = -1;
303
304
 
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)
306
307
    {
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))
324
325
        {
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;
331
 
 
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);
 
330
 
 
331
          drawstate->true_font_size = drawstate->font_size;
 
332
 
 
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;
336
337
 
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;
346
347
          return true;
347
348
        }
348
349
    }
350
351
}
351
352
 
352
353
static bool
353
 
#ifdef _HAVE_PROTOS
354
354
_match_stick_font (plDrawState *drawstate, bool have_extra_stick_fonts)
355
 
#else
356
 
_match_stick_font (drawstate, have_extra_stick_fonts)
357
 
     plDrawState *drawstate;
358
 
     bool have_extra_stick_fonts;
359
 
#endif
360
355
{
361
356
  int i = -1;
362
357
 
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)
365
360
    {
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
369
364
           ones */
370
365
        continue;
371
366
      
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 */
375
370
        {
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;
383
378
 
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;
388
383
 
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 */
403
398
  return false;
404
399
}
405
400
 
 
401
/* This is the generic version of the _retrieve_font method, which does
 
402
   nothing.  Many types of Plotter use this, but some, e.g., FigPlotters
 
403
   and XDrawablePlotters (and X Plotters) override it.  See
 
404
   _pl_f_retrieve_font() and _pl_x_retrieve_font(). */
 
405
 
406
406
bool
407
 
#ifdef _HAVE_PROTOS
408
 
_g_retrieve_font (S___(Plotter *_plotter))
409
 
#else
410
 
_g_retrieve_font (S___(_plotter))
411
 
     S___(Plotter *_plotter;)
412
 
#endif
 
407
_pl_g_retrieve_font (S___(Plotter *_plotter))
413
408
{
414
409
  return true;
415
410
}