[pango/pango2: 289/301] pangocairo-font.c: Fix Windows DirectWrite build




commit 4a32502e28b97f09be4ab622e524e10b6278fba2
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Tue Jun 14 16:49:16 2022 +0800

    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.

 pango/meson.build                |  5 ++++
 pango/pangocairo-dwrite-font.cpp | 53 ++++++++++++++++++++++++++++++++++++++++
 pango/pangocairo-font.c          | 24 +++---------------
 pango/pangocairo-private.h       |  9 +++++++
 4 files changed, 71 insertions(+), 20 deletions(-)
---
diff --git a/pango/meson.build b/pango/meson.build
index c94044456..9677beedb 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 000000000..ed5b4f0c9
--- /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 a3c394a57..432d0166e 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 0f1ce314b..bf5185807 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]