add Outputable instance for OccIfaceEq
[ghc-hetmet.git] / utils / hp2ps / Key.c
1 #include "Main.h"
2 #include <stdio.h>
3 #include <math.h>
4 #include "Defines.h"
5 #include "Dimensions.h"
6 #include "HpFile.h"
7 #include "Shade.h"
8 #include "PsFile.h"
9
10 /* own stuff */
11 #include "Key.h"
12
13 static void KeyEntry PROTO((floatish, char *, floatish));
14
15 void Key()
16 {
17     intish i;
18     floatish c;
19     floatish dc;
20
21     for (i = 0; i < nidents; i++)    /* count identifiers */ 
22         ;
23
24     c  = multipageflag ? 0 : graphy0;
25     dc = graphheight / (floatish) ((i <= 20) ? (i + 1) : 20);
26
27     for (i = 0; i < nidents; i++) {
28         c += dc;
29         KeyEntry(c, identtable[i]->name, ShadeOf(identtable[i]->name));
30         // if we have spit out 20 entries and we're going to output more
31         // advance the page
32         if (i % DEFAULT_TWENTY == (DEFAULT_TWENTY - 1) && i != nidents - 1) {
33           c = 0;
34           NextPage();
35         }
36     }
37 }
38
39
40
41 static void
42 KeyEntry(centreline, name, colour)
43   floatish centreline; char* name; floatish colour;
44 {
45     floatish namebase;
46     floatish keyboxbase;
47     floatish kstart;
48
49     namebase = centreline - (floatish) (NORMAL_FONT / 2);
50     keyboxbase = centreline - ((floatish) KEY_BOX_WIDTH / 2.0);
51
52     kstart = graphx0 + (multipageflag ? 0 : graphwidth);
53
54     fprintf(psfp, "%f %f moveto\n", kstart + borderspace, keyboxbase);
55     fprintf(psfp, "0 %d rlineto\n", KEY_BOX_WIDTH);
56     fprintf(psfp, "%d 0 rlineto\n", KEY_BOX_WIDTH);
57     fprintf(psfp, "0 %d rlineto\n", -KEY_BOX_WIDTH);
58     fprintf(psfp, "closepath\n");
59
60     fprintf(psfp, "gsave\n"); 
61     SetPSColour(colour);
62     fprintf(psfp, "fill\n");
63     fprintf(psfp, "grestore\n");
64     fprintf(psfp, "stroke\n");
65
66     fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
67     fprintf(psfp, "%f %f moveto\n", kstart + (floatish) KEY_BOX_WIDTH + 2 * borderspace, namebase);
68
69     fprintf(psfp, "(%s) show\n", name); 
70 }