New function width_of_m to get the width of M rendered in a widget.
[pspp] / src / ui / gui / helper.c
index cde9d92b8f186a29525a00b24fb55e09b3707771..0737d2fb7b08a8401b46a167a866eccac6afa818 100644 (file)
@@ -230,3 +230,23 @@ paste_syntax_to_window (gchar *syntax)
 
   return syntax;
 }
+
+
+/* Return the width of an upper case M (in pixels) when rendered onto
+   WIDGET with its current style.  */
+gdouble
+width_of_m (GtkWidget *widget)
+{
+  PangoContext *context = gtk_widget_create_pango_context (widget);
+  PangoLayout *layout = pango_layout_new (context);
+  PangoRectangle rect;
+
+  pango_layout_set_text (layout, "M", 1);
+  pango_layout_get_extents (layout, NULL, &rect);
+
+  g_object_unref (G_OBJECT (layout));
+  g_object_unref (G_OBJECT (context));
+
+  return rect.width / (gdouble) PANGO_SCALE;
+}
+