-
Notifications
You must be signed in to change notification settings - Fork 52
/
FileMaker.cpp
119 lines (109 loc) · 2.64 KB
/
FileMaker.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
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
#include "StdAfx.h"
#include "FileMaker.h"
static const char hex_encode(int ch)
{
static const char hex_code[]={"0123456789ABCDEF"};
return hex_code[ch];
}
static int bin_to_hex(char* output, void* input, int len)
{
int i;
char* start;
char* pch;
start = output;
pch = (char*)input;
for(i=0; i<len; i++)
{
*output++ = '0';
*output++ = 'x';
*output++ = hex_encode((*pch>>4)&0x0F);
*output++ = hex_encode((*pch)&0x0F);
*output++ = ',';
if((i&0xF)==0xF)
{
*output++ = '\r';
*output++ = '\n';
}
pch++;
}
*output = 0;
return (int)(output-start);
}
static int UnicodeToUTF8(const WCHAR* input, char* output, int size)
{
memset(output, 0, size);
return WideCharToMultiByte(CP_UTF8, 0, input, 1, output, size, NULL, NULL);
}
//Éú³ÉCÎļþ
BOOL CFileMaker::MakeCppFile(CBitFont* pBitFont, CCharset* pCharset, CFile* pFile, int scan, BOOL msb, BOOL var_width)
{
INT i;
INT count;
INT len;
WCHAR ch;
char utf8[8];
char* text;
UINT text_size;
BYTE* bits;
UINT bits_size;
bits_size = pBitFont->GetBits(NULL,0,scan,msb,var_width);
bits = (BYTE*)malloc(bits_size);
if(bits==NULL)
{
return FALSE;
}
text_size = bits_size * 8 + 64;
text = (char*)malloc(text_size);
if(text==NULL)
{
free(bits);
return FALSE;
}
len = sprintf_s(text, text_size,"static const unsigned char bits[][%d]=\r\n{\r\n",bits_size);
pFile->Write(text,len);
count = pCharset->GetCharCount();
for(i=0;i<count;i++)
{
ch = pCharset->GetChar(i);
UnicodeToUTF8(&ch, utf8, 8);
len = sprintf_s(text, text_size, "//U+%04X(%s)\r\n", ch, utf8);
pFile->Write(text,len);
pBitFont->PaintChar(ch);
len = pBitFont->GetBits(bits,bits_size,scan,msb,var_width);
len = bin_to_hex(text,bits,len);
pFile->Write(text,len);
len = sprintf_s(text, text_size, "\r\n",ch);
pFile->Write(text,len);
}
len = sprintf_s(text, text_size, "};\r\n");
pFile->Write(text,len);
free(bits);
free(text);
return TRUE;
}
//Éú³ÉBINÎļþ
BOOL CFileMaker::MakeBinFile(CBitFont* pBitFont, CCharset* pCharset, CFile* pFile, int scan, BOOL msb, BOOL var_width)
{
INT i;
INT count;
INT size;
WCHAR ch;
BYTE* bits;
UINT bits_size;
bits_size = pBitFont->GetBits(NULL,0,scan,msb,var_width);
bits = (BYTE*)malloc(bits_size);
if(bits==NULL)
{
return FALSE;
}
count = pCharset->GetCharCount();
for(i=0;i<count;i++)
{
ch = pCharset->GetChar(i);
pBitFont->PaintChar(ch);
size = pBitFont->GetBits(bits,bits_size,scan,msb,var_width);
pFile->Write(bits,size);
}
free(bits);
return TRUE;
}