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