5
/*----------------------------------------*/
6
/* HPGL specific section */
7
/*----------------------------------------*/
9
typedef struct hpglrecord {
14
static hpglrecord hpglrec[5]; /* HPGL-specifics*/
15
static double hpglcell; /* character cell size */
16
static int actcol; /* actual color No. */
17
static int hpglpen; /* actual pen No. (1-8/0) */
18
static char *hpglhatch; /* actual hatch type */
21
static char *hatches[HATCHES] = { "", "3,0.8,45", "4,0.8,0", "1" };
23
/* -------------- VERY simple output optimizer */
33
static STORE store[MAX_STORE];
34
static int store_idx = 0;
35
static int print_len = 0;
38
static void print(char *fmt, ...) {
42
va_start(argptr, fmt);
43
len = vsprintf(buf, fmt, argptr);
45
if (print_len+len > 78) {
46
uwriteln(&outfile, "");
49
fprintf(outfile.f, "%s", buf);
54
/* select a new pen */
55
static int select_pen(int pen) {
58
print("SP%d;", hpglpen);
64
/* write out all stored characters */
65
static void flush_fg(int pen) {
68
for (idx = 0; idx < store_idx; ++idx) {
69
if ( store[idx].c != ' '
70
&& hpglrec[store[idx].col].fgnd == pen ) {
72
print("PU%1.2f,%1.2f;", store[idx].px, store[idx].py);
73
print("LB%c\003;", store[idx].c);
78
/* draw all saved background shadings */
79
static void flush_bg(int pen) {
83
for (idx = 0; idx < store_idx; ++idx) {
84
if (hpglrec[store[idx].col].bgnd != pen) continue;
85
for (h = 0; h < HATCHES; ++h) {
86
if (hpglrec[store[idx].col].hatch == hatches[h]) {
87
double act_x = store[idx].px - dev_xsize/8;
88
double act_y = store[idx].py - dev_ysize/4;
90
print("PU%1.2f,%1.2f;", act_x, act_y);
91
if (hatches[h] != hpglhatch) {
92
hpglhatch = hatches[h];
93
print("FT%s;", hpglhatch);
95
print("RR%1.2f,%1.2f;", dev_xsize, dev_ysize);
101
/* save stored character cells */
102
static void store_flush(void) {
105
/* first background */
107
flush_bg(sp); /* actual pen first */
108
for (p=1; p < 10; ++p)
112
/* then foreground */
114
flush_fg(sp); /* actual pen first */
115
for (p=0; p < 10; ++p)
122
/* save a character for optimizing HPGL output */
123
static void store_char(char c, int col, double px, double py) {
124
store[store_idx].c = c;
125
store[store_idx].px = (float) px;
126
store[store_idx].py = (float) py;
127
store[store_idx].col= (byte) col;
129
if (store_idx == MAX_STORE)
133
/* - - - - - - - - - - - - - - */
135
static void menu_hpgl(hpglrecord *hpglrec, BOOL *lc, char *txt, char *parstring)
141
printf("\n-------------------------------------------------------------\n"
142
"Enter the text attributes for printing of **>%s<** residues:\n", txt);
143
printf("First choose color and hatching type of the letter **>background<**\n"
144
"NUMBERS specify plotter Pens,\n"
145
"LETTERS specify hatching types.\n"
146
"input has to be composed of a number and a letter\n"
147
"1-9, 0 : PEN No. (0 means no background)\n"
148
"(N) : no hatching (S) : slash\n"
149
"(C) : crosshatch (F) : fill\n\n"
150
"choose a number and a letter ( * %c%c * ) : ",
151
parstring[0], parstring[1]);
152
Fgets(instring, 41, stdin);
155
if (*instring == '\0') {
156
code1 = parstring[0];
157
code2 = parstring[1];
162
code1 = toupper(code1);
163
code2 = toupper(code2);
164
if (strchr("NSCF", code2) == NULL)
168
hpglrec->hatch = hatches[0];
171
hpglrec->hatch = hatches[1];
174
hpglrec->hatch = hatches[2];
177
hpglrec->hatch = hatches[3];
180
hpglrec->bgnd = code1-'0';
182
printf("\n\nEnter the text attributes for printing of **>%s<** residues:\n",
184
printf("Now choose color and case of the letter **>foreground<**\n"
185
"NUMBERS specify plotter Pens,\n"
186
"A letter \"n\" behind the number means \"normal printing\"\n"
187
"A letter \"l\" behind the number means \"lowercase printing\"\n"
188
"1-9, 0 : PEN No. (0 means no printing)\n"
189
"e.g. \"1n\" means : PEN #1 is to be used\n"
190
"e.g. \"2l\" means : PEN #2 and lowercase types are to be used\n\n"
191
"choose a number and a letter ( * %c%c * ) : ",
192
parstring[2], parstring[3]);
193
Fgets(instring, 41, stdin);
196
if (*instring == '\0') {
197
code1 = parstring[2];
198
code2 = parstring[3];
203
if (code2 == 'L' || code2 == 'l')
207
hpglrec->fgnd = code1 - '0';
211
static void ask_hpgl(void)
219
"-----------------------------------------------------------------------\n");
220
Fgets(parstring, 6, parfile);
222
menu_hpgl(hpglrec, lc, "different", parstring);
223
Fgets(parstring, 6, parfile);
225
menu_hpgl(&hpglrec[1], &lc[1], "identical", parstring);
226
Fgets(parstring, 6, parfile);
229
menu_hpgl(&hpglrec[2], &lc[2], "similar", parstring);
231
hpglrec[2] = hpglrec[0];
234
Fgets(parstring, 6, parfile);
237
menu_hpgl(&hpglrec[3], &lc[3], "conserved", parstring);
239
hpglrec[3] = hpglrec[1];
243
hpglrec[4].hatch = hatches[0];
244
hpglrec[4].fgnd = hpglrec[0].fgnd;
246
fscanf(parfile, "%lg%*[^\n]", &hpglcell);
248
Fgets(parstring, 6, parfile);
249
if (parstring[0] == 'Y' || parstring[0] == 'y')
250
landscapeflag = TRUE;
252
landscapeflag = FALSE;
255
printf("Character size in Points ( * %4.1f * ) : ", hpglcell);
256
Fgets(instring, 41, stdin);
257
if (*instring != '\0')
258
hpglcell = str2int((void *)instring);
259
} while (hpglcell < 1 || hpglcell > 100);
260
printf("Rotate plot ( * %c * ) : ", YESNO(landscapeflag));
261
Fgets(instring, 41, stdin);
262
if (*instring != '\0') {
263
if (instring[0] == 'Y' || instring[0] == 'y')
264
landscapeflag = TRUE;
266
landscapeflag = FALSE;
270
printf("filename for HPGL-output : ");
276
static void HPGLinit(double *xpos, double *ypos) {
280
dev_minx = 10.75; /* borders of a A4 page in mm */
285
dev_minx = 5.0; /* borders of a A4 page in mm */
290
dev_xsize = hpglcell * 0.351;
291
dev_ysize = hpglcell * 0.351 * 2.0 / 1.5;
293
hpglhatch = hatches[0];
295
*ypos = dev_maxy; /* 0,0 is lower left corner */
296
assert(outopen(&outfile, outname) != NULL);
297
xd = dev_xsize * 100 / 1.5 / (dev_maxx - dev_minx);
298
yd = dev_ysize * 100 / 2.0 / (dev_maxy - dev_miny);
299
print("IN;%sIP;SI%5.3f;", (landscapeflag?"RO 90;":""), hpglcell*0.351);
300
print("SC%1.2f,%1.2f,%1.2f,%1.2f;", dev_minx,dev_maxx, dev_miny,dev_maxy);
301
print("SR%1.4f,%1.4f;", xd, yd);
302
uwriteln(&outfile, "PU;");
306
static void HPGLsetcolor(int colno) {
310
static void HPGLcharout(char c, double *xpos, double *ypos) {
311
store_char(c, actcol, *xpos, *ypos);
315
static void HPGLnewline(double *xpos, double *ypos) {
320
static void HPGLnewpage(double *xpos, double *ypos) {
322
uwriteln(&outfile, "PG");
329
static void HPGLexit(void) {
331
uwriteln(&outfile, "PG");
333
if (outfile.f != NULL)
338
GraphicsDevice Hpgl = {