This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
mgFont.c
131 lines (103 loc) · 2.85 KB
/
mgFont.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* LEAF Visual Novel System For MGL2 - Font Plus Extension
* (c) Copyright 2001 Hiroshi Kuwagata <[email protected]>
* All rights reserverd.
*
* ORIGINAL LVNS (c) Copyright 1996-1999 LEAF/AQUAPLUS Inc.
*
* $Id: mgFont.c,v 1.4 2001/08/12 11:35:44 tf Exp $
*
*/
/*
* vi:ts=4:sw=4;
*/
#ifdef FONT_PLUS
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "mgFont.h"
LvnsFont*
lvnsfont_load( const u_char* fname)
{
FILE* fp;
LvnsFont* ret;
struct stat st;
if( stat( fname, &st)){
perror( "Lvns - font load (stat)\n");
return NULL;
}
if( ( fp = fopen( (char*)fname, "rb")) == NULL){
perror( "Lvns - font load (fopen)\n");
return NULL;
}
if( (ret = malloc( sizeof( LvnsFont))) == NULL){
perror( "Lvns - font load (malloc LvnsFont)\n");
return NULL;
}
if( ( ret->draw_buf = malloc( sizeof( int) * 12 * 12)) == NULL){
perror( "Lvns - font load (malloc draw_buf)\n");
free( ret);
return NULL;
}
if( ( ret->font_data = malloc( st.st_size)) == NULL){
perror( "Lvns - font load (malloc draw_buf)\n");
free( ret->draw_buf);
free( ret);
return NULL;
}
//ret->width = width;
//ret->height = height;
// font¥Ç¡¼¥¿Æɤ߹þ¤ß
fread( ret->font_data, st.st_size, 1, fp);
return ret;
}
LvnsFont*
lvnsfont_new( const u_char* dat)
{
LvnsFont* ret;
if( (ret = malloc( sizeof( LvnsFont))) == NULL){
perror( "Lvns - font load (malloc LvnsFont)\n");
return NULL;
}
if( ( ret->draw_buf = malloc( sizeof( int) * 12 * 12)) == NULL){
perror( "Lvns - font load (malloc draw_buf)\n");
free( ret);
return NULL;
}
ret->font_data = dat;
return ret;
}
void lvnsfont_discard( LvnsFont* fnt)
{
free( fnt->draw_buf);
free( fnt->font_data);
free( fnt);
}
static int default_cmap[ 4] = {
COLOR_TRANSPARENT, 0x00000004, 0x0000000c, 0x0000000f
};
void lvnsfont_draw( LvnsFont* fnt, int x, int y, int code, int* cmap)
{
int i;
u_char *fptn;
if( cmap == NULL){
cmap = default_cmap;
}
fptn = fnt->font_data + ( 3 * 12 * code);
for( i = 0; i < 12; i++, fptn += 3){
fnt->draw_buf[ i * 12 + 0] = cmap[ (fptn[ 0] >> 6) & 0x03];
fnt->draw_buf[ i * 12 + 1] = cmap[ (fptn[ 0] >> 4) & 0x03];
fnt->draw_buf[ i * 12 + 2] = cmap[ (fptn[ 0] >> 2) & 0x03];
fnt->draw_buf[ i * 12 + 3] = cmap[ (fptn[ 0] >> 0) & 0x03];
fnt->draw_buf[ i * 12 + 4] = cmap[ (fptn[ 1] >> 6) & 0x03];
fnt->draw_buf[ i * 12 + 5] = cmap[ (fptn[ 1] >> 4) & 0x03];
fnt->draw_buf[ i * 12 + 6] = cmap[ (fptn[ 1] >> 2) & 0x03];
fnt->draw_buf[ i * 12 + 7] = cmap[ (fptn[ 1] >> 0) & 0x03];
fnt->draw_buf[ i * 12 + 8] = cmap[ (fptn[ 2] >> 6) & 0x03];
fnt->draw_buf[ i * 12 + 9] = cmap[ (fptn[ 2] >> 4) & 0x03];
fnt->draw_buf[ i * 12 + 10] = cmap[ (fptn[ 2] >> 2) & 0x03];
fnt->draw_buf[ i * 12 + 11] = cmap[ (fptn[ 2] >> 0) & 0x03];
}
put_pixstream_rect( x, y, fnt->draw_buf, 12 * 12, DIR_NORTH, 12);
}
#endif /* FONT_PLUS */