[pango/pango2: 84/84] fontmap: Cleanups
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 84/84] fontmap: Cleanups
- Date: Sat, 11 Jun 2022 20:05:25 +0000 (UTC)
commit 82d471181ba6263e100be853065b88b2527b3371
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 11 15:33:48 2022 -0400
fontmap: Cleanups
Add pango_font_map_get_resolution.
Also, make fontmap resolution a float property.
pango/pango-fontmap-private.h | 2 +-
pango/pango-fontmap.c | 79 ++++++++++++++++++++++++++++++++++++++++++-
pango/pango-fontmap.h | 5 ++-
3 files changed, 83 insertions(+), 3 deletions(-)
---
diff --git a/pango/pango-fontmap-private.h b/pango/pango-fontmap-private.h
index 47b0c34a9..e2410e96c 100644
--- a/pango/pango-fontmap-private.h
+++ b/pango/pango-fontmap-private.h
@@ -35,7 +35,7 @@ struct _PangoFontMap
GHashTable *fontsets;
GQueue fontset_cache;
- double dpi;
+ float dpi;
gboolean in_populate;
guint serial;
};
diff --git a/pango/pango-fontmap.c b/pango/pango-fontmap.c
index 4f5d732e7..fb405f939 100644
--- a/pango/pango-fontmap.c
+++ b/pango/pango-fontmap.c
@@ -350,6 +350,13 @@ synthesize_bold_and_italic_faces (PangoFontMap *map)
/* }}} */
/* {{{ PangoFontMap implementation */
+enum {
+ PROP_RESOLUTION = 1,
+ N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES] = { NULL };
+
G_DEFINE_TYPE_WITH_CODE (PangoFontMap, pango_font_map, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, pango_font_map_list_model_init))
@@ -386,6 +393,45 @@ pango_font_map_finalize (GObject *object)
G_OBJECT_CLASS (pango_font_map_parent_class)->finalize (object);
}
+static void
+pango_font_map_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PangoFontMap *map = PANGO_FONT_MAP (object);
+
+ switch (property_id)
+ {
+ case PROP_RESOLUTION:
+ pango_font_map_set_resolution (map, g_value_get_float (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+/* Load a font from the first matching family */
+static void
+pango_font_map_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PangoFontMap *map = PANGO_FONT_MAP (object);
+
+ switch (property_id)
+ {
+ case PROP_RESOLUTION:
+ g_value_set_float (value, map->dpi);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
/* Load a font from the first matching family */
static PangoFont *
pango_font_map_default_load_font (PangoFontMap *self,
@@ -553,6 +599,8 @@ pango_font_map_class_init (PangoFontMapClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = pango_font_map_finalize;
+ object_class->set_property = pango_font_map_set_property;
+ object_class->get_property = pango_font_map_get_property;
class->load_font = pango_font_map_default_load_font;
class->load_fontset = pango_font_map_default_load_fontset;
@@ -560,6 +608,12 @@ pango_font_map_class_init (PangoFontMapClass *class)
class->changed = pango_font_map_default_changed;
class->get_family = pango_font_map_default_get_family;
class->populate = pango_font_map_default_populate;
+
+ properties[PROP_RESOLUTION] =
+ g_param_spec_float ("resolution", NULL, NULL, 0, G_MAXFLOAT, 96.0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
/* }}} */
@@ -970,15 +1024,38 @@ pango_font_map_remove_family (PangoFontMap *self,
*/
void
pango_font_map_set_resolution (PangoFontMap *self,
- double dpi)
+ float dpi)
{
g_return_if_fail (PANGO_IS_FONT_MAP (self));
g_return_if_fail (dpi > 0);
+ if (self->dpi == dpi)
+ return;
+
self->dpi = dpi;
clear_caches (self);
pango_font_map_changed (self);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RESOLUTION]);
+}
+
+/**
+ * pango_font_map_get_resolution:
+ * @self: a `PangoFontMap`
+ *
+ * Returns the resolution for the fontmap.
+ *
+ * See [method@Pango.FontMap.set_resolution].
+ *
+ * Return value: the resolution for the fontmap
+ */
+float
+pango_font_map_get_resolution (PangoFontMap *self)
+{
+ g_return_val_if_fail (PANGO_IS_FONT_MAP (self), 0);
+
+ return self->dpi;
}
/* }}} */
diff --git a/pango/pango-fontmap.h b/pango/pango-fontmap.h
index 104a63d5f..ac106b08b 100644
--- a/pango/pango-fontmap.h
+++ b/pango/pango-fontmap.h
@@ -70,9 +70,12 @@ PANGO_AVAILABLE_IN_ALL
void pango_font_map_remove_family (PangoFontMap *self,
PangoFontFamily *family);
+PANGO_AVAILABLE_IN_ALL
+float pango_font_map_get_resolution (PangoFontMap *self);
+
PANGO_AVAILABLE_IN_ALL
void pango_font_map_set_resolution (PangoFontMap *self,
- double dpi);
+ float dpi);
PANGO_AVAILABLE_IN_ALL
PangoFontMap * pango_font_map_new_default (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]