diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2022-06-14 16:49:16 +0800 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-06-22 13:57:26 -0400 |
commit | 43bb4a8868bdd70a33f71367c95d091867808d01 (patch) | |
tree | 74235915fcdefb278fc7ce2eb88d9a3088ca4f04 /pango | |
parent | a7cc5f4800d357938df0dfa97c3486ab0cf8e942 (diff) | |
download | pango-43bb4a8868bdd70a33f71367c95d091867808d01.tar.gz |
pangocairo-font.c: Fix Windows DirectWrite build
Sadly, the APIs and COM types in dwrite.h that is shipped with the
Windows SDK at least is C++ only, so we can't just include it in C files
directly. No version of the Windows SDK ship dwrite.h that is
compatible with C, unlike many of the DirectX headers that at least
shipped in the past with C support.
Instead, add a C++ source file that does the work to acquire the
cairo_font_face_t that we need from the DirectWrite IDWriteFontFace that
we added whe we populated the font map, and call that function from
pangocairo-font.c. Make the definition of
create_cairo_font_face_for_hb_font() on DirectWrite builds marked with
static, as with the CoreText and FontConfig builds.
As a consequence, make sure pangocairo-private.h uses C linkage so that
things will link properly when DirectWrite is being used.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/meson.build | 5 | ||||
-rw-r--r-- | pango/pangocairo-dwrite-font.cpp | 53 | ||||
-rw-r--r-- | pango/pangocairo-font.c | 24 | ||||
-rw-r--r-- | pango/pangocairo-private.h | 9 |
4 files changed, 71 insertions, 20 deletions
diff --git a/pango/meson.build b/pango/meson.build index c9404445..9677beed 100644 --- a/pango/meson.build +++ b/pango/meson.build @@ -152,6 +152,11 @@ if host_system == 'windows' pango_sources += [ 'pangodwrite-fontmap.cpp', ] + if cairo_dep.found() + pango_sources += [ + 'pangocairo-dwrite-font.cpp', + ] + endif pango_deps += [ cc.find_library('gdi32'), diff --git a/pango/pangocairo-dwrite-font.cpp b/pango/pangocairo-dwrite-font.cpp new file mode 100644 index 00000000..ed5b4f0c --- /dev/null +++ b/pango/pangocairo-dwrite-font.cpp @@ -0,0 +1,53 @@ +/* Pango + * pangocairo-dwrite-font.cpp: PangoCairo fonts using DirectWrite + * + * Copyright (C) 2022 the GTK team + * + * 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" + +#ifdef HAVE_DIRECT_WRITE + +#include <windows.h> +#include <dwrite.h> +#include <hb-directwrite.h> +#include <cairo-win32.h> + +#include "pangocairo-private.h" + +/* {{{ DirectWrite PangoCairo utilities */ +cairo_font_face_t * +pango_cairo_create_font_face_for_dwrite_pango_font (PangoFont *font) +{ + hb_font_t *hb_font; + IDWriteFontFace *dwrite_font_face = NULL; + cairo_font_face_t *result; + + hb_font = pango_font_get_hb_font (font); + dwrite_font_face = hb_directwrite_face_get_font_face (hb_font_get_face (hb_font)); + + result = cairo_dwrite_font_face_create_for_dwrite_fontface (dwrite_font_face); + + return result; +} + +#endif /* HAVE_DIRECT_WRITE */ + +/* }}} */ + +/* vim:set foldmethod=marker expandtab: */ diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index a3c394a5..432d0166 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -41,16 +41,9 @@ #include <cairo-quartz.h> #include <hb-coretext.h> -#elif defined (HAVE_DIRECT_WRITE) - -#include <windows.h> -#include <dwrite.h> -#include <hb-directwrite.h> -#include <cairo-win32.h> - -#else +#elif defined (HAVE_FONTCONFIG) -#include <hb-ft.h> +#include <hb-ot.h> #include <cairo-ft.h> #include <freetype/ftmm.h> @@ -181,19 +174,10 @@ create_cairo_font_face_for_hb_font (PangoFont *font) #elif defined (HAVE_DIRECT_WRITE) -cairo_font_face_t * +static cairo_font_face_t * create_cairo_font_face_for_hb_font (PangoFont *font) { - hb_font_t *hbfont; - IDWriteFontFace *dfont = NULL; - cairo_font_face_t *cairo_face; - - hbfont = pango_font_get_hb_font (font); - dfont = hb_directwrite_face_get_font_face (hb_font_get_face (hbfont)); - - cairo_face = cairo_dwrite_font_face_create_for_dwrite_fontface (dfont); - - return cairo_face; + return pango_cairo_create_font_face_for_dwrite_pango_font (font); } #else diff --git a/pango/pangocairo-private.h b/pango/pangocairo-private.h index 0f1ce314..bf518580 100644 --- a/pango/pangocairo-private.h +++ b/pango/pangocairo-private.h @@ -22,6 +22,8 @@ #include <pango/pangocairo.h> #include <pango/pango-renderer.h> +G_BEGIN_DECLS + typedef struct _PangoCairoFontPrivate PangoCairoFontPrivate; typedef struct _HexBoxInfo PangoCairoFontHexBoxInfo; typedef struct _PangoCairoFontPrivateScaledFontData PangoCairoFontPrivateScaledFontData; @@ -63,3 +65,10 @@ GType pango_cairo_renderer_get_type (void) G_GNUC_CONST; const cairo_font_options_t * pango_cairo_context_get_merged_font_options (PangoContext *context); + +#ifdef HAVE_DIRECT_WRITE +cairo_font_face_t * +pango_cairo_create_font_face_for_dwrite_pango_font (PangoFont *font); +#endif + +G_END_DECLS |