Fixed some of tools/neofont generation code to make neofont a monospace one.

This commit is contained in:
linshier
2010-08-15 12:40:27 +00:00
parent 14f2b6288a
commit e8431047de
12 changed files with 115 additions and 12 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4
View File
@@ -10,3 +10,7 @@ neofont : neofont.o
clean :
@rm -f neofont *.o *.asc *.gbk
update : neofont fallback.ttf gkai00mp.ttf mono.ttf
@./neofont && mv *.asc *.gbk ../../Res/graphics/
+1 -1
View File
@@ -1,2 +1,2 @@
fallback.ttf from http://android.git.kernel.org/?p=platform/frameworks/base.git;a=tree;f=data/fonts;hb=HEAD
fallback.ttf & mono.ttf from http://android.git.kernel.org/?p=platform/frameworks/base.git;a=tree;f=data/fonts;hb=HEAD
gkai00mp.ttf from http://cle.linux.org.tw/fonts/Arphic/
Binary file not shown.
+110 -11
View File
@@ -27,6 +27,85 @@ unsigned short to_unicode(char * szStr)
#endif
}
unsigned char islot[5][16 * 16 / 2];
unsigned char pspicons[5] = {0xA1, 0xf7, 0xf0, 0xc1, 0xf5};
int render_icon12(const char * szFilename)
{
FT_Face face;
unsigned char i, j, y;
if (FT_New_Face(m_library, szFilename, 0, &face) != 0)
return -1;
if (FT_Set_Char_Size(face, 0, 20 * 64, 72, 0) != 0) {
FT_Done_Face(face);
return -1;
}
for (j = 0; j < 5; j ++) {
unsigned char s[3] = {(unsigned char)0xa1, pspicons[j], 0};
unsigned short code = to_unicode((char *)s);
memset(islot[j], 0, 12 * 12 / 2);
if (code && FT_Load_Char(face, code, FT_LOAD_RENDER) == 0) {
if (face->glyph->bitmap.buffer != NULL && face->glyph->bitmap_top > 0) {
if (j == 0) continue;
unsigned char left = 1;
for (y = 0; y < face->glyph->bitmap.rows; y++) {
unsigned char h = 1 + y;
unsigned char l = face->glyph->bitmap.pitch;
unsigned char u = 0;
for (u = 0; u < l; u++)
islot[j][(h * 12 + left + u) / 2]
|= (face->glyph->bitmap.buffer[y * face->glyph->bitmap.pitch + u]
& 0xF0) >> 4 * (1 - (left + u) & 1);
}
}
}
}
FT_Done_Face(face);
return 0;
}
int render_icon16(const char * szFilename)
{
FT_Face face;
unsigned char i, j, y;
if (FT_New_Face(m_library, szFilename, 0, &face) != 0)
return -1;
if (FT_Set_Char_Size(face, 0, 30 * 64, 72, 0) != 0) {
FT_Done_Face(face);
return -1;
}
for (j = 0; j < 5; j ++)
{
unsigned char s[3] = {(unsigned char)0xa1, pspicons[j], 0};
unsigned short code = to_unicode((char *)s);
memset(islot[j], 0, 16 * 16 / 2);
if (code && FT_Load_Char(face, code, FT_LOAD_RENDER) == 0) {
if (face->glyph->bitmap.buffer != NULL && face->glyph->bitmap_top > 0) {
if (j == 0) continue;
unsigned char left = 1;
for (y = 0; y < face->glyph->bitmap.rows; y++) {
unsigned char h = 2 + y;
unsigned char l = face->glyph->bitmap.pitch;
unsigned char u = 0;
for (u = 0; u < l; u++)
islot[j][(h * 16 + left + u) / 2]
|= (face->glyph->bitmap.buffer[y * face->glyph->bitmap.pitch + u]
& 0xF0) >> 4 * (1 - (left + u) & 1);
}
}
}
}
FT_Done_Face(face);
return 0;
}
int render_cn12(const char * szFilename, const char * szOutputname)
{
unsigned char zslot[12 * 12 / 2];
@@ -77,7 +156,15 @@ int render_cn12(const char * szFilename, const char * szOutputname)
}
}
}
if (i == 0xA1 && j == 0xA1) memset(zslot, 0, 12 * 12 / 2);
if (i == 0xA1) {
switch (j) {
case 0xA1: memcpy(zslot, islot[0], 12 * 12 / 2); break;
case 0xF7: memcpy(zslot, islot[1], 12 * 12 / 2); break;
case 0xF0: memcpy(zslot, islot[2], 12 * 12 / 2); break;
case 0xC1: memcpy(zslot, islot[3], 12 * 12 / 2); break;
case 0xF5: memcpy(zslot, islot[4], 12 * 12 / 2); break;
}
}
fwrite(zslot, sizeof(unsigned char), 12 * 12 / 2, fp);
}
}
@@ -97,11 +184,12 @@ int render_cn16(const char * szFilename, const char * szOutputname)
if (FT_New_Face(m_library, szFilename, 0, &face) != 0)
return -1;
if (FT_Set_Char_Size(face, 0, 16 * 64, 72, 0) != 0 || (fp = fopen(szOutputname,"w")) == NULL) {
FT_Done_Face(face);
return -1;
}
#if 0
// GBK encoding
for (i = 0x81; i < 0xFF; i ++) {
@@ -137,7 +225,15 @@ int render_cn16(const char * szFilename, const char * szOutputname)
}
}
}
if (i == 0xA1 && j == 0xA1) memset(zslot, 0, 16 * 16 / 2);
if (i == 0xA1) {
switch (j) {
case 0xA1: memcpy(zslot, islot[0], 16 * 16 / 2); break;
case 0xF7: memcpy(zslot, islot[1], 16 * 16 / 2); break;
case 0xF0: memcpy(zslot, islot[2], 16 * 16 / 2); break;
case 0xC1: memcpy(zslot, islot[3], 16 * 16 / 2); break;
case 0xF5: memcpy(zslot, islot[4], 16 * 16 / 2); break;
}
}
fwrite(zslot, sizeof(unsigned char), 16 * 16 / 2, fp);
}
}
@@ -196,7 +292,7 @@ int render_en12(const char * szFilename, const char * szOutputname)
if (FT_New_Face(m_library, szFilename, 0, &face) != 0)
return -1;
if (FT_Set_Char_Size(face, 0, 10 * 64, 72, 0) != 0 || (fp = fopen(szOutputname,"w")) == NULL) {
if (FT_Set_Char_Size(face, 0, 11 * 64, 72, 0) != 0 || (fp = fopen(szOutputname,"w")) == NULL) {
FT_Done_Face(face);
return -1;
}
@@ -236,7 +332,7 @@ int render_en16(const char * szFilename, const char * szOutputname)
if (FT_New_Face(m_library, szFilename, 0, &face) != 0)
return -1;
if (FT_Set_Char_Size(face, 0, 12 * 64, 72, 0) != 0 || (fp = fopen(szOutputname,"w")) == NULL) {
if (FT_Set_Char_Size(face, 0, 14 * 64, 72, 0) != 0 || (fp = fopen(szOutputname,"w")) == NULL) {
FT_Done_Face(face);
return -1;
}
@@ -246,7 +342,7 @@ int render_en16(const char * szFilename, const char * szOutputname)
if (code > 0x20 && FT_Load_Char(face, code, FT_LOAD_RENDER) == 0) {
if (face->glyph->bitmap.buffer != NULL && face->glyph->bitmap_top > 0) {
for (y = 0; y < face->glyph->bitmap.rows && y < 16 && y - face->glyph->bitmap_top < 2; y++) {
unsigned char h = 16 - 2 - face->glyph->bitmap_top + y;
unsigned char h = 15 - 2 - face->glyph->bitmap_top + y;
unsigned char u = 0;
unsigned char left = face->glyph->bitmap.pitch > 8 ? 1 : 0;
for (u = 0; u < left + face->glyph->bitmap.pitch; u++)
@@ -274,15 +370,18 @@ int main()
ic = iconv_open("unicode", "gb2312");
if (ic == 0) printf("Error initializing iconv!\n");
render_icon12("fallback.ttf");
render_cn12("fallback.ttf", "simon.gbk");
render_en12("fallback.ttf", "simon.asc");
render_cn16("fallback.ttf", "f3.gbk");
render_en16("fallback.ttf", "f3.asc");
render_cn16("gkai00mp.ttf", "magic.gbk");
render_en16("gkai00mp.ttf", "magic.asc");
render_en12("mono.ttf", "simon.asc");
render_cn12("gkai00mp.ttf", "smallface.gbk");
render_en12("gkai00mp.ttf", "smallface.asc");
render_icon16("fallback.ttf");
render_cn16("fallback.ttf", "f3.gbk");
render_en16("mono.ttf", "f3.asc");
render_cn16("gkai00mp.ttf", "magic.gbk");
render_en16("gkai00mp.ttf", "magic.asc");
iconv_close(ic);
FT_Done_FreeType(m_library);
printf("done\n");