From 6e17bd374fb5d91e4e1bc2d32f5df497bff23bb0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 15:12:51 -0600 Subject: [PATCH 01/13] [README.mingw] Add a couple Ubuntu lines --- README.mingw.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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. From 201a0fe3612d85972d5615059a8bfb23cb860843 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 15:32:05 -0600 Subject: [PATCH 02/13] [coretext] Fix a warning --- src/hb-coretext-shape.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From f0b0d92ab5a3a4e8420b5a90db408d54cfa1e0e0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 15:44:50 -0600 Subject: [PATCH 03/13] [directwrite] Deprecate hb_directwrite_font_get_dw_font() --- docs/harfbuzz-sections.txt | 2 +- src/hb-directwrite.cc | 7 ++++--- src/hb-directwrite.h | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 5bdc968b9..536cf154f 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,6 @@ 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_set_funcs diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index 1dc3a5844..e10a4125d 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -390,16 +390,17 @@ done: * 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..8eaadc50b 100644 --- a/src/hb-directwrite.h +++ b/src/hb-directwrite.h @@ -48,9 +48,6 @@ hb_directwrite_face_get_dw_font_face (hb_face_t *face); HB_EXTERN hb_font_t * hb_directwrite_font_create (IDWriteFont *dw_font); -HB_EXTERN IDWriteFont * -hb_directwrite_font_get_dw_font (hb_font_t *font); - HB_EXTERN void hb_directwrite_font_set_funcs (hb_font_t *font); @@ -60,6 +57,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 From c274ee7b3eb864bc8b580ee870901348b697f169 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 16:02:39 -0600 Subject: [PATCH 04/13] [directwrite] Add hb_font_t setter/getter from IDWriteFontFace Changed API: +hb_directwrite_font_create() New API: +hb_directwrite_font_get_dw_font_face() --- docs/harfbuzz-sections.txt | 1 + src/hb-directwrite.cc | 34 ++++++++++++++++++++++++---------- src/hb-directwrite.h | 5 ++++- test/api/test-directwrite.cc | 36 ++++++++++++++++++++---------------- 4 files changed, 49 insertions(+), 27 deletions(-) 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 (); } From 91bd6bf0df131bc9e5010ab2c9381dc184664e9f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 16:37:25 -0600 Subject: [PATCH 05/13] [directwrite] Make variations work on font-funcs --- src/hb-directwrite-font.cc | 2 +- src/hb-directwrite-shape.cc | 85 +++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/src/hb-directwrite-font.cc b/src/hb-directwrite-font.cc index 977cd62a0..f3a70e1fe 100644 --- a/src/hb-directwrite-font.cc +++ b/src/hb-directwrite-font.cc @@ -372,7 +372,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, 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; } From 24a23aca6907debf669a51bbebe0ab53ea60b01a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 16:41:39 -0600 Subject: [PATCH 06/13] [directwrite] Make font-funcs respond to font changes --- src/hb-directwrite-font.cc | 45 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/hb-directwrite-font.cc b/src/hb-directwrite-font.cc index f3a70e1fe..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 @@ -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 From 298a367ad3de3bf8b4177588159a4a40abd38703 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 16:42:56 -0600 Subject: [PATCH 07/13] [directwrite] Graduate from experimental --- meson_options.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', From b159f5c74e38a0a2db3295d6e356cd7b6a165958 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 16:46:43 -0600 Subject: [PATCH 08/13] [directwrite] Fix docs --- src/hb-directwrite.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index b1e5bf446..b891554bc 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -328,7 +328,7 @@ hb_directwrite_face_get_font_face (hb_face_t *face) /** * hb_directwrite_font_create: - * @dw_font: a DirectWrite IDWriteFontFace object. + * @dw_face: a DirectWrite IDWriteFontFace object. * * Constructs a new font object from the specified DirectWrite IDWriteFontFace. * From f53befb6a0c60ea83f1b209a18a746481298a593 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 16:54:56 -0600 Subject: [PATCH 09/13] [test/directwrite] Fix a leak --- test/api/test-directwrite.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/api/test-directwrite.cc b/test/api/test-directwrite.cc index 2f4ed0a9f..72396f2b5 100644 --- a/test/api/test-directwrite.cc +++ b/test/api/test-directwrite.cc @@ -100,6 +100,8 @@ get_dwfontface (const wchar_t *family_name) hr = font->CreateFontFace (&dw_face); g_assert_true (SUCCEEDED (hr)); + font->Release (); + return dw_face; } From 45a724b90c618d1397a382abe1bc875c3646abab Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 17:04:08 -0600 Subject: [PATCH 10/13] [coretext] Make font-funcs respond to font changes Fixes https://github.com/harfbuzz/harfbuzz/issues/5173 --- src/hb-coretext-font.cc | 61 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 33 deletions(-) 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 From 9afdc7e1d2f4faea4a4e997be154c525e79f56c8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 19:39:48 -0600 Subject: [PATCH 11/13] [test-directwrite] Simplify --- test/api/test-directwrite.cc | 71 ++++-------------------------------- 1 file changed, 8 insertions(+), 63 deletions(-) diff --git a/test/api/test-directwrite.cc b/test/api/test-directwrite.cc index 72396f2b5..5f7ecd0d7 100644 --- a/test/api/test-directwrite.cc +++ b/test/api/test-directwrite.cc @@ -37,72 +37,17 @@ typedef HRESULT (WINAPI *t_DWriteCreateFactory)( ); IDWriteFontFace * -get_dwfontface (const wchar_t *family_name) +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; - 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); + 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); - g_assert_true (SUCCEEDED (hr)); - g_assert_true (exists); - } - - 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)); - - factory->Release (); - - IDWriteFontFace *dw_face = nullptr; - hr = font->CreateFontFace (&dw_face); - g_assert_true (SUCCEEDED (hr)); - - font->Release (); - - return dw_face; + return dw_font_face; } static void @@ -112,7 +57,7 @@ test_native_directwrite_basic (void) hb_font_t *font; IDWriteFontFace *dwfontface2; - dwfontface = get_dwfontface (nullptr); + dwfontface = get_dwfontface ("fonts/Roboto-Regular.abc.ttf"); g_assert_nonnull (dwfontface); font = hb_directwrite_font_create (dwfontface); @@ -134,7 +79,7 @@ test_native_directwrite_variations (void) hb_font_t *font; unsigned int length; - dwfontface = get_dwfontface (L"Bahnschrift"); + dwfontface = get_dwfontface ("fonts/AdobeVFPrototype.abc.ttf"); g_assert_nonnull (dwfontface); font = hb_directwrite_font_create (dwfontface); From 55743b239f6c34fca871383df8d239b6fdeae171 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 19:56:00 -0600 Subject: [PATCH 12/13] [test/shape] Skip uniscribe/directwrite shapers under Wine --- test/shape/run-tests.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 From 3259f9f89a426571a523f7aa427f88c157837bbd Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 22 Mar 2025 19:57:51 -0600 Subject: [PATCH 13/13] [test-directwrite] Fix test --- test/api/test-directwrite.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/api/test-directwrite.cc b/test/api/test-directwrite.cc index 5f7ecd0d7..85d80d1ea 100644 --- a/test/api/test-directwrite.cc +++ b/test/api/test-directwrite.cc @@ -45,7 +45,8 @@ get_dwfontface (const char *font_path) dw_font_face->AddRef (); - hb_face_destroy (face); + // Don't destroy face, as dw_font_face is backed by its data I think. + //hb_face_destroy (face); return dw_font_face; } @@ -79,12 +80,13 @@ test_native_directwrite_variations (void) hb_font_t *font; unsigned int length; - dwfontface = get_dwfontface ("fonts/AdobeVFPrototype.abc.ttf"); + dwfontface = get_dwfontface ("fonts/AdobeVFPrototype.abc.otf"); g_assert_nonnull (dwfontface); 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);