用freetype2显示ascii-art中文
2009-06-30 16:19
204 查看
getbitmap.c
Makefile
运行效果:
#include <ft2build.h> #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 %d/n" , ucode, psize); if (FT_Init_FreeType(&library) || FT_New_Face(library, argv[1], 0, &face) || FT_Set_Pixel_Sizes(face, psize, 0)){ return 1; } glyph_index = FT_Get_Char_Index(face, ucode); if (glyph_index == 0){ return 2; } if (FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT)){ return 3; } if (FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO)){ return 4; } printf("bitmap_left=%d/n" "bitmap_top=%d/n" "bitmap.rows=%d/n" "bitmap.width=%d/n" "bitmap.pitch=%d/n" "bitmap.pixel_mode=%d/n" , 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("/n/n" ); 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; }
Makefile
all : getbitmap getbitmap.o : getbitmap.c gcc $(CXXFLAGS ) -c `pkg-config freetype2 --cflags` $< -o $ @ getbitmap : getbitmap.o gcc $(CXXFLAGS ) `pkg-config freetype2 --libs` -lm $< -o $ @ clean : rm -f *.o getbitmap
运行效果:
hellwolf @ cocteau # pts/1 % J0S2 : getbitmap $ ./getbitmap /usr/share/fonts/chinese/True Type/uming.ttf $(mygetunicode 永) 12 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 hellwolf @ cocteau # pts/1 % J0S2 : getbitmap $ ./getbitmap /usr/share/fonts/chinese/True Type/uming.ttf $(mygetunicode 永) 16 unicode +6C38 size 16 bitmap_left=1 bitmap_top=14 bitmap.rows=15 bitmap.width=14 bitmap.pitch=2 bitmap.pixel_mode=1 ______________ _____OO________ ______OOO______ _______OO______ _______________ __OOOOOOO__OOO_ _______OO__OO__ ____OO_OO_OO___ _OOOOOOOOOO____ ____OO_OOO_____ ___OO__OOOO____ ___OO__OOOO____ __OO___OO_OO___ _OO_OO_OO__OOO_ _O___OOOO___OOO ______OO_____OO hellwolf @ cocteau # pts/1 % J0S2 : getbitmap $ ./getbitmap /usr/share/fonts/chinese/True Type/uming.ttf $(mygetunicode 永) 20 unicode +6C38 size 20 bitmap_left=0 bitmap_top=18 bitmap.rows=20 bitmap.width=20 bitmap.pitch=4 bitmap.pixel_mode=1 ____________________ ____________________ ____________________ ________OOO_________ _________OOO________ ____________________ _________OO_________ ____OOOOOOOO____O___ _________OO___OOOO__ _________OOO__OO____ OOOOOOOO_OOO_OO_____ _____OOO_OOOOO______ _____OO__OOOO_______ _____OO__OOOO_______ ____OOO__OO_OO______ ____OO___OO__OO_____ ___OO____OO__OOO____ ___OO____OO___OOO___ __OO_____OO_____OOOO _OO______OO_________ OO______OOO_________ ____________________ hellwolf @ cocteau # pts/1 % J0S2 : getbitmap $ ./getbitmap /usr/share/fonts/chinese/True Type/uming.ttf $(mygetunicode 中) 16 unicode +4E2D size 16 bitmap_left=1 bitmap_top=14 bitmap.rows=15 bitmap.width=14 bitmap.pitch=2 bitmap.pixel_mode=1 ______________ ______OOO______ ______OO_______ ______OO_______ ______OO____OO_ _OOOOOOOOOOOOOO _O____OO____OO_ _O____OO____OO_ _O____OO____OO_ _OOOOOOOOOOOOO_ _O____OO____OO_ ______OO_______ ______OO_______ ______OO_______ ______OO_______ ______OO_______ hellwolf @ cocteau # pts/1 % J0S2 : getbitmap $ ./getbitmap /usr/share/fonts/chinese/True Type/uming.ttf $(mygetunicode 中) 32 unicode +4E2D size 32 bitmap_left=4 bitmap_top=28 bitmap.rows=32 bitmap.width=26 bitmap.pitch=4 bitmap.pixel_mode=1 __________________________ __________________________ __________________________ __________________________ ______________OO______________ ______________OOOO____________ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ____O_________OOO________OOO__ ____OOOOOOOOOOOOOOOOOOOOOOOOO_ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____OOOOOOOOOOOOOOOOOOOOOOOO__ ____OO________OOO________OOO__ ____OO________OOO________OOO__ ____O_________OOO________OO___ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ______________OOO_____________ ______________OO______________ ______________________________ hellwolf @ cocteau # pts/1 % J0S2 : getbitmap $
相关文章推荐
- 用freetype2显示ascii-art中文
- 【python在git bash下的中文显示】 UnicodeEncodeError: 'ascii' codec can't encode characters in position ...
- asciidoctor-pdf中文乱码问题或显示不全
- ASCII Art—使用纯文本来显示图像:综述
- OGREFont的研究与OGRE的中文显示(二) freetype2攻略
- C语义char*显示中文---ASCII、DBCS、Unicode三种编码---char* CString string区别
- 通过swagger2markup+asciidoctorj生成html和pdf文档并解决asciidoctorj生成的pdf文件中文显示不全问题(maven方式及java代码方式)
- 用freetype2显示ascii-art中文
- 中文ascii转为中文显示问题
- freetype2 中文显示
- 解决Ubuntu系统中文乱码显示问题
- ubuntu下无法显示中文的解决办法
- .properties文件显示成中文
- Qt编码方式(中文显示)
- sublime_text3汉化,破解,安装Package_control支持中文显示
- MySQL 5.7.x 数据库名中文访问出错或表内中文显示?? 解决方法
- fedora18 startx如何显示中文界面及文本模式和窗口模式切换
- Qt编译安装后中文无法显示问题
- html文件的中文乱码问题与在浏览器中的显示
- TP5 layui 储存type分类ID,记录显示中显示对应的中文名称