[pango/pango2-windows: 77/77] PangoCairo: Add support creating GDI-based cairo_font_face_t's




commit 9f549ecc29325b52286e1d783d3c97d14a71d972
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jul 4 18:27:33 2022 +0800

    PangoCairo: Add support creating GDI-based cairo_font_face_t's
    
    If HarfBuzz is built with GDI/Uniscribe support, allow one to create LOGFONTW-
    based cairo_font_face_t's by retrieving a LOGFONTW from the hb_font_t, so that
    applications that still rely on GDI can continue to work with Pango2 even if
    they do not have the custom renderer that is needed for DirectWrite fonts.
    
    Support for enabling this code path, as with creating the hb_face_t with
    GDI-based LOGFONTW's, is not yet added into the code.

 meson.build                  |  7 +++---
 pango2/meson.build           |  5 ++++
 pango2/pangocairo-font.c     | 19 ++++++++++++++-
 pango2/pangocairo-gdi-font.c | 58 ++++++++++++++++++++++++++++++++++++++++++++
 pango2/pangocairo-private.h  |  5 ++++
 5 files changed, 90 insertions(+), 4 deletions(-)
---
diff --git a/meson.build b/meson.build
index 34f1b5815..53d907cf8 100644
--- a/meson.build
+++ b/meson.build
@@ -325,9 +325,10 @@ if host_system == 'windows'
     cc.find_library('dwrite'),
   ]
 
-  if cc.has_header_symbol('hb-gdi.h',
-                          'hb_gdi_face_create',
-                          dependencies: harfbuzz_dep)
+  harfbuzz_have_gdi = cc.has_header_symbol('hb-gdi.h',
+                                           'hb_gdi_face_create',
+                                           dependencies: harfbuzz_dep)
+  if harfbuzz_have_gdi
     pango_conf.set('HAVE_GDI', 1)
   endif
 
diff --git a/pango2/meson.build b/pango2/meson.build
index e0f0626db..ee86b278c 100644
--- a/pango2/meson.build
+++ b/pango2/meson.build
@@ -177,6 +177,11 @@ if host_system == 'windows'
     pango_sources += [
       'pangocairo-dwrite-font.cpp',
     ]
+    if harfbuzz_have_gdi
+      pango_sources += [
+        'pangocairo-gdi-font.c',
+      ]
+    endif
   endif
 
   pango_features_conf.set('PANGO2_HAS_DIRECT_WRITE_FONTMAP', 1)
diff --git a/pango2/pangocairo-font.c b/pango2/pangocairo-font.c
index bdbf8f06d..28f4ab1e2 100644
--- a/pango2/pangocairo-font.c
+++ b/pango2/pangocairo-font.c
@@ -36,6 +36,7 @@
 #include "pango-userfont-private.h"
 #include "pango-userface-private.h"
 #include "pango-font-private.h"
+#include "pangodwrite-fontmap.h"
 
 static Pango2CairoFontPrivate * _pango2_font_get_cairo_font_private (Pango2Font *font);
 static cairo_scaled_font_t * _pango2_font_get_scaled_font (Pango2Font *font,
@@ -87,7 +88,23 @@ create_cairo_font_face (Pango2Font *font)
 #endif
 
 #ifdef HAVE_DIRECT_WRITE
-  cairo_face = create_cairo_dwrite_font_face (font);
+#ifdef HAVE_GDI
+  gboolean use_gdi = FALSE;
+  Pango2FontFamily *family = pango2_font_face_get_family (pango2_font_get_face (font));
+  if (family)
+    {
+      Pango2FontMap *fontmap = pango2_font_family_get_font_map (family);
+
+      if (PANGO2_IS_DIRECT_WRITE_FONT_MAP (fontmap))
+        use_gdi = pango2_direct_write_font_map_get_use_gdi (fontmap);
+    }
+
+  if (use_gdi)
+    cairo_face = create_cairo_gdi_font_face (font);
+  else
+#endif
+    cairo_face = create_cairo_dwrite_font_face (font);
+
   if (cairo_face)
     return cairo_face;
 #endif
diff --git a/pango2/pangocairo-gdi-font.c b/pango2/pangocairo-gdi-font.c
new file mode 100644
index 000000000..0531c2afb
--- /dev/null
+++ b/pango2/pangocairo-gdi-font.c
@@ -0,0 +1,58 @@
+/* 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 "pangocairo-private.h"
+#include "pango-font-private.h"
+#include "pango-font.h"
+
+#include <windows.h>
+#include <hb-uniscribe.h>
+#include <cairo-win32.h>
+
+cairo_font_face_t *
+create_cairo_gdi_font_face (Pango2Font *font)
+{
+  HFONT hfont = NULL;
+  hb_font_t *hb_font;
+  hb_font_t *hb_font_new = hb_font_get_empty ();
+  hb_face_t *hb_face;
+  hb_face_t *hb_face_new = hb_face_get_empty ();
+  hb_blob_t *blob = hb_blob_get_empty ();
+  unsigned int idx;
+  cairo_font_face_t *result = NULL;
+
+  hb_font = pango2_font_get_hb_font (font);
+
+  hfont = hb_uniscribe_font_get_hfont (hb_font);
+
+  if (hfont)
+    result = cairo_win32_font_face_create_for_hfont (hfont);
+
+  return result;
+}
+
+#endif /* HAVE_DIRECT_WRITE */
+
+/* vim:set foldmethod=marker expandtab: */
diff --git a/pango2/pangocairo-private.h b/pango2/pangocairo-private.h
index 0ff05b98d..cd00fcb57 100644
--- a/pango2/pangocairo-private.h
+++ b/pango2/pangocairo-private.h
@@ -83,4 +83,9 @@ cairo_font_face_t *     create_cairo_core_text_font_face                (Pango2F
 cairo_font_face_t *     create_cairo_dwrite_font_face                   (Pango2Font     *font);
 #endif
 
+#ifdef HAVE_GDI
+cairo_font_face_t *
+create_cairo_gdi_font_face (Pango2Font *font);
+#endif
+
 G_END_DECLS


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