Re: How to check if a font exists in Cairo and Pango?
Ken Resander <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
Many thanks Bill for the very useful information. I will use it to check that family, style and weight are available for a choice. Would have liked to include size (in pts) too, but it (psz) was always returned as 0 by: pfd = pango_font_face_describe(face); pstyle = pango_font_description_get_style( pfd ); //ok pwt = pango_font_description_get_weight( pfd ); //ok psz = pango_font_description_get_size( pfd ); // 0 - not ok Your dump_stuff function also did not return any size-list information. What might be the cause? Ken ________________________________ From: Bill Spitzak <[email protected]> To: Ken Resander <[email protected]>; Cairo Mailing List <[email protected]> Sent: Wednesday, 10 April 2013, 18:10 Subject: Re: [cairo] How to check if a font exists in Cairo and Pango? This code dumps the list of Pango fonts, and I believe the same strings are usable as toy fonts: #include "cairot.h" #include <cairo/cairo.h> #include <pango/pangocairo.h> #include <math.h> #include <stdio.h> // PangoLayout* layout = pango_cairo_create_layout(cairo_t); void dump_stuff(PangoLayout* layout) { PangoContext* context = pango_layout_get_context(layout); PangoFontFamily** families; int n; pango_context_list_families(context, &families, &n); printf("%d families:\n", n); for (int i=0; i < n; i++) { PangoFontFamily* family = families[i]; if (!PANGO_IS_FONT_FAMILY(family)) { printf("a %s\n", G_OBJECT_TYPE_NAME(family)); continue; } printf("%s\n", pango_font_family_get_name(family)); PangoFontFace** faces; int m; pango_font_family_list_faces(family, &faces, &m); for (int j = 0; j < m; j++) { PangoFontFace* face = faces[j]; printf(" %s", pango_font_face_get_face_name(face)); int* sizes; int nsizes; pango_font_face_list_sizes(face, &sizes, &nsizes); if (sizes) { for (int k = 0; k < nsizes; ++k) printf(" %d", sizes[k]); g_free(sizes); } if (pango_font_face_is_synthesized(face)) printf(" *"); printf("\n"); } g_free(faces); } g_free(families); } On 04/10/2013 09:01 AM, Ken Resander wrote: > My application should check if a font exists and if it does not try the > next font preference obtained from the user, a bit like processing a > font-choice list in CSS. > > Cairo: > const char * str = "nosuchfont"; > cairo_font_face_t * ff = > cairo_toy_font_face_create ( str , > CAIRO_FONT_SLANT_NORMAL , > CAIRO_FONT_WEIGHT_NORMAL ) ; > const char * toyfamilyis = cairo_toy_font_face_get_family ( ff ); > > The toyfamilyis was returned as 'nosuchfont'. The manual mentions that > toy_font_face_create and the cairo_font_select_face do not report back > whether the font exists or not. A pity. If it returned NULL for a > non-existent choice then my program could loop through the user preferences. > > I also tried pango: > PangoFontDescription * pfd = pango_font_description_from_string ( str ); > const char * familyis = pango_font_description_get_family(pfd); > > This time familyis was also returned as 'nosuchfont'. > > I have read somewhere that pango can tell if a font exists. > > How can I make it return this information? > > Ken > > -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo