[pango/pango2-windows] pangodwrite-fontmap: Add property for whether GDI will be used
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2-windows] pangodwrite-fontmap: Add property for whether GDI will be used
- Date: Fri, 1 Jul 2022 11:18:11 +0000 (UTC)
commit 673b0f0279f30b44863badeaaecbd30cba53d44e
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Fri Jul 1 19:15:42 2022 +0800
pangodwrite-fontmap: Add property for whether GDI will be used
...to create font maps, instead of DirectWrite. This is so that we can use
GDI interop in the DirectWrite code to use the classic HFONTS/LOGFONTS to
create our hb_face's, so that we can use them to work with GDI-based libraries
and apps that do not have custom renderers to handle the DirectWrite fonts.
pango2/pangodwrite-fontmap.cpp | 108 +++++++++++++++++++++++++++++++++++++++++
pango2/pangodwrite-fontmap.h | 9 +++-
2 files changed, 116 insertions(+), 1 deletion(-)
---
diff --git a/pango2/pangodwrite-fontmap.cpp b/pango2/pangodwrite-fontmap.cpp
index 7f4ead157..b381dd3ec 100644
--- a/pango2/pangodwrite-fontmap.cpp
+++ b/pango2/pangodwrite-fontmap.cpp
@@ -56,6 +56,7 @@ struct _Pango2DirectWriteFontMap
Pango2FontMap parent_instance;
IDWriteFactory *dwrite_factory;
+ gboolean use_gdi;
};
struct _Pango2DirectWriteFontMapClass
@@ -338,6 +339,13 @@ pango2_direct_write_font_map_populate (Pango2FontMap *map)
/* }}} */
/* {{{ Pango2DirectWriteFontMap implementation */
+enum {
+ PROP_USE_GDI = 1,
+ N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL, };
+
G_DEFINE_FINAL_TYPE (Pango2DirectWriteFontMap, pango2_direct_write_font_map, PANGO2_TYPE_FONT_MAP)
static void
@@ -366,15 +374,70 @@ pango2_direct_write_font_map_finalize (GObject *object)
G_OBJECT_CLASS (pango2_direct_write_font_map_parent_class)->finalize (object);
}
+static void
+pango2_direct_write_font_map_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ Pango2FontMap *map = PANGO2_FONT_MAP (object);
+
+ switch (property_id)
+ {
+ case PROP_USE_GDI:
+ pango2_direct_write_font_map_set_use_gdi (map, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+pango2_direct_write_font_map_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ Pango2FontMap *map = PANGO2_FONT_MAP (object);
+
+ switch (property_id)
+ {
+ case PROP_USE_GDI:
+ g_value_set_boolean (value, pango2_direct_write_font_map_get_use_gdi (map));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
static void
pango2_direct_write_font_map_class_init (Pango2DirectWriteFontMapClass *class_)
{
GObjectClass *object_class = G_OBJECT_CLASS (class_);
Pango2FontMapClass *font_map_class = PANGO2_FONT_MAP_CLASS (class_);
+ object_class->set_property = pango2_direct_write_font_map_set_property;
+ object_class->get_property = pango2_direct_write_font_map_get_property;
object_class->finalize = pango2_direct_write_font_map_finalize;
font_map_class->populate = pango2_direct_write_font_map_populate;
+
+ /**
+ * Pango2DirectWriteFontMap:use-gdi: (attributes
org.gtk.Property.get=pango2_direct_write_font_map_get_use_gdi
org.gtk.Property.set=pango2_direct_write_font_map_set_use_gdi)
+ *
+ * Determines whether this context should create GDI LOGFONT-based font maps
+ * instead of DirectWrite ones.
+ *
+ * This is useful when the custom GDI renderer for the DirectWrite fonts is not
+ * ready for the application and the application has not migrated to Direct2D.
+ */
+ properties[PROP_USE_GDI] =
+ g_param_spec_boolean ("use-gdi", NULL, NULL, FALSE,
+ (GParamFlags)(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
/* }}} */
@@ -393,6 +456,51 @@ pango2_direct_write_font_map_new (void)
return (Pango2DirectWriteFontMap *) g_object_new (PANGO2_TYPE_DIRECT_WRITE_FONT_MAP, NULL);
}
+/**
+ * pango2_direct_write_set_use_gdi:
+ * @map: a `Pango2FontMap`
+ * @use_gdi: whether to use GDI
+ *
+ * Sets whether this font map should use GDI-based font maps
+ * instead of the normal DirectWrite-based font maps.
+ *
+ * This is useful when the custom renderer for DirectWrite fonts
+ * for GDI is not ready and Direct2D is not used for the application
+ * or library.
+ *
+ * The default value is to use DirectWrite-based font maps.
+ */
+void
+pango2_direct_write_font_map_set_use_gdi (Pango2FontMap *map,
+ gboolean use_gdi)
+{
+ Pango2DirectWriteFontMap *dwrite_map;
+
+ g_return_if_fail (PANGO2_IS_DIRECT_WRITE_FONT_MAP (map));
+
+ dwrite_map = PANGO2_DIRECT_WRITE_FONT_MAP (map);
+
+ if (dwrite_map->use_gdi == use_gdi)
+ return;
+
+ dwrite_map->use_gdi = use_gdi;
+ g_object_notify_by_pspec (G_OBJECT (dwrite_map), properties[PROP_USE_GDI]);
+}
+
+/**
+ * pango2_direct_write_get_use_gdi:
+ * @map: a `Pango2FontMap`
+ *
+ * Returns whether GDI-based font maps are used with this FontMap.
+ */
+gboolean
+pango2_direct_write_font_map_get_use_gdi (Pango2FontMap *map)
+{
+ g_return_val_if_fail (PANGO2_IS_DIRECT_WRITE_FONT_MAP (map), FALSE);
+
+ return PANGO2_DIRECT_WRITE_FONT_MAP (map)->use_gdi;
+}
+
/* }}} */
/* vim:set foldmethod=marker expandtab: */
diff --git a/pango2/pangodwrite-fontmap.h b/pango2/pangodwrite-fontmap.h
index c873759da..2f13d18d5 100644
--- a/pango2/pangodwrite-fontmap.h
+++ b/pango2/pangodwrite-fontmap.h
@@ -34,7 +34,14 @@ PANGO2_DECLARE_INTERNAL_TYPE (Pango2DirectWriteFontMap,
Pango2FontMap)
PANGO2_AVAILABLE_IN_ALL
-Pango2DirectWriteFontMap * pango2_direct_write_font_map_new (void);
+Pango2DirectWriteFontMap *pango2_direct_write_font_map_new (void);
+
+PANGO2_AVAILABLE_IN_ALL
+void pango2_direct_write_font_map_set_use_gdi (Pango2FontMap *map,
+ gboolean use_gdi);
+
+PANGO2_AVAILABLE_IN_ALL
+gboolean pango2_direct_write_font_map_get_use_gdi (Pango2FontMap *map);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]