Пример #1
0
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;
}
Пример #2
0
void font_factory::GetUIFamiliesAndStyles(FamilyToStylesMap *map)
{
    g_assert(map);

    if (map) {

        // Gather the family names as listed by Pango
        PangoFontFamily**  families = NULL;
        int numFamilies = 0;
        pango_font_map_list_families(fontServer, &families, &numFamilies);

        for (int currentFamily=0; currentFamily < numFamilies; currentFamily++) {

            // Gather the styles for this family
            PangoFontFace** faces = NULL;
            int numFaces = 0;
            pango_font_family_list_faces(families[currentFamily], &faces, &numFaces);

            for (int currentFace=0; currentFace < numFaces; currentFace++) {

                // If the face has a name, describe it, and then use the
                // description to get the UI family and face strings

                const gchar* displayName = pango_font_face_get_face_name(faces[currentFace]);
                if (displayName == NULL) {
                    continue;
                }

                PangoFontDescription *faceDescr = pango_font_face_describe(faces[currentFace]);
                if (faceDescr) {
                    Glib::ustring familyUIName = GetUIFamilyString(faceDescr);
                    Glib::ustring styleUIName = GetUIStyleString(faceDescr);

                    // Disable synthesized (faux) font faces except for CSS generic faces
                    if (pango_font_face_is_synthesized(faces[currentFace]) ) {
                        if( familyUIName.compare( "sans-serif" ) != 0 &&
                            familyUIName.compare( "serif"      ) != 0 &&
                            familyUIName.compare( "monospace"  ) != 0 &&
                            familyUIName.compare( "fantasy"    ) != 0 &&
                            familyUIName.compare( "cursive"    ) != 0 ) {
                            //std::cout << "faux: " << familyUIName << "  |  " << styleUIName << std::endl;
                            continue;
                        }
                    } 

                    if (!familyUIName.empty() && !styleUIName.empty()) {

                        // Find the right place to put the style information, adding
                        // a map entry for the family name if it doesn't yet exist

                        FamilyToStylesMap::iterator iter = map->find(familyUIName);

                        // Insert new family
                        if (iter == map->end()) {
                            map->insert(std::make_pair(familyUIName, std::list<StyleNames>()));
                        }

                        // Insert into the style list and save the info in the reference maps
                        // only if the style does not yet exist

                        bool exists = false;
                        std::list<StyleNames> &styleList = (*map)[familyUIName];

                        for (std::list<StyleNames>::iterator it=styleList.begin();
                                 it != styleList.end();
                                 ++it) {
                            if ( (*it).CssName == styleUIName) {
                                exists = true;
                                break;
                            }
                        }

                        if (!exists) {
                            styleList.push_back( StyleNames(styleUIName,displayName) );

                            // Add the string info needed in the reference maps
                            fontStringMap.insert(
                                    std::make_pair(
                                            Glib::ustring(familyUIName) + Glib::ustring(styleUIName),
                                            ConstructFontSpecification(faceDescr)));
                            fontInstanceMap.insert(
                                    std::make_pair(ConstructFontSpecification(faceDescr), faceDescr));

                        } else {
                            pango_font_description_free(faceDescr);
                        }
                    } else {
                        pango_font_description_free(faceDescr);
                    }
                }
            }
            g_free(faces);
            faces = 0;
        }
        g_free(families);
        families = 0;

        // Sort the style lists
        for (FamilyToStylesMap::iterator iter = map->begin() ; iter != map->end(); ++iter) {
            (*iter).second.sort(StyleNameCompareInternal);
        }
    }
}