Advertising
- Fonts listing
- Monday, February 27th, 2006 at 5:17:18am MST
- /* testing & playing with pango :-) */
- #include <pango/pango.h>
- #include <gtk/gtk.h>
- #include <stdio.h>
- #include <math.h>
- /* signal handler(s) */
- gboolean handle_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
- {
- return FALSE;
- }
- gboolean handle_destroy(GtkWidget *widget, gpointer data)
- {
- gtk_main_quit();
- }
- int main(int argc, char *argv[])
- {
- PangoContext *pg_context = NULL;
- PangoFontFamily **pg_families = NULL;
- gint num_families = 0;
- GtkWidget *window = NULL;
- GtkWidget **labels = NULL;
- GtkWidget *table = NULL;
- GtkWidget *scroller = NULL;
- gint table_dim = 0;
- gint family_offset = 0;
- gint row = 0, col = 0;
- gboolean all_done = FALSE;
- PangoContext *pg_labels_context = NULL;
- PangoFontDescription *pg_labels_desc = NULL;
- const gchar *family_name = NULL;
- /* setup GTK environment */
- gtk_init(&argc, &argv);
- /* create a window & attach required signals */
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(window), "Pango example");
- gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
- /* attach signal handlers to the window */
- gtk_signal_connect(GTK_OBJECT(window), "delete-event", GTK_SIGNAL_FUNC(handle_delete_event), NULL);
- gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(handle_destroy), NULL);
- /* get a pango context form the window */
- pg_context = gtk_widget_get_pango_context(window);
- /* get the font_family listing */
- pango_context_list_families(pg_context, &pg_families, &num_families);
- /* initialize the labels array */
- labels = (GtkWidget **)g_malloc(sizeof(GtkWidget *) * num_families);
- /* init a GtkTable instance to hold all the labels */
- table_dim = ceil(sqrt(num_families));
- table = gtk_table_new(table_dim, table_dim, TRUE);
- /* render each label with its own font */
- pg_labels_desc = pango_font_description_new();
- for(row = 0; row < table_dim; ++row)
- {
- for(col = 0; col < table_dim; ++col)
- {
- /* get the family name in a string & create a label for that name */
- family_name = pango_font_family_get_name(pg_families[family_offset]);
- labels[family_offset] = gtk_label_new(family_name);
- /* get the pango context for that label & modify its font */
- pg_labels_context = gtk_widget_get_pango_context(labels[family_offset]);
- pango_font_description_set_family(pg_labels_desc, family_name);
- gtk_widget_modify_font(labels[family_offset], pg_labels_desc);
- /* add the font to the gtk-table */
- 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);
- family_offset ++;
- /* finish adding to gtk-table when all done */
- if(family_offset == (num_families - 1))
- {
- all_done = TRUE;
- break;
- }
- }
- if(TRUE == all_done)
- break;
- }
- /* pack the window & show it */;
- scroller = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scroller), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
- gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroller), table);
- gtk_container_add(GTK_CONTAINER(window), scroller);
- gtk_window_maximize(GTK_WINDOW(window));
- gtk_widget_show_all(window);
- gtk_main();
- g_free(labels);
- return 0;
- }
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.
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.