[pango/pango2: 72/168] fontmap: Cleanups
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 72/168] fontmap: Cleanups
- Date: Mon, 20 Jun 2022 16:28:42 +0000 (UTC)
commit c7369f68d0017ce4873751fb88d082d5610a0b39
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 | 127 +++++++++++++++++++++++++++++++++++++++++-
pango/pango-fontmap.h | 5 +-
3 files changed, 129 insertions(+), 5 deletions(-)
---
diff --git a/pango/pango-fontmap-private.h b/pango/pango-fontmap-private.h
index 47b0c34a..e2410e96 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 fbcfd376..1753d703 100644
--- a/pango/pango-fontmap.c
+++ b/pango/pango-fontmap.c
@@ -344,6 +344,15 @@ synthesize_bold_and_italic_faces (PangoFontMap *map)
/* }}} */
/* {{{ PangoFontMap implementation */
+enum {
+ PROP_RESOLUTION = 1,
+ PROP_ITEM_TYPE,
+ PROP_N_ITEMS,
+ 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))
@@ -380,6 +389,52 @@ 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);
+ }
+}
+
+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;
+
+ case PROP_ITEM_TYPE:
+ g_value_set_gtype (value, PANGO_TYPE_FONT_FAMILY);
+ break;
+
+ case PROP_N_ITEMS:
+ g_value_set_uint (value, pango_font_map_get_n_items (G_LIST_MODEL (object)));
+ 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,
@@ -547,6 +602,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;
@@ -554,6 +611,40 @@ 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;
+
+ /**
+ * PangoFontMap:resolution: (attributes org.gtk.Property.get=pango_font_map_get_resolution
org.gtk.Property.set=pango_font_map_set_resolution)
+ *
+ * The resolution for the fontmap.
+ *
+ * This is a scale factor between points specified in a
+ * `PangoFontDescription` and Cairo units. The default value
+ * is 96, meaning that a 10 point font will be 13 units high.
+ * (10 * 96. / 72. = 13.3).
+ */
+ properties[PROP_RESOLUTION] =
+ g_param_spec_float ("resolution", NULL, NULL, 0, G_MAXFLOAT, 96.0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PangoFontMap:item-type:
+ *
+ * The type of items contained in this list.
+ */
+ properties[PROP_ITEM_TYPE] =
+ g_param_spec_gtype ("item-type", "", "", G_TYPE_OBJECT,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * PangoFontMap:n-items:
+ *
+ * The number of items contained in this list.
+ */
+ properties[PROP_N_ITEMS] =
+ g_param_spec_uint ("n-items", "", "", 0, G_MAXUINT, 0,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
/* }}} */
@@ -607,6 +698,7 @@ pango_font_map_repopulate (PangoFontMap *self,
added = self->families->len;
g_list_model_items_changed (G_LIST_MODEL (self), 0, removed, added);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
pango_font_map_changed (self);
}
@@ -912,7 +1004,10 @@ pango_font_map_add_family (PangoFontMap *self,
g_hash_table_add (self->families_hash, family);
if (!self->in_populate)
- g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
+ {
+ g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
+ }
pango_font_map_changed (self);
}
@@ -943,7 +1038,10 @@ pango_font_map_remove_family (PangoFontMap *self,
pango_font_family_set_font_map (family, NULL);
if (!self->in_populate)
- g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0);
+ {
+ g_list_model_items_changed (G_LIST_MODEL (self), position, 1, 0);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_ITEMS]);
+ }
pango_font_map_changed (self);
@@ -964,15 +1062,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 104a63d5..ac106b08 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]