diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2022-08-16 17:10:48 +0800 |
---|---|---|
committer | Chun-wei Fan <fanchunwei@src.gnome.org> | 2022-09-26 11:04:26 +0800 |
commit | 6b0aa77d23ac969c12eab00b178957a63befe5bd (patch) | |
tree | 1175dd76512ea5d92220f60a10cde1b78346640b | |
parent | 3ab3e076665d0722d6f12938f3bddf263322539b (diff) | |
download | pango-6b0aa77d23ac969c12eab00b178957a63befe5bd.tar.gz |
PangoWin32: Use HarfBuzz platform APIs if available
Use the DirectWrite and/or GDI APIs in HarfBuzz to create the hb_font_t's that
we need, if they are available in HarfBuzz. Use the former raw-data method
if neither are available, or if using DirectWrite failed and GDI support is
not available.
-rw-r--r-- | pango/pangowin32-dwrite-fontmap.cpp | 12 | ||||
-rw-r--r-- | pango/pangowin32-private.h | 2 | ||||
-rw-r--r-- | pango/pangowin32.c | 39 |
3 files changed, 48 insertions, 5 deletions
diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp index a2c03675..6e1d9f0a 100644 --- a/pango/pangowin32-dwrite-fontmap.cpp +++ b/pango/pangowin32-dwrite-fontmap.cpp @@ -25,6 +25,10 @@ #include <initguid.h> #include <dwrite_1.h> +#ifdef HAVE_HARFBUZZ_DIRECT_WRITE +#include <hb-directwrite.h> +#endif + #ifdef STRICT #undef STRICT #endif @@ -559,6 +563,14 @@ pango_win32_dwrite_font_check_is_hinted (PangoWin32Font *font) return result; } +#ifdef HAVE_HARFBUZZ_DIRECT_WRITE +hb_face_t * +pango_win32_dwrite_font_face_create_hb_face (gpointer face) +{ + return hb_directwrite_face_create ((IDWriteFontFace *)face); +} +#endif + void pango_win32_dwrite_font_release (gpointer dwrite_font) { diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h index 1502ecd9..f69d2b6b 100644 --- a/pango/pangowin32-private.h +++ b/pango/pangowin32-private.h @@ -321,6 +321,8 @@ gpointer pango_win32_logfontw_get_dwrite_font (LOGFONTW PangoFontDescription * pango_win32_font_description_from_logfontw_dwrite (const LOGFONTW *logfontw); +hb_face_t *pango_win32_dwrite_font_face_create_hb_face (gpointer face); + G_END_DECLS #endif /* __PANGOWIN32_PRIVATE_H__ */ diff --git a/pango/pangowin32.c b/pango/pangowin32.c index 5a26ee98..09b97a55 100644 --- a/pango/pangowin32.c +++ b/pango/pangowin32.c @@ -29,6 +29,10 @@ #include <glib.h> #include <hb.h> +#if defined (HAVE_HARFBUZZ_GDI) +#include <hb-gdi.h> +#endif + #include "pango-impl-utils.h" #include "pangowin32.h" #include "pangowin32-private.h" @@ -1285,20 +1289,45 @@ hfont_reference_table (hb_face_t *face, hb_tag_t tag, void *user_data) static hb_font_t * pango_win32_font_create_hb_font (PangoFont *font) { - PangoWin32Font *win32font = (PangoWin32Font *)font; - HFONT hfont; + PangoWin32Font *win32font = PANGO_WIN32_FONT (font); + HFONT hfont = NULL; hb_face_t *face = NULL; hb_font_t *hb_font = NULL; + static const hb_user_data_key_t key; + hb_destroy_func_t destroy_func = NULL; + void *destroy_obj = NULL; + gpointer dwrite_font_face = NULL; g_return_val_if_fail (font != NULL, NULL); - hfont = _pango_win32_font_get_hfont (font); +#ifdef HAVE_HARFBUZZ_DIRECT_WRITE + dwrite_font_face = pango_win32_font_get_dwrite_font_face (win32font); + + if (dwrite_font_face != NULL) + { + face = pango_win32_dwrite_font_face_create_hb_face (dwrite_font_face); + destroy_func = pango_win32_dwrite_font_face_release; + destroy_obj = dwrite_font_face; + } +#endif + if (face == NULL) + { + hfont = _pango_win32_font_get_hfont (font); - /* We are *not* allowed to destroy the HFONT here ! */ - face = hb_face_create_for_tables (hfont_reference_table, (void *)hfont, NULL); +#ifdef HAVE_HARFBUZZ_GDI + face = hb_gdi_face_create (hfont); +#else + face = hb_face_create_for_tables (hfont_reference_table, (void *)hfont, NULL); +#endif + } hb_font = hb_font_create (face); hb_font_set_scale (hb_font, win32font->size, win32font->size); + + /* We are supposed to destroy the IDWriteFontFace, but *not* the HFONT! */ + if (destroy_func != NULL && destroy_obj != NULL) + hb_font_set_user_data (hb_font, &key, destroy_obj, destroy_func, TRUE); + hb_face_destroy (face); return hb_font; |