<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Many thanks Bill for the very useful information.<br><br>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:<br><br>pfd = pango_font_face_describe(face);<br>pstyle = pango_font_description_get_style( pfd ); //ok<br>pwt = pango_font_description_get_weight( pfd ); //ok<br>psz = pango_font_description_get_size( pfd ); // 0 - not ok<br><br>Your dump_stuff function also did not return any size-list information.<br>What might be the cause?<br><br>Ken<br> <br><br></span></div><div><br></div>  <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1">  <font
 face="Arial" size="2"> <b><span style="font-weight:bold;">From:</span></b> Bill Spitzak <spitzak@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> Ken Resander <kresander@yahoo.com>; Cairo Mailing List <cairo@cairographics.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Wednesday, 10 April 2013, 18:10<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [cairo] How to check if a font exists in Cairo and Pango?<br> </font> </div> <div class="y_msg_container"><br>This code dumps the list of Pango fonts, and I believe the same strings are usable as toy fonts:<br><br><br>#include "cairot.h"<br>#include <cairo/cairo.h><br>#include <pango/pangocairo.h><br>#include <math.h><br>#include <stdio.h><br><br>// PangoLayout* layout = pango_cairo_create_layout(cairo_t);<br><br>void dump_stuff(PangoLayout* layout) {<br>  PangoContext* context =
 pango_layout_get_context(layout);<br>  PangoFontFamily** families; int n;<br>  pango_context_list_families(context, &families, &n);<br>  printf("%d families:\n", n);<br>  for (int i=0; i < n; i++) {<br>    PangoFontFamily* family = families[i];<br>    if (!PANGO_IS_FONT_FAMILY(family)) {<br>      printf("a %s\n", G_OBJECT_TYPE_NAME(family));<br>      continue;<br>    }<br>    printf("%s\n", pango_font_family_get_name(family));<br>    PangoFontFace** faces; int m;<br>    pango_font_family_list_faces(family, &faces, &m);<br>    for (int j = 0; j < m; j++) {<br>      PangoFontFace* face = faces[j];<br>      printf("  %s", pango_font_face_get_face_name(face));<br>      int* sizes; int nsizes;<br>      pango_font_face_list_sizes(face, &sizes,
 &nsizes);<br>      if (sizes) {<br>    for (int k = 0; k < nsizes; ++k) printf(" %d", sizes[k]);<br>    g_free(sizes);<br>      }<br>      if (pango_font_face_is_synthesized(face)) printf(" *");<br>      printf("\n");<br>    }<br>    g_free(faces);<br>  }<br>  g_free(families);<br>}<br><br><br>On 04/10/2013 09:01 AM, Ken Resander wrote:<br>> My application should check if a font exists and if it does not try the<br>> next font preference obtained from the user, a bit like processing a<br>> font-choice list in CSS.<br>> <br>> Cairo:<br>> const char * str = "nosuchfont";<br>> cairo_font_face_t * ff =<br>>   cairo_toy_font_face_create ( str ,<br>>                                CAIRO_FONT_SLANT_NORMAL ,<br>> 
                               CAIRO_FONT_WEIGHT_NORMAL ) ;<br>> const char * toyfamilyis = cairo_toy_font_face_get_family ( ff );<br>> <br>> The toyfamilyis was returned as 'nosuchfont'. The manual mentions that<br>> toy_font_face_create and the cairo_font_select_face do not report back<br>> whether the font exists or not. A pity. If it returned NULL for a<br>> non-existent choice then my program could loop through the user preferences.<br>> <br>> I also tried pango:<br>> PangoFontDescription * pfd = pango_font_description_from_string ( str );<br>> const char * familyis = pango_font_description_get_family(pfd);<br>> <br>> This time familyis was also returned as 'nosuchfont'.<br>> <br>> I have read somewhere that pango can tell if a font exists.<br>> <br>> How can I make it return this information?<br>> <br>> Ken<br>>
 <br>> <br><br><br><br></div> </div> </div>  </div></body></html>