File: h-demo.c

package info (click to toggle)
plotutils 2.4.1-15
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,072 kB
  • ctags: 6,952
  • sloc: ansic: 76,305; cpp: 12,402; sh: 8,475; yacc: 2,604; makefile: 894; lex: 144
file content (190 lines) | stat: -rw-r--r-- 6,828 bytes parent folder | download | duplicates (4)
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
/* This C program, h-demo.c, when compiled and linked with GNU libplot,
   will emit to standard output a sample page illustrating many of the
   Hershey fonts.  The file will be in portable metafile format.  It may be
   translated to other formats, or viewed in an X window, with the `plot'
   utility.  The sample page is taken from Allen Hershey's 1972 article in
   Computer Graphics and Image Processing (vol. 1, no. 4, pp. 373-385).

   Compile and link with: 

       gcc h-demo.c -lplot -lXaw -lXmu -lXt -lXext -lX11 -lm

   or, in recent versions of the X Window System,

       gcc h-demo.c -lplot -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11 -lm

   To translate the sample page to Postscript, you would do 
   `a.out | plot -T ps > page.ps'.  To display the page in an 
   X Window, you would do `a.out | plot -T X', etc.  

   The above compilation instructions assume that your linker will be able
   to find libplot and the X Window System libraries.  You may need to
   include such options as -L/usr/local/lib and -L/usr/X11/lib to ensure
   this.  Also, the linking options may differ if you are using Motif.
   If you are using a C compiler other than gcc, consult your system
   administrator.
   
   (The -DNO_CONST_SUPPORT option may need to be used if the C compiler,
   like the version of `cc' supplied with SunOS 4.1.x, is so old that it
   does not understand the `const' type qualifier.  If compiling under
   SunOS 4.1.x, you may also need to specify the `-static' option, to work
   around problems with undefined symbols in the SunOS X libraries.)

   If you have any trouble running the demo after compiling it, be sure
   your LD_LIBRARY_PATH environment variable includes the directory in
   which libplot is stored.  This only applies on systems in which libplot
   is implemented as a shared library that is linked at run time. */

#include <stdio.h> 
#include <plot.h>

#ifdef M_SQRT1_2
#undef M_SQRT1_2
#endif
#define M_SQRT1_2   (0.70710678118654752440) /* 1/sqrt(2) */

#define NUM_DEMO_WORDS 34
struct hershey_word 
{
  char *word;
  char *fontname;
  double m[6];
  char just;
};

#define CART (9.0/21.0)		/* `cartographic' size */
#define INDEXICAL (13.0/21.0)	/* `indexical' size */

#define LLX -3800.0
#define LLY -3450.0
#define URX 3800.0
#define URY 4150.0

#define BASE_FONTSIZE 220.0

struct hershey_word demo_word[NUM_DEMO_WORDS] = 
{
  {"Invitation", "HersheyScript-Bold", 
     { 1., 0., 0., 1., -3125., 3980. }, 'l' },
  {"ECONOMY", "HersheySans",           
     { 1., 0., 0., 1., -3125., 3340. }, 'l'},
  {"CARTOGRAPHY", "HersheySans",       
     { CART, 0., 0., CART, -3125., 2700. }, 'l'},
  {"Gramma", "HersheySerifSymbol",    
     { 1., 0., 0., 1., -3125., 2060. }, 'l'},
  {"\347\322\301\306\311\313\301", "HersheyCyrillic",       
     { 1., 0., 0., 1., -3125., 1420. }, 'l'},

  {"COMMUNICATION", "HersheySans-Bold", 
     { 1., 0., 0., 1., 0., 3980. }, 'c'},
  {"VERSATILITY", "HersheySerif-Italic",
     { 1., 0., 0., 1., 0., 3340. }, 'c'},
  {"Standardization", "HersheySerif",   
     { 1., 0., 0., 1., 0., 2700. }, 'c'},
  {"Sumbolon", "HersheySerifSymbol",  
     { INDEXICAL, 0., 0., INDEXICAL, 0., 2060. }, 'c'},
  {"\363\354\357\366\356\357\363\364\370", "HersheyCyrillic",      
     { 1., 0., 0., 1., 0., 1420. }, 'c'},

