static PyObject * pango_GetFontMap(PyObject *self, PyObject *args) { PangoFontMap *fm; PangoContext *ctx; PangoFontFamily **families; PangoFontFace **faces; PyObject *family; int n_families, n_faces, i, j; int *sizes, n_sizes; PyObject *faces_tuple; PyObject *ret; fm = pango_cairo_font_map_get_default(); ctx = pango_font_map_create_context(fm); pango_context_list_families(ctx, &families, &n_families); ret = PyTuple_New(n_families); for (i = 0; i < n_families; i++) { family = PyTuple_New(2); PyTuple_SetItem(family, 0, Py_BuildValue("s", pango_font_family_get_name(families[i]))); pango_font_family_list_faces(families[i], &faces, &n_faces); pango_font_face_list_sizes(faces[0], &sizes, &n_sizes); if (!sizes) { faces_tuple = PyTuple_New(n_faces); for (j = 0; j < n_faces; j++) { PyTuple_SetItem(faces_tuple, j, Py_BuildValue("s", pango_font_face_get_face_name(faces[j]))); } PyTuple_SetItem(family, 1, faces_tuple); } else { Py_INCREF(Py_None); PyTuple_SetItem(family, 1, Py_None); } PyTuple_SetItem(ret, i, family); g_free(sizes); g_free(faces); } g_free(families); g_object_unref(ctx); return ret; }
int main (int argc, char **argv) { PangoFontMap *fontmap; PangoFontFamily **families; int n_families; int i, j, k; #if !GLIB_CHECK_VERSION (2, 35, 3) g_type_init(); #endif g_set_prgname ("pango-list"); /* Use PangoCairo to get default fontmap so it works on every platform. */ fontmap = pango_cairo_font_map_get_default (); pango_font_map_list_families (fontmap, &families, &n_families); for (i = 0; i < n_families; i++) { PangoFontFace **faces; int n_faces; const char *family_name = pango_font_family_get_name (families[i]); g_print ("%s\n", family_name); pango_font_family_list_faces (families[i], &faces, &n_faces); for (j = 0; j < n_faces; j++) { const char *face_name = pango_font_face_get_face_name (faces[j]); gboolean is_synth = pango_font_face_is_synthesized (faces[j]); const char *synth_str = is_synth ? "*" : ""; g_print (" %s%s\n", synth_str, face_name); if (0) { int *sizes; int n_sizes; pango_font_face_list_sizes (faces[j], &sizes, &n_sizes); if (n_sizes) { g_print (" {"); for (k = 0; k < n_sizes; k++) { if (k) g_print (", "); g_print ("%g", pango_units_to_double (sizes[k])); } g_print ("}\n"); } g_free (sizes); } if (1) { PangoFontDescription *desc = pango_font_face_describe (faces[j]); char *desc_str = pango_font_description_to_string (desc); g_print (" \"%s\"\n", desc_str); g_free (desc_str); pango_font_description_free (desc); } } g_free (faces); } g_free (families); g_object_unref (fontmap); return 0; }