Fix dwrite toy fonts

This commit is contained in:
Adrian Johnson 2021-08-11 07:19:54 +09:30
parent fa76ebec03
commit 7e644409ea
2 changed files with 25 additions and 10 deletions

View file

@ -677,6 +677,12 @@ extern const cairo_private struct _cairo_font_face_backend _cairo_win32_font_fac
#endif
#if CAIRO_HAS_DWRITE_FONT
extern const cairo_private struct _cairo_font_face_backend _cairo_dwrite_font_face_backend;
#endif
#if CAIRO_HAS_QUARTZ_FONT
extern const cairo_private struct _cairo_font_face_backend _cairo_quartz_font_face_backend;
@ -705,11 +711,17 @@ struct _cairo_surface_attributes {
#define CAIRO_FONT_WEIGHT_DEFAULT CAIRO_FONT_WEIGHT_NORMAL
#define CAIRO_WIN32_FONT_FAMILY_DEFAULT "Arial"
#define CAIRO_DWRITE_FONT_FAMILY_DEFAULT "Arial"
#define CAIRO_QUARTZ_FONT_FAMILY_DEFAULT "Helvetica"
#define CAIRO_FT_FONT_FAMILY_DEFAULT ""
#define CAIRO_USER_FONT_FAMILY_DEFAULT "@cairo:"
#if CAIRO_HAS_WIN32_FONT
#if CAIRO_HAS_DWRITE_FONT
#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_DWRITE_FONT_FAMILY_DEFAULT
#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_dwrite_font_face_backend
#elif CAIRO_HAS_WIN32_FONT
#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_WIN32_FONT_FAMILY_DEFAULT
#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_win32_font_face_backend

View file

@ -276,17 +276,20 @@ _cairo_dwrite_font_face_create_for_toy (cairo_toy_font_face_t *toy_face,
break;
}
cairo_dwrite_font_face_t *face = (cairo_dwrite_font_face_t*)malloc(sizeof(cairo_dwrite_font_face_t));
HRESULT hr = family->GetFirstMatchingFont(weight, DWRITE_FONT_STRETCH_NORMAL, style, &face->font);
// Cannot use C++ style new since cairo deallocates this.
cairo_dwrite_font_face_t *face = (cairo_dwrite_font_face_t*)_cairo_malloc(sizeof(cairo_dwrite_font_face_t));
IDWriteFont *font;
HRESULT hr = family->GetFirstMatchingFont(weight, DWRITE_FONT_STRETCH_NORMAL, style, &font);
if (SUCCEEDED(hr)) {
// Cannot use C++ style new since cairo deallocates this.
*font_face = (cairo_font_face_t*)face;
_cairo_font_face_init (&(*(_cairo_dwrite_font_face**)font_face)->base, &_cairo_dwrite_font_face_backend);
} else {
free(face);
hr = font->CreateFontFace(&face->dwriteface);
if (SUCCEEDED(hr)) {
*font_face = (cairo_font_face_t*)face;
_cairo_font_face_init (&(*(_cairo_dwrite_font_face**)font_face)->base, &_cairo_dwrite_font_face_backend);
return CAIRO_STATUS_SUCCESS;
}
}
return CAIRO_STATUS_SUCCESS;
free(face);
return (cairo_status_t)CAIRO_INT_STATUS_UNSUPPORTED;
}
static cairo_bool_t