File: g_retrieve.c

package info (click to toggle)
plotutils 2.0-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 5,964 kB
  • ctags: 2,522
  • sloc: ansic: 38,416; sh: 1,853; yacc: 856; makefile: 181; lex: 144
file content (135 lines) | stat: -rw-r--r-- 4,231 bytes parent folder | download
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
/* This file contains the internal _retrieve_font method, which is called
   when when the font_name, font_size, and textangle fields of the current
   drawing state have been filled in.  It retrieves the specified font, and
   fills in the font_type, typeface_index, font_index, font_is_iso8858,
   true_font_size, and font_ascent, and font_descent fields of the drawing
   state. */

#include "sys-defines.h"
#include "plot.h"
#include "extern.h"
#include "g_her_metr.h"

void
#ifdef _HAVE_PROTOS
_g_retrieve_font(void)
#else
_g_retrieve_font()
#endif
{
  char *old_font_name;
  int i;

  /* try to match user-specified font name */

  if (_plotter->have_hershey_fonts)
    {
      /* is font a vector font? */
      i = -1;
      while (_vector_font_info[++i].name)
	{
	  if (_vector_font_info[i].visible) /* i.e. font not internal-only */
	    if (strcasecmp (_vector_font_info[i].name, 
			    _plotter->drawstate->font_name) == 0
		|| strcasecmp (_vector_font_info[i].othername, 
			       _plotter->drawstate->font_name) == 0)
	      {
		_plotter->drawstate->font_type = F_HERSHEY;
		_plotter->drawstate->typeface_index = 
		  _vector_font_info[i].typeface_index;
		_plotter->drawstate->font_index = 
		  _vector_font_info[i].font_index;
		_plotter->drawstate->font_is_iso8859 = 
		  _vector_font_info[i].iso8859_1;
		_plotter->drawstate->true_font_size = 
		  _plotter->drawstate->font_size;
		/* N.B. this macro uses true_font_size, see g_alabel_her.c */
		_plotter->drawstate->font_ascent = 
		  HERSHEY_UNITS_TO_USER_UNITS(HERSHEY_ASCENT);
		_plotter->drawstate->font_descent = 
		  HERSHEY_UNITS_TO_USER_UNITS(HERSHEY_DESCENT);
		return;
	      }
	} 
    }

  if (_plotter->have_ps_fonts)
    {
      /* is font a PS font? */
      i = -1;
      while (_ps_font_info[++i].ps_name)
	{
	  if (strcasecmp (_ps_font_info[i].ps_name, 
			  _plotter->drawstate->font_name) == 0
	      || strcasecmp (_ps_font_info[i].x_name, 
			     _plotter->drawstate->font_name) == 0)
	    {
	      _plotter->drawstate->font_type = F_POSTSCRIPT;
	      _plotter->drawstate->typeface_index = 
		_ps_font_info[i].typeface_index;
	      _plotter->drawstate->font_index = 
		_ps_font_info[i].font_index;
	      _plotter->drawstate->font_is_iso8859 = 
		_ps_font_info[i].iso8859_1;
	      _plotter->drawstate->font_ascent 
		= _plotter->drawstate->font_size 
		  * (double)(_ps_font_info[i].font_ascent)/1000.0;
	      _plotter->drawstate->font_descent 
		= _plotter->drawstate->font_size 
		  * (double)(_ps_font_info[i].font_descent)/1000.0;
	      _plotter->drawstate->true_font_size = 
		_plotter->drawstate->font_size;
	      return;
	    }
	}
    }
  
  if (_plotter->have_pcl_fonts)
    {
      /* is font a PCL font? */
      i = -1;
      while (_pcl_font_info[++i].ps_name)
	{
	  if (strcasecmp (_pcl_font_info[i].ps_name, 
			  _plotter->drawstate->font_name) == 0)
	    {
	      _plotter->drawstate->font_type = F_PCL;
	      _plotter->drawstate->typeface_index = 
		_pcl_font_info[i].typeface_index;
	      _plotter->drawstate->font_index = 
		_pcl_font_info[i].font_index;
	      _plotter->drawstate->font_is_iso8859 = 
		(_pcl_font_info[i].pcl_symbol_set == PCL_ISO_8859_1);
	      _plotter->drawstate->font_ascent 
		= _plotter->drawstate->font_size 
		  * (double)(_pcl_font_info[i].font_ascent)/1000.0;
	      _plotter->drawstate->font_descent 
		= _plotter->drawstate->font_size 
		  * (double)(_pcl_font_info[i].font_descent)/1000.0;
	      _plotter->drawstate->true_font_size = 
		_plotter->drawstate->font_size;
	      return;
	    }
	}
    }

  if (!_plotter->font_warning_issued)
    {
      char *buf;
      
      buf = (char *)_plot_xmalloc (sizeof (_plotter->drawstate->font_name) + sizeof (_plotter->default_drawstate->font_name) + 100);
      sprintf (buf, "cannot retrieve font \"%s\", using default \"%s\"", 
	       _plotter->drawstate->font_name, 
	       _plotter->default_drawstate->font_name);
      _plotter->warning (buf);
      free (buf);
      _plotter->font_warning_issued = true;
    }

  old_font_name = _plotter->drawstate->font_name;
  _plotter->drawstate->font_name = _plotter->default_drawstate->font_name;
  _g_retrieve_font();
  _plotter->drawstate->font_name = old_font_name;
  
  return;
}