nrelease - fix/improve livecd
[dragonfly.git] / lib / libvgl / text.c
CommitLineData
984263bc 1/*-
f6e8a0a1 2 * Copyright (c) 1991-1997 Søren Schmidt
984263bc
MD
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
4d9022e3 15 * derived from this software without specific prior written permission
984263bc
MD
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: src/lib/libvgl/text.c,v 1.4 1999/11/08 11:37:39 yokota Exp $
29 */
30
31#include <stdio.h>
32#include <machine/console.h>
33#include "vgl.h"
34
678e8cc6 35static VGLText *VGLTextFont = NULL;
984263bc
MD
36
37extern byte VGLFont[];
38
39int
40VGLTextSetFontFile(char *filename)
41{
42FILE *fd;
43
44 if (VGLTextFont) {
45 if (VGLTextFont->BitmapArray)
46 free (VGLTextFont->BitmapArray);
47 free(VGLTextFont);
48 }
49
60233e58 50 if ((VGLTextFont=(VGLText*)malloc(sizeof(VGLText))) == NULL)
984263bc
MD
51 return 1;
52
53 if (filename==NULL) {
54 VGLTextFont->Width = 8;
55 VGLTextFont->Height = 8;
56 VGLTextFont->BitmapArray = VGLFont;
57 }
58 else {
60233e58 59 if ((fd=fopen(filename, "r"))==NULL)
984263bc
MD
60 return 1;
61 fread(&VGLTextFont->Width, 1 , 1, fd);
62 fread(&VGLTextFont->Height, 1 , 1, fd);
63 VGLTextFont->BitmapArray =
64 (byte*)malloc(256*((VGLTextFont->Width + 7)/8)*VGLTextFont->Height);
65 fread(VGLTextFont->BitmapArray, 1,
66 (256*VGLTextFont->Width* VGLTextFont->Height), fd);
67 fclose(fd);
68 }
69 return 0;
70}
71
72void
73VGLBitmapPutChar(VGLBitmap *Object, int x, int y, byte ch,
74 byte fgcol, byte bgcol, int fill, int dir)
75{
76 int lin, bit;
77
78 for(lin = 0; lin < VGLTextFont->Height; lin++) {
79 for(bit = 0; bit < VGLTextFont->Width; bit++) {
80 if (VGLTextFont->BitmapArray[((ch*VGLTextFont->Height)+lin)]&(1<<bit))
81 switch (dir) {
82 case 0:
83 VGLSetXY(Object, (x+7-bit), (y+lin), fgcol);
84 break;
85 case 1:
86 VGLSetXY(Object, (x+lin), (y-7+bit), fgcol);
87 break;
88 case 2:
89 VGLSetXY(Object, (x-7+bit), (y-lin), fgcol);
90 break;
91 case 3:
92 VGLSetXY(Object, (x-lin), (y+7-bit), fgcol);
93 break;
94 case 4:
95 VGLSetXY(Object, (x+lin+7-bit), (y+lin+bit), fgcol);
96 break;
97 }
98 else if (fill)
99 switch (dir) {
100 case 0:
101 VGLSetXY(Object, (x+7-bit), (y+lin), bgcol);
102 break;
103 case 1:
104 VGLSetXY(Object, (x+lin), (y-7+bit), bgcol);
105 break;
106 case 2:
107 VGLSetXY(Object, (x-7+bit), (y-lin), bgcol);
108 break;
109 case 3:
110 VGLSetXY(Object, (x-lin), (y+7-bit), bgcol);
111 break;
112 case 4:
113 VGLSetXY(Object, (x+lin+7-bit), (y+lin+bit), bgcol);
114 break;
115 }
116 }
117 }
118}
119
120void
121VGLBitmapString(VGLBitmap *Object, int x, int y, char *str,
122 byte fgcol, byte bgcol, int fill, int dir)
123{
124 int pos;
125
126 for (pos=0; pos<strlen(str); pos++) {
127 switch (dir) {
128 case 0:
129 VGLBitmapPutChar(Object, x+(pos*VGLTextFont->Width), y,
130 str[pos], fgcol, bgcol, fill, dir);
131 break;
132 case 1:
133 VGLBitmapPutChar(Object, x, y-(pos*VGLTextFont->Width),
134 str[pos], fgcol, bgcol, fill, dir);
135 break;
136 case 2:
137 VGLBitmapPutChar(Object, x-(pos*VGLTextFont->Width), y,
138 str[pos], fgcol, bgcol, fill, dir);
139 break;
140 case 3:
141 VGLBitmapPutChar(Object, x, y+(pos*VGLTextFont->Width),
142 str[pos], fgcol, bgcol, fill, dir);
143 break;
144 case 4:
145 VGLBitmapPutChar(Object, x+(pos*VGLTextFont->Width),
146 y-(pos*VGLTextFont->Width),
147 str[pos], fgcol, bgcol, fill, dir);
148 break;
149 }
150 }
151}
152
153byte VGLFont[] = {
1540,0,0,0,0,0,0,0,126,129,165,129,189,153,129,126,126,255,219,255,195,231,
155255,126,108,254,254,254,124,56,16,0,16,56,124,254,124,56,16,0,56,124,56,
156254,254,124,56,124,16,16,56,124,254,124,56,124,0,0,24,60,60,24,0,0,255,
157255,231,195,195,231,255,255,0,60,102,66,66,102,60,0,255,195,153,189,189,
158153,195,255,15,7,15,125,204,204,204,120,60,102,102,102,60,24,126,24,63,
15951,63,48,48,112,240,224,127,99,127,99,99,103,230,192,153,90,60,231,231,
16060,90,153,128,224,248,254,248,224,128,0,2,14,62,254,62,14,2,0,24,60,126,
16124,24,126,60,24,102,102,102,102,102,0,102,0,127,219,219,123,27,27,27,0,
16262,99,56,108,108,56,204,120,0,0,0,0,126,126,126,0,24,60,126,24,126,60,24,
163255,24,60,126,24,24,24,24,0,24,24,24,24,126,60,24,0,0,24,12,254,12,24,0,
1640,0,48,96,254,96,48,0,0,0,0,192,192,192,254,0,0,0,36,102,255,102,36,0,0,
1650,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,
166120,48,48,0,48,0,108,108,108,0,0,0,0,0,108,108,254,108,254,108,108,0,48,
167124,192,120,12,248,48,0,0,198,204,24,48,102,198,0,56,108,56,118,220,204,
168118,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,
1690,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,
170252,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,
171230,124,0,48,112,48,48,48,48,252,0,120,204,12,56,96,204,252,0,120,204,12,
17256,12,204,120,0,28,60,108,204,254,12,30,0,252,192,248,12,12,204,120,0,56,
17396,192,248,204,204,120,0,252,204,12,24,48,48,48,0,120,204,204,120,204,204,
174120,0,120,204,204,124,12,24,112,0,0,48,48,0,0,48,48,0,0,48,48,0,0,48,48,
17596,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,
176204,12,24,48,0,48,0,124,198,222,222,222,192,120,0,48,120,204,204,252,204,
177204,0,252,102,102,124,102,102,252,0,60,102,192,192,192,102,60,0,248,108,
178102,102,102,108,248,0,254,98,104,120,104,98,254,0,254,98,104,120,104,96,
179240,0,60,102,192,192,206,102,62,0,204,204,204,252,204,204,204,0,120,48,
18048,48,48,48,120,0,30,12,12,12,204,204,120,0,230,102,108,120,108,102,230,
1810,240,96,96,96,98,102,254,0,198,238,254,254,214,198,198,0,198,230,246,222,
182206,198,198,0,56,108,198,198,198,108,56,0,252,102,102,124,96,96,240,0,120,
183204,204,204,220,120,28,0,252,102,102,124,108,102,230,0,120,204,224,112,
18428,204,120,0,252,180,48,48,48,48,120,0,204,204,204,204,204,204,252,0,204,
185204,204,204,204,120,48,0,198,198,198,214,254,238,198,0,198,198,108,56,56,
186108,198,0,204,204,204,120,48,48,120,0,254,198,140,24,50,102,254,0,120,96,
18796,96,96,96,120,0,192,96,48,24,12,6,2,0,120,24,24,24,24,24,120,0,16,56,
188108,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,
189118,0,224,96,96,124,102,102,220,0,0,0,120,204,192,204,120,0,28,12,12,124,
190204,204,118,0,0,0,120,204,252,192,120,0,56,108,96,240,96,96,240,0,0,0,118,
191204,204,124,12,248,224,96,108,118,102,102,230,0,48,0,112,48,48,48,120,0,
19212,0,12,12,12,204,204,120,224,96,102,108,120,108,230,0,112,48,48,48,48,
19348,120,0,0,0,204,254,254,214,198,0,0,0,248,204,204,204,204,0,0,0,120,204,
194204,204,120,0,0,0,220,102,102,124,96,240,0,0,118,204,204,124,12,30,0,0,
195220,118,102,96,240,0,0,0,124,192,120,12,248,0,16,48,124,48,48,52,24,0,0,
1960,204,204,204,204,118,0,0,0,204,204,204,120,48,0,0,0,198,214,254,254,108,
1970,0,0,198,108,56,108,198,0,0,0,204,204,204,124,12,248,0,0,252,152,48,100,
198252,0,28,48,48,224,48,48,28,0,24,24,24,0,24,24,24,0,224,48,48,28,48,48,
199224,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,
20060,126,255,126,24,0,170,85,85,170,170,85,85,170,68,68,68,68,31,4,4,4,124,
20164,64,64,31,16,16,16,56,68,68,56,30,17,20,19,64,64,64,124,31,16,16,16,56,
202108,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,
20316,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,
20424,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,
2050,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,
20624,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,
20724,24,24,24,24,24,24,24,24,24,24,0,12,48,96,24,12,126,0,0,48,12,6,24,48,
208126,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,
2090,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,
210192,124,16,0,56,96,96,240,96,252,0,0,195,60,102,102,60,195,0,0,204,204,
211120,48,252,48,0,24,24,24,0,24,24,24,0,126,192,124,198,124,6,252,0,198,0,
2120,0,0,0,0,0,124,130,186,162,186,130,124,0,28,6,30,34,31,63,0,0,0,51,102,
213204,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,
214124,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,
2156,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,
216118,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,
21714,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,
218108,51,103,15,3,96,224,102,108,54,106,4,14,240,32,150,108,51,103,15,3,48,
2190,48,96,192,204,120,0,24,12,48,120,204,252,204,0,96,192,48,120,204,252,
220204,0,120,132,48,120,204,252,204,0,102,152,48,120,204,252,204,0,204,0,48,
221120,204,252,204,0,48,72,48,120,204,252,204,0,62,120,152,156,248,152,158,
2220,60,102,192,192,192,102,28,48,48,24,254,98,120,98,254,0,24,48,254,98,120,
22398,254,0,56,68,254,98,120,98,254,0,102,0,254,98,120,98,254,0,96,48,120,
22448,48,48,120,0,24,48,120,48,48,48,120,0,120,132,120,48,48,48,120,0,204,
2250,120,48,48,48,120,0,120,108,102,246,102,108,120,0,102,152,230,246,222,
226206,198,0,48,24,124,198,198,198,124,0,24,48,124,198,198,198,124,0,56,68,
227124,198,198,198,124,0,102,152,124,198,198,198,124,0,198,0,124,198,198,198,
228124,0,0,198,108,56,56,108,198,0,6,124,206,154,178,230,120,192,96,48,204,
229204,204,204,252,0,24,48,204,204,204,204,252,0,120,132,204,204,204,204,252,
2300,204,0,204,204,204,204,252,0,24,48,204,204,120,48,120,0,96,120,108,120,
23196,96,96,0,120,204,196,220,198,198,220,192,48,24,120,12,124,204,118,0,24,
23248,120,12,124,204,118,0,120,132,120,12,124,204,118,0,102,152,120,12,124,
233204,118,0,204,0,120,12,124,204,118,0,48,72,56,12,124,204,118,0,0,0,236,
23450,126,176,110,0,0,0,60,102,192,102,28,48,48,24,120,204,252,192,120,0,24,
23548,120,204,252,192,120,0,120,132,120,204,252,192,120,0,204,0,120,204,252,
236192,120,0,96,48,0,112,48,48,120,0,24,48,0,112,48,48,120,0,112,136,0,112,
23748,48,120,0,204,0,0,112,48,48,120,0,108,56,108,12,108,204,120,0,102,152,
238248,204,204,204,204,0,96,48,0,124,198,198,124,0,24,48,0,124,198,198,124,
2390,56,68,0,124,198,198,124,0,102,152,0,124,198,198,124,0,198,0,0,124,198,
240198,124,0,0,0,24,0,126,0,24,0,0,0,6,124,222,246,124,192,96,48,0,204,204,
241204,118,0,24,48,0,204,204,204,118,0,48,72,0,204,204,204,118,0,204,0,0,204,
242204,204,118,0,24,48,204,204,204,124,12,248,224,120,108,102,108,120,224,
2430,204,0,204,204,204,124,12,248
244};