昵称:烦夫子
类别:界面/平面设计师
年龄:38
现所在地:北京
主页浏览总数:24255
总积分:89
文章数:88
作品数:70
//
// TEXTSET.CPP
//
#include "stdafx.h"
#include "textset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
FontFile::FontFile ()
{
}
int FontFile::GetCharData (const char *str, char *buf)
{
long code, position;
unsigned int len;
unsigned char ch1, ch2;
LibIndex index;
ch1 = str[0];
ch2 = str[1];
if (ch1 > 0xa0 && ch2 > 0xa0) // CHINESE
code = (ch1 - 0xa1) * 94L + (ch2 - 0xa1);
else { // ASCII
if (ch1 >= ' ')
code = ch1 - ' ' + 3;
else
code = ch1 - 11;
}
position = code * sizeof (LibIndex) + HEADER;
Seek (position, CFile::begin);
Read (&index, sizeof (LibIndex));
len = index.len2 + (index.len1 << 8);
ASSERT (len < 1024);
position = (((long)index.add1)<<24) +
(((long)index.add2)<<16) +
(((long)index.add3)<<8) +
index.add4;
Seek (position, CFile::begin);
Read (buf, len);
return len;
}
void FontFile::GetCharStroke (const char *string, Vector& org, FontData& fdata)
{
int i, j, k, len, n_points;
char pbuf[1024];
Vector temp;
len = GetCharData (string, pbuf);
StrokeData *s = new StrokeData[100]; //100
for (i = j = 0; i < len && j<100;) {
n_points = pbuf[i++];
if (n_points == 0) continue;
s[j].v = new Vector[n_points];
s[j].num = n_points;
for (k = 0; k < n_points; k++) {
temp.x = pbuf[i++];
temp.y = 128 - pbuf[i++];
s[j].v[k] = temp / 128.0;
}
j++;
}
fdata.org = org;
fdata.num = j;
fdata.s = new StrokeData[j];
memcpy (fdata.s, s, j * sizeof (StrokeData));
delete [] s;
}