Beispiel #1
0
static void
gimp_font_list_load_names (GimpFontList *list,
                           PangoFontMap *fontmap,
                           PangoContext *context)
{
  PangoFontFamily **families;
  PangoFontFace   **faces;
  gint              n_families;
  gint              n_faces;
  gint              i, j;

  pango_font_map_list_families (fontmap, &families, &n_families);

  for (i = 0; i < n_families; i++)
    {
      pango_font_family_list_faces (families[i], &faces, &n_faces);

      for (j = 0; j < n_faces; j++)
        {
          PangoFontDescription *desc;

          desc = pango_font_face_describe (faces[j]);
          gimp_font_list_add_font (list, context, desc);
          pango_font_description_free (desc);
        }
    }

  g_free (families);
}
Beispiel #2
0
static void
gnm_font_button_update_font_data (GnmFontButton *font_button)
{
  GnmFontButtonPrivate *priv = font_button->priv;
  PangoFontFamily **families;
  PangoFontFace **faces;
  gint n_families, n_faces, i;
  const gchar *family;

  g_assert (priv->font_desc != NULL);

  priv->fontname = pango_font_description_to_string (priv->font_desc);

  family = pango_font_description_get_family (priv->font_desc);
  if (family == NULL)
    return;

  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))
        {
          priv->font_family = g_object_ref (families[i]);

          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, priv->font_desc))
        {
          priv->font_face = g_object_ref (faces[i]);

          pango_font_description_free (tmp_desc);
          break;
        }
      else
        pango_font_description_free (tmp_desc);
    }

  g_free (faces);
}
Beispiel #3
0
/* static */
const vector<string>& FontUtils::ListAvailableFonts() {
  static vector<string> available_fonts_;  // cache list
  if (available_fonts_.size()) {
    return available_fonts_;
  }
#ifndef USE_STD_NAMESPACE
  if (FLAGS_use_only_legacy_fonts) {
    // Restrict view to list of fonts in legacy_fonts.h
    tprintf("Using list of legacy fonts only\n");
    const int kNumFontLists = 4;
    for (int i = 0; i < kNumFontLists; ++i) {
      for (int j = 0; kFontlists[i][j] != NULL; ++j) {
        available_fonts_.push_back(kFontlists[i][j]);
      }
    }
    return available_fonts_;
  }
#endif

  PangoFontFamily** families = 0;
  int n_families = 0;
  ListFontFamilies(&families, &n_families);
  for (int i = 0; i < n_families; ++i) {
    const char* family_name = pango_font_family_get_name(families[i]);
    tlog(2, "Listing family %s\n", family_name);
    if (ShouldIgnoreFontFamilyName(family_name))
      continue;

    int n_faces;
    PangoFontFace** faces = NULL;
    pango_font_family_list_faces(families[i], &faces, &n_faces);
    for (int j = 0; j < n_faces; ++j) {
      PangoFontDescription* desc = pango_font_face_describe(faces[j]);
      char* desc_str = pango_font_description_to_string(desc);
      if (IsAvailableFont(desc_str)) {
        available_fonts_.push_back(desc_str);
      }
      pango_font_description_free(desc);
      g_free(desc_str);
    }
    g_free(faces);
  }
  g_free(families);
  sort(available_fonts_.begin(), available_fonts_.end());
  return available_fonts_;
}
Beispiel #4
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);
} 
Beispiel #5
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;
}
Beispiel #6
0
static void
fill_styles_combo (GtkWidget *combo)
{
  int i;
  GList *style_list = NULL;
  PangoFontFace **faces;
  PangoFontFamily *family, **families;
  FontDescInfo *info;
  int n_families;
  const char *family_name = pango_font_description_get_family(font_description);

  /* 
   * Now map back the given family name to the family. There are more efficient
   * ways to handle this but it should not matter much ...
   */
  pango_context_list_families (context, &families, &n_families);
  g_assert(n_families > 0);
  family = families[0]; /* just in case */
  for (i = 0; i < n_families; i++)
    {
      if (0 == g_strcasecmp(pango_font_family_get_name(families[i]), family_name))
        {
	  family = families[i];
	  break;
	}
    }
  g_free (families);

  info = g_new (FontDescInfo, 1);
  pango_font_family_list_faces (family, &faces, &info->n_descs);

  info->descs = g_new0 (PangoFontDescription*, info->n_descs);
  for (i = 0; i < info->n_descs; i++)
    {
      info->descs[i] = pango_font_face_describe(faces[i]);
    }
  g_free (faces);

  gtk_object_set_data_full (GTK_OBJECT (combo), "descs", info, (GtkDestroyNotify)free_info);

  qsort (info->descs, info->n_descs, sizeof(PangoFontDescription *), font_description_sort_func);

  for (i=0; i<info->n_descs; i++)
    {
      char *str;
	
      PangoFontDescription *tmp_desc;

      tmp_desc = info->descs[i];
      pango_font_description_set_family(tmp_desc, NULL);
      pango_font_description_unset_fields(tmp_desc, PANGO_FONT_MASK_SIZE);
      
      str = pango_font_description_to_string (tmp_desc);
      style_list = g_list_prepend (style_list, str);
    }

  style_list = g_list_reverse (style_list);

  gtk_combo_set_popdown_strings (GTK_COMBO (combo), style_list);
  g_list_foreach (style_list, (GFunc)g_free, NULL);
}
Beispiel #7
0
int main(void)
{
	GtkWidget *mainwin;
	GtkWidget *vbox;
	GtkWidget *sizeSlider;
	GtkWidget *sw;
	GtkWidget *list;
	GtkListStore *fontStore;
	GtkTreeViewColumn *col;
	GtkCellRenderer *r;
	PangoFontMap *pcfm;
	PangoFontFamily **fams;
	int i, n;

	gtk_init(NULL, NULL);

	mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(mainwin, "destroy", G_CALLBACK(gtk_main_quit), NULL);
	gtk_container_set_border_width(GTK_CONTAINER(mainwin), 12);

	vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
	gtk_container_add(GTK_CONTAINER(mainwin), vbox);

	sizeSlider = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, 4, 96, 1);
	gtk_range_set_value(GTK_RANGE(sizeSlider), 10);
	gtk_widget_set_vexpand(sizeSlider, FALSE);
	gtk_container_add(GTK_CONTAINER(vbox), sizeSlider);

	sw = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
	gtk_widget_set_hexpand(sw, TRUE);
	gtk_widget_set_vexpand(sw, TRUE);
	gtk_container_add(GTK_CONTAINER(vbox), sw);

	fontStore = gtk_list_store_new(3,
		G_TYPE_STRING,
		G_TYPE_STRING,
		PANGO_TYPE_FONT_DESCRIPTION);
	list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(fontStore));
	r = gtk_cell_renderer_text_new();
	col = gtk_tree_view_column_new_with_attributes("Family", r,
		"text", 0,
		NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(list), col);
	r = gtk_cell_renderer_text_new();
	g_object_bind_property(gtk_range_get_adjustment(GTK_RANGE(sizeSlider)), "value",
		r, "size-points",
		G_BINDING_SYNC_CREATE);
	col = gtk_tree_view_column_new_with_attributes("Sample", r,
		"text", 1,
		"font-desc", 2,
		NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(list), col);
	gtk_container_add(GTK_CONTAINER(sw), list);

	pcfm = pango_cairo_font_map_get_default();
	pango_font_map_list_families(pcfm, &fams, &n);
	for (i = 0; i < n; i++) {
		PangoFontFace **faces;
		int j, m;

		pango_font_family_list_faces(fams[i], &faces, &m);
		for (j = 0; j < m; j++) {
			PangoFontDescription *desc;
			GtkTreeIter iter;

			desc = pango_font_face_describe(faces[j]);
			if (pango_font_description_get_variant(desc) != PANGO_VARIANT_SMALL_CAPS) {
				pango_font_description_free(desc);
				continue;
			}
			gtk_list_store_append(fontStore, &iter);
			gtk_list_store_set(fontStore, &iter,
				0, pango_font_description_get_family(desc),
				1, "The quick brown fox jumped over the lazy dog.",
				2, desc,
				-1);
		}
		g_free(faces);
	}
	g_free(fams);

	gtk_widget_show_all(mainwin);
	gtk_main();
	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);
        }
    }
}