pango_layout_get_size() return 0


I have some code that enumerates Pango font families
and then calculates the widths of some text (actually
only some characters). The problem I have is that
pango_layout_get_size() return 0 width for many
font families (even Sans) so I must be doing something
wrong. The code is as simple as this:

        PangoFontFamily **families = NULL;
        gint n_families = 0;
        pango_context_list_families( context,  &families, &n_families

        for (int i=0; i<n_families; i++)
            const gchar *name = pango_font_family_get_name( families[i]
            if (true)
                PangoFontDescription *desc =
                pango_font_description_set_family( desc, name );
                pango_font_description_set_size( desc, 12 );
                PangoLayout *layout = pango_layout_new(context);
                pango_layout_set_font_description(layout, desc);
                pango_layout_set_text(layout, "i", 1 );
                int i_width = 0;
                pango_layout_get_size(layout, &i_width, NULL);
                pango_layout_set_text(layout, "W", 1 );
                int W_width = 0;
                pango_layout_get_size(layout, &W_width, NULL);
                g_object_unref( G_OBJECT( layout ) );
                pango_font_description_free( desc );
                if (W_width != i_width) continue;

But W_width and i_width are 0 for many font families (sometimes
for both "i" and "W", sometimes for either of them, sometimes
for none of them. It seems arbitrary and surely not right.

Thanks for any hint,

Robert Roebling, MD <robert roebling medizin uni-ulm de>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]