#define _WIN32_WINNT 0x500 #include #include #pragma comment(lib, "gdi32.lib") #pragma comment(lib, "user32.lib") int main(int argc, char** argv) { LOGFONTW lf = { 12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, L"Times New Roman" }; HFONT hfont = CreateFontIndirectW(&lf); cairo_font_face_t *font = cairo_win32_font_face_create_for_hfont(hfont); cairo_matrix_t size, device; cairo_matrix_init_scale(&size, 12, 12); cairo_matrix_init_identity(&device); cairo_font_options_t *options = cairo_font_options_create(); cairo_scaled_font_t *scaled = cairo_scaled_font_create(font, &size, &device, options); // get glyph index for 'a' WORD index; HDC dc = CreateCompatibleDC(0); SelectObject(dc, hfont); GetGlyphIndicesA(dc, "a", 1, &index, 0); // get extents for real glyph cairo_text_extents_t extents; cairo_glyph_t glyphA = { index, 0, 0 }; cairo_scaled_font_glyph_extents(scaled, &glyphA, 1, &extents); printf("x/y advance for char 'a' -> glyph '0x%x': %f/%f\n", index, extents.x_advance, extents.y_advance); // what's the font's status? const char* status = cairo_status_to_string(cairo_scaled_font_status(scaled)); printf("status of cairo_scaled_font_t: %s\n", status); // get extents for garbage glyph cairo_glyph_t glyphF = { 0xffff, 0, 0 }; cairo_scaled_font_glyph_extents(scaled, &glyphF, 1, &extents); printf("x/y advance for non-existing glyph '0xffff': %f/%f\n", extents.x_advance, extents.y_advance); // what's the font's status? status = cairo_status_to_string(cairo_scaled_font_status(scaled)); printf("status of cairo_scaled_font_t: %s\n", status); // get extents for real glyph again cairo_scaled_font_glyph_extents(scaled, &glyphA, 1, &extents); printf("x/y advance for char 'a' -> glyph '0x%x': %f/%f\n", index, extents.x_advance, extents.y_advance); }