使用freetype2从ttf字库中提取任意大点阵字体
2013-03-19 10:17
295 查看
#include <ft2build.h>
#include FT_FREETYPE_H
int main(int argc, char **argv)
{
FT_Library library;
FT_Face face;
int error;
int i, j, k, counter;
unsigned char temp;
int char_index;
int font_size;
if (argc != 4)
{
printf("Usage:
test filename font_size index\n");
return 0;
}
char_index = atoi(argv[3]);
font_size = atoi(argv[2]);
error = FT_Init_FreeType(&library);
if (error)
{
printf("can
not init free type library!\n");
return 0;
}
error = FT_New_Face(library, argv[1], 0, &face);
if (error)
{
printf("create
new face falied!\n");
return 0;
}
error = FT_Set_Pixel_Sizes(face, 0, font_size);
if (error)
{
printf("set
font size error!\n");
return 0;
}
//printf("file family name
%s\n", face->family_name);
//printf("file style name
%s\n", face->style_name);
//printf("number of char
%d\n", face->num_glyphs);
//printf("number of fixed
bitmap %d\n", face->num_fixed_sizes);
//printf("Char size %d\n", face->size);
error = FT_Load_Glyph(face, char_index, FT_LOAD_DEFAULT);
if (error)
{
printf("Load
char error!\n");
return 0;
}
if (face->glyph->format != FT_GLYPH_FORMAT_BITMAP)
{
error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO);
if (error)
{
printf("render
char failed!\n");
return 0;
}
}
// printf("rows %d, width %d\n", face->glyph->bitmap.rows, face->glyph->bitmap.width);
//printf("pitch %d\n", face->glyph->bitmap.pitch);
// printf("bit_map_left %d bit_map_top %d\n", face->glyph->bitmap_left,
// face->glyph->bitmap_top);
// printf("width %d height %d\n", face->glyph->metrics.width, face->glyph->metrics.height);
// printf("%d %d %d\n", face->glyph->metrics.horiBearingX, face->glyph->metrics.horiBearingY,
// face->glyph->metrics.horiAdvance);
for (j = 0; j < (font_size * 26) / 32 - face->glyph->bitmap_top; j++)
{
for (i = 0; i < font_size; i++)
{
printf("_");
}
printf("\n");
}
for (; j < face->glyph->bitmap.rows + (font_size * 26) / 32 - face->glyph->bitmap_top; j++)
{
for (i = 1; i <= face->glyph->bitmap_left; i++)
{
printf("_");
}
for (k = 0; k < face->glyph->bitmap.pitch; k++)
{
temp = face->glyph->bitmap.buffer[face->glyph->bitmap.pitch*(j + face->glyph->bitmap_top - (font_size * 26) / 32) + k];
for (counter = 0; counter < 8; counter++)
{
if (temp & 0x80)
{
printf("*");
}
else
{
printf("_");
}
temp <<= 1;
i++;
if (i > font_size)
{
break;
}
}
}
for (; i <= font_size; i++)
{
// printf("|");
}
printf("\n");
}
for (; j < font_size; j++)
{
for (i = 0; i < font_size; i++)
{
printf("_");
}
printf("\n");
}
return 0;
}
#include FT_FREETYPE_H
int main(int argc, char **argv)
{
FT_Library library;
FT_Face face;
int error;
int i, j, k, counter;
unsigned char temp;
int char_index;
int font_size;
if (argc != 4)
{
printf("Usage:
test filename font_size index\n");
return 0;
}
char_index = atoi(argv[3]);
font_size = atoi(argv[2]);
error = FT_Init_FreeType(&library);
if (error)
{
printf("can
not init free type library!\n");
return 0;
}
error = FT_New_Face(library, argv[1], 0, &face);
if (error)
{
printf("create
new face falied!\n");
return 0;
}
error = FT_Set_Pixel_Sizes(face, 0, font_size);
if (error)
{
printf("set
font size error!\n");
return 0;
}
//printf("file family name
%s\n", face->family_name);
//printf("file style name
%s\n", face->style_name);
//printf("number of char
%d\n", face->num_glyphs);
//printf("number of fixed
bitmap %d\n", face->num_fixed_sizes);
//printf("Char size %d\n", face->size);
error = FT_Load_Glyph(face, char_index, FT_LOAD_DEFAULT);
if (error)
{
printf("Load
char error!\n");
return 0;
}
if (face->glyph->format != FT_GLYPH_FORMAT_BITMAP)
{
error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO);
if (error)
{
printf("render
char failed!\n");
return 0;
}
}
// printf("rows %d, width %d\n", face->glyph->bitmap.rows, face->glyph->bitmap.width);
//printf("pitch %d\n", face->glyph->bitmap.pitch);
// printf("bit_map_left %d bit_map_top %d\n", face->glyph->bitmap_left,
// face->glyph->bitmap_top);
// printf("width %d height %d\n", face->glyph->metrics.width, face->glyph->metrics.height);
// printf("%d %d %d\n", face->glyph->metrics.horiBearingX, face->glyph->metrics.horiBearingY,
// face->glyph->metrics.horiAdvance);
for (j = 0; j < (font_size * 26) / 32 - face->glyph->bitmap_top; j++)
{
for (i = 0; i < font_size; i++)
{
printf("_");
}
printf("\n");
}
for (; j < face->glyph->bitmap.rows + (font_size * 26) / 32 - face->glyph->bitmap_top; j++)
{
for (i = 1; i <= face->glyph->bitmap_left; i++)
{
printf("_");
}
for (k = 0; k < face->glyph->bitmap.pitch; k++)
{
temp = face->glyph->bitmap.buffer[face->glyph->bitmap.pitch*(j + face->glyph->bitmap_top - (font_size * 26) / 32) + k];
for (counter = 0; counter < 8; counter++)
{
if (temp & 0x80)
{
printf("*");
}
else
{
printf("_");
}
temp <<= 1;
i++;
if (i > font_size)
{
break;
}
}
}
for (; i <= font_size; i++)
{
// printf("|");
}
printf("\n");
}
for (; j < font_size; j++)
{
for (i = 0; i < font_size; i++)
{
printf("_");
}
printf("\n");
}
return 0;
}
相关文章推荐
- opencv读取ttf字库使用freetype提取汉字笔划笔顺
- iOS使用自定义字体的方法(内置和任意下载ttf\otf\ttc字体文件)
- 提取TTF字库字模
- caffe:使用C++来提取任意一张图片的特征(从内存读取数据)
- iOS使用自定义字体的方法(内置和任意下载ttf\otf\ttc字体文件)
- iOS使用自定义字体的方法(内置和任意下载ttf\otf\ttc字体文件)
- cocos2dx的CCLabelTTF类使用不同的TTF字库时字体没有变化的问题
- Unity3D下NGUI插件使用中文TrueTypeFont(ttf)字库教程
- MiniGui使用ttf失量字库支持中英文
- (libgdx小结)TTF字库的使用(优美字体的绘制)
- opencv读取ttf字库使用freetype生成图
- cocos2dx的CCLabelTTF类使用不同的TTF字库时字体没有变化的问题
- Unity3D下NGUI插件使用中文TrueTypeFont(ttf)字库教程
- 关于使用字库-雅黑字体(msyh.ttf )显示中文的一些。。。
- android游戏开发框架libgdx的使用(二十一)—使用TTF字库支持中文
- caffe:使用C++来提取任意一张图片的特征
- libgdx基础教程——TTF字库的使用
- 关于QT字库的移植和使用总结(能够任意改变字体和颜色)
- android游戏开发框架libgdx的使用(二十一)—使用TTF字库支持中文
- TextView使用指定的TTF字库