diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 536cf154f..650c07a98 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -368,6 +368,7 @@ hb_directwrite_face_create_from_file_or_fail hb_directwrite_face_create_from_blob_or_fail hb_directwrite_face_get_dw_font_face hb_directwrite_font_create +hb_directwrite_font_get_dw_font_face hb_directwrite_font_set_funcs diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index e10a4125d..b1e5bf446 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -328,23 +328,19 @@ hb_directwrite_face_get_font_face (hb_face_t *face) /** * hb_directwrite_font_create: - * @dw_font: a DirectWrite IDWriteFont object. + * @dw_font: a DirectWrite IDWriteFontFace object. * - * Constructs a new font object from the specified DirectWrite IDWriteFont. + * Constructs a new font object from the specified DirectWrite IDWriteFontFace. * * Return value: #hb_font_t object corresponding to the given input * - * Since: 10.3.0 + * XSince: REPLACEME **/ hb_font_t * -hb_directwrite_font_create (IDWriteFont *dw_font) +hb_directwrite_font_create (IDWriteFontFace *dw_face) { - IDWriteFontFace *dw_face = nullptr; IDWriteFontFace5 *dw_face5 = nullptr; - if (FAILED (dw_font->CreateFontFace (&dw_face))) - return hb_font_get_empty (); - hb_face_t *face = hb_directwrite_face_create (dw_face); hb_font_t *font = hb_font_create (face); hb_face_destroy (face); @@ -378,14 +374,32 @@ hb_directwrite_font_create (IDWriteFont *dw_font) dw_face5->Release (); } - dw_font->AddRef (); - font->data.directwrite.cmpexch (nullptr, (hb_directwrite_font_data_t *) dw_font); + /* Let there be dragons here... */ + dw_face->AddRef (); + font->data.directwrite.cmpexch (nullptr, (hb_directwrite_font_data_t *) dw_face); done: dw_face->Release (); return font; } +/** +* hb_directwrite_font_get_dw_font_face: +* @font: a #hb_font_t object +* +* Gets the DirectWrite IDWriteFontFace associated with @font. +* +* Return value: DirectWrite IDWriteFontFace object corresponding to the given input +* +* XSince: REPLACEME +**/ +IDWriteFontFace * +hb_directwrite_font_get_dw_font_face (hb_font_t *font) +{ + return (IDWriteFontFace *) (const void *) font->data.directwrite; +} + + /** * hb_directwrite_font_get_dw_font: * @font: a #hb_font_t object diff --git a/src/hb-directwrite.h b/src/hb-directwrite.h index 8eaadc50b..a05b1a40e 100644 --- a/src/hb-directwrite.h +++ b/src/hb-directwrite.h @@ -46,7 +46,10 @@ HB_EXTERN IDWriteFontFace * hb_directwrite_face_get_dw_font_face (hb_face_t *face); HB_EXTERN hb_font_t * -hb_directwrite_font_create (IDWriteFont *dw_font); +hb_directwrite_font_create (IDWriteFontFace *dw_face); + +HB_EXTERN IDWriteFontFace * +hb_directwrite_font_get_dw_font_face (hb_font_t *font); HB_EXTERN void hb_directwrite_font_set_funcs (hb_font_t *font); diff --git a/test/api/test-directwrite.cc b/test/api/test-directwrite.cc index c48572192..2f4ed0a9f 100644 --- a/test/api/test-directwrite.cc +++ b/test/api/test-directwrite.cc @@ -36,8 +36,8 @@ typedef HRESULT (WINAPI *t_DWriteCreateFactory)( IUnknown **factory ); -IDWriteFont * -get_dwfont (const wchar_t *family_name) +IDWriteFontFace * +get_dwfontface (const wchar_t *family_name) { HRESULT hr; t_DWriteCreateFactory CreateFactory; @@ -96,48 +96,52 @@ get_dwfont (const wchar_t *family_name) factory->Release (); - return font; + IDWriteFontFace *dw_face = nullptr; + hr = font->CreateFontFace (&dw_face); + g_assert_true (SUCCEEDED (hr)); + + return dw_face; } static void test_native_directwrite_basic (void) { - IDWriteFont *dwfont; + IDWriteFontFace *dwfontface; hb_font_t *font; - IDWriteFont *dwfont2; + IDWriteFontFace *dwfontface2; - dwfont = get_dwfont (nullptr); - g_assert_nonnull (dwfont); + dwfontface = get_dwfontface (nullptr); + g_assert_nonnull (dwfontface); - font = hb_directwrite_font_create (dwfont); + font = hb_directwrite_font_create (dwfontface); - dwfont2 = hb_directwrite_font_get_dw_font (font); + dwfontface2 = hb_directwrite_font_get_dw_font_face (font); - g_assert_true (dwfont2 == dwfont); + g_assert_true (dwfontface2 == dwfontface); hb_font_destroy (font); - dwfont->Release (); + dwfontface->Release (); } static void test_native_directwrite_variations (void) { - IDWriteFont *dwfont; + IDWriteFontFace *dwfontface; hb_font_t *font; unsigned int length; - dwfont = get_dwfont (L"Bahnschrift"); - g_assert_nonnull (dwfont); + dwfontface = get_dwfontface (L"Bahnschrift"); + g_assert_nonnull (dwfontface); - font = hb_directwrite_font_create (dwfont); + font = hb_directwrite_font_create (dwfontface); hb_font_get_var_coords_normalized(font, &length); g_assert_cmpuint (length, !=, 0); hb_font_destroy (font); - dwfont->Release (); + dwfontface->Release (); }