[pango/pango2-windows: 2/4] 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: 2/4] pangodwrite-fontmap: Add property for whether GDI will be used
- Date: Tue, 5 Jul 2022 09:27:27 +0000 (UTC)
commit 1c58ba33c38a9673b496649e0321e1c694531b96
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 | 110 +++++++++++++++++++++++++++++++++++++++++
pango2/pangodwrite-fontmap.h | 7 +++
2 files changed, 117 insertions(+)
---
diff --git a/pango2/pangodwrite-fontmap.cpp b/pango2/pangodwrite-fontmap.cpp
index 585472425..c7ccb4d2a 100644
--- a/pango2/pangodwrite-fontmap.cpp
+++ b/pango2/pangodwrite-fontmap.cpp
@@ -57,6 +57,7 @@ struct _Pango2DirectWriteFontMap
IDWriteFactory *dwrite_factory;
IDWriteGdiInterop *gdi_interop;
+ gboolean use_gdi;
};
struct _Pango2DirectWriteFontMapClass
@@ -339,6 +340,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
@@ -381,15 +389,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);
}
/* }}} */
@@ -482,6 +545,53 @@ pango2_direct_write_font_map_get_font_description_from_logfontw (Pango2FontMap *
return desc;
}
+
+/**
+ * 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_font_map_repopulate (map, TRUE);
+}
+
+/**
+ * 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 f52ddf5ec..085d06d82 100644
--- a/pango2/pangodwrite-fontmap.h
+++ b/pango2/pangodwrite-fontmap.h
@@ -47,4 +47,11 @@ PANGO2_AVAILABLE_IN_ALL
Pango2FontDescription *pango2_direct_write_font_map_get_font_description_from_logfontw (Pango2FontMap
*font_map,
LOGFONTW
*lfw);
+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]