text.c revision 28328
128328Ssos/*-
228328Ssos * Copyright (c) 1991-1997 S�ren Schmidt
328328Ssos * All rights reserved.
428328Ssos *
528328Ssos * Redistribution and use in source and binary forms, with or without
628328Ssos * modification, are permitted provided that the following conditions
728328Ssos * are met:
828328Ssos * 1. Redistributions of source code must retain the above copyright
928328Ssos *    notice, this list of conditions and the following disclaimer
1028328Ssos *    in this position and unchanged.
1128328Ssos * 2. Redistributions in binary form must reproduce the above copyright
1228328Ssos *    notice, this list of conditions and the following disclaimer in the
1328328Ssos *    documentation and/or other materials provided with the distribution.
1428328Ssos * 3. The name of the author may not be used to endorse or promote products
1528328Ssos *    derived from this software withough specific prior written permission
1628328Ssos *
1728328Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1828328Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1928328Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2028328Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2128328Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2228328Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2328328Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2428328Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2528328Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2628328Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2728328Ssos *
2828328Ssos *  $Id: text.c,v 1.4 1997/08/13 19:34:23 sos Exp $
2928328Ssos */
3028328Ssos
3128328Ssos#include <stdio.h>
3228328Ssos#include "vgl.h"
3328328Ssos
3428328Ssosstatic VGLText		*VGLTextFont = 0;
3528328Ssos
3628328Ssosextern byte VGLFont[];
3728328Ssos
3828328Ssosint
3928328SsosVGLTextSetFontFile(char *filename)
4028328Ssos{
4128328SsosFILE *fd;
4228328Ssos
4328328Ssos  if (VGLTextFont) {
4428328Ssos    if (VGLTextFont->BitmapArray)
4528328Ssos      free (VGLTextFont->BitmapArray);
4628328Ssos    free(VGLTextFont);
4728328Ssos  }
4828328Ssos
4928328Ssos  if ((VGLTextFont=(VGLText*)malloc(sizeof(VGLText))) == (VGLText*)0)
5028328Ssos	return 1;
5128328Ssos
5228328Ssos  if (filename==NULL) {
5328328Ssos    VGLTextFont->Width = 8;
5428328Ssos    VGLTextFont->Height = 8;
5528328Ssos    VGLTextFont->BitmapArray = VGLFont;
5628328Ssos  }
5728328Ssos  else {
5828328Ssos    if ((fd=fopen(filename, "r"))==(FILE*)0)
5928328Ssos      return 1;
6028328Ssos    fread(&VGLTextFont->Width, 1 , 1, fd);
6128328Ssos    fread(&VGLTextFont->Height, 1 , 1, fd);
6228328Ssos    VGLTextFont->BitmapArray =
6328328Ssos      (byte*)malloc(256*VGLTextFont->Width*VGLTextFont->Height);
6428328Ssos    fread(VGLTextFont->BitmapArray, 1,
6528328Ssos      (256*VGLTextFont->Width* VGLTextFont->Height), fd);
6628328Ssos    fclose(fd);
6728328Ssos  }
6828328Ssos  return 0;
6928328Ssos}
7028328Ssos
7128328Ssosvoid
7228328SsosVGLBitmapPutChar(VGLBitmap *Object, int x, int y, byte ch,
7328328Ssos		 byte fgcol, byte bgcol, int fill, int dir)
7428328Ssos{
7528328Ssos  int lin, bit;
7628328Ssos
7728328Ssos  for(lin = 0; lin < VGLTextFont->Height; lin++) {
7828328Ssos    for(bit = 0; bit < VGLTextFont->Width; bit++) {
7928328Ssos      if (VGLTextFont->BitmapArray[((ch*VGLTextFont->Height)+lin)]&(1<<bit))
8028328Ssos        switch (dir) {
8128328Ssos          case 0:
8228328Ssos            VGLSetXY(Object, (x+7-bit), (y+lin), fgcol);
8328328Ssos	    break;
8428328Ssos          case 1:
8528328Ssos            VGLSetXY(Object, (x+lin), (y-7+bit), fgcol);
8628328Ssos	    break;
8728328Ssos          case 2:
8828328Ssos            VGLSetXY(Object, (x-7+bit), (y-lin), fgcol);
8928328Ssos	    break;
9028328Ssos          case 3:
9128328Ssos            VGLSetXY(Object, (x-lin), (y+7-bit), fgcol);
9228328Ssos	    break;
9328328Ssos          case 4:
9428328Ssos            VGLSetXY(Object, (x+lin+7-bit), (y+lin+bit), fgcol);
9528328Ssos	    break;
9628328Ssos        }
9728328Ssos      else if (fill)
9828328Ssos        switch (dir) {
9928328Ssos          case 0:
10028328Ssos            VGLSetXY(Object, (x+7-bit), (y+lin), bgcol);
10128328Ssos	    break;
10228328Ssos          case 1:
10328328Ssos            VGLSetXY(Object, (x+lin), (y-7+bit), bgcol);
10428328Ssos	    break;
10528328Ssos          case 2:
10628328Ssos            VGLSetXY(Object, (x-7+bit), (y-lin), bgcol);
10728328Ssos	    break;
10828328Ssos          case 3:
10928328Ssos            VGLSetXY(Object, (x-lin), (y+7-bit), bgcol);
11028328Ssos	    break;
11128328Ssos          case 4:
11228328Ssos            VGLSetXY(Object, (x+lin+7-bit), (y+lin+bit), bgcol);
11328328Ssos	    break;
11428328Ssos        }
11528328Ssos    }
11628328Ssos  }
11728328Ssos}
11828328Ssos
11928328Ssosvoid
12028328SsosVGLBitmapString(VGLBitmap *Object, int x, int y, char *str,
12128328Ssos		byte fgcol, byte bgcol, int fill, int dir)
12228328Ssos{
12328328Ssos  int pos;
12428328Ssos
12528328Ssos  for (pos=0; pos<strlen(str); pos++) {
12628328Ssos    switch (dir) {
12728328Ssos      case 0:
12828328Ssos        VGLBitmapPutChar(Object, x+(pos*VGLTextFont->Width), y,
12928328Ssos                         str[pos], fgcol, bgcol, fill, dir);
13028328Ssos	break;
13128328Ssos      case 1:
13228328Ssos        VGLBitmapPutChar(Object, x, y-(pos*VGLTextFont->Width),
13328328Ssos		         str[pos], fgcol, bgcol, fill, dir);
13428328Ssos	break;
13528328Ssos      case 2:
13628328Ssos        VGLBitmapPutChar(Object, x-(pos*VGLTextFont->Width), y,
13728328Ssos		         str[pos], fgcol, bgcol, fill, dir);
13828328Ssos	break;
13928328Ssos      case 3:
14028328Ssos        VGLBitmapPutChar(Object, x, y+(pos*VGLTextFont->Width),
14128328Ssos		         str[pos], fgcol, bgcol, fill, dir);
14228328Ssos	break;
14328328Ssos      case 4:
14428328Ssos        VGLBitmapPutChar(Object, x+(pos*VGLTextFont->Width),
14528328Ssos                         y-(pos*VGLTextFont->Width),
14628328Ssos		         str[pos], fgcol, bgcol, fill, dir);
14728328Ssos	break;
14828328Ssos    }
14928328Ssos  }
15028328Ssos}
15128328Ssos
15228328Ssosbyte VGLFont[] = {
15328328Ssos0,0,0,0,0,0,0,0,126,129,165,129,189,153,129,126,126,255,219,255,195,231,
15428328Ssos255,126,108,254,254,254,124,56,16,0,16,56,124,254,124,56,16,0,56,124,56,
15528328Ssos254,254,124,56,124,16,16,56,124,254,124,56,124,0,0,24,60,60,24,0,0,255,
15628328Ssos255,231,195,195,231,255,255,0,60,102,66,66,102,60,0,255,195,153,189,189,
15728328Ssos153,195,255,15,7,15,125,204,204,204,120,60,102,102,102,60,24,126,24,63,
15828328Ssos51,63,48,48,112,240,224,127,99,127,99,99,103,230,192,153,90,60,231,231,
15928328Ssos60,90,153,128,224,248,254,248,224,128,0,2,14,62,254,62,14,2,0,24,60,126,
16028328Ssos24,24,126,60,24,102,102,102,102,102,0,102,0,127,219,219,123,27,27,27,0,
16128328Ssos62,99,56,108,108,56,204,120,0,0,0,0,126,126,126,0,24,60,126,24,126,60,24,
16228328Ssos255,24,60,126,24,24,24,24,0,24,24,24,24,126,60,24,0,0,24,12,254,12,24,0,
16328328Ssos0,0,48,96,254,96,48,0,0,0,0,192,192,192,254,0,0,0,36,102,255,102,36,0,0,
16428328Ssos0,24,60,126,255,255,0,0,0,255,255,126,60,24,0,0,0,0,0,0,0,0,0,0,48,120,
16528328Ssos120,48,48,0,48,0,108,108,108,0,0,0,0,0,108,108,254,108,254,108,108,0,48,
16628328Ssos124,192,120,12,248,48,0,0,198,204,24,48,102,198,0,56,108,56,118,220,204,
16728328Ssos118,0,96,96,192,0,0,0,0,0,24,48,96,96,96,48,24,0,96,48,24,24,24,48,96,0,
16828328Ssos0,102,60,255,60,102,0,0,0,48,48,252,48,48,0,0,0,0,0,0,0,48,48,96,0,0,0,
16928328Ssos252,0,0,0,0,0,0,0,0,0,48,48,0,6,12,24,48,96,192,128,0,124,198,206,222,246,
17028328Ssos230,124,0,48,112,48,48,48,48,252,0,120,204,12,56,96,204,252,0,120,204,12,
17128328Ssos56,12,204,120,0,28,60,108,204,254,12,30,0,252,192,248,12,12,204,120,0,56,
17228328Ssos96,192,248,204,204,120,0,252,204,12,24,48,48,48,0,120,204,204,120,204,204,
17328328Ssos120,0,120,204,204,124,12,24,112,0,0,48,48,0,0,48,48,0,0,48,48,0,0,48,48,
17428328Ssos96,24,48,96,192,96,48,24,0,0,0,252,0,0,252,0,0,96,48,24,12,24,48,96,0,120,
17528328Ssos204,12,24,48,0,48,0,124,198,222,222,222,192,120,0,48,120,204,204,252,204,
17628328Ssos204,0,252,102,102,124,102,102,252,0,60,102,192,192,192,102,60,0,248,108,
17728328Ssos102,102,102,108,248,0,254,98,104,120,104,98,254,0,254,98,104,120,104,96,
17828328Ssos240,0,60,102,192,192,206,102,62,0,204,204,204,252,204,204,204,0,120,48,
17928328Ssos48,48,48,48,120,0,30,12,12,12,204,204,120,0,230,102,108,120,108,102,230,
18028328Ssos0,240,96,96,96,98,102,254,0,198,238,254,254,214,198,198,0,198,230,246,222,
18128328Ssos206,198,198,0,56,108,198,198,198,108,56,0,252,102,102,124,96,96,240,0,120,
18228328Ssos204,204,204,220,120,28,0,252,102,102,124,108,102,230,0,120,204,224,112,
18328328Ssos28,204,120,0,252,180,48,48,48,48,120,0,204,204,204,204,204,204,252,0,204,
18428328Ssos204,204,204,204,120,48,0,198,198,198,214,254,238,198,0,198,198,108,56,56,
18528328Ssos108,198,0,204,204,204,120,48,48,120,0,254,198,140,24,50,102,254,0,120,96,
18628328Ssos96,96,96,96,120,0,192,96,48,24,12,6,2,0,120,24,24,24,24,24,120,0,16,56,
18728328Ssos108,198,0,0,0,0,0,0,0,0,0,0,0,255,48,48,24,0,0,0,0,0,0,0,120,12,124,204,
18828328Ssos118,0,224,96,96,124,102,102,220,0,0,0,120,204,192,204,120,0,28,12,12,124,
18928328Ssos204,204,118,0,0,0,120,204,252,192,120,0,56,108,96,240,96,96,240,0,0,0,118,
19028328Ssos204,204,124,12,248,224,96,108,118,102,102,230,0,48,0,112,48,48,48,120,0,
19128328Ssos12,0,12,12,12,204,204,120,224,96,102,108,120,108,230,0,112,48,48,48,48,
19228328Ssos48,120,0,0,0,204,254,254,214,198,0,0,0,248,204,204,204,204,0,0,0,120,204,
19328328Ssos204,204,120,0,0,0,220,102,102,124,96,240,0,0,118,204,204,124,12,30,0,0,
19428328Ssos220,118,102,96,240,0,0,0,124,192,120,12,248,0,16,48,124,48,48,52,24,0,0,
19528328Ssos0,204,204,204,204,118,0,0,0,204,204,204,120,48,0,0,0,198,214,254,254,108,
19628328Ssos0,0,0,198,108,56,108,198,0,0,0,204,204,204,124,12,248,0,0,252,152,48,100,
19728328Ssos252,0,28,48,48,224,48,48,28,0,24,24,24,0,24,24,24,0,224,48,48,28,48,48,
19828328Ssos224,0,118,220,0,0,0,0,0,0,0,16,56,108,198,198,254,0,0,0,0,0,0,0,0,0,0,0,
19928328Ssos60,126,255,126,24,0,170,85,85,170,170,85,85,170,68,68,68,68,31,4,4,4,124,
20028328Ssos64,64,64,31,16,16,16,56,68,68,56,30,17,20,19,64,64,64,124,31,16,16,16,56,
20128328Ssos108,56,0,0,0,0,0,0,0,24,24,24,24,126,0,68,100,76,68,16,16,16,31,68,68,40,
20228328Ssos16,31,4,4,4,24,24,24,24,248,0,0,0,0,0,0,0,248,24,24,24,0,0,0,0,31,24,24,
20328328Ssos24,24,24,24,24,31,0,0,0,24,24,24,24,255,24,24,24,0,0,0,0,0,0,0,0,0,0,0,
20428328Ssos0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,24,24,24,
20528328Ssos24,31,24,24,24,24,24,24,24,248,24,24,24,24,24,24,24,255,0,0,0,0,0,0,0,255,
20628328Ssos24,24,24,24,24,24,24,24,24,24,24,0,12,48,96,24,12,126,0,0,48,12,6,24,48,
20728328Ssos126,0,0,0,3,62,54,54,108,0,0,0,4,126,16,126,64,0,0,28,48,48,48,48,126,0,
20828328Ssos0,0,0,24,0,0,0,0,0,0,0,0,0,0,0,0,48,0,48,48,120,120,48,0,0,0,16,124,192,
20928328Ssos192,124,16,0,56,96,96,240,96,252,0,0,195,60,102,102,60,195,0,0,204,204,
21028328Ssos120,48,252,48,0,24,24,24,0,24,24,24,0,126,192,124,198,124,6,252,0,198,0,
21128328Ssos0,0,0,0,0,0,124,130,186,162,186,130,124,0,28,6,30,34,31,63,0,0,0,51,102,
21228328Ssos204,102,51,0,0,0,254,6,0,0,0,0,0,0,0,0,0,0,0,0,0,124,130,186,178,170,130,
21328328Ssos124,0,254,0,0,0,0,0,0,0,56,108,56,0,0,0,0,0,0,16,124,16,0,124,0,0,28,54,
21428328Ssos6,24,62,0,0,0,30,2,14,2,30,0,0,0,24,48,0,0,0,0,0,0,0,0,204,204,204,204,
21528328Ssos118,192,126,202,202,126,10,10,10,0,0,0,0,24,0,0,0,0,0,0,0,0,0,0,24,48,6,
21628328Ssos14,6,6,6,0,0,0,14,17,17,17,14,31,0,0,0,204,102,51,102,204,0,0,96,224,102,
21728328Ssos108,51,103,15,3,96,224,102,108,54,106,4,14,240,32,150,108,51,103,15,3,48,
21828328Ssos0,48,96,192,204,120,0,24,12,48,120,204,252,204,0,96,192,48,120,204,252,
21928328Ssos204,0,120,132,48,120,204,252,204,0,102,152,48,120,204,252,204,0,204,0,48,
22028328Ssos120,204,252,204,0,48,72,48,120,204,252,204,0,62,120,152,156,248,152,158,
22128328Ssos0,60,102,192,192,192,102,28,48,48,24,254,98,120,98,254,0,24,48,254,98,120,
22228328Ssos98,254,0,56,68,254,98,120,98,254,0,102,0,254,98,120,98,254,0,96,48,120,
22328328Ssos48,48,48,120,0,24,48,120,48,48,48,120,0,120,132,120,48,48,48,120,0,204,
22428328Ssos0,120,48,48,48,120,0,120,108,102,246,102,108,120,0,102,152,230,246,222,
22528328Ssos206,198,0,48,24,124,198,198,198,124,0,24,48,124,198,198,198,124,0,56,68,
22628328Ssos124,198,198,198,124,0,102,152,124,198,198,198,124,0,198,0,124,198,198,198,
22728328Ssos124,0,0,198,108,56,56,108,198,0,6,124,206,154,178,230,120,192,96,48,204,
22828328Ssos204,204,204,252,0,24,48,204,204,204,204,252,0,120,132,204,204,204,204,252,
22928328Ssos0,204,0,204,204,204,204,252,0,24,48,204,204,120,48,120,0,96,120,108,120,
23028328Ssos96,96,96,0,120,204,196,220,198,198,220,192,48,24,120,12,124,204,118,0,24,
23128328Ssos48,120,12,124,204,118,0,120,132,120,12,124,204,118,0,102,152,120,12,124,
23228328Ssos204,118,0,204,0,120,12,124,204,118,0,48,72,56,12,124,204,118,0,0,0,236,
23328328Ssos50,126,176,110,0,0,0,60,102,192,102,28,48,48,24,120,204,252,192,120,0,24,
23428328Ssos48,120,204,252,192,120,0,120,132,120,204,252,192,120,0,204,0,120,204,252,
23528328Ssos192,120,0,96,48,0,112,48,48,120,0,24,48,0,112,48,48,120,0,112,136,0,112,
23628328Ssos48,48,120,0,204,0,0,112,48,48,120,0,108,56,108,12,108,204,120,0,102,152,
23728328Ssos248,204,204,204,204,0,96,48,0,124,198,198,124,0,24,48,0,124,198,198,124,
23828328Ssos0,56,68,0,124,198,198,124,0,102,152,0,124,198,198,124,0,198,0,0,124,198,
23928328Ssos198,124,0,0,0,24,0,126,0,24,0,0,0,6,124,222,246,124,192,96,48,0,204,204,
24028328Ssos204,118,0,24,48,0,204,204,204,118,0,48,72,0,204,204,204,118,0,204,0,0,204,
24128328Ssos204,204,118,0,24,48,204,204,204,124,12,248,224,120,108,102,108,120,224,
24228328Ssos0,204,0,204,204,204,124,12,248
24328328Ssos};
244