]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libvgl/text.c
Make linux_ptrace() use linux_msg() instead of printf().
[FreeBSD/FreeBSD.git] / lib / libvgl / text.c
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1991-1997 Søren Schmidt
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer
12  *    in this position and unchanged.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33
34 #include <stdio.h>
35 #include <sys/fbio.h>
36 #include "vgl.h"
37
38 static VGLText          *VGLTextFont;
39
40 extern byte VGLFont[];
41
42 int
43 VGLTextSetFontFile(char *filename)
44 {
45 FILE *fd;
46
47   if (VGLTextFont) {
48     if (VGLTextFont->BitmapArray != VGLFont) 
49       free (VGLTextFont->BitmapArray);
50     free(VGLTextFont);
51   }
52
53   if ((VGLTextFont=(VGLText*)malloc(sizeof(VGLText))) == (VGLText*)0)
54         return 1;
55
56   if (filename==NULL) {
57     VGLTextFont->Width = 8;
58     VGLTextFont->Height = 8;
59     VGLTextFont->BitmapArray = VGLFont;
60   }
61   else {
62     if ((fd=fopen(filename, "r"))==(FILE*)0)
63       return 1;
64     fread(&VGLTextFont->Width, 1 , 1, fd);
65     fread(&VGLTextFont->Height, 1 , 1, fd);
66     VGLTextFont->BitmapArray = 
67       (byte*)malloc(256*((VGLTextFont->Width + 7)/8)*VGLTextFont->Height);
68     fread(VGLTextFont->BitmapArray, 1, 
69       (256*((VGLTextFont->Width + 7)/8)*VGLTextFont->Height), fd);
70     fclose(fd);
71   }
72   return 0;
73 }
74
75 void
76 VGLBitmapPutChar(VGLBitmap *Object, int x, int y, byte ch, 
77                  u_long fgcol, u_long bgcol, int fill, int dir)
78 {
79   int b, Bpc, Bpl, lin, bit, topbit;
80
81   Bpl = (VGLTextFont->Width + 7) / 8;
82   Bpc = Bpl * VGLTextFont->Height;
83   topbit = VGLTextFont->Width - 1;
84   for(lin = 0; lin < VGLTextFont->Height; lin++) {
85     for(bit = 0; bit < VGLTextFont->Width; bit++) {
86       b = bit + (-VGLTextFont->Width & 7);
87       if (VGLTextFont->BitmapArray[(ch*Bpc)+(lin*Bpl)+(b/8)]&(1<<(b%8)))
88         switch (dir) {
89           case 0:
90             VGLSetXY(Object, (x+topbit-bit), (y+lin), fgcol);
91             break;
92           case 1:
93             VGLSetXY(Object, (x+lin), (y-topbit+bit), fgcol);
94             break;
95           case 2:
96             VGLSetXY(Object, (x-topbit+bit), (y-lin), fgcol);
97             break;
98           case 3:
99             VGLSetXY(Object, (x-lin), (y+topbit-bit), fgcol);
100             break;
101           case 4:
102             VGLSetXY(Object, (x+lin+topbit-bit), (y+lin+bit), fgcol);
103             break;
104         }
105       else if (fill)
106         switch (dir) {
107           case 0:
108             VGLSetXY(Object, (x+topbit-bit), (y+lin), bgcol);
109             break;
110           case 1:
111             VGLSetXY(Object, (x+lin), (y-topbit+bit), bgcol);
112             break;
113           case 2:
114             VGLSetXY(Object, (x-topbit+bit), (y-lin), bgcol);
115             break;
116           case 3:
117             VGLSetXY(Object, (x-lin), (y+topbit-bit), bgcol);
118             break;
119           case 4:
120             VGLSetXY(Object, (x+lin+topbit-bit), (y+lin+bit), bgcol);
121             break;
122         }
123     }
124   }
125 }
126
127 void
128 VGLBitmapString(VGLBitmap *Object, int x, int y, char *str, 
129                 u_long fgcol, u_long bgcol, int fill, int dir)
130 {
131   int pos;
132
133   for (pos=0; pos<strlen(str); pos++) {
134     switch (dir) {
135       case 0:
136         VGLBitmapPutChar(Object, x+(pos*VGLTextFont->Width), y, 
137                          str[pos], fgcol, bgcol, fill, dir);
138         break;
139       case 1:
140         VGLBitmapPutChar(Object, x, y-(pos*VGLTextFont->Width), 
141                          str[pos], fgcol, bgcol, fill, dir);
142         break;
143       case 2:
144         VGLBitmapPutChar(Object, x-(pos*VGLTextFont->Width), y, 
145                          str[pos], fgcol, bgcol, fill, dir);
146         break;
147       case 3:
148         VGLBitmapPutChar(Object, x, y+(pos*VGLTextFont->Width),  
149                          str[pos], fgcol, bgcol, fill, dir);
150         break;
151       case 4:
152         VGLBitmapPutChar(Object, x+(pos*VGLTextFont->Width),
153                          y-(pos*VGLTextFont->Width), 
154                          str[pos], fgcol, bgcol, fill, dir);
155         break;
156     }
157   }
158 }
159
160 byte VGLFont[] = {
161 0,0,0,0,0,0,0,0,126,129,165,129,189,153,129,126,126,255,219,255,195,231,
162 255,126,108,254,254,254,124,56,16,0,16,56,124,254,124,56,16,0,56,124,56,
163 254,254,124,56,124,16,16,56,124,254,124,56,124,0,0,24,60,60,24,0,0,255,
164 255,231,195,195,231,255,255,0,60,102,66,66,102,60,0,255,195,153,189,189,
165 153,195,255,15,7,15,125,204,204,204,120,60,102,102,102,60,24,126,24,63,
166 51,63,48,48,112,240,224,127,99,127,99,99,103,230,192,153,90,60,231,231,
167 60,90,153,128,224,248,254,248,224,128,0,2,14,62,254,62,14,2,0,24,60,126,
168 24,24,126,60,24,102,102,102,102,102,0,102,0,127,219,219,123,27,27,27,0,
169 62,99,56,108,108,56,204,120,0,0,0,0,126,126,126,0,24,60,126,24,126,60,24,
170 255,24,60,126,24,24,24,24,0,24,24,24,24,126,60,24,0,0,24,12,254,12,24,0,
171 0,0,48,96,254,96,48,0,0,0,0,192,192,192,254,0,0,0,36,102,255,102,36,0,0,
172 0,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,
173 120,48,48,0,48,0,108,108,108,0,0,0,0,0,108,108,254,108,254,108,108,0,48,
174 124,192,120,12,248,48,0,0,198,204,24,48,102,198,0,56,108,56,118,220,204,
175 118,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,
176 0,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,
177 252,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,
178 230,124,0,48,112,48,48,48,48,252,0,120,204,12,56,96,204,252,0,120,204,12,
179 56,12,204,120,0,28,60,108,204,254,12,30,0,252,192,248,12,12,204,120,0,56,
180 96,192,248,204,204,120,0,252,204,12,24,48,48,48,0,120,204,204,120,204,204,
181 120,0,120,204,204,124,12,24,112,0,0,48,48,0,0,48,48,0,0,48,48,0,0,48,48,
182 96,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,
183 204,12,24,48,0,48,0,124,198,222,222,222,192,120,0,48,120,204,204,252,204,
184 204,0,252,102,102,124,102,102,252,0,60,102,192,192,192,102,60,0,248,108,
185 102,102,102,108,248,0,254,98,104,120,104,98,254,0,254,98,104,120,104,96,
186 240,0,60,102,192,192,206,102,62,0,204,204,204,252,204,204,204,0,120,48,
187 48,48,48,48,120,0,30,12,12,12,204,204,120,0,230,102,108,120,108,102,230,
188 0,240,96,96,96,98,102,254,0,198,238,254,254,214,198,198,0,198,230,246,222,
189 206,198,198,0,56,108,198,198,198,108,56,0,252,102,102,124,96,96,240,0,120,
190 204,204,204,220,120,28,0,252,102,102,124,108,102,230,0,120,204,224,112,
191 28,204,120,0,252,180,48,48,48,48,120,0,204,204,204,204,204,204,252,0,204,
192 204,204,204,204,120,48,0,198,198,198,214,254,238,198,0,198,198,108,56,56,
193 108,198,0,204,204,204,120,48,48,120,0,254,198,140,24,50,102,254,0,120,96,
194 96,96,96,96,120,0,192,96,48,24,12,6,2,0,120,24,24,24,24,24,120,0,16,56,
195 108,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,
196 118,0,224,96,96,124,102,102,220,0,0,0,120,204,192,204,120,0,28,12,12,124,
197 204,204,118,0,0,0,120,204,252,192,120,0,56,108,96,240,96,96,240,0,0,0,118,
198 204,204,124,12,248,224,96,108,118,102,102,230,0,48,0,112,48,48,48,120,0,
199 12,0,12,12,12,204,204,120,224,96,102,108,120,108,230,0,112,48,48,48,48,
200 48,120,0,0,0,204,254,254,214,198,0,0,0,248,204,204,204,204,0,0,0,120,204,
201 204,204,120,0,0,0,220,102,102,124,96,240,0,0,118,204,204,124,12,30,0,0,
202 220,118,102,96,240,0,0,0,124,192,120,12,248,0,16,48,124,48,48,52,24,0,0,
203 0,204,204,204,204,118,0,0,0,204,204,204,120,48,0,0,0,198,214,254,254,108,
204 0,0,0,198,108,56,108,198,0,0,0,204,204,204,124,12,248,0,0,252,152,48,100,
205 252,0,28,48,48,224,48,48,28,0,24,24,24,0,24,24,24,0,224,48,48,28,48,48,
206 224,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,
207 60,126,255,126,24,0,170,85,85,170,170,85,85,170,68,68,68,68,31,4,4,4,124,
208 64,64,64,31,16,16,16,56,68,68,56,30,17,20,19,64,64,64,124,31,16,16,16,56,
209 108,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,
210 16,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,
211 24,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,
212 0,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,
213 24,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,
214 24,24,24,24,24,24,24,24,24,24,24,0,12,48,96,24,12,126,0,0,48,12,6,24,48,
215 126,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,
216 0,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,
217 192,124,16,0,56,96,96,240,96,252,0,0,195,60,102,102,60,195,0,0,204,204,
218 120,48,252,48,0,24,24,24,0,24,24,24,0,126,192,124,198,124,6,252,0,198,0,
219 0,0,0,0,0,0,124,130,186,162,186,130,124,0,28,6,30,34,31,63,0,0,0,51,102,
220 204,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,
221 124,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,
222 6,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,
223 118,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,
224 14,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,
225 108,51,103,15,3,96,224,102,108,54,106,4,14,240,32,150,108,51,103,15,3,48,
226 0,48,96,192,204,120,0,24,12,48,120,204,252,204,0,96,192,48,120,204,252,
227 204,0,120,132,48,120,204,252,204,0,102,152,48,120,204,252,204,0,204,0,48,
228 120,204,252,204,0,48,72,48,120,204,252,204,0,62,120,152,156,248,152,158,
229 0,60,102,192,192,192,102,28,48,48,24,254,98,120,98,254,0,24,48,254,98,120,
230 98,254,0,56,68,254,98,120,98,254,0,102,0,254,98,120,98,254,0,96,48,120,
231 48,48,48,120,0,24,48,120,48,48,48,120,0,120,132,120,48,48,48,120,0,204,
232 0,120,48,48,48,120,0,120,108,102,246,102,108,120,0,102,152,230,246,222,
233 206,198,0,48,24,124,198,198,198,124,0,24,48,124,198,198,198,124,0,56,68,
234 124,198,198,198,124,0,102,152,124,198,198,198,124,0,198,0,124,198,198,198,
235 124,0,0,198,108,56,56,108,198,0,6,124,206,154,178,230,120,192,96,48,204,
236 204,204,204,252,0,24,48,204,204,204,204,252,0,120,132,204,204,204,204,252,
237 0,204,0,204,204,204,204,252,0,24,48,204,204,120,48,120,0,96,120,108,120,
238 96,96,96,0,120,204,196,220,198,198,220,192,48,24,120,12,124,204,118,0,24,
239 48,120,12,124,204,118,0,120,132,120,12,124,204,118,0,102,152,120,12,124,
240 204,118,0,204,0,120,12,124,204,118,0,48,72,56,12,124,204,118,0,0,0,236,
241 50,126,176,110,0,0,0,60,102,192,102,28,48,48,24,120,204,252,192,120,0,24,
242 48,120,204,252,192,120,0,120,132,120,204,252,192,120,0,204,0,120,204,252,
243 192,120,0,96,48,0,112,48,48,120,0,24,48,0,112,48,48,120,0,112,136,0,112,
244 48,48,120,0,204,0,0,112,48,48,120,0,108,56,108,12,108,204,120,0,102,152,
245 248,204,204,204,204,0,96,48,0,124,198,198,124,0,24,48,0,124,198,198,124,
246 0,56,68,0,124,198,198,124,0,102,152,0,124,198,198,124,0,198,0,0,124,198,
247 198,124,0,0,0,24,0,126,0,24,0,0,0,6,124,222,246,124,192,96,48,0,204,204,
248 204,118,0,24,48,0,204,204,204,118,0,48,72,0,204,204,204,118,0,204,0,0,204,
249 204,204,118,0,24,48,204,204,204,124,12,248,224,120,108,102,108,120,224,
250 0,204,0,204,204,204,124,12,248
251 };