~ubuntu-branches/ubuntu/raring/boxshade/raring-proposed

« back to all changes in this revision

Viewing changes to .pc/kickOutGets.patch/dv_hpgl.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille, David Paleino, Andreas Tille
  • Date: 2011-01-14 08:27:01 UTC
  • Revision ID: james.westby@ubuntu.com-20110114082701-etwd13n9n7nz8h78
Tags: 3.3.1-5
[ David Paleino ]
* Removed myself from Uploaders

[ Andreas Tille ]
* debian/control
  - Standards-Version: 3.9.1 (no changes needed)
  - Debhelper 7
  - Fix spelling of Debian Med in maintainer address
* debian/rules: s/dh_clean -k/dh_prep/
* debian/source/format: 3.0 (quilt)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "dv_all.h"
 
2
 
 
3
#include <stdarg.h>
 
4
 
 
5
/*----------------------------------------*/
 
6
/*   HPGL  specific section               */
 
7
/*----------------------------------------*/
 
8
 
 
9
typedef struct hpglrecord {
 
10
  char *hatch;
 
11
  int bgnd, fgnd;
 
12
} hpglrecord;
 
13
 
 
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 */
 
19
 
 
20
#define HATCHES 4
 
21
static char *hatches[HATCHES] = { "", "3,0.8,45", "4,0.8,0", "1" };
 
22
 
 
23
/* -------------- VERY simple output optimizer */
 
24
 
 
25
typedef struct {
 
26
  char   c;
 
27
  byte   col;
 
28
  float  px, py;
 
29
} STORE;
 
30
 
 
31
#define MAX_STORE 256
 
32
 
 
33
static STORE store[MAX_STORE];
 
34
static int   store_idx = 0;
 
35
static int   print_len = 0;
 
36
 
 
37
static char buf[100];
 
38
static void print(char *fmt, ...) {
 
39
   va_list argptr;
 
40
   int len;
 
41
 
 
42
   va_start(argptr, fmt);
 
43
   len = vsprintf(buf, fmt, argptr);
 
44
   va_end(argptr);
 
45
   if (print_len+len > 78) {
 
46
     uwriteln(&outfile, "");
 
47
     print_len = 0;
 
48
   }
 
49
   fprintf(outfile.f, "%s", buf);
 
50
   print_len += len;
 
51
}
 
52
 
 
53
 
 
54
/* select a new pen */
 
55
static int select_pen(int pen) {
 
56
  if (pen != hpglpen) {
 
57
    hpglpen = pen;
 
58
    print("SP%d;", hpglpen);
 
59
    return TRUE;
 
60
  }
 
61
  return FALSE;
 
62
}
 
63
 
 
64
/* write out all stored characters */
 
65
static void flush_fg(int pen) {
 
66
  int idx;
 
67
 
 
68
  for (idx = 0; idx < store_idx; ++idx) {
 
69
    if (   store[idx].c != ' '
 
70
        && hpglrec[store[idx].col].fgnd == pen ) {
 
71
      select_pen(pen);
 
72
      print("PU%1.2f,%1.2f;", store[idx].px, store[idx].py);
 
73
      print("LB%c\003;", store[idx].c);
 
74
    }
 
75
  }
 
76
}
 
77
 
 
78
/* draw all saved background shadings */
 
79
static void flush_bg(int pen) {
 
80
  int idx, h;
 
81
 
 
82
  if (pen <= 0) return;
 
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;
 
89
        select_pen(pen);
 
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);
 
94
        }
 
95
        print("RR%1.2f,%1.2f;", dev_xsize, dev_ysize);
 
96
      }
 
97
    }
 
98
  }
 
99
}
 
100
 
 
101
/* save stored character cells */
 
102
static void store_flush(void) {
 
103
  int p, sp;
 
104
 
 
105
  /* first background */
 
106
  sp = hpglpen;
 
107
  flush_bg(sp); /* actual pen first */
 
108
  for (p=1; p < 10; ++p)
 
109
    if (p!=sp)
 
110
      flush_bg(p);
 
111
 
 
112
  /* then foreground */
 
113
  sp = hpglpen;
 
114
  flush_fg(sp); /* actual pen first */
 
115
  for (p=0; p < 10; ++p)
 
116
    if (p!=sp)
 
117
      flush_fg(p);
 
118
 
 
119
  store_idx = 0;
 
120
}
 
121
 
 
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;
 
128
  ++store_idx;
 
129
  if (store_idx == MAX_STORE)
 
130
    store_flush();
 
131
}
 
132
 
 
133
/* - - - - - - - - - - - - - - */
 
134
 
 
135
static void menu_hpgl(hpglrecord *hpglrec, BOOL *lc, char *txt, char *parstring)
 
136
{
 
137
  char code1, code2;
 
138
  char instring[41];
 
139
 
 
140
  if (interactflag) {
 
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);
 
153
  } else
 
154
    *instring = '\0';
 
155
  if (*instring == '\0') {
 
156
    code1 = parstring[0];
 
157
    code2 = parstring[1];
 
158
  } else {
 
159
    code1 = instring[0];
 
160
    code2 = instring[1];
 
161
  }
 
162
  code1 = toupper(code1);
 
163
  code2 = toupper(code2);
 
164
  if (strchr("NSCF", code2) == NULL)
 
165
    code2 = 'N';
 
166
  switch (code2) {
 
167
    case 'N':
 
168
      hpglrec->hatch = hatches[0];
 
169
      break;
 
170
    case 'S':
 
171
      hpglrec->hatch = hatches[1];
 
172
      break;
 
173
    case 'C':
 
174
      hpglrec->hatch = hatches[2];
 
175
      break;
 
176
    case 'F':
 
177
      hpglrec->hatch = hatches[3];
 
178
      break;
 
179
  }
 
