[pango/pango2-windows: 47/50] DirectWrite: Add utility to acquire Cairo font face




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

    DirectWrite: Add utility to acquire Cairo font face
    
    Add a C++ source file (sadly, but necessary to access DirectWrite COM
    types needed for using HarfBuzz's functions for acquiring the
    IDWriteFontFace bound to the hb_font_t) that creates with Cairo's newly-
    added functions to create a Cairo font face from DirectWrite's
    IDWriteFontFace.
    
    As a consequence, make sure pangocairo-private.h uses C linkage so that
    things will link properly when DirectWrite is being used.
    
    Add the file to the build, albeit that the compiled object is not yet
    used by anything, which will be added in the next commit.

 pango/meson.build                |  5 ++++
 pango/pangocairo-dwrite-font.cpp | 53 ++++++++++++++++++++++++++++++++++++++++
 pango/pangocairo-private.h       |  9 +++++++
 3 files changed, 67 insertions(+)
---
diff --git a/pango/meson.build b/pango/meson.build
index 663b33c6..7902db85 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-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


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