#include #include #include #include FT_FREETYPE_H static const char * SCALE = " .:-=+*%#@"; static const char * FONT = "/usr/share/fonts/TTF/DejaVuSans.ttf"; int main(int argc, char * argv[]) { if(argc<1) return 1; char letter = argv[1][0]; FT_UInt height = 16; if(argc>2) height = atoi(argv[2]); FT_Library library; FT_Error error; error = FT_Init_FreeType(&library); if(error) return 2; FT_Face face; error = FT_New_Face(library, FONT, 0, &face); if(error) return 3; error = FT_Set_Pixel_Sizes(face, 0, height); if(error) return 4; FT_UInt index = FT_Get_Char_Index(face, letter); error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT); if(error) return 5; FT_GlyphSlot slot = face->glyph; error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); if(error) return 6; printf("%d x %d\n", slot->bitmap.width, slot->bitmap.rows); for(unsigned y = 0; y < slot->bitmap.rows; ++y) { for(unsigned x = 0; x < slot->bitmap.width; ++x) { unsigned char value = slot->bitmap.buffer[y*slot->bitmap.pitch+x]; value /= 28.33; putchar(SCALE[value]); } printf("\n"); } error = FT_Done_Face(face); if(error) return 7; error = FT_Done_FreeType(library); if(error) return 8; }