diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index b891554bc..4c2a8e1d6 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -346,7 +346,7 @@ hb_directwrite_font_create (IDWriteFontFace *dw_face) hb_face_destroy (face); if (unlikely (hb_object_is_immutable (font))) - goto done; + return font; /* Copy font variations */ if (SUCCEEDED (dw_face->QueryInterface (__uuidof (IDWriteFontFace5), (void**) &dw_face5))) @@ -378,8 +378,6 @@ hb_directwrite_font_create (IDWriteFontFace *dw_face) dw_face->AddRef (); font->data.directwrite.cmpexch (nullptr, (hb_directwrite_font_data_t *) dw_face); -done: - dw_face->Release (); return font; } diff --git a/test/api/test-directwrite.cc b/test/api/test-directwrite.cc index 85d80d1ea..a9d3a4bb5 100644 --- a/test/api/test-directwrite.cc +++ b/test/api/test-directwrite.cc @@ -45,8 +45,7 @@ get_dwfontface (const char *font_path) dw_font_face->AddRef (); - // Don't destroy face, as dw_font_face is backed by its data I think. - //hb_face_destroy (face); + hb_face_destroy (face); return dw_font_face; } @@ -76,21 +75,58 @@ test_native_directwrite_basic (void) static void test_native_directwrite_variations (void) { - IDWriteFontFace *dwfontface; + IDWriteFontFace *dw_face; + IDWriteFontResource *dw_fontresource; + IDWriteFontFace5 *dw_face5, *dw_facevariations; + DWRITE_FONT_AXIS_VALUE dw_axisvalues[5]; hb_font_t *font; + const float *coords; unsigned int length; - dwfontface = get_dwfontface ("fonts/AdobeVFPrototype.abc.otf"); - g_assert_nonnull (dwfontface); + dw_face = get_dwfontface ("fonts/AdobeVFPrototype.abc.otf"); + g_assert_nonnull (dw_face); - font = hb_directwrite_font_create (dwfontface); - hb_font_get_var_coords_normalized(font, &length); - // Currently we optimize out coords if none is non-zero - //g_assert_cmpuint (length, !=, 0); + dw_face->QueryInterface (__uuidof(IDWriteFontFace5), (void **)&dw_face5); + dw_face->Release (); + g_assert_nonnull (dw_face5); + + // Check that wght axis originally set on the face is different from what we will set. + if (!dw_face5->HasVariations ()) + { + g_test_skip ("Font has no variations. Possiply using Wine’s DWrite.dll"); + return; + } + g_assert_cmpuint (dw_face5->GetFontAxisValueCount (), ==, 5); + dw_face5->GetFontAxisValues (dw_axisvalues, 5); + g_assert_cmpuint (dw_axisvalues[0].axisTag, ==, DWRITE_FONT_AXIS_TAG_WEIGHT); + g_assert_cmpfloat (dw_axisvalues[0].value, !=, 900.0f); + + dw_face5->GetFontResource (&dw_fontresource); + dw_face5->Release(); + g_assert_nonnull (dw_fontresource); + + // Set wght axis to 900.0 + dw_axisvalues[0].value = 900.0f; + dw_fontresource->CreateFontFace (DWRITE_FONT_SIMULATIONS_NONE, dw_axisvalues, 5, &dw_facevariations); + dw_fontresource->Release (); + g_assert_nonnull (dw_facevariations); + + // Check that wght axis is now set to 900.0 + g_assert_cmpuint (dw_facevariations->GetFontAxisValueCount (), ==, 5); + dw_facevariations->GetFontAxisValues (dw_axisvalues, 5); + g_assert_cmpuint (dw_axisvalues[0].axisTag, ==, DWRITE_FONT_AXIS_TAG_WEIGHT); + g_assert_cmpfloat (dw_axisvalues[0].value, ==, 900.0f); + + font = hb_directwrite_font_create (dw_facevariations); + + // Check that wght axis is also set to 900.0 on the hb_font_t + coords = hb_font_get_var_coords_design(font, &length); + g_assert_cmpuint (length, ==, 2); + g_assert_cmpfloat (coords[0], ==, 900.0f); hb_font_destroy (font); - dwfontface->Release (); + dw_facevariations->Release (); }