Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

Fonts listing
Monday, February 27th, 2006 at 5:17:18am MST 

  1. /* testing & playing with pango :-) */
  2.  
  3. #include <pango/pango.h>
  4. #include <gtk/gtk.h>
  5. #include <stdio.h>
  6. #include <math.h>
  7.  
  8.  
  9. /* signal handler(s) */
  10. gboolean handle_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
  11. {
  12.         return FALSE;
  13. }
  14.  
  15.  
  16. gboolean handle_destroy(GtkWidget *widget, gpointer data)
  17. {
  18.         gtk_main_quit();
  19. }
  20.  
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24.         PangoContext *pg_context = NULL;
  25.         PangoFontFamily **pg_families = NULL;
  26.         gint num_families = 0;
  27.        
  28.         GtkWidget *window = NULL;
  29.         GtkWidget **labels = NULL;
  30.         GtkWidget *table = NULL;
  31.         GtkWidget *scroller = NULL;
  32.         gint table_dim = 0;
  33.         gint family_offset = 0;
  34.         gint row = 0, col = 0;
  35.         gboolean all_done = FALSE;
  36.  
  37.         PangoContext *pg_labels_context = NULL;
  38.         PangoFontDescription *pg_labels_desc = NULL;
  39.         const gchar *family_name = NULL;
  40.  
  41.         /* setup GTK environment */
  42.         gtk_init(&argc, &argv);
  43.        
  44.         /* create a window & attach required signals */
  45.         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  46.         gtk_window_set_title(GTK_WINDOW(window), "Pango example");
  47.         gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
  48.        
  49.         /* attach signal handlers to the window */
  50.         gtk_signal_connect(GTK_OBJECT(window), "delete-event", GTK_SIGNAL_FUNC(handle_delete_event), NULL);
  51.         gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(handle_destroy), NULL);
  52.  
  53.         /* get a pango context form the window */
  54.         pg_context = gtk_widget_get_pango_context(window);
  55.  
  56.         /* get the font_family listing */
  57.         pango_context_list_families(pg_context, &pg_families, &num_families);
  58.        
  59.         /* initialize the labels array */
  60.         labels = (GtkWidget **)g_malloc(sizeof(GtkWidget *) * num_families);
  61.        
  62.         /* init a GtkTable instance to hold all the labels */
  63.         table_dim = ceil(sqrt(num_families));
  64.         table = gtk_table_new(table_dim, table_dim, TRUE);
  65.                
  66.         /* render each label with its own font */
  67.         pg_labels_desc = pango_font_description_new();
  68.         for(row = 0; row < table_dim; ++row)
  69.         {
  70.                 for(col = 0; col < table_dim; ++col)
  71.                 {
  72.                         /* get the family name in a string & create a label for that name */
  73.                         family_name = pango_font_family_get_name(pg_families[family_offset]);
  74.                         labels[family_offset] = gtk_label_new(family_name);
  75.                        
  76.                         /* get the pango context for that label & modify its font */
  77.                         pg_labels_context = gtk_widget_get_pango_context(labels[family_offset]);
  78.                         pango_font_description_set_family(pg_labels_desc, family_name);
  79.                         gtk_widget_modify_font(labels[family_offset], pg_labels_desc);
  80.                        
  81.                         /* add the font to the gtk-table */
  82.                         gtk_table_attach(GTK_TABLE(table), labels[family_offset], col, col + 1, row, row + 1, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 6, 6);
  83.                         family_offset ++;
  84.                        
  85.                         /* finish adding to gtk-table when all done */
  86.                         if(family_offset == (num_families - 1))
  87.                         {
  88.                                 all_done = TRUE;               
  89.                                 break;
  90.                         }
  91.                 }
  92.                
  93.                 if(TRUE == all_done)
  94.                         break;
  95.         }       
  96.        
  97.         /* pack the window & show it */;
  98.         scroller = gtk_scrolled_window_new(NULL, NULL);
  99.         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scroller), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
  100.         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroller), table);
  101.         gtk_container_add(GTK_CONTAINER(window), scroller);
  102.        
  103.         gtk_window_maximize(GTK_WINDOW(window));
  104.         gtk_widget_show_all(window);
  105.        
  106.         gtk_main();
  107.  
  108.         g_free(labels);
  109.        
  110.         return 0;
  111. }

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
worth-right