  {"Publication", "HersheyScript-Bold", 
     { 1., 0., 0., 1., 3125., 3980. }, 'r'},
  {"Quality", "HersheyGothicEnglish",  
     { 1., 0., 0., 1., 3125., 3340. }, 'r'},
  {"TYPOGRAPHY", "HersheySans",         
     { CART, 0., 0., CART, 3125., 2700. }, 'r'},
  {"AriJmo\\s-", "HersheySerifSymbol",    
     { 1., 0., 0., 1., 3125., 2060. }, 'r'},
  {"\346\317\316\305\324\311\313\301", "HersheyCyrillic",       
     { 1., 0., 0., 1., 3125., 1420. }, 'r'},

  {"EXTENSION", "HersheySans", 
     { 17./7., 0., 0., 2./7., 0., 780. }, 'c'},
  {"CONDENSATION", "HersheySans", 
     { 5./7., 0., 0., 17./7., 0., -20. }, 'c'},
  {"Rotation", "HersheySans", 
     { M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2, -2880., -20. }, 'l'},
  {"ROTATION", "HersheySans", 
     { M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, 2880., -20. }, 'r'},

  {"Syllabary", "HersheySerif",           
     { 1., 0., 0., 1., -3125., -780. }, 'l'},
  {"Art", "HersheyGothicEnglish",        
     { 1., 0., 0., 1., -3125., -1420. }, 'l'},
  {"Meteorology", "HersheySerif-Italic",  
     { INDEXICAL, 0., 0., INDEXICAL, -3125., -2060.}, 'l'},
  {"CHEMISTRY", "HersheySerif",           
     { 1., 0., 0., 1., -3125., -2700.}, 'l'},
  {"Analysis", "HersheySerif-BoldItalic", 
     { 1., 0., 0., 1., -3125., -3340.}, 'l'},

  {"LEXIKON", "HersheySerifSymbol-Bold",      
     { 1., 0., 0., 1., 0., -780.}, 'c'},
  {"\\#J3d71\\#J463b", "HersheySerif",      
     { 1./.7, 0., 0., 1./.7, 0., -1420.}, 'c'},
  {"Wissenschaft", "HersheyGothicGerman",
     { 1., 0., 0., 1., 0., -2060.}, 'c'},
  {"Electronics", "HersheySerif-Italic",  
     { 1., 0., 0., 1., 0., -2700.}, 'c'},
  {"COMPUTATION", "HersheySerif-Bold",    
     { 1., 0., 0., 1., 0., -3340.}, 'c'},

  {"Alphabet", "HersheySerif",            
     { 1., 0., 0., 1., 3125., -780.}, 'r'},
  {"Music", "HersheyGothicItalian",      
     { 1., 0., 0., 1., 3125., -1420.}, 'r'},
  {"Astronomy", "HersheySerif",           
     { INDEXICAL, 0., 0., INDEXICAL, 3125., -2060.}, 'r'},
  {"MATHEMATICS", "HersheySerif",         
     { 1., 0., 0., 1., 3125., -2700.}, 'r'},
  {"Program", "HersheySerif-BoldItalic",  
     { 1., 0., 0., 1., 3125., -3340.}, 'r'},
};

int
main()
{
  plPlotter *plotter;
  plPlotterParams *plotter_params;
  int i;

  /* set Plotter parameters */
  plotter_params = pl_newplparams ();
  pl_setplparam (plotter_params, "META_PORTABLE", "yes");

  /* create a Metafile Plotter with the specified parameters */
  if ((plotter = pl_newpl_r ("meta", stdin, stdout, stderr,
			     plotter_params)) == NULL)
    {
      fprintf (stderr, "Couldn't create Plotter\n");
      return 1;
    }
  
  /* open it, set up user coordinate system */
  pl_openpl_r (plotter);
  pl_erase_r (plotter);
  pl_fspace_r (plotter, LLX, LLY, URX, URY);

  /* loop through words, each time saving and restoring graphics state */
  for (i = 0; i < NUM_DEMO_WORDS; i++)
    {
      pl_savestate_r (plotter);
      pl_fontname_r (plotter, demo_word[i].fontname);
      pl_fconcat_r (plotter,
		    demo_word[i].m[0], demo_word[i].m[1], 
		    demo_word[i].m[2], demo_word[i].m[3],
		    demo_word[i].m[4], demo_word[i].m[5]);
      pl_ffontsize_r (plotter, BASE_FONTSIZE);
      pl_fmove_r (plotter, 0.0, 0.0);
      pl_alabel_r (plotter, demo_word[i].just, 'c', demo_word[i].word);
      pl_restorestate_r (plotter);
    }

  /* close and delete Plotter */
  pl_closepl_r (plotter);
  if (pl_deletepl_r (plotter) < 0)
    {
      fprintf (stderr, "Couldn't delete Plotter\n");
      return 1;
    }
  return 0;
}