-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.c
53 lines (45 loc) · 902 Bytes
/
text.c
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
#include <stddef.h>
#include "defs.h"
#include "text.h"
typedef struct {
Byte width,
bitmap[7];
} FontGlyph;
extern const FontGlyph g_font[96];
#define GetGlyphData(n) (g_font + ((n)-32))
const char *DrawTextLine(Pen *pen, const char *text)
{
const char *result = NULL;
for (; *text; ++text) {
if (*text == '\n') {
pen->x = pen->drawArea.x1;
++pen->y;
} else if (DrawGlyph(pen, *text)) {
result = text;
break;
}
}
return result;
}
const char *DrawText(Pen *pen, const char *text)
{
while (text && pen->y <= pen->drawArea.y2) {
const char *advance = DrawTextLine(pen, text);
if (advance == text) {
pen->x = pen->drawArea.x1;
++pen->y;
}
text = advance;
}
return text;
}
Byte DrawTextChar(Pen *pen, char c)
{
static char str[] = "a";
str[0] = c;
return !DrawText(pen, str);
}
Byte MeasureTextCharLength(char c)
{
return GetGlyphData(c)->width;
}