- 精华
- 0
- 帖子
- 495
- 威望
- 0 点
- 积分
- 531 点
- 种子
- 12 点
- 注册时间
- 2007-3-8
- 最后登录
- 2024-9-24
|
楼主 |
发表于 2008-8-14 17:08 · 广东
|
显示全部楼层
#include
#include FT_FREETYPE_H
int main(int argc, char **argv){
int psize;
FT_Library library;
FT_Face face;
unsigned int ucode;
FT_UInt glyph_index;
int row, pixel;
if(argc != 4){
? return 10;
}
ucode = strtol(argv[2], NULL, 16);
psize = strtol(argv[3], NULL, 10);
printf("unicode +%X size %dn", ucode, psize);
if(FT_Init_FreeType(&library)
??|| FT_New_Face(library, argv[1], 0, &face)
??|| FT_Set_Pixel_Sizes(face, psize, 0)){
? return 1;
}
//get glyph index
glyph_index = FT_Get_Char_Index(face, ucode);
if(glyph_index == 0){
? return 2;
}
//load the chinese glyph
if(FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT)){
? return 3;
}
if(FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO)){ //遍历所有的点,使用合适的render画上去
? return 4;
}
printf("bitmap_left=%dn"
? ? ?"bitmap_top=%dn"
? ? ?"bitmap.rows=%dn"
? ? ?"bitmap.width=%dn"
? ? ?"bitmap.pitch=%dn"
? ? ?"bitmap.pixel_mode=%dn",
? ? ?face->glyph->bitmap_left,
? ? ?face->glyph->bitmap_top,
? ? ?face->glyph->bitmap.rows,
? ? ?face->glyph->bitmap.width,
? ? ?face->glyph->bitmap.pitch,
? ? ?face->glyph->bitmap.pixel_mode);
printf("nn");
for(row = 0;
? ?row < (face->glyph->bitmap.rows - face->glyph->bitmap_top);
? ?++row){
? ?for(pixel = 0; pixel < face->glyph->bitmap.width; ++pixel){
? ??printf("_");
? ?}
? ?printf("n");
}
for(row = 0; row < face->glyph->bitmap.rows; ++row){
? for(pixel = 0; pixel < face->glyph->bitmap_left; ++pixel)
? ?printf("_");
? for(pixel = 0; pixel < face->glyph->bitmap.width; ++pixel){
? ?printf("%c", (face->glyph->bitmap.buffer
? ? ? ? ? ??[row * face->glyph->bitmap.pitch +
? ? ? ? ? ? ?pixel/8] & (0xC0 >> (pixel % 8)))?'O':'_');
? }
? printf("n");
}
return 0;
}
cat ~/bin/mygetunicode
#!/bin/sh
echo -n $1 |iconv -t ucs2 | od -tx1 | head -n1 |awk '{print $3$2}'
./getbitmap /usr/share/fonts/chinese/TrueType/uming.ttf $(mygetunicode 永) 12 ? ? ? //mygetunicode 这个程序是返回汉字的unicode编码? ? ? ? ? ? ? ? ? ? ?
unicode +6C38 size 12
bitmap_left=0
bitmap_top=10
bitmap.rows=11
bitmap.width=11
bitmap.pitch=2
bitmap.pixel_mode=1
___________
____OOO____
______OO___
__OOOOO____
_____OO_OO_
OOOOOOO_O__
___OOOOO___
___OOOOO___
__OO_OO_O__
_OOOOOO_OO_
OO__OOO_OOO
O___OO___OO
标记:字体变换(旋转和缩放)
error = FT_Set_Transform( face, /* target face object */
&matrix, /* pointer to 2x2 matrix */
&delta ); /* pointer to 2d vector */ |
|