pango pango_context_get_language
// Returns the approximate number of characters that can horizontally fit in // |pixel_width| pixels. int GetCharacterWidthForPixels(GtkWidget* widget, int pixel_width) { DCHECK(gtk_widget_get_realized(widget)) << " widget must be realized to compute font metrics correctly"; PangoContext* context = gtk_widget_create_pango_context(widget); GtkStyle* style = gtk_widget_get_style(widget); PangoFontMetrics* metrics = pango_context_get_metrics( context, style->font_desc, pango_context_get_language(context)); <====== // This technique (max of char and digit widths) matches the code in // gtklabel.c. int char_width = pixel_width * PANGO_SCALE / std::max(pango_font_metrics_get_approximate_char_width(metrics), pango_font_metrics_get_approximate_digit_width(metrics)); pango_font_metrics_unref(metrics); g_object_unref(context); return char_width; }
chromium/gtk_util.cc at master · trevorlinton/chromium · GitHub