-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZXMonospaceFont.c
72 lines (52 loc) · 1.74 KB
/
ZXMonospaceFont.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// ZX Graphics library, part of Another Graphics library
//
// Created by error on 27.01.18.
// Copyright © 2018 errorsoft. All rights reserved.
//
#include "ZXMonospaceFont.h"
#include <stdlib.h>
#include <string.h>
ZXMonospaceFontRef ZXMonospaceFontCreate(int symbolWidth, int symbolHeight, int cols, ZXConstData fontData) {
ZXMonospaceFontRef font;
font = (ZXMonospaceFontRef)malloc(sizeof(ZXMonospaceFont));
if(font == NULL)
return NULL;
font->bitmap = ZXLinkBitmapCreate(symbolWidth * cols, symbolHeight * (256 / cols), (ZXData)fontData);
if(font->bitmap == NULL) {
free(font);
return NULL;
}
font->cols = cols;
font->width = symbolWidth;
font->height = symbolHeight;
return font;
}
void ZXMonospaceFontFree(ZXMonospaceFontRef font) {
ZXLinkBitmapFree(font->bitmap);
free(font);
}
//FIXME: дописать вывод кол-ва напечатаных символов
int ZXDrawText(ZXBitmapRef bitmap, ZXMonospaceFontRef font, int x, int y, const CXChar* text, unsigned char color) {
CXChar* p;
int count = 0, ch;
p = (CXChar*)text;
while(*p != 0) {
ch = (unsigned char)(*p);
ZXBitBlit(bitmap, x, y, font->bitmap,
(ch % font->cols) * font->width,
(ch / font->cols) * font->height,
font->width, font->height, color);
//ZXSetPoint(bitmap, x, y, ZXInvert);
x += font->width;
count++;
p++;
}
return count;
}
int ZXTextWidth(ZXMonospaceFontRef font, const CXChar* text) {
return (int)strlen(text) * font->width;
}
int ZXTextHeight(ZXMonospaceFontRef font) {
return font->height;
}