summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2001-02-28 21:15:15 +0000
committerHavoc Pennington <hp@src.gnome.org>2001-02-28 21:15:15 +0000
commit94742208d8f1e274d8a5db4515acfbd4b3d9e4fa (patch)
tree57e31004de3d14316ad1d54a416bf680b45c3cf2 /pango
parent77626cb70d108fcba67dbc6085b864fcf166598d (diff)
downloadpango-94742208d8f1e274d8a5db4515acfbd4b3d9e4fa.tar.gz
add approximate_digit_width field
2001-02-28 Havoc Pennington <hp@redhat.com> * pango/pango-font.h (struct _PangoFontMetrics): add approximate_digit_width field * pango/pangox.c (pango_x_font_get_metrics): make up an approximate digit width number
Diffstat (limited to 'pango')
-rw-r--r--pango/pango-font.h1
-rw-r--r--pango/pangox.c28
2 files changed, 25 insertions, 4 deletions
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 109a7819..d0619f24 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -91,6 +91,7 @@ struct _PangoFontMetrics
int ascent;
int descent;
int approximate_char_width;
+ int approximate_digit_width;
};
PangoFontDescription *pango_font_description_copy (const PangoFontDescription *desc);
diff --git a/pango/pangox.c b/pango/pangox.c
index 172f64aa..06b4cea8 100644
--- a/pango/pangox.c
+++ b/pango/pangox.c
@@ -525,9 +525,9 @@ pango_x_font_get_glyph_extents (PangoFont *font,
static gboolean
get_int_prop (Atom atom,
XFontStruct *fs,
- gint *val)
+ int *val)
{
- gint i;
+ int i;
*val = 0;
@@ -556,8 +556,8 @@ get_font_metrics_from_subfonts (PangoFont *font,
PangoXFont *xfont = (PangoXFont *)font;
GSList *tmp_list = subfonts;
gboolean first = TRUE;
- gint total_avg_widths = 0;
- gint n_avg_widths = 0;
+ int total_avg_widths = 0;
+ int n_avg_widths = 0;
Atom avg_width_atom;
avg_width_atom = pango_x_fontmap_atom_from_name (xfont->fontmap,
@@ -780,12 +780,32 @@ pango_x_font_get_metrics (PangoFont *font,
if (!tmp_list)
{
+ PangoLayout *layout;
+ PangoRectangle extents;
+ PangoContext *context;
+
info = g_new (PangoXMetricsInfo, 1);
info->lang = lookup_lang;
xfont->metrics_by_lang = g_slist_prepend (xfont->metrics_by_lang, info);
get_font_metrics_from_string (font, lang, str, &info->metrics);
+
+ /* This is sort of a sledgehammer solution, but we cache this
+ * stuff so not a huge deal hopefully. Get the avg. width of the
+ * chars in "0123456789"
+ */
+ context = pango_x_get_context (pango_x_fontmap_get_display (xfont->fontmap));
+ pango_context_set_lang (context, lang);
+ layout = pango_layout_new (context);
+ pango_layout_set_text (layout, "0123456789", -1);
+
+ pango_layout_get_extents (layout, NULL, &extents);
+
+ metrics->approximate_digit_width = extents.width / 10;
+
+ g_object_unref (G_OBJECT (layout));
+ g_object_unref (G_OBJECT (context));
}
*metrics = info->metrics;