summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2001-02-28 20:22:09 +0000
committerHavoc Pennington <hp@src.gnome.org>2001-02-28 20:22:09 +0000
commit77626cb70d108fcba67dbc6085b864fcf166598d (patch)
tree6456900bad57025c22579b6490a2b71f71e237eb /pango
parent835ef9ddfc5d71b136ed5c491533d76875bd6951 (diff)
downloadpango-77626cb70d108fcba67dbc6085b864fcf166598d.tar.gz
Add approximate_char_width field
2001-02-28 Havoc Pennington <hp@redhat.com> * pango/pango-font.h (struct _PangoFontMetrics): Add approximate_char_width field * pango/pangox.c (get_font_metrics_from_subfonts): "compute" the approximate char width. Other backends need to add this.
Diffstat (limited to 'pango')
-rw-r--r--pango/pango-font.h1
-rw-r--r--pango/pangox.c42
2 files changed, 43 insertions, 0 deletions
diff --git a/pango/pango-font.h b/pango/pango-font.h
index cac1b7bb..109a7819 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -90,6 +90,7 @@ struct _PangoFontMetrics
{
int ascent;
int descent;
+ int approximate_char_width;
};
PangoFontDescription *pango_font_description_copy (const PangoFontDescription *desc);
diff --git a/pango/pangox.c b/pango/pangox.c
index 509c5c35..172f64aa 100644
--- a/pango/pangox.c
+++ b/pango/pangox.c
@@ -522,6 +522,30 @@ pango_x_font_get_glyph_extents (PangoFont *font,
}
}
+static gboolean
+get_int_prop (Atom atom,
+ XFontStruct *fs,
+ gint *val)
+{
+ gint i;
+
+ *val = 0;
+
+ i = 0;
+ while (i < fs->n_properties)
+ {
+ if (fs->properties[i].name == atom)
+ {
+ *val = fs->properties[i].card32;
+ return TRUE;
+ }
+
+ ++i;
+ }
+
+ return FALSE;
+}
+
/* Get composite font metrics for all subfonts in list
*/
static void
@@ -529,8 +553,15 @@ get_font_metrics_from_subfonts (PangoFont *font,
GSList *subfonts,
PangoFontMetrics *metrics)
{
+ PangoXFont *xfont = (PangoXFont *)font;
GSList *tmp_list = subfonts;
gboolean first = TRUE;
+ gint total_avg_widths = 0;
+ gint n_avg_widths = 0;
+ Atom avg_width_atom;
+
+ avg_width_atom = pango_x_fontmap_atom_from_name (xfont->fontmap,
+ "AVERAGE_WIDTH");
metrics->ascent = 0;
metrics->descent = 0;
@@ -542,6 +573,8 @@ get_font_metrics_from_subfonts (PangoFont *font,
if (subfont)
{
XFontStruct *fs = pango_x_get_font_struct (font, subfont);
+ gint avg_width;
+
if (fs)
{
if (first)
@@ -556,12 +589,21 @@ get_font_metrics_from_subfonts (PangoFont *font,
metrics->descent = MAX (fs->descent * PANGO_SCALE, metrics->descent);
}
}
+
+ if (!get_int_prop (avg_width_atom, fs, &avg_width))
+ avg_width = (fs->min_bounds.width + fs->max_bounds.width) / 2;
+
+ total_avg_widths += avg_width;
+ n_avg_widths += 1;
}
else
g_warning ("Error parsing ligature info: Invalid subfont %d in get_font_metrics_from_subfonts", GPOINTER_TO_UINT (tmp_list->data));
tmp_list = tmp_list->next;
}
+
+ /* This is pretty darn bogus. */
+ metrics->approximate_char_width = total_avg_widths / n_avg_widths;
}
/* Get composite font metrics for all subfonts resulting from shaping