1 /* This file is part of the GNU plotutils package.  Copyright (C) 1995,
2    1996, 1997, 1998, 1999, 2000, 2005, 2008, 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 fontname, fontsize, and textangle methods, which
20    are a GNU extension to libplot.  They set drawing attributes: the name
21    of the font used for text subsequent drawn on the graphics device, the
22    size, and the text angle.
23 
24    The fontname, fontsize, and textangle methods return the fontsize in
25    user units, as an aid to vertical positioning by the user.  (The
26    fontsize is normally taken to be a minimum vertical spacing between
27    adjacent lines of text.)
28 
29    The return value may depend on the mapping from user coordinates to
30    graphics device coordinates, and hence, e.g., on the arguments given to
31    the space() method.
32 
33    Note that the size of the font may change when the rotation angle is
34    changed, since some fonts may not be available at all rotation angles,
35    so that a default font must be switched to.  Also, not all font sizes
36    may be available (there may need to be some size quantization).  So the
37    return value should always be checked. */
38 
39 #include "sys-defines.h"
40 #include "extern.h"
41 
42 double
_API_ffontname(R___ (Plotter * _plotter)const char * s)43 _API_ffontname (R___(Plotter *_plotter) const char *s)
44 {
45   char *font_name;
46 
47   if (!_plotter->data->open)
48     {
49       _plotter->error (R___(_plotter)
50 		       "ffontname: invalid operation");
51       return -1;
52     }
53 
54   /* Null pointer resets to default.  (N.B. we don't look at the font_name
55      field in _default_drawstate, because it's a dummy.) */
56   if ((s == NULL) || (*s == '\0') || !strcmp(s, "(null)"))
57     switch (_plotter->data->default_font_type)
58       {
59       case PL_F_HERSHEY:
60       default:
61 	s = PL_DEFAULT_HERSHEY_FONT;
62 	break;
63       case PL_F_POSTSCRIPT:
64 	s = PL_DEFAULT_POSTSCRIPT_FONT;
65 	break;
66       case PL_F_PCL:
67 	s = PL_DEFAULT_PCL_FONT;
68 	break;
69       case PL_F_STICK:
70 	s = PL_DEFAULT_STICK_FONT;
71 	break;
72       }
73 
74   /* save new font name */
75   free ((char *)_plotter->drawstate->font_name);
76   font_name = (char *)_pl_xmalloc (strlen (s) + 1);
77   strcpy (font_name, s);
78   _plotter->drawstate->font_name = font_name;
79 
80   /* retrieve font and metrics; compute `true' font size (may differ) */
81   _pl_g_set_font (S___(_plotter));
82 
83   /* return value is size in user units */
84   return _plotter->drawstate->true_font_size;
85 }
86 
87 double
_API_ffontsize(R___ (Plotter * _plotter)double size)88 _API_ffontsize (R___(Plotter *_plotter) double size)
89 {
90   if (!_plotter->data->open)
91     {
92       _plotter->error (R___(_plotter)
93 		       "ffontsize: invalid operation");
94       return -1;
95     }
96 
97   if (size < 0.0)		/* reset to default */
98     {
99       size = _plotter->drawstate->default_font_size;
100       _plotter->drawstate->font_size_is_default = true;
101     }
102   else
103     _plotter->drawstate->font_size_is_default = false;
104 
105   /* set the new nominal size in the drawing state */
106   _plotter->drawstate->font_size = size;
107 
108   /* retrieve font and metrics; compute `true' font size (may differ) */
109   _pl_g_set_font (S___(_plotter));
110 
111   /* flag fontsize as having been invoked (so that fsetmatrix will no
112      longer automatically adjust the font size to a reasonable value) */
113   _plotter->data->fontsize_invoked = true;
114 
115   /* return quantized user-specified font size */
116   return _plotter->drawstate->true_font_size;
117 }
118 
119 double
_API_ftextangle(R___ (Plotter * _plotter)double angle)120 _API_ftextangle (R___(Plotter *_plotter) double angle)
121 {
122   if (!_plotter->data->open)
123     {
124       _plotter->error (R___(_plotter)
125 		       "ftextangle: invalid operation");
126       return -1;
127     }
128 
129   /* save new rotation angle */
130   _plotter->drawstate->text_rotation = angle;
131 
132   /* retrieve font and metrics; compute `true' font size (may differ) */
133   _pl_g_set_font (S___(_plotter));
134 
135   /* return quantized user-specified font size */
136   return _plotter->drawstate->true_font_size;
137 }
138 
139 /* Below are four rather silly Plotter methods that are an undocumented
140    part of the libplot/libplotter API.  Each returns a pointer to the head
141    of a font database in g_fontdb.c, so that an application program that is
142    too nosy for its own good can pry out font information.
143 
144    These should be replaced by a properly crafted API for querying font
145    names, font metrics, etc. */
146 
147 void *
_pl_get_hershey_font_info(S___ (Plotter * _plotter))148 _pl_get_hershey_font_info (S___(Plotter *_plotter))
149 {
150   return (void *)_pl_g_hershey_font_info;
151 }
152 
153 void *
_pl_get_ps_font_info(S___ (Plotter * _plotter))154 _pl_get_ps_font_info (S___(Plotter *_plotter))
155 {
156   return (void *)_pl_g_ps_font_info;
157 }
158 
159 void *
_pl_get_pcl_font_info(S___ (Plotter * _plotter))160 _pl_get_pcl_font_info (S___(Plotter *_plotter))
161 {
162   return (void *)_pl_g_pcl_font_info;
163 }
164 
165 void *
_pl_get_stick_font_info(S___ (Plotter * _plotter))166 _pl_get_stick_font_info (S___(Plotter *_plotter))
167 {
168   return (void *)_pl_g_stick_font_info;
169 }
170 
171