#include #include #include #include FT_FREETYPE_H #define WIDTH 100 #define HEIGHT 50 unsigned char image[HEIGHT][WIDTH]; void draw_bitmap( FT_Bitmap* bitmap, FT_Int x, FT_Int y ) { FT_Int i, j, p, q; FT_Int x_max = x + bitmap->width; FT_Int y_max = y + bitmap->rows; for ( i = x, p = 0; i < x_max; i++, p++ ) { for ( j = y, q = 0; j < y_max; j++, q++ ) { if ( i < 0 || j < 0 || i >= WIDTH || j >= HEIGHT ) continue; image[j][i] |= bitmap->buffer[q * bitmap->width + p]; } } } void show_image( void ) { int i, j; for ( i = 0; i < HEIGHT; i++ ) { for ( j = 0; j < WIDTH; j++ ) putchar( image[i][j] == 0 ? ' ' : image[i][j] < 128 ? '+' : '*' ); putchar( '\n' ); } } int main( int argc, char** argv ) { FT_Library library; FT_Face face; FT_GlyphSlot slot; FT_Matrix matrix; /* transformation matrix */ FT_Vector pen; /* untransformed origin */ FT_Error error; char* filename; FT_ULong text[2]; int target_height; int n, num_chars; if ( argc != 2 ) { exit( 1 ); } filename = argv[1]; text[0] = 0x21d0; text[1] = 0x21d1; num_chars = 2; target_height = HEIGHT; error = FT_Init_FreeType( &library ); error = FT_New_Face( library, filename, 0, &face ); error = FT_Set_Char_Size( face, 24 * 64, 0, 200, 100 ); /* different x and y! */ slot = face->glyph; matrix.xx = (FT_Fixed)( 1 * 0x10000L ); matrix.xy = (FT_Fixed)( 0 * 0x10000L ); matrix.yx = (FT_Fixed)( 0 * 0x10000L ); matrix.yy = (FT_Fixed)( 1 * 0x10000L ); pen.x = 0 * 64; pen.y = ( target_height - 25 ) * 64; for ( n = 0; n < num_chars; n++ ) { FT_Set_Transform( face, &matrix, &pen ); error = FT_Load_Char( face, text[n], FT_LOAD_RENDER ); if ( error ) continue; draw_bitmap( &slot->bitmap, slot->bitmap_left, target_height - slot->bitmap_top ); pen.x += slot->advance.x; pen.y += slot->advance.y; } show_image(); FT_Done_Face ( face ); FT_Done_FreeType( library ); return 0; } /* EOF */