#include #include FT_FREETYPE_H #include FT_OUTLINE_H #include FT_SIZES_H #include FT_GLYPH_H static void eerror(const char *msg, FT_Error e) { printf("%s 0x%0x\n", msg, e); exit(1); } int main(int argc, char *argv[]) { FT_Face face; FT_Vector offset; FT_GlyphSlot slot; FT_UInt gid; FT_Matrix matrix; FT_Library lib; FT_Error e; if (e = FT_Init_FreeType(&lib)) eerror("1", e); if (e = FT_New_Face(lib, "font.ttf", 0, &face)) eerror("2", e); if (e = FT_New_Size(face, &face->size)) eerror("3", e); if (e = FT_Set_Pixel_Sizes(face, 0, 28)) eerror("6", e); matrix.xx = (FT_Fixed)(0); matrix.yx = (FT_Fixed)(65536); matrix.xy = (FT_Fixed)(-65536); matrix.yy = (FT_Fixed)(0); offset.x = 0; offset.y = 0; FT_Set_Transform(face, &matrix, &offset); slot = face->glyph; gid = (FT_UInt)45; if (e = FT_Load_Glyph(face, gid, FT_LOAD_NO_BITMAP)) eerror("4", e); FT_Glyph_Metrics *glyphMetrics = &(face->glyph->metrics); int x = -glyphMetrics->horiBearingX / 64.0; int y = glyphMetrics->horiBearingY / 64.0; int w = glyphMetrics->width / 64.0; int h = glyphMetrics->height / 64.0; if (e = FT_Render_Glyph(slot, ft_render_mode_normal)) eerror("5", e); int x2 = -slot->bitmap_left; int y2 = slot->bitmap_top; int w2 = slot->bitmap.width; int h2 = slot->bitmap.rows; printf("%d %d\n", x, x2); printf("%d %d\n", y, y2); printf("%d %d\n", w, w2); printf("%d %d\n", h, h2); }