diff options
author | Havoc Pennington <hp@redhat.com> | 2001-02-28 21:15:15 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2001-02-28 21:15:15 +0000 |
commit | 94742208d8f1e274d8a5db4515acfbd4b3d9e4fa (patch) | |
tree | 57e31004de3d14316ad1d54a416bf680b45c3cf2 /pango/pangox.c | |
parent | 77626cb70d108fcba67dbc6085b864fcf166598d (diff) | |
download | pango-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/pangox.c')
-rw-r--r-- | pango/pangox.c | 28 |
1 files changed, 24 insertions, 4 deletions
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; |