-
Notifications
You must be signed in to change notification settings - Fork 1
/
UTFEnglishRules.c
executable file
·331 lines (280 loc) · 6.08 KB
/
UTFEnglishRules.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
Copyright (C) shenzhen sowell technology CO.,LTD
*/
/* This is a copy of UTF Tool source code and you should have a copy
** of sowell license to permit use this program.
**
** This source code can create UI enviroment and manage message of
** each window, you can easy to draw window face and process message
** with it,
**
** This code realsed to dareglobal CO.,LTD shanghai
*/
#include "stdafx.h"
#include "UTFTypeDef.h"
#include "UTFPalette.h"
#include "UTFGraphPort.h"
#include "UTFGraphPortPriv.h"
#include "UTFEnglishRules.h"
#include "UTFDrawAPI.h"
#include "UTFMemoryPriv.h"
TEXTPROC ENGTextFunc;
/*************************************************************************/
WORD ENGTextWidth(LPTEXT pText, int charInterval, LPUTFLOGFONT lpFont)
{
WORD index,count = 0;
WORD textWidth = 0;
BYTE charactor;
BYTE *pVect;
if(lpFont->lfAddr1 == NULL)
return 0;
pVect = (BYTE *)(lpFont->lfAddr1+2);
while(*pText)
{
charactor = *pText;
if(charactor == '\n')
break;
if((charactor > 31) || (charactor < 5))
{
count++;
if(charactor < 5)
{
index = charactor - 1;
}
else
{
index = charactor - 28;
}
textWidth += pVect[index<<1];
}
pText++;
}
if(count > 1)
{
textWidth += (count-1)*charInterval;
}
return textWidth;
}
static void ENGTextFunc8(LPTEXT pText, WORD left, WORD top, WORD width, WORD height, WORD charInterval, UTFCOLOR textColor, LPUTFLOGFONT lpFont)
{
WORD i,j,k,count;
WORD startx = 0;
WORD position;
WORD wVectSize;
WORD dx=0,dy=0;
DWORD dwSize;
BYTE data,bDrawMode=1;
BYTE *pVect,*pData;
BYTE *ptrWrite;
BYTE *ptrHeader;
UTFBITMAP bitmap;
if(lpFont->lfAddr1 == NULL)
return;
if(height > lpFont->lfHeight)
{
height = lpFont->lfHeight;
}
UTFGetMemoryBitmap(&bitmap);
if(bitmap.data)
{
bDrawMode = 0;
dx = left;
dy = top;
}
else
{
if(width%32)
{
WORD wOldWidth = width;
UTFRECT rcFullScreen;
UTFGetFullScreenRect(&rcFullScreen);
width += 32-width%32;
if((left+width) > (rcFullScreen.right-rcFullScreen.left))
{
width = wOldWidth;
}
}
dwSize = width*height;
ptrHeader = (BYTE *)SOWMalloc(dwSize);
if(ptrHeader == NULL)
return;
bitmap.data = ptrHeader;
bitmap.Width = width;
bitmap.Height = height;
bitmap.bitPerPixel = 8;
UTFSaveScreen(left, top, &bitmap, 0);
}
UTFMemCpyWORD(&wVectSize, (void *)lpFont->lfAddr1, 2);
pVect = (BYTE *)(lpFont->lfAddr1+2);
pData = pVect+wVectSize;
while(*pText != NULL)
{
if((*pText > 31) || (*pText < 5))
{
DWORD address = 0;
if(*pText < 5)
{
position = *pText - 1;
}
else
{
position = *pText - 28;
}
for(i=0; i<position; i++)
{
address += pVect[(i<<1)+1];
}
address *= lpFont->lfHeight;
ptrWrite = bitmap.data+dy*bitmap.Width+dx+startx;
for(i=0; i<height; i++)
{
BYTE ByteNum = pVect[(position<<1)+1];
count = 0;
for(k=0; k<ByteNum; k++)
{
data = pData[address];
for(j=0; j<8; j++)
{
if(count >= pVect[position<<1])
{
break;
}
if(data & 0x80)
{
*(ptrWrite+count) = (BYTE)textColor;
}
count++;
data <<= 1;
}
address++;
}
ptrWrite += bitmap.Width;
}
startx += pVect[position<<1] + charInterval;
}
pText++;
}
if(bDrawMode)
{
UTFPutScreen(left, top, &bitmap, 0);
SOWFree((void *)ptrHeader);
}
}
static void ENGTextFunc16(LPTEXT pText, WORD left, WORD top, WORD width, WORD height, WORD charInterval, UTFCOLOR textColor, LPUTFLOGFONT lpFont)
{
WORD i,j,k,count;
WORD startx = 0;
WORD position;
WORD wVectSize;
WORD dx=0,dy=0;
DWORD dwSize;
BYTE data,bDrawMode=1;
BYTE *pVect,*pData;
WORD *ptrWrite;
BYTE *ptrHeader;
UTFBITMAP bitmap;
if(lpFont->lfAddr1 == NULL)
return;
if(height > lpFont->lfHeight)
{
height = lpFont->lfHeight;
}
UTFGetMemoryBitmap(&bitmap);
if(bitmap.data)
{
bDrawMode = 0;
dx = left;
dy = top;
}
else
{
if(width%32)
{
WORD wOldWidth = width;
UTFRECT rcFullScreen;
UTFGetFullScreenRect(&rcFullScreen);
width += 32-width%32;
if((left+width) > (rcFullScreen.right-rcFullScreen.left))
{
width = wOldWidth;
}
}
dwSize = width*height;
ptrHeader = (BYTE *)SOWMalloc(dwSize<<1);
if(ptrHeader == NULL)
return;
bitmap.data = ptrHeader;
bitmap.Width = width;
bitmap.Height = height;
bitmap.bitPerPixel = 16;
UTFSaveScreen(left, top, &bitmap, 0);
}
UTFMemCpyWORD(&wVectSize, (void *)lpFont->lfAddr1, 2);
pVect = (BYTE *)(lpFont->lfAddr1+2);
pData = pVect+wVectSize;
while(*pText != NULL)
{
if((*pText > 31) || (*pText < 5))
{
DWORD address = 0;
if(*pText < 5)
{
position = *pText - 1;
}
else
{
position = *pText - 28;
}
for(i=0; i<position; i++)
{
address += pVect[(i<<1)+1];
}
address *= lpFont->lfHeight;
ptrWrite = (WORD *)bitmap.data;
ptrWrite += dy*bitmap.Width+dx+startx;
for(i=0; i<height; i++)
{
BYTE ByteNum = pVect[(position<<1)+1];
count = 0;
for(k=0; k<ByteNum; k++)
{
data = pData[address];
for(j=0; j<8; j++)
{
if(count >= pVect[position<<1])
{
break;
}
if(data & 0x80)
{
*(ptrWrite+count) = (WORD)textColor;
}
count++;
data <<= 1;
}
address++;
}
ptrWrite += bitmap.Width;
}
startx += pVect[position<<1] + charInterval;
}
pText++;
}
if(bDrawMode)
{
UTFPutScreen(left, top, &bitmap, 0);
SOWFree((void *)ptrHeader);
}
}
/*************************************************************************/
void UTFENGSetColorMode(BYTE bitPerPixel)
{
if(bitPerPixel == 8)
{
ENGTextFunc = ENGTextFunc8;
}
if(bitPerPixel == 16)
{
ENGTextFunc = ENGTextFunc16;
}
}