Reorganisation of the source tree
[ghc-hetmet.git] / utils / hp2ps / Dimensions.c
1 #include "Main.h"
2 #include <ctype.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include "Defines.h"
6 #include "HpFile.h"
7 #include "Scale.h"
8
9 /* own stuff */
10 #include "Dimensions.h"
11
12 /*
13  *      Get page and other dimensions before printing.
14  */
15
16 floatish borderheight   = BORDER_HEIGHT;
17 floatish borderwidth    = BORDER_WIDTH;
18 floatish borderspace    = BORDER_SPACE;
19 floatish borderthick    = BORDER_THICK;
20
21 floatish titlewidth     = (BORDER_WIDTH  - (2 * BORDER_SPACE)); 
22 floatish titletextspace = TITLE_TEXT_SPACE;
23 floatish titleheight; 
24
25 floatish graphx0 = GRAPH_X0;
26 floatish graphy0 = GRAPH_Y0;
27
28 floatish graphheight;
29 floatish graphwidth;
30
31 static floatish KeyWidth PROTO((void)); /* forward */
32
33 void
34 Dimensions()
35 {
36     xrange = samplemap[nsamples - 1] - samplemap[0];
37     xrange = max(xrange, auxxrange);
38     if (xrange == 0.0) xrange = 1.0;            /* avoid division by 0.0 */
39  
40     yrange = MaxCombinedHeight();
41     yrange = max(yrange, auxyrange);
42     if (yrange == 0.0) yrange = 1.0;            /* avoid division by 0.0 */
43
44     if (!bflag && !sflag) {
45         bflag = strlen(jobstring) > SMALL_JOB_STRING_WIDTH; 
46     }
47
48     if (bflag) {
49         titleheight = 2 * TITLE_HEIGHT;
50     } else {
51         titleheight = TITLE_HEIGHT;
52     } 
53
54     graphwidth  = titlewidth - graphx0 - (TWENTY ? KeyWidth() : 0);
55     graphheight = borderheight - titleheight - (2 * borderspace) - graphy0;
56 }
57
58 /*
59  *      Calculate the width of the key.
60  */
61
62 static floatish
63 KeyWidth()
64 {
65     intish i;
66     floatish c;
67
68     c = 0.0;
69
70     for (i = 0; i < nidents; i++) {
71         c = max(c, StringSize(identtable[i]->name));
72     }
73
74     c += 3.0 * borderspace;
75
76     c += (floatish) KEY_BOX_WIDTH;
77
78     return c;
79 }
80
81
82 /*
83  *      A desperately grim solution.
84  */
85
86
87 floatish fonttab[] = {
88     /*  20 (' ') = */ 3.0,
89     /*  21 ('!') = */ 1.0,
90     /*  22 ('"') = */ 1.0,
91     /*  23 ('#') = */ 3.0,
92     /*  24 ('$') = */ 3.0,
93     /*  25 ('%') = */ 3.0,
94     /*  26 ('&') = */ 3.0,
95     /*  27 (''') = */ 1.0,
96     /*  28 ('(') = */ 3.0,
97     /*  29 (')') = */ 3.0,
98     /*  2a ('*') = */ 2.0,
99     /*  2b ('+') = */ 3.0,
100     /*  2c (',') = */ 1.0,
101     /*  2d ('-') = */ 3.0,
102     /*  2e ('.') = */ 1.0,
103     /*  2f ('/') = */ 3.0,
104     /*  30 ('0') = */ 4.0,
105     /*  31 ('1') = */ 4.0,
106     /*  32 ('2') = */ 4.0,
107     /*  33 ('3') = */ 4.0,
108     /*  34 ('4') = */ 4.0,
109     /*  35 ('5') = */ 4.0,
110     /*  36 ('6') = */ 4.0,
111     /*  37 ('7') = */ 4.0,
112     /*  38 ('8') = */ 4.0,
113     /*  39 ('9') = */ 4.0,
114     /*  3a (':') = */ 1.0,
115     /*  3b (';') = */ 1.0,
116     /*  3c ('<') = */ 3.0,
117     /*  3d ('=') = */ 3.0,
118     /*  3e ('>') = */ 3.0,
119     /*  3f ('?') = */ 2.0,
120     /*  40 ('@') = */ 3.0,
121     /*  41 ('A') = */ 5.0,
122     /*  42 ('B') = */ 5.0,
123     /*  43 ('C') = */ 5.0,
124     /*  44 ('D') = */ 5.0,
125     /*  45 ('E') = */ 5.0,
126     /*  46 ('F') = */ 5.0,
127     /*  47 ('G') = */ 5.0,
128     /*  48 ('H') = */ 5.0,
129     /*  49 ('I') = */ 1.0,
130     /*  4a ('J') = */ 5.0,
131     /*  4b ('K') = */ 5.0,
132     /*  4c ('L') = */ 5.0,
133     /*  4d ('M') = */ 5.0,
134     /*  4e ('N') = */ 5.0,
135     /*  4f ('O') = */ 5.0,
136     /*  50 ('P') = */ 5.0,
137     /*  51 ('Q') = */ 5.0,
138     /*  52 ('R') = */ 5.0,
139     /*  53 ('S') = */ 5.0,
140     /*  54 ('T') = */ 5.0,
141     /*  55 ('U') = */ 5.0,
142     /*  56 ('V') = */ 5.0,
143     /*  57 ('W') = */ 5.0,
144     /*  58 ('X') = */ 5.0,
145     /*  59 ('Y') = */ 5.0,
146     /*  5a ('Z') = */ 5.0,
147     /*  5b ('[') = */ 2.0,
148     /*  5c ('\') = */ 3.0,
149     /*  5d (']') = */ 2.0,
150     /*  5e ('^') = */ 1.0,
151     /*  5f ('_') = */ 3.0,
152     /*  60 ('`') = */ 1.0,
153     /*  61 ('a') = */ 3.0,
154     /*  62 ('b') = */ 3.0,
155     /*  63 ('c') = */ 3.0,
156     /*  64 ('d') = */ 3.0,
157     /*  65 ('e') = */ 3.0,
158     /*  66 ('f') = */ 3.0,
159     /*  67 ('g') = */ 3.0,
160     /*  68 ('h') = */ 3.0,
161     /*  69 ('i') = */ 1.0,
162     /*  6a ('j') = */ 2.0,
163     /*  6b ('k') = */ 3.0,
164     /*  6c ('l') = */ 1.0,
165     /*  6d ('m') = */ 5.0,
166     /*  6e ('n') = */ 3.0,
167     /*  6f ('o') = */ 3.0,
168     /*  70 ('p') = */ 3.0,
169     /*  71 ('q') = */ 3.0,
170     /*  72 ('r') = */ 2.0,
171     /*  73 ('s') = */ 3.0,
172     /*  74 ('t') = */ 2.0,
173     /*  75 ('u') = */ 3.0,
174     /*  76 ('v') = */ 3.0,
175     /*  77 ('w') = */ 3.0,
176     /*  78 ('x') = */ 3.0,
177     /*  79 ('y') = */ 3.0,
178     /*  7a ('z') = */ 3.0,
179     /*  7b ('{') = */ 2.0,
180     /*  7c ('|') = */ 1.0,
181     /*  7d ('}') = */ 2.0,
182     /*  7e ('~') = */ 2.0
183 };
184
185
186 /*
187  *      What size is a string (in points)?
188  */
189
190 #define FUDGE (2.834646 * 0.6)
191
192 floatish
193 StringSize(s)
194   char* s;
195 {
196     floatish r;
197
198     for (r = 0.0; *s; s++) {
199         r += fonttab[(*s) - 0x20];
200     }
201
202     return r * FUDGE;
203 }