-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvtext.cpp
74 lines (64 loc) · 1.7 KB
/
vtext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <string.h>
#include <stdio.h>
#include "image.h"
#include "vtext.h"
#include "types.h"
#include "fonts.h"
vtext::vtext()
{
font_num=0;
max_width=320;
max_height=200;
bgcolor=0;
font=NULL;
}
vtext::vtext(int width, int height, unsigned char background)
{
max_width=width;
max_height=height;
bgcolor=background;
font_num=0;
font=(fontdef *)&fonts[font_num];
debug(printf("init vtext fontwidth %d fontheight %d\n",font->font_width,font->font_height);)
}
vtext::~vtext()
{
}
bool vtext::drawtext(image& img, const char *string, unsigned char color)
{
int width,height;
int slen,x,y,x_cursor,y_cursor;
int scount;
unsigned char *cptr;
unsigned char font_bits;
char bitset=0;
slen=strlen(string);
width=(slen*font->font_width) % max_width;
height=(((slen*font->font_width) / max_width) + 1) * font->font_height;
debug(printf("setting width %d height %d\n",width,height);)
if (!img.size(width,height)) {
debug(printf("img.size failed\n");)
return false;
}
x_cursor=0;
y_cursor=0;
for(scount=0;scount<slen;scount++){
cptr=&font->font[string[scount]*font->bytes_per_char];
debug(printf("cptr %c %02x xc %d yc %d\n",string[scount],*cptr,x_cursor,y_cursor);)
for (y=0;y<font->font_height;y++) {
font_bits=cptr[y];
for (x=0;x<font->font_width;x++) {
bitset=(font_bits>>(7-(x&7))) & 0x1;
debug(printf("%s",bitset?".":" ");)
if (bitset) img.setpixel(x+x_cursor,y+y_cursor,color);
else img.setpixel(x+x_cursor,y+y_cursor);
}
debug(printf("\n");)
}
x_cursor+=font->font_width;;
x_cursor%=width;
y_cursor=(scount*font->font_width)/width;
debug(printf("scount %d sw %d w %d\n",scount,scount*font->font_width,(scount*font->font_width)/width);)
}
return true;
}