//============================================================================ // Name : test-freetype.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include "ft2build.h" #include "freetype/freetype.h" #include FT_RENDER_H #include "stdio.h" int main(int argc, char **argv) { int major, minor, patch, sz = 100; if(argc == 2) sz = atoi(argv[1]); FT_Library library; FT_Face face; FT_StreamRec_ ft_st = { nullptr, 0, 0, {-1}, {0}, nullptr, nullptr, nullptr, nullptr, nullptr }; FT_Open_Args ft_oa = { FT_OPEN_PATHNAME, nullptr, 0, (FT_String *)"/usr/fonts/arial.ttf", &ft_st, 0, 0, nullptr }; FT_Init_FreeType(&library); FT_Open_Face(library, &ft_oa, 0, &face); FT_Library_Version(library, &major, &minor, &patch); FT_Set_Charmap(face, face->charmaps[0]); FT_Set_Pixel_Sizes(face, sz, sz); FT_Load_Char(face, 'e', FT_LOAD_DEFAULT | FT_LOAD_TARGET_LIGHT | FT_LOAD_MONOCHROME | FT_LOAD_NO_BITMAP); FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO); printf("Freetype V.%d.%d.%d - size:%d\n", major, minor, patch, sz); unsigned int row, column; for(column = 0; column < face->glyph->bitmap.width; column++) printf("--"); printf("\n"); for(row = 0; row < face->glyph->bitmap.rows; row++) { for(column = 0; column < face->glyph->bitmap.width; column++) printf((0x80 >> (column & 0x7)) & face->glyph->bitmap.buffer[row * face->glyph->bitmap.pitch + column / 8] ? "XX" : " "); printf("\n"); } for(column = 0; column < face->glyph->bitmap.width; column++) printf("--"); printf("\n"); FT_Done_Face(face); FT_Done_FreeType(library); return 0; }