diff options
Diffstat (limited to 'pango/pangowin32-dwrite-fontmap.cpp')
-rw-r--r-- | pango/pangowin32-dwrite-fontmap.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/pango/pangowin32-dwrite-fontmap.cpp b/pango/pangowin32-dwrite-fontmap.cpp new file mode 100644 index 00000000..bb22efea --- /dev/null +++ b/pango/pangowin32-dwrite-fontmap.cpp @@ -0,0 +1,86 @@ +/* Pango + * pangowin32-dwrite-fontmap.cpp: Win32 font handling with DirectWrite + * + * Copyright (C) 2022 Luca Bacci + * Copyright (C) 2022 Chun-wei Fan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include <initguid.h> +#include <dwrite.h> + +#ifdef STRICT +#undef STRICT +#endif +#include "pangowin32-private.h" + +#ifdef _MSC_VER +# define UUID_OF_IDWriteFactory __uuidof (IDWriteFactory) +#else +# define UUID_OF_IDWriteFactory IID_IDWriteFactory +#endif + +struct _PangoWin32DWriteItems +{ + IDWriteFactory *dwrite_factory; + IDWriteGdiInterop *gdi_interop; +}; + +PangoWin32DWriteItems * +pango_win32_init_direct_write (void) +{ + PangoWin32DWriteItems *dwrite_items = g_new0 (PangoWin32DWriteItems, 1); + HRESULT hr; + gboolean failed = FALSE; + + hr = DWriteCreateFactory (DWRITE_FACTORY_TYPE_SHARED, + UUID_OF_IDWriteFactory, + reinterpret_cast<IUnknown**> (&dwrite_items->dwrite_factory)); + + if (SUCCEEDED (hr) && dwrite_items->dwrite_factory != NULL) + { + hr = dwrite_items->dwrite_factory->GetGdiInterop (&dwrite_items->gdi_interop); + if (FAILED (hr) || dwrite_items->gdi_interop == NULL) + { + g_error ("DWriteCreateFactory::GetGdiInterop failed with error code %x", (unsigned)hr); + dwrite_items->dwrite_factory->Release (); + failed = TRUE; + } + } + else + { + g_error ("DWriteCreateFactory failed with error code %x", (unsigned)hr); + failed = TRUE; + } + + + if (failed) + g_free (dwrite_items); + + return failed ? NULL : dwrite_items; +} + +void +pango_win32_dwrite_items_destroy (PangoWin32DWriteItems *dwrite_items) +{ + dwrite_items->gdi_interop->Release (); + dwrite_items->dwrite_factory->Release (); + + g_free (dwrite_items); +} |