views:

113

answers:

1

I have a PangoFontDescription and I want to know whether it describes a monospace font.

I have seen the function pango_font_family_is_monospace() in the Pango API documentation but after several hours of puzzling it is still not clear to me what the relationships are between PangoFontFamily, PangoFontMap, PangoFont, PangoFontset, PangoContext, and PangoFontDescription and whether I need any or all of these to achieve what I want. So far, PangoFontDescription is the only part of Pango I've needed to use, as GTK manages to abstract everything else away.

Can anyone who has done this before help me out?

+2  A: 

You can use pango_font_description_get_family() and after that call pango_font_family_is_monospace() on the result.

EDIT:

Since pango_font_description_get_family() returns only a name you can do this: call pango_context_list_families() and search for a family object that has that name. After that, call pango_font_family_is_monospace() on the found object. Not sure what to do if no family object with that name is found, though.

doublep
But pango_font_description_get_family() returns the name of the font family, and pangofont_family_is_monospace() requires an actual PangoFontFamily pointer. I don't think this works.
unwind
@unwind: See edit.
doublep
How do I get the `PangoContext` from the `PangoFontDescription`? Usually the `PangoContext` is associated with a `GtkWidget` but it seems to me I shouldn't need a widget to find out whether a font is monospace or not.
ptomato
@ptomato: You can't. I looked it up in source code and `PangoFontDescription` simply doesn't refer to a family object. There is no way to find whether a family is monospace just from name and the only way to get a `PangoFontFamily` appears to be from a `PangoContext`.
doublep
@doublep: Thanks. @ptomato: It might be that theming can change which actual font a family maps to, which might make it impossible to determine without becoming a bit more concrete. Not saying that is *is* so, but it that it could be.
unwind
Hmm. Thanks for the answers. Disappointing, but I guess you're right.
ptomato