Example #1
0
int main(int argc, char **argv) {
	PangoFontMap* map;
	PangoFontFamily **families;
	int n_families;
	int i;
	PangoFontFace **faces;
	int n_faces;
	int j;

	gtk_init(&argc, &argv);

	map = pango_cairo_font_map_get_default();

	pango_font_map_list_families(map, &families, &n_families);

	for (i = 0; i < n_families; i++) {
		g_print("%s\n", pango_font_family_get_name(families[i]));

		pango_font_family_list_faces(families[i], &faces, &n_faces);
		for (j = 0; j < n_faces; j++) {
			g_print("  %s\n", pango_font_face_get_face_name(faces[j]));
		}
	}

	return 0;
}
static int get_faces(PangoFontFamily * family)
{
    PangoFontFace **faces;
    PangoFontFace *face;
    int i, j, n_faces;
    const char *name;
    int availfaces = 0;
    /* Get the faces (Bold, Italic, etc.) for the current font family */
    pango_font_family_list_faces(family, &faces, &n_faces);
    for (i = 0; i < n_faces; i++) {
	face = faces[i];
	name = pango_font_face_get_face_name(face);

	/* if the family face type is one of the known types, logically OR the known type value
	   to the available faces integer */
	for (j = 0; j < FACELIST_SZ; j++) {
	    if (strcasestr(name, facelist[j].name)) {
		availfaces |= facelist[j].flag;
		break;
	    }
	}
    }
    g_free(faces);
    return availfaces;
}
Example #3
0
void
font_print_result (void)
{
  if (options.font_data.separate_output)
    {
      PangoFontFace *face;
      PangoFontFamily *family;
      gint size;

      face = gtk_font_selection_get_face (GTK_FONT_SELECTION (font));
      family = gtk_font_selection_get_family (GTK_FONT_SELECTION (font));
      size = gtk_font_selection_get_size (GTK_FONT_SELECTION (font));

      if (options.common_data.quoted_output)
        {
          gchar *q1 = g_shell_quote (pango_font_family_get_name (family));
          gchar *q2 = g_shell_quote (pango_font_face_get_face_name (face));

          g_printf ("%s%s%s%s%d\n", q1, options.common_data.separator, q2,
                    options.common_data.separator, size / 1000);

          g_free (q1);
          g_free (q2);
        }
      else
        {
          g_printf ("%s%s%s%s%d\n", pango_font_family_get_name (family), options.common_data.separator,
                    pango_font_face_get_face_name (face), options.common_data.separator, size / 1000);
        }
    }
  else
    {
      gchar *fn = gtk_font_selection_get_font_name (GTK_FONT_SELECTION (font));

      if (options.common_data.quoted_output)
        {
          gchar *buf = g_shell_quote (fn);
          g_printf ("%s\n", buf);
          g_free (buf);
        }
      else
        g_printf ("%s\n", fn);

      g_free (fn);
    }
}
Example #4
0
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;
}
Example #5
0
static void
gtk_font_button_update_font_info (GtkFontButton *font_button)
{
  GtkFontButtonPrivate *priv = font_button->priv;
  const gchar *fam_name;
  const gchar *face_name;
  gchar *family_style;

  if (priv->font_family)
    fam_name = pango_font_family_get_name (priv->font_family);
  else
    fam_name = C_("font", "None");
  if (priv->font_face)
    face_name = pango_font_face_get_face_name (priv->font_face);
  else
    face_name = "";

  if (priv->show_style)
    family_style = g_strconcat (fam_name, " ", face_name, NULL);
  else
    family_style = g_strdup (fam_name);

  gtk_label_set_text (GTK_LABEL (font_button->priv->font_label), family_style);
  g_free (family_style);

  if (font_button->priv->show_size) 
    {
      /* mirror Pango, which doesn't translate this either */
      gchar *size = g_strdup_printf ("%2.4g%s",
                                     pango_font_description_get_size (priv->font_desc) / (double)PANGO_SCALE,
                                     pango_font_description_get_size_is_absolute (priv->font_desc) ? "px" : "");
      
      gtk_label_set_text (GTK_LABEL (font_button->priv->size_label), size);
      
      g_free (size);
    }

  gtk_font_button_label_use_font (font_button);
} 
Example #6
0
static void
notify_font_cb (GtkFontChooser *fontchooser, GParamSpec *pspec, gpointer data)
{
  PangoFontFamily *family;
  PangoFontFace *face;

  g_debug ("Changed font name %s", gtk_font_chooser_get_font (fontchooser));

  family = gtk_font_chooser_get_font_family (fontchooser);
  face = gtk_font_chooser_get_font_face (fontchooser);
  if (family)
    {
       g_debug ("  Family: %s is-monospace:%s",
                pango_font_family_get_name (family),
                pango_font_family_is_monospace (family) ? "true" : "false");
    }
  else
    g_debug ("  No font family!");

  if (face)
    g_debug ("  Face description: %s", pango_font_face_get_face_name (face));
  else
    g_debug ("  No font face!");
}
Example #7
0
static void
gtk_font_button_update_font_info (GtkFontButton *font_button)
{
  PangoFontDescription *desc;
  const gchar *family;
  gchar *style;
  gchar *family_style;
  
  desc = pango_font_description_from_string (font_button->priv->fontname);
  family = pango_font_description_get_family (desc);
  
#if 0
  /* This gives the wrong names, e.g. Italic when the font selection
   * dialog displayed Oblique.
   */
  pango_font_description_unset_fields (desc, PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_SIZE);
  style = pango_font_description_to_string (desc);
  gtk_label_set_text (GTK_LABEL (font_button->priv->style_label), style);      
#endif

  style = NULL;
  if (font_button->priv->show_style && family) 
    {
      PangoFontFamily **families;
      PangoFontFace **faces;
      gint n_families, n_faces, i;

      n_families = 0;
      families = NULL;
      pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (font_button)),
                                   &families, &n_families);
      n_faces = 0;
      faces = NULL;
      for (i = 0; i < n_families; i++) 
        {
          const gchar *name = pango_font_family_get_name (families[i]);
          
          if (!g_ascii_strcasecmp (name, family)) 
            {
              pango_font_family_list_faces (families[i], &faces, &n_faces);
              break;
            }
        }
      g_free (families);
      
      for (i = 0; i < n_faces; i++) 
        {
          PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]);
          
          if (font_description_style_equal (tmp_desc, desc)) 
            {
              style = g_strdup (pango_font_face_get_face_name (faces[i]));
              pango_font_description_free (tmp_desc);
              break;
            }
          else
            pango_font_description_free (tmp_desc);
        }
      g_free (faces);
    }

  if (style == NULL || !g_ascii_strcasecmp (style, "Regular"))
    family_style = g_strdup (family);
  else
    family_style = g_strdup_printf ("%s %s", family, style);
  
  gtk_label_set_text (GTK_LABEL (font_button->priv->font_label), family_style);
  
  g_free (style);
  g_free (family_style);

  if (font_button->priv->show_size) 
    {
      gchar *size = g_strdup_printf ("%g",
                                     pango_font_description_get_size (desc) / (double)PANGO_SCALE);
      
      gtk_label_set_text (GTK_LABEL (font_button->priv->size_label), size);
      
      g_free (size);
    }

  gtk_font_button_label_use_font (font_button);
  
  pango_font_description_free (desc);
} 
Example #8
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;
}
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);
        }
    }
}