import source from 1.3.40
[external/swig.git] / Examples / GIFPlot / Lib / font.c
1 /* ----------------------------------------------------------------------------- 
2  * font.c
3  *
4  *     Some basic fonts.
5  * 
6  * Author(s) : David Beazley (beazley@cs.uchicago.edu)
7  * Copyright (C) 1995-1996
8  *
9  * See the file LICENSE for information on usage and redistribution.    
10  * ----------------------------------------------------------------------------- */
11
12 #define FONT
13 #include "gifplot.h"
14
15 static char Char_A[80] = "\
16 ...x....\
17 ...x....\
18 ..x.x...\
19 ..x.x...\
20 .x...x..\
21 .xxxxx..\
22 x.....x.\
23 x.....x.\
24 x.....x.\
25 ........";
26
27 static char Char_B[80] = "\
28 xxxxxx..\
29 x.....x.\
30 x.....x.\
31 x.....x.\
32 xxxxxx..\
33 x.....x.\
34 x.....x.\
35 x.....x.\
36 xxxxxx..\
37 ........";
38
39 static char Char_C[80] = "\
40 ..xxxx..\
41 .x....x.\
42 x.......\
43 x.......\
44 x.......\
45 x.......\
46 x.......\
47 .x....x.\
48 ..xxxx..\
49 ........";
50
51 static char Char_D[80] = "\
52 xxxxx...\
53 x....x..\
54 x.....x.\
55 x.....x.\
56 x.....x.\
57 x.....x.\
58 x.....x.\
59 x....x..\
60 xxxxx...\
61 ........";
62 static char Char_E[80] = "\
63 xxxxxxx.\
64 x.......\
65 x.......\
66 x.......\
67 xxxxx...\
68 x.......\
69 x.......\
70 x.......\
71 xxxxxxx.\
72 ........";
73 static char Char_F[80] = "\
74 xxxxxxx.\
75 x.......\
76 x.......\
77 x.......\
78 xxxxx...\
79 x.......\
80 x.......\
81 x.......\
82 x.......\
83 ........";
84 static char Char_G[80] = "\
85 .xxxxx..\
86 x.....x.\
87 x.......\
88 x.......\
89 x...xxx.\
90 x.....x.\
91 x.....x.\
92 x.....x.\
93 .xxxxx..\
94 ........";
95 static char Char_H[80] = "\
96 x.....x.\
97 x.....x.\
98 x.....x.\
99 x.....x.\
100 xxxxxxx.\
101 x.....x.\
102 x.....x.\
103 x.....x.\
104 x.....x.\
105 ........";
106 static char Char_I[80] = "\
107 xxxxxxx.\
108 ...x....\
109 ...x....\
110 ...x....\
111 ...x....\
112 ...x....\
113 ...x....\
114 ...x....\
115 xxxxxxx.\
116 ........";
117 static char Char_J[80] = "\
118 ......x.\
119 ......x.\
120 ......x.\
121 ......x.\
122 ......x.\
123 ......x.\
124 x.....x.\
125 .x...x..\
126 ..xxx...\
127 ........";
128 static char Char_K[80] = "\
129 x.....x.\
130 x....x..\
131 x...x...\
132 x..x....\
133 xxx.....\
134 x..x....\
135 x...x...\
136 x....x..\
137 x.....x.\
138 ........";
139 static char Char_L[80] = "\
140 x.......\
141 x.......\
142 x.......\
143 x.......\
144 x.......\
145 x.......\
146 x.......\
147 x.......\
148 xxxxxxx.\
149 ........";
150 static char Char_M[80] = "\
151 x.....x.\
152 xx...xx.\
153 xx...xx.\
154 x.x.x.x.\
155 x.x.x.x.\
156 x..x..x.\
157 x..x..x.\
158 x.....x.\
159 x.....x.\
160 ........";
161 static char Char_N[80] = "\
162 x.....x.\
163 xx....x.\
164 x.x...x.\
165 x.x...x.\
166 x..x..x.\
167 x...x.x.\
168 x...x.x.\
169 x....xx.\
170 x.....x.\
171 ........";
172 static char Char_O[80] = "\
173 .xxxxx..\
174 x.....x.\
175 x.....x.\
176 x.....x.\
177 x.....x.\
178 x.....x.\
179 x.....x.\
180 x.....x.\
181 .xxxxx..\
182 ........";
183 static char Char_P[80] = "\
184 xxxxxx..\
185 x.....x.\
186 x.....x.\
187 x.....x.\
188 xxxxxx..\
189 x.......\
190 x.......\
191 x.......\
192 x.......\
193 ........";
194 static char Char_Q[80] = "\
195 .xxxxx..\
196 x.....x.\
197 x.....x.\
198 x.....x.\
199 x.....x.\
200 x.....x.\
201 x...x.x.\
202 x....x..\
203 .xxxx.x.\
204 ........";
205 static char Char_R[80] = "\
206 xxxxxx..\
207 x.....x.\
208 x.....x.\
209 x.....x.\
210 xxxxxx..\
211 x..x....\
212 x...x...\
213 x....x..\
214 x.....x.\
215 ........";
216 static char Char_S[80] = "\
217 .xxxxx..\
218 x.....x.\
219 x.......\
220 x.......\
221 .xxxxx..\
222 ......x.\
223 ......x.\
224 x.....x.\
225 .xxxxx..\
226 ........";
227 static char Char_T[80] = "\
228 xxxxxxx.\
229 ...x....\
230 ...x....\
231 ...x....\
232 ...x....\
233 ...x....\
234 ...x....\
235 ...x....\
236 ...x....\
237 ........";
238 static char Char_U[80] = "\
239 x.....x.\
240 x.....x.\
241 x.....x.\
242 x.....x.\
243 x.....x.\
244 x.....x.\
245 x.....x.\
246 x.....x.\
247 .xxxxx..\
248 ........";
249 static char Char_V[80] = "\
250 x.....x.\
251 x.....x.\
252 .x...x..\
253 .x...x..\
254 ..x.x...\
255 ..x.x...\
256 ...x....\
257 ...x....\
258 ...x....\
259 ........";
260 static char Char_W[80] = "\
261 x.....x.\
262 x.....x.\
263 x.....x.\
264 x.....x.\
265 x.....x.\
266 x..x..x.\
267 x..x..x.\
268 x.x.x.x.\
269 .x...x..\
270 ........";
271 static char Char_X[80] = "\
272 x.....x.\
273 x.....x.\
274 .x...x..\
275 ..x.x...\
276 ...x....\
277 ..x.x...\
278 .x...x..\
279 x.....x.\
280 x.....x.\
281 ........";
282 static char Char_Y[80] = "\
283 x.....x.\
284 x.....x.\
285 .x...x..\
286 ..x.x...\
287 ...x....\
288 ...x....\
289 ...x....\
290 ...x....\
291 ...x....\
292 ........";
293 static char Char_Z[80] = "\
294 xxxxxxx.\
295 ......x.\
296 .....x..\
297 ....x...\
298 ...x....\
299 ..x.....\
300 .x......\
301 x.......\
302 xxxxxxx.\
303 ........";
304 static char Char_0[80] = "\
305 .xxxxx..\
306 x....xx.\
307 x...x.x.\
308 x..x..x.\
309 x..x..x.\
310 x.x...x.\
311 x.x...x.\
312 xx....x.\
313 .xxxxx..\
314 ........";
315 static char Char_1[80] = "\
316 ...x....\
317 ..xx....\
318 ...x....\
319 ...x....\
320 ...x....\
321 ...x....\
322 ...x....\
323 ...x....\
324 ..xxx...\
325 ........";
326 static char Char_2[80] = "\
327 ..xxxx..\
328 .x....x.\
329 x.....x.\
330 .....x..\
331 ....x...\
332 ...x....\
333 ..x.....\
334 .x......\
335 xxxxxxx.\
336 ........";
337 static char Char_3[80] = "\
338 .xxxxx..\
339 x.....x.\
340 ......x.\
341 ......x.\
342 ...xxx..\
343 ......x.\
344 ......x.\
345 x.....x.\
346 .xxxxx..\
347 ........";
348 static char Char_4[80] = "\
349 ....xx..\
350 ...x.x..\
351 ..x..x..\
352 .x...x..\
353 xxxxxxx.\
354 .....x..\
355 .....x..\
356 .....x..\
357 .....x..\
358 ........";
359 static char Char_5[80] = "\
360 xxxxxxx.\
361 x.......\
362 x.......\
363 x.......\
364 xxxxxx..\
365 ......x.\
366 ......x.\
367 x.....x.\
368 .xxxxx..\
369 ........";
370 static char Char_6[80] = "\
371 ....xxx.\
372 ..xx....\
373 .x......\
374 x.......\
375 x.xxx...\
376 xx...x..\
377 x.....x.\
378 .x...x..\
379 ..xxx...\
380 ........";
381 static char Char_7[80] = "\
382 xxxxxxx.\
383 x.....x.\
384 .....x..\
385 ....x...\
386 ...x....\
387 ..x.....\
388 .x......\
389 x.......\
390 x.......\
391 ........";
392 static char Char_8[80] = "\
393 .xxxxx..\
394 x.....x.\
395 x.....x.\
396 x.....x.\
397 .xxxxx..\
398 x.....x.\
399 x.....x.\
400 x.....x.\
401 .xxxxx..\
402 ........";
403 static char Char_9[80] = "\
404 ..xxxx..\
405 .x....x.\
406 x.....x.\
407 x....xx.\
408 .xxxx.x.\
409 ......x.\
410 ......x.\
411 ....xx..\
412 .xxx....\
413 ........";
414 static char Char_MINUS[80] = "\
415 ........\
416 ........\
417 ........\
418 ........\
419 .xxxxxx.\
420 ........\
421 ........\
422 ........\
423 ........\
424 ........";
425 static char Char_PLUS[80] = "\
426 ........\
427 ........\
428 ...x....\
429 ...x....\
430 .xxxxx..\
431 ...x....\
432 ...x....\
433 ........\
434 ........\
435 ........";
436 static char Char_EQUAL[80] = "\
437 ........\
438 ........\
439 ........\
440 .xxxxx..\
441 ........\
442 .xxxxx..\
443 ........\
444 ........\
445 ........\
446 ........";
447 static char Char_LPAREN[80] = "\
448 ....x...\
449 ...x....\
450 ..x.....\
451 .x......\
452 .x......\
453 .x......\
454 ..x.....\
455 ...x....\
456 ....x...\
457 ........";
458 static char Char_RPAREN[80] = "\
459 ...x....\
460 ....x...\
461 .....x..\
462 ......x.\
463 ......x.\
464 ......x.\
465 .....x..\
466 ....x...\
467 ...x....\
468 ........";
469 static char Char_QUOTE[80] = "\
470 ..x.x...\
471 ..x.x...\
472 ........\
473 ........\
474 ........\
475 ........\
476 ........\
477 ........\
478 ........\
479 ........";
480 static char Char_COLON[80] = "\
481 ........\
482 ........\
483 ...xx...\
484 ...xx...\
485 ........\
486 ...xx...\
487 ...xx...\
488 ........\
489 ........\
490 ........";
491 static char Char_PERIOD[80] = "\
492 ........\
493 ........\
494 ........\
495 ........\
496 ........\
497 ........\
498 ........\
499 ...xx...\
500 ...xx...\
501 ........";
502 static char Char_COMMA[80] = "\
503 ........\
504 ........\
505 ........\
506 ........\
507 ........\
508 ........\
509 ...xx...\
510 ...xx...\
511 ....x...\
512 ...x....";
513
514 static char Char_SLASH[80] = "\
515 ........\
516 ......x.\
517 .....x..\
518 ....x...\
519 ...x....\
520 ..x.....\
521 .x......\
522 x.......\
523 ........\
524 ........";
525
526 static char Char_SPACE[80] = "\
527 ........\
528 ........\
529 ........\
530 ........\
531 ........\
532 ........\
533 ........\
534 ........\
535 ........\
536 ........";
537
538 static char  *GP_Font[128];
539 static int    InitGP_Font = 0;
540
541 static void initGP_Fonts(void) {
542
543   int i;
544   for (i = 0; i < 128; i++)
545     GP_Font[i] = (char *) 0;
546   
547   GP_Font['A'] = GP_Font['a'] = Char_A;
548   GP_Font['B'] = GP_Font['b'] = Char_B;
549   GP_Font['C'] = GP_Font['c'] = Char_C;
550   GP_Font['D'] = GP_Font['d'] = Char_D;
551   GP_Font['E'] = GP_Font['e'] = Char_E;
552   GP_Font['F'] = GP_Font['f'] = Char_F;
553   GP_Font['G'] = GP_Font['g'] = Char_G;
554   GP_Font['H'] = GP_Font['h'] = Char_H;
555   GP_Font['I'] = GP_Font['i'] = Char_I;
556   GP_Font['J'] = GP_Font['j'] = Char_J;
557   GP_Font['K'] = GP_Font['k'] = Char_K;
558   GP_Font['L'] = GP_Font['l'] = Char_L;
559   GP_Font['M'] = GP_Font['m'] = Char_M;
560   GP_Font['N'] = GP_Font['n'] = Char_N;
561   GP_Font['O'] = GP_Font['o'] = Char_O;
562   GP_Font['P'] = GP_Font['p'] = Char_P;
563   GP_Font['Q'] = GP_Font['q'] = Char_Q;
564   GP_Font['R'] = GP_Font['r'] = Char_R;
565   GP_Font['S'] = GP_Font['s'] = Char_S;
566   GP_Font['T'] = GP_Font['t'] = Char_T;
567   GP_Font['U'] = GP_Font['u'] = Char_U;
568   GP_Font['V'] = GP_Font['v'] = Char_V;
569   GP_Font['W'] = GP_Font['w'] = Char_W;
570   GP_Font['X'] = GP_Font['x'] = Char_X;
571   GP_Font['Y'] = GP_Font['y'] = Char_Y;
572   GP_Font['Z'] = GP_Font['z'] = Char_Z;
573   GP_Font['0'] = Char_0;
574   GP_Font['1'] = Char_1;
575   GP_Font['2'] = Char_2;
576   GP_Font['3'] = Char_3;
577   GP_Font['4'] = Char_4;
578   GP_Font['5'] = Char_5;
579   GP_Font['6'] = Char_6;
580   GP_Font['7'] = Char_7;
581   GP_Font['8'] = Char_8;
582   GP_Font['9'] = Char_9;
583   GP_Font['.'] = Char_PERIOD;
584   GP_Font[','] = Char_COMMA;
585   GP_Font['='] = Char_EQUAL;
586   GP_Font['-'] = Char_MINUS;
587   GP_Font['+'] = Char_PLUS;
588   GP_Font['\"'] = Char_QUOTE;
589   GP_Font['('] = Char_LPAREN;
590   GP_Font[')'] = Char_RPAREN;
591   GP_Font[':'] = Char_COLON;
592   GP_Font['/'] = Char_SLASH;
593   GP_Font[' '] = Char_SPACE;
594   InitGP_Font = 1;
595 }
596
597 /* -----------------------------------------------------------------------
598    void FrameBuffer_drawchar(FrameBuffer *f, int x, int y, Pixel fgcolor, Pixel bgcolor, char chr, int orientation)
599
600    Draws a character at location x, y with given color and orientation parameters.
601    Orientation can either be HORIZONTAL or VERTICAL
602    ----------------------------------------------------------------------- */
603 void FrameBuffer_drawchar(FrameBuffer *f, int x, int y, int fgcolor,
604                           int bgcolor, char chr, int orientation) {
605
606   Pixel c, bc,*p,*p1;
607   char *ch;
608   int i,j;
609   int xpixels,ypixels;
610
611   if (!InitGP_Font) initGP_Fonts();
612   
613   c =  (Pixel) fgcolor;
614   bc = (Pixel) bgcolor;
615   xpixels = f->width;
616   ypixels = f->height;
617
618   if (orientation == HORIZONTAL) {
619     if ((x < f->xmin) || (x > f->xmax-8) ||
620         (y < f->ymin) || (y > f->ymax-10)) return;
621   
622     ch = GP_Font[(int) chr];
623     if (!ch) return;
624     p = &f->pixels[y+9][x];
625     for (i = 0; i < 10; i++) {
626       p1 = p;
627       for (j = 0; j< 8; j++) {
628         if (*(ch++) == 'x') *p= c;
629         else if (bgcolor >= 0)
630           *p = bc;
631         p++;
632       }
633       p = (p1 - xpixels);
634     }
635   } else {
636     if ((x < f->xmin+10) || (x >= f->xmax) ||
637         (y < f->ymin) || (y > f->ymax-8)) return;
638   
639     ch = GP_Font[(int) chr];
640     if (!ch) return;
641     p = &f->pixels[y][x-9];
642     for (i = 0; i < 10; i++) {
643       p1 = p;
644       for (j = 0; j< 8; j++) {
645         if (*(ch++) == 'x') *p= c;
646         else if (bgcolor >= 0)
647           *p = bc;
648         p+=xpixels;
649       }
650       p = p1 + 1;
651     }
652   }    
653 }
654
655 /* ----------------------------------------------------------------------
656    void FrameBuffer_drawstring(FrameBuffer *f, int x, int y, int fgcolor,
657                                int bgcolor, char *text, int orientation)
658
659    Draws an ASCII string on the framebuffer.   Can be oriented either horizontally
660    or vertically.  
661    ---------------------------------------------------------------------- */
662
663 void FrameBuffer_drawstring(FrameBuffer *f, int x, int y, int fgcolor, int bgcolor, char *text, int orientation) {
664
665   char *c;
666   int  x1, y1;
667   int xpixels, ypixels;
668   
669   x1 = x;
670   y1 = y;
671   xpixels = f->width;
672   ypixels = f->height;
673   c = text;
674   while (*c) {
675     if (*c == '\n') {
676       if (orientation == HORIZONTAL) {
677         x1 = x; y1= y1- 10*xpixels;
678       } else {
679         y1 = y; x1= x1 + 10*ypixels;
680       }
681     } else {
682       FrameBuffer_drawchar(f, x1,y1,fgcolor, bgcolor,*c, orientation);
683       if (orientation == HORIZONTAL) {
684         x1+=8;
685         if (x1 >= (xpixels-8)) {
686           x1 = x; y1= y1- 10;}
687         if (y1 < 0) return;
688       } else {
689         y1 += 8;
690         if (y1 >= (ypixels-8)) {
691           y1 = y; x1 = x1 + 10;}
692         if (x1 > (xpixels-10)) return;
693       }
694     }
695     c++;
696   }
697 }
698
699
700   
701   
702   
703   
704   
705