180
  hpglrec->bgnd = code1-'0';
 
181
  if (interactflag) {
 
182
    printf("\n\nEnter the text attributes for printing of **>%s<** residues:\n",
 
183
           txt);
 
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);
 
194
  } else
 
195
    *instring = '\0';
 
196
  if (*instring == '\0') {
 
197
    code1 = parstring[2];
 
198
    code2 = parstring[3];
 
199
  } else {
 
200
    code1 = instring[0];
 
201
    code2 = instring[1];
 
202
  }
 
203
  if (code2 == 'L' || code2 == 'l')
 
204
    *lc = TRUE;
 
205
  else
 
206
    *lc = FALSE;
 
207
  hpglrec->fgnd = code1 - '0';
 
208
}
 
209
 
 
210
 
 
211
static void ask_hpgl(void)
 
212
{
 
213
  char parstring[6];
 
214
  char instring[41];
 
215
 
 
216
  term_par("HPGL");
 
217
  if (interactflag)
 
218
    printf(
 
219
      "-----------------------------------------------------------------------\n");
 
220
  Fgets(parstring, 6, parfile);
 
221
  parstring[4] = '\0';
 
222
  menu_hpgl(hpglrec, lc, "different", parstring);
 
223
  Fgets(parstring, 6, parfile);
 
224
  parstring[4] = '\0';
 
225
  menu_hpgl(&hpglrec[1], &lc[1], "identical", parstring);
 
226
  Fgets(parstring, 6, parfile);
 
227
  parstring[4] = '\0';
 
228
  if (simflag)
 
229
    menu_hpgl(&hpglrec[2], &lc[2], "similar", parstring);
 
230
  else {
 
231
    hpglrec[2] = hpglrec[0];
 
232
    lc[2] = lc[0];
 
233
  }
 
234
  Fgets(parstring, 6, parfile);
 
235
  parstring[4] = '\0';
 
236
  if (globalflag)
 
237
    menu_hpgl(&hpglrec[3], &lc[3], "conserved", parstring);
 
238
  else {
 
239
    hpglrec[3] = hpglrec[1];
 
240
    lc[3] = lc[1];
 
241
  }
 
242
  hpglrec[4].bgnd = 0;
 
243
  hpglrec[4].hatch = hatches[0];
 
244
  hpglrec[4].fgnd = hpglrec[0].fgnd;
 
245
  lc[4] = FALSE;
 
246
  fscanf(parfile, "%lg%*[^\n]", &hpglcell);
 
247
  getc(parfile);
 
248
  Fgets(parstring, 6, parfile);
 
249
  if (parstring[0] == 'Y' || parstring[0] == 'y')
 
250
    landscapeflag = TRUE;
 
251
  else
 
252
    landscapeflag = FALSE;
 
253
  if (interactflag) {
 
254
    do {
 
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;
 
265
      else
 
266
        landscapeflag = FALSE;
 
267
    }
 
268
  }
 
269
  if (!cloutflag) {
 
270
    printf("filename for HPGL-output  : ");
 
271
    gets(outname);
 
272
  }
 
273
}
 
274
 
 
275
 
 
276
static void HPGLinit(double *xpos, double *ypos) {
 
277
  double xd, yd;
 
278
 
 
279
  if (landscapeflag) {
 
280
    dev_minx = 10.75;   /* borders of a A4 page in mm */
 
281
    dev_miny = 5.0;
 
282
    dev_maxx = 260.75;
 
283
    dev_maxy = 185.0;
 
284
  } else {
 
285
    dev_minx = 5.0;   /* borders of a A4 page in mm */
 
286
    dev_miny = 10.75;
 
287
    dev_maxx = 185.0;
 
288
    dev_maxy = 260.75;
 
289
  }
 
290
  dev_xsize = hpglcell * 0.351;
 
291
  dev_ysize = hpglcell * 0.351 * 2.0 / 1.5;
 
292
  hpglpen = 0;
 
293
  hpglhatch = hatches[0];
 
294
  *xpos = dev_minx;
 
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;");
 
303
  print_len = 0;
 
304
}
 
305
 
 
306
static void HPGLsetcolor(int colno) {
 
307
  actcol  = colno;
 
308
}
 
309
 
 
310
static void HPGLcharout(char c, double *xpos, double *ypos) {
 
311
  store_char(c, actcol, *xpos, *ypos);
 
312
  *xpos += dev_xsize;
 
313
}
 
314
 
 
315
static void HPGLnewline(double *xpos, double *ypos) {
 
316
  *xpos = dev_minx;
 
317
  *ypos -= dev_ysize;
 
318
}
 
319
 
 
320
static void HPGLnewpage(double *xpos, double *ypos) {
 
321
  store_flush();
 
322
  uwriteln(&outfile, "PG");
 
323
  print_len = 0;
 
324
  *xpos = dev_minx;
 
325
  *ypos = dev_maxy;
 
326
  print("PU;");
 
327
}
 
328
 
 
329
static void HPGLexit(void) {
 
330
  store_flush();
 
331
  uwriteln(&outfile, "PG");
 
332
  print_len = 0;
 
333
  if (outfile.f != NULL)
 
334
    fclose(outfile.f);
 
335
  outfile.f = NULL;
 
336
}
 
337
 
 
338
GraphicsDevice Hpgl = {
 
339
  "HPGL",
 
340
  ask_hpgl,
 
341
  HPGLinit,
 
342
  HPGLsetcolor,
 
343
  HPGLcharout,
 
344
  GenericStringOut,
 
345
  HPGLnewline,
 
346
  HPGLnewpage,
 
347
  HPGLexit
 
348
};