#include #include #include void TestWin32Emf (bool metafile) { cairo_surface_t *surface; cairo_t *cr; HDC hdc; if (metafile) { hdc = CreateEnhMetaFile(NULL, "test.emf", NULL, "Test\0\0"); surface = cairo_win32_printing_surface_create (hdc); } else surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 600, 600); cr = cairo_create(surface); LOGFONTW lf; lf.lfHeight = lf.lfWidth = 1; lf.lfEscapement = lf.lfOrientation = 0; lf.lfWeight = FW_NORMAL; lf.lfItalic = lf.lfUnderline = lf.lfStrikeOut = false; lf.lfCharSet = DEFAULT_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = CLEARTYPE_QUALITY; memcpy(lf.lfFaceName, L"Arial", sizeof(L"Arial")); cairo_font_face_t *ff = cairo_win32_font_face_create_for_logfontw(&lf); cairo_matrix_t font_scale, ctm; cairo_matrix_init_identity(&ctm); cairo_matrix_init_identity(&font_scale); cairo_matrix_scale(&font_scale, 14, 14); cairo_font_options_t *fopt = cairo_font_options_create(); cairo_scaled_font_t*sf = cairo_scaled_font_create(ff, &font_scale, &ctm, fopt); cairo_set_source_rgb(cr, 0, 0, 0); const char* txt = "0"; cairo_set_scaled_font(cr, sf); cairo_text_extents_t ext; cairo_text_extents(cr, txt, &ext); for (int j = 0; j < 50; ++j) for (int i = 0; i < 50; ++i) { cairo_move_to(cr, (ext.width * (1.999 + j * 0.0005)) * i + 20, j * (1.5f * ext.height) + 11); cairo_show_text(cr, txt); } cairo_destroy(cr); if (!metafile) cairo_surface_write_to_png(surface, "test.png"); cairo_surface_destroy(surface); if (metafile) CloseEnhMetaFile(hdc); }