diff --git a/README.mingw.md b/README.mingw.md index 4227e1d41..22f14def2 100644 --- a/README.mingw.md +++ b/README.mingw.md @@ -26,13 +26,16 @@ a few different ways to build and test HarfBuzz for Windows. 1. Install Wine. - Fedora: `dnf install wine`. + - Ubuntu, 32bit: `apt install wine wine32`. + - Ubuntu, 64bit: `apt install wine wine64`. - Mac: `brew install wine-stable`. 2. Install the `mingw-w64` cross-compiler. - Fedora, 32bit: `dnf install mingw32-gcc-c++` - Fedora, 64bit: `dnf install mingw64-gcc-c++` - - Debian: `apt install g++-mingw-w64` + - Ubuntu, 32bit: `apt install g++-mingw-w64-i686` + - Ubuntu, 64bit: `apt install g++-mingw-w64-x86-64` - Mac: `brew install mingw-w64` 3. Install dependencies. diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 5bdc968b9..650c07a98 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -342,6 +342,7 @@ hb_font_get_glyph_v_kerning hb_font_get_glyph_v_kerning_func_t HB_AAT_LAYOUT_FEATURE_TYPE_CURISVE_CONNECTION hb_directwrite_face_get_font_face +hb_directwrite_font_get_dw_font hb_ft_font_get_face hb_graphite2_font_get_gr_font @@ -367,7 +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 +hb_directwrite_font_get_dw_font_face hb_directwrite_font_set_funcs diff --git a/meson_options.txt b/meson_options.txt index fbfdbb57b..86258f89d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -20,7 +20,7 @@ option('fontations', type: 'feature', value: 'disabled', option('gdi', type: 'feature', value: 'disabled', description: 'Enable GDI helpers and Uniscribe shaper backend (Windows only)') option('directwrite', type: 'feature', value: 'disabled', - description: 'Enable DirectWrite shaper backend on Windows (experimental)') + description: 'Enable DirectWrite shaper backend on Windows') option('coretext', type: 'feature', value: 'disabled', description: 'Enable CoreText shaper backend on macOS') option('wasm', type: 'feature', value: 'disabled', diff --git a/src/hb-coretext-font.cc b/src/hb-coretext-font.cc index 436588ad6..76c1fa02d 100644 --- a/src/hb-coretext-font.cc +++ b/src/hb-coretext-font.cc @@ -44,22 +44,15 @@ #define MAX_GLYPHS 256u -static void -_hb_coretext_font_destroy (void *font_data) -{ - CTFontRef ct_font = (CTFontRef) font_data; - - CFRelease (ct_font); -} - static hb_bool_t -hb_coretext_get_nominal_glyph (hb_font_t *font HB_UNUSED, - void *font_data, +hb_coretext_get_nominal_glyph (hb_font_t *font, + void *font_data HB_UNUSED, hb_codepoint_t unicode, hb_codepoint_t *glyph, void *user_data HB_UNUSED) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; + UniChar ch[2]; CGGlyph cg_glyph[2]; unsigned count = 0; @@ -85,7 +78,7 @@ hb_coretext_get_nominal_glyph (hb_font_t *font HB_UNUSED, } static unsigned int -hb_coretext_get_nominal_glyphs (hb_font_t *font HB_UNUSED, +hb_coretext_get_nominal_glyphs (hb_font_t *font, void *font_data, unsigned int count, const hb_codepoint_t *first_unicode, @@ -94,6 +87,8 @@ hb_coretext_get_nominal_glyphs (hb_font_t *font HB_UNUSED, unsigned int glyph_stride, void *user_data HB_UNUSED) { + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; + // If any non-BMP codepoint is requested, use the slow path. bool slow_path = false; auto *unicode = first_unicode; @@ -119,8 +114,6 @@ hb_coretext_get_nominal_glyphs (hb_font_t *font HB_UNUSED, return count; } - CTFontRef ct_font = (CTFontRef) font_data; - UniChar ch[MAX_GLYPHS]; CGGlyph cg_glyph[MAX_GLYPHS]; for (unsigned i = 0; i < count; i += MAX_GLYPHS) @@ -152,14 +145,14 @@ hb_coretext_get_nominal_glyphs (hb_font_t *font HB_UNUSED, } static hb_bool_t -hb_coretext_get_variation_glyph (hb_font_t *font HB_UNUSED, - void *font_data, +hb_coretext_get_variation_glyph (hb_font_t *font, + void *font_data HB_UNUSED, hb_codepoint_t unicode, hb_codepoint_t variation_selector, hb_codepoint_t *glyph, void *user_data HB_UNUSED) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; UniChar ch[4]; CGGlyph cg_glyph[4]; @@ -203,7 +196,8 @@ hb_coretext_get_variation_glyph (hb_font_t *font HB_UNUSED, } static void -hb_coretext_get_glyph_h_advances (hb_font_t* font, void* font_data, +hb_coretext_get_glyph_h_advances (hb_font_t* font, + void* font_data HB_UNUSED, unsigned count, const hb_codepoint_t *first_glyph, unsigned glyph_stride, @@ -211,7 +205,7 @@ hb_coretext_get_glyph_h_advances (hb_font_t* font, void* font_data, unsigned advance_stride, void *user_data HB_UNUSED) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; CGFloat ct_font_size = CTFontGetSize (ct_font); CGFloat x_mult = (CGFloat) font->x_scale / ct_font_size; @@ -237,7 +231,8 @@ hb_coretext_get_glyph_h_advances (hb_font_t* font, void* font_data, #ifndef HB_NO_VERTICAL static void -hb_coretext_get_glyph_v_advances (hb_font_t* font, void* font_data, +hb_coretext_get_glyph_v_advances (hb_font_t* font, + void* font_data HB_UNUSED, unsigned count, const hb_codepoint_t *first_glyph, unsigned glyph_stride, @@ -245,7 +240,7 @@ hb_coretext_get_glyph_v_advances (hb_font_t* font, void* font_data, unsigned advance_stride, void *user_data HB_UNUSED) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; CGFloat ct_font_size = CTFontGetSize (ct_font); CGFloat y_mult = (CGFloat) -font->y_scale / ct_font_size; @@ -271,13 +266,13 @@ hb_coretext_get_glyph_v_advances (hb_font_t* font, void* font_data, static hb_bool_t hb_coretext_get_glyph_v_origin (hb_font_t *font, - void *font_data, + void *font_data HB_UNUSED, hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y, void *user_data HB_UNUSED) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; CGFloat ct_font_size = CTFontGetSize (ct_font); CGFloat x_mult = (CGFloat) -font->x_scale / ct_font_size; @@ -296,12 +291,12 @@ hb_coretext_get_glyph_v_origin (hb_font_t *font, static hb_bool_t hb_coretext_get_glyph_extents (hb_font_t *font, - void *font_data, + void *font_data HB_UNUSED, hb_codepoint_t glyph, hb_glyph_extents_t *extents, void *user_data HB_UNUSED) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; CGFloat ct_font_size = CTFontGetSize (ct_font); CGFloat x_mult = (CGFloat) font->x_scale / ct_font_size; @@ -321,11 +316,12 @@ hb_coretext_get_glyph_extents (hb_font_t *font, static hb_bool_t hb_coretext_get_font_h_extents (hb_font_t *font, - void *font_data, + void *font_data HB_UNUSED, hb_font_extents_t *metrics, void *user_data HB_UNUSED) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; + CGFloat ct_font_size = CTFontGetSize (ct_font); CGFloat y_mult = (CGFloat) font->y_scale / ct_font_size; @@ -373,7 +369,7 @@ hb_coretext_draw_glyph (hb_font_t *font, hb_draw_funcs_t *draw_funcs, void *draw_data, void *user_data) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; CGFloat ct_font_size = CTFontGetSize (ct_font); CGFloat x_mult = (CGFloat) font->x_scale / ct_font_size; @@ -424,13 +420,13 @@ hb_coretext_get_glyph_name (hb_font_t *font, } static hb_bool_t -hb_coretext_get_glyph_from_name (hb_font_t *font HB_UNUSED, - void *font_data, +hb_coretext_get_glyph_from_name (hb_font_t *font, + void *font_data HB_UNUSED, const char *name, int len, hb_codepoint_t *glyph, void *user_data HB_UNUSED) { - CTFontRef ct_font = (CTFontRef) font_data; + CTFontRef ct_font = (CTFontRef) (const void *) font->data.coretext; if (len == -1) len = strlen (name); @@ -533,8 +529,7 @@ hb_coretext_font_set_funcs (hb_font_t *font) hb_font_set_funcs (font, _hb_coretext_get_font_funcs (), - (void *) CFRetain (ct_font), - _hb_coretext_font_destroy); + nullptr, nullptr); } #undef MAX_GLYPHS diff --git a/src/hb-coretext-shape.cc b/src/hb-coretext-shape.cc index 5551e3284..c874d4956 100644 --- a/src/hb-coretext-shape.cc +++ b/src/hb-coretext-shape.cc @@ -559,7 +559,7 @@ resize_and_retry: CFArrayRef glyph_runs = CTLineGetGlyphRuns (line); unsigned int num_runs = CFArrayGetCount (glyph_runs); - DEBUG_MSG (CORETEXT, nullptr, "Num runs: %d", num_runs); + DEBUG_MSG (CORETEXT, nullptr, "Num runs: %u", num_runs); buffer->len = 0; uint32_t status_or = 0; diff --git a/src/hb-directwrite-font.cc b/src/hb-directwrite-font.cc index 977cd62a0..4e140b767 100644 --- a/src/hb-directwrite-font.cc +++ b/src/hb-directwrite-font.cc @@ -39,8 +39,8 @@ #define MAX_GLYPHS 256u static unsigned int -hb_directwrite_get_nominal_glyphs (hb_font_t *font HB_UNUSED, - void *font_data, +hb_directwrite_get_nominal_glyphs (hb_font_t *font, + void *font_data HB_UNUSED, unsigned int count, const hb_codepoint_t *first_unicode, unsigned int unicode_stride, @@ -48,7 +48,7 @@ hb_directwrite_get_nominal_glyphs (hb_font_t *font HB_UNUSED, unsigned int glyph_stride, void *user_data HB_UNUSED) { - IDWriteFontFace *dw_face = (IDWriteFontFace *) font_data; + IDWriteFontFace *dw_face = (IDWriteFontFace *) (const void *) font->data.directwrite; for (unsigned i = 0; i < count;) { @@ -82,11 +82,11 @@ hb_directwrite_get_nominal_glyphs (hb_font_t *font HB_UNUSED, static hb_bool_t hb_directwrite_get_font_h_extents (hb_font_t *font, - void *font_data, + void *font_data HB_UNUSED, hb_font_extents_t *metrics, void *user_data HB_UNUSED) { - IDWriteFontFace *dw_face = (IDWriteFontFace *) font_data; + IDWriteFontFace *dw_face = (IDWriteFontFace *) (const void *) font->data.directwrite; DWRITE_FONT_METRICS dw_metrics; dw_face->GetMetrics (&dw_metrics); @@ -99,7 +99,8 @@ hb_directwrite_get_font_h_extents (hb_font_t *font, } static void -hb_directwrite_get_glyph_h_advances (hb_font_t* font, void* font_data, +hb_directwrite_get_glyph_h_advances (hb_font_t* font, + void* font_data HB_UNUSED, unsigned count, const hb_codepoint_t *first_glyph, unsigned glyph_stride, @@ -107,7 +108,8 @@ hb_directwrite_get_glyph_h_advances (hb_font_t* font, void* font_data, unsigned advance_stride, void *user_data HB_UNUSED) { - IDWriteFontFace *dw_face = (IDWriteFontFace *) font_data; + IDWriteFontFace *dw_face = (IDWriteFontFace *) (const void *) font->data.directwrite; + IDWriteFontFace1 *dw_face1 = nullptr; dw_face->QueryInterface (__uuidof(IDWriteFontFace1), (void**)&dw_face1); assert (dw_face1); @@ -139,7 +141,8 @@ hb_directwrite_get_glyph_h_advances (hb_font_t* font, void* font_data, #ifndef HB_NO_VERTICAL static void -hb_directwrite_get_glyph_v_advances (hb_font_t* font, void* font_data, +hb_directwrite_get_glyph_v_advances (hb_font_t* font, + void* font_data HB_UNUSED, unsigned count, const hb_codepoint_t *first_glyph, unsigned glyph_stride, @@ -147,7 +150,8 @@ hb_directwrite_get_glyph_v_advances (hb_font_t* font, void* font_data, unsigned advance_stride, void *user_data HB_UNUSED) { - IDWriteFontFace *dw_face = (IDWriteFontFace *) font_data; + IDWriteFontFace *dw_face = (IDWriteFontFace *) (const void *) font->data.directwrite; + IDWriteFontFace1 *dw_face1 = nullptr; dw_face->QueryInterface (__uuidof(IDWriteFontFace1), (void**)&dw_face1); assert (dw_face1); @@ -178,13 +182,13 @@ hb_directwrite_get_glyph_v_advances (hb_font_t* font, void* font_data, static hb_bool_t hb_directwrite_get_glyph_v_origin (hb_font_t *font, - void *font_data, + void *font_data HB_UNUSED, hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y, void *user_data HB_UNUSED) { - IDWriteFontFace *dw_face = (IDWriteFontFace *) font_data; + IDWriteFontFace *dw_face = (IDWriteFontFace *) (const void *) font->data.directwrite; UINT16 gid = glyph; DWRITE_GLYPH_METRICS metrics; @@ -201,12 +205,12 @@ hb_directwrite_get_glyph_v_origin (hb_font_t *font, static hb_bool_t hb_directwrite_get_glyph_extents (hb_font_t *font, - void *font_data, + void *font_data HB_UNUSED, hb_codepoint_t glyph, hb_glyph_extents_t *extents, void *user_data HB_UNUSED) { - IDWriteFontFace *dw_face = (IDWriteFontFace *) font_data; + IDWriteFontFace *dw_face = (IDWriteFontFace *) (const void *) font->data.directwrite; UINT16 gid = glyph; DWRITE_GLYPH_METRICS metrics; @@ -273,12 +277,12 @@ public: static void hb_directwrite_draw_glyph (hb_font_t *font, - void *font_data, + void *font_data HB_UNUSED, hb_codepoint_t glyph, hb_draw_funcs_t *draw_funcs, void *draw_data, void *user_data) { - IDWriteFontFace *dw_face = (IDWriteFontFace *) font_data; + IDWriteFontFace *dw_face = (IDWriteFontFace *) (const void *) font->data.directwrite; GeometrySink sink (font, draw_funcs, draw_data); UINT16 gid = static_cast(glyph); @@ -343,14 +347,6 @@ _hb_directwrite_get_font_funcs () return static_directwrite_funcs.get_unconst (); } -static void -_hb_directwrite_font_face_destroy (void *font_data) -{ - IDWriteFontFace *dw_face = (IDWriteFontFace *) font_data; - - dw_face->Release (); -} - /** * hb_directwrite_font_set_funcs: * @font: #hb_font_t to work upon @@ -372,7 +368,7 @@ _hb_directwrite_font_face_destroy (void *font_data) void hb_directwrite_font_set_funcs (hb_font_t *font) { - IDWriteFontFace *dw_face = hb_directwrite_face_get_dw_font_face (font->face); + IDWriteFontFace *dw_face = (IDWriteFontFace *) (const void *) font->data.directwrite; if (unlikely (!dw_face)) { hb_font_set_funcs (font, @@ -384,8 +380,7 @@ hb_directwrite_font_set_funcs (hb_font_t *font) dw_face->AddRef (); hb_font_set_funcs (font, _hb_directwrite_get_font_funcs (), - (void *) dw_face, - _hb_directwrite_font_face_destroy); + nullptr, nullptr); } #undef MAX_GLYPHS diff --git a/src/hb-directwrite-shape.cc b/src/hb-directwrite-shape.cc index e686cf2b8..485075e64 100644 --- a/src/hb-directwrite-shape.cc +++ b/src/hb-directwrite-shape.cc @@ -65,14 +65,49 @@ struct hb_directwrite_font_data_t {}; hb_directwrite_font_data_t * _hb_directwrite_shaper_font_data_create (hb_font_t *font) { - return (hb_directwrite_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; + IDWriteFontFace *fontFace = (IDWriteFontFace *) (const void *) font->face->data.directwrite; + + /* + * Set up variations. + */ + IDWriteFontFace5 *fontFaceVariations = nullptr; + { + IDWriteFontFace5 *fontFace5; + if (SUCCEEDED (fontFace->QueryInterface (__uuidof (IDWriteFontFace5), (void **) &fontFace5))) + { + IDWriteFontResource *fontResource; + if (SUCCEEDED (fontFace5->GetFontResource (&fontResource))) + { + hb_vector_t axis_values; + if (likely (axis_values.resize_exact (font->num_coords))) + { + for (unsigned int i = 0; i < font->num_coords; i++) + { + hb_ot_var_axis_info_t info; + unsigned int c = 1; + hb_ot_var_get_axis_infos (font->face, i, &c, &info); + axis_values[i].axisTag = (DWRITE_FONT_AXIS_TAG) hb_uint32_swap (info.tag); + axis_values[i].value = i < font->num_coords ? + hb_clamp (font->design_coords[i], info.min_value, info.max_value) : + info.default_value; + } + + fontResource->CreateFontFace (DWRITE_FONT_SIMULATIONS::DWRITE_FONT_SIMULATIONS_NONE, + axis_values.arrayZ, axis_values.length, &fontFaceVariations); + } + fontResource->Release (); + } + fontFace5->Release (); + } + } + + return (hb_directwrite_font_data_t *) fontFaceVariations; } void _hb_directwrite_shaper_font_data_destroy (hb_directwrite_font_data_t *data) { - if (data != HB_SHAPER_DATA_SUCCEEDED) - ((IDWriteFont *) (const void *) data)->Release(); + ((IDWriteFontFace *) data)->Release (); } @@ -354,8 +389,7 @@ _hb_directwrite_shape (hb_shape_plan_t *shape_plan, const hb_feature_t *features, unsigned int num_features) { - hb_face_t *face = font->face; - IDWriteFontFace *fontFace = (IDWriteFontFace *) (const void *) face->data.directwrite; + IDWriteFontFace *fontFace = (IDWriteFontFace *) (const void *) font->data.directwrite; auto *global = get_directwrite_global (); if (unlikely (!global)) return false; @@ -442,44 +476,6 @@ _hb_directwrite_shape (hb_shape_plan_t *shape_plan, mbstowcs ((wchar_t*) localeName, hb_language_to_string (buffer->props.language), 20); - /* - * Set up variations. - */ - IDWriteFontFace5 *fontFaceVariations = nullptr; - if (font->num_coords) - { - IDWriteFontFace5 *fontFace5; - if (SUCCEEDED (fontFace->QueryInterface (__uuidof (IDWriteFontFace5), (void **) &fontFace5))) - { - IDWriteFontResource *fontResource; - if (SUCCEEDED (fontFace5->GetFontResource (&fontResource))) - { - hb_vector_t axis_values; - if (likely (axis_values.resize_exact (font->num_coords))) - { - for (unsigned int i = 0; i < font->num_coords; i++) - { - hb_ot_var_axis_info_t info; - unsigned int c = 1; - hb_ot_var_get_axis_infos (font->face, i, &c, &info); - axis_values[i].axisTag = (DWRITE_FONT_AXIS_TAG) hb_uint32_swap (info.tag); - axis_values[i].value = i < font->num_coords ? - hb_clamp (font->design_coords[i], info.min_value, info.max_value) : - info.default_value; - } - - if (SUCCEEDED (fontResource->CreateFontFace (DWRITE_FONT_SIMULATIONS::DWRITE_FONT_SIMULATIONS_NONE, - axis_values.arrayZ, axis_values.length, &fontFaceVariations))) - { - fontFace = fontFaceVariations; - } - } - fontResource->Release (); - } - fontFace5->Release (); - } - } - /* * Set up features. */ @@ -652,9 +648,6 @@ retry_getglyphs: delete [] glyphAdvances; delete [] glyphOffsets; - if (fontFaceVariations) - fontFaceVariations->Release (); - /* Wow, done! */ return true; } diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index 1dc3a5844..b891554bc 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_face: 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,28 +374,47 @@ 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 * -* Gets the DirectWrite IDWriteFont associated with @font. +* Deprecated. * -* Return value: DirectWrite IDWriteFont object corresponding to the given input +* Return value: Returns `NULL`. * * Since: 10.3.0 +* XDeprecated: REPLACEME: **/ IDWriteFont * hb_directwrite_font_get_dw_font (hb_font_t *font) { - return (IDWriteFont *) (const void *) font->data.directwrite; + return nullptr; } #endif diff --git a/src/hb-directwrite.h b/src/hb-directwrite.h index 8b3c0d703..a05b1a40e 100644 --- a/src/hb-directwrite.h +++ b/src/hb-directwrite.h @@ -46,10 +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 IDWriteFont * -hb_directwrite_font_get_dw_font (hb_font_t *font); +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); @@ -60,6 +60,10 @@ HB_DEPRECATED_FOR (hb_directwrite_face_get_dw_font_face) HB_EXTERN IDWriteFontFace * hb_directwrite_face_get_font_face (hb_face_t *face); +HB_DEPRECATED +HB_EXTERN IDWriteFont * +hb_directwrite_font_get_dw_font (hb_font_t *font); + #endif HB_END_DECLS diff --git a/test/api/test-directwrite.cc b/test/api/test-directwrite.cc index 9367818e3..85d80d1ea 100644 --- a/test/api/test-directwrite.cc +++ b/test/api/test-directwrite.cc @@ -36,117 +36,61 @@ typedef HRESULT (WINAPI *t_DWriteCreateFactory)( IUnknown **factory ); -IDWriteFont * -get_dwfont (const wchar_t *family_name) +IDWriteFontFace * +get_dwfontface (const char *font_path) { - HRESULT hr; - t_DWriteCreateFactory CreateFactory; - HMODULE dwrite_dll; - IDWriteFactory *factory; - IDWriteFactory7 *factory7; - IDWriteFontCollection3 *collection; - UINT32 count; - IDWriteFontFamily2 *family; - IDWriteFont *font = nullptr; - UINT32 index = 0; + auto *face = hb_test_open_font_file (font_path); - dwrite_dll = LoadLibrary (TEXT ("DWRITE")); - g_assert_nonnull (dwrite_dll); + auto *dw_font_face = hb_directwrite_face_get_dw_font_face (face); -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-function-type" -#endif + dw_font_face->AddRef (); - CreateFactory = (t_DWriteCreateFactory) GetProcAddress (dwrite_dll, "DWriteCreateFactory"); - g_assert_nonnull (CreateFactory); + // Don't destroy face, as dw_font_face is backed by its data I think. + //hb_face_destroy (face); -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - - hr = CreateFactory (DWRITE_FACTORY_TYPE_SHARED, __uuidof (IDWriteFactory), (IUnknown**) &factory); - g_assert_true (SUCCEEDED (hr)); - - hr = factory->QueryInterface (__uuidof (IDWriteFactory7), (void**) &factory7); - g_assert_true (SUCCEEDED (hr)); - - hr = factory7->GetSystemFontCollection (FALSE, DWRITE_FONT_FAMILY_MODEL_TYPOGRAPHIC, &collection); - g_assert_true (SUCCEEDED (hr)); - - count = collection->GetFontFamilyCount (); - g_assert_cmpuint (count, >, 0); - - if (family_name) - { - BOOL exists; - hr = collection->FindFamilyName (family_name, &index, &exists); - if (FAILED (hr) || !exists) - goto done; - } - - hr = collection->GetFontFamily (index, &family); - g_assert_true (SUCCEEDED (hr)); - - hr = family->GetFirstMatchingFont (DWRITE_FONT_WEIGHT_NORMAL, - DWRITE_FONT_STRETCH_NORMAL, - DWRITE_FONT_STYLE_NORMAL, - &font); - g_assert_true (SUCCEEDED (hr)); - -done: - factory->Release (); - - return font; + return dw_font_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 ("fonts/Roboto-Regular.abc.ttf"); + 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"); + dwfontface = get_dwfontface ("fonts/AdobeVFPrototype.abc.otf"); + g_assert_nonnull (dwfontface); - const char *env = getenv ("MESON_EXE_WRAPPER"); - if (env && strstr (env, "wine")) - { - g_test_skip ("Failed to load \"Bahnschrift\" font under Wine"); - return; - } - - g_assert_nonnull (dwfont); - - 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); + // Currently we optimize out coords if none is non-zero + //g_assert_cmpuint (length, !=, 0); hb_font_destroy (font); - dwfont->Release (); + dwfontface->Release (); } diff --git a/test/shape/run-tests.py b/test/shape/run-tests.py index c7ca38248..8e6a31f97 100755 --- a/test/shape/run-tests.py +++ b/test/shape/run-tests.py @@ -102,6 +102,17 @@ for what in ["shaper", "face-loader", "font-funcs"]: globals()[var_name] = what_list print(f"Supported {whats}: {what_list}") +# If running under Wine and not native dlls, make the respective shapers unavailable. +if os.environ.get("WINEPATH"): + overrides = os.environ.get("WINEDLLOVERRIDES", "").lower() + if "directwrite" in supported_shapers and overrides.find("dwrite") == -1: + supported_shapers.remove("directwrite") + print("Skipping DirectWrite shaper under Wine.") + if "uniscribe" in supported_shapers and overrides.find("usp10") == -1: + supported_shapers.remove("uniscribe") + print("Skipping Uniscribe shaper under Wine.") + + passes = 0 fails = 0 skips = 0