3
/* This small program shows how to print a rotated string with the */
4
/* FreeType 2 library. */
13
#include FT_FREETYPE_H
18
/* origin is the upper left corner */
22
/* Replace this function with something useful. */
25
draw_bitmap( FT_Bitmap* bitmap,
30
FT_Int x_max = x + bitmap->width;
31
FT_Int y_max = y + bitmap->rows;
33
for ( i = x, p = 0; i < x_max; i++, p++ )
35
for ( j = y, q = 0; j < y_max; j++, q++ )
37
if ( i < 0 || j < 0 ||
38
i >= WIDTH || j >= HEIGHT )
41
image[j*WIDTH + i] |= bitmap->buffer[q * bitmap->width + p];
53
for ( i = 0; i < HEIGHT; i++ )
55
for ( j = 0; j < WIDTH; j++ )
57
if (image[i*WIDTH + j]) count++;
58
putchar(image[i*WIDTH + j] == 0? ' '
59
: image[i*WIDTH + j] < 128 ? '+'
64
printf("Non-0s: %d\n", count);
87
fprintf ( stderr, "usage: %s font sample-text width height angle\n", argv[0] );
91
// Only test the character 'w'
94
filename = argv[1]; /* first argument */
95
WIDTH = atoi(argv[3]);
96
HEIGHT = atoi(argv[4]);
97
target_height = HEIGHT;
99
image = (unsigned char*)malloc(WIDTH*HEIGHT);
100
for (int x = 0; x < WIDTH; x++)
101
for (int y = 0; y < HEIGHT; y++)
102
image[y*WIDTH + x] = 0;
104
error = FT_Init_FreeType( &library ); /* initialize library */
105
if (error) printf("Init Error! %d\n", error);
107
error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
108
if (error) printf("New_Face Error! %d\n", error);
110
/* use 50pt at 100dpi */
111
error = FT_Set_Char_Size( face, 0, 32 * 64, 0, 0 ); /* set character size */
112
if (error) printf("Set_Cshar_Size Error! %d\n", error);
116
glyphIndex = FT_Get_Char_Index(face, text[0]);
118
/* load glyph image into the slot (erase previous one) */
119
error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_NO_BITMAP);
120
if(error) printf("FT_Load_Glyph Error! %d\n", error);
122
error = FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
123
if(error) printf("FT_Render_Glyph Error! %d\n", error);
125
/* now, draw to our target surface (convert position) */
126
draw_bitmap(&slot->bitmap, slot->bitmap_left, target_height - slot->bitmap_top);
131
FT_Done_FreeType(library);
b'\\ No newline at end of file'