3
/* This small program shows how to print a rotated string with the */
4
/* FreeType 2 library. */
13
#include FT_FREETYPE_H
19
/* origin is the upper left corner */
23
/* Replace this function with something useful. */
26
draw_bitmap( FT_Bitmap* bitmap,
31
FT_Int x_max = x + bitmap->width;
32
FT_Int y_max = y + bitmap->rows;
35
for ( i = x, p = 0; i < x_max; i++, p++ )
37
for ( j = y, q = 0; j < y_max; j++, q++ )
39
if ( i < 0 || j < 0 ||
40
i >= WIDTH || j >= HEIGHT )
43
image[j*WIDTH + i] |= bitmap->buffer[q * bitmap->width + p];
55
for ( i = 0; i < HEIGHT; i++ )
57
for ( j = 0; j < WIDTH; j++ ) {
58
if (image[i*WIDTH + j]) count++;
59
putchar( image[i*WIDTH + j] == 0 ? ' '
60
: image[i*WIDTH + j] < 128 ? '+'
65
printf("Non-0s: %d\n", count);
77
FT_Matrix matrix; /* transformation matrix */
78
FT_Vector pen; /* untransformed origin */
90
fprintf ( stderr, "usage: %s font sample-text width height angle\n", argv[0] );
94
filename = argv[1]; /* first argument */
95
text = argv[2]; /* second argument */
96
num_chars = strlen( text );
97
WIDTH = atoi(argv[3]);
98
HEIGHT = atoi(argv[4]);
99
angle = ( ((float)atoi(argv[5])) / 360 ) * 3.14159 * 2; /* use 25 degrees */
100
target_height = HEIGHT;
102
image = (unsigned char*)malloc(WIDTH*HEIGHT);
103
for (int x = 0; x < WIDTH; x++)
104
for (int y = 0; y < HEIGHT; y++)
105
image[y*WIDTH + x] = 0;
107
error = FT_Init_FreeType( &library ); /* initialize library */
108
if (error) printf("Init Error! %d\n", error);
110
error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
111
if (error) printf("New_Face Error! %d\n", error);
113
/* use 50pt at 100dpi */
114
error = FT_Set_Char_Size( face, 50 * 64, 0,
115
100, 0 ); /* set character size */
116
if (error) printf("Set_Char_Size Error! %d\n", error);
121
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
122
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
123
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
124
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
129
for ( n = 0; n < num_chars; n++ )
131
/* set transformation */
132
FT_Set_Transform( face, &matrix, &pen );
134
/* load glyph image into the slot (erase previous one) */
135
error = FT_Load_Char( face, text[n], FT_LOAD_RENDER );
137
continue; /* ignore errors */
139
/* now, draw to our target surface (convert position) */
140
draw_bitmap( &slot->bitmap,
142
target_height - slot->bitmap_top );
144
/* increment pen position */
145
pen.x += slot->advance.x;
146
pen.y += slot->advance.y;
151
FT_Done_Face ( face );
152
FT_Done_FreeType( library );