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