[pango/win32-font-language] PangoWin32: Initialize DirectWrite as well
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/win32-font-language] PangoWin32: Initialize DirectWrite as well
- Date: Sat, 14 Nov 2020 02:25:38 +0000 (UTC)
commit b9fc0f5e65d38a984dc01d1b8e7707ee95a95a5e
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Wed Nov 11 20:15:25 2020 +0800
PangoWin32: Initialize DirectWrite as well
We want to start using DirectWrite to help us implement some features
that are not that easily done with GDI/Uniscribe, via a GDI interop
layer as provided by DirectWrite.
pango/meson.build | 1 +
pango/pangowin32.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
---
diff --git a/pango/meson.build b/pango/meson.build
index 91261274..21b620ec 100644
--- a/pango/meson.build
+++ b/pango/meson.build
@@ -413,6 +413,7 @@ if host_system == 'windows'
pangowin32_deps = pango_deps + [
libpango_dep,
cc.find_library('gdi32'),
+ cc.find_library('dwrite'),
]
pangowin32_rc = configure_file(
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index 213a665e..2da6473d 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -32,6 +32,9 @@
*/
#include "config.h"
+#define COBJMACROS
+#include <initguid.h>
+
#include <string.h>
#include <stdlib.h>
#include <glib.h>
@@ -41,6 +44,9 @@
#include "pangowin32.h"
#include "pangowin32-private.h"
+/* this is a C-compatible counterpart of the DirectWrite headers */
+#include "dwrite_c.h"
+
#define MAX_FREED_FONTS 256
gboolean _pango_win32_debug = FALSE;
@@ -134,6 +140,8 @@ _pango_win32_font_init (PangoWin32Font *win32font)
}
static GPrivate display_dc_key = G_PRIVATE_INIT ((GDestroyNotify) DeleteDC);
+static GPrivate dwrite_factory_key;
+static GPrivate dwrite_gdi_key;
HDC
_pango_win32_get_display_dc (void)
@@ -190,6 +198,34 @@ pango_win32_get_debug_flag (void)
return _pango_win32_debug;
}
+static void
+_pango_win32_setup_dwrite (void)
+{
+ IDWriteFactory *dwrite_factory = NULL;
+ IDWriteGdiInterop *dwrite_gdi = NULL;
+
+ dwrite_factory = g_private_get (&dwrite_factory_key);
+ if (dwrite_factory == NULL)
+ {
+ if (DWriteCreateFactory (DWRITE_FACTORY_TYPE_SHARED,
+ &IID_IDWriteFactory,
+ (IUnknown **)&dwrite_factory) != S_OK)
+ g_warning ("DWrite factory creation failed!");
+ else
+ g_private_set (&dwrite_factory_key, dwrite_factory);
+ }
+
+ dwrite_gdi = g_private_get (&dwrite_gdi_key);
+ if (dwrite_factory != NULL && dwrite_gdi == NULL)
+ {
+ if (IDWriteFactory_GetGdiInterop (dwrite_factory,
+ &dwrite_gdi) != S_OK)
+ g_warning ("DWrite GDI interop creation failed!");
+ else
+ g_private_set (&dwrite_gdi_key, dwrite_gdi);
+ }
+}
+
static void
_pango_win32_font_class_init (PangoWin32FontClass *class)
{
@@ -212,6 +248,7 @@ _pango_win32_font_class_init (PangoWin32FontClass *class)
class->get_metrics_factor = pango_win32_font_real_get_metrics_factor;
_pango_win32_get_display_dc ();
+ _pango_win32_setup_dwrite ();
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]