Re: Weird behaviour when etting font size in vte



Eduardo M KALINOWSKI wrote:

I'm using a vte in my program. I wanted the hability to set the font used by the terminal emulator, so I'm using a GtkFontButton to pop-up a font selector, and then I set the vte font from what the user chose.

The code works, but there is an interesting behaviour: the size of the font that the vte starts using is not the size of the font that is displayed in the preview area of the font selection dialog.

   I'm attaching a sample program that shows this strange behaviour.

Here is the program:
#include <string.h>
#include <gtk/gtk.h>
#include <vte/vte.h>


void
font_set_cb(GtkFontButton *font_btn, gpointer data)
{
 VteTerminal *vte;
 char *font_name;

 vte = VTE_TERMINAL(data);
 font_name = gtk_font_button_get_font_name(font_btn);
 printf("Changing to %s\n", font_name);
 vte_terminal_set_font_from_string(vte, font_name);
 font_name = pango_font_description_to_string(vte_terminal_get_font(vte));
 printf("Changed to %s\n", font_name);
 g_free(font_name);
}


GtkWidget*
create_main_window()
{
 GtkWidget *window;
 GtkWidget *vbox;
 GtkWidget *vte;
 GtkWidget *fontBtn;
 char      *font_name;
 int        i;
 char      *test_str = "The Quick Brown Fox Jumps Over The Lazy Dog\n\r";

 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_window_set_title(GTK_WINDOW(window), "VTE Test");

 vbox = gtk_vbox_new(FALSE, 0);

 vte = vte_terminal_new();
 vte_terminal_set_encoding(VTE_TERMINAL(vte), "UTF-8");
 vte_terminal_set_size(VTE_TERMINAL(vte), 80, 24);

 gtk_box_pack_start(GTK_BOX(vbox), vte, TRUE, TRUE, 0);

font_name = pango_font_description_to_string(vte_terminal_get_font(VTE_TERMINAL(vte)));
 printf("Initial font: %s\n", font_name);
 fontBtn = gtk_font_button_new_with_font(font_name);
 g_free(font_name);
 g_signal_connect(G_OBJECT(fontBtn), "font-set",
                  G_CALLBACK(font_set_cb), vte);
 gtk_box_pack_start(GTK_BOX(vbox), fontBtn, FALSE, FALSE, 0);

 /* Add some sample text to the terminal */
 for (i = 0; i < 20; ++i) {
   vte_terminal_feed(VTE_TERMINAL(vte), test_str, strlen(test_str));
 }

 gtk_container_add(GTK_CONTAINER(window), vbox);

 return window;
}


int
main(int argc, char *argv[], char *env[])
{
 GtkWidget *wndMain;

 gtk_init(&argc, &argv);
 wndMain = create_main_window();
 gtk_widget_show_all(wndMain);

 gtk_main();

 return 0;
}


--
Necessity hath no law.
                -- Oliver Cromwell

Eduardo M KALINOWSKI
ekalin bol com br
http://move.to/hpkb




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]