GTk Related Question

From: Date: Mon, 15 Sep 2003 20:40:28 +0000
Subject: GTk Related Question
Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-3891@lists.php.net to get a copy of this message
Greetings PHP-GTK Crew, This question does not related directly to the php-gtk project, but I am hoping that you all wont mind and will perhaps be able to offer some advice, it would be greatly appreciated. I have some c code which accesses Pango to find out what the width is of a given string with font and font size. Works well when called from the command line. When I call this program from PHP (with exec) it works, but the output array contains no data from after the points I initialise a GTK object ( e.g. gtk_init(&argc, &argv); ). It seems wasteful to write the output from the program to file, when I should be able to pipe it directly into PHP, and I just thought that as Pango is part of GTK you guys might have an idea about what is causing the problem .... I've included the code just for fun, it really is a simple problem, but it is sure causing me a large headache. Thanks to all, Zitan. /* pango_get_width Compile Instructions: gcc pkg-config --cflags gtk+-2.0 pango_get_width.c \ pkg-config --libs gtk+-2.0 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <gtk/gtk.h> /* Written by Attin Cotteral */ static gint char_width_from_layout (PangoFontDescription *pfd, const gchar *s) { GtkWidget *w; PangoContext *pc; PangoLayout *pl; gint width; w = gtk_label_new(NULL); pc = gtk_widget_get_pango_context(w); pango_context_set_font_description(pc, pfd); pl = pango_layout_new(pc); pango_layout_set_text(pl, s, -1); pango_layout_get_pixel_size(pl, &width, NULL); g_object_unref(G_OBJECT(pl)); g_object_unref(G_OBJECT(pc)); gtk_widget_destroy(w); return width; } int main (int argc, char *argv[]) { gint i, width; gchar fontname[128]; gchar inputtext[255]; gchar width_output[255]; PangoFontDescription *pfd; if (argc < 2) { fprintf(stderr, "%s: error fontname < 128 chars\n",argv[0]); exit(EXIT_FAILURE); } *fontname = 0; strcpy(fontname, argv[1]); strcpy(inputtext, argv[2]); i = 2; printf("Got fontname '%s', %d\n", fontname,i); gtk_init(&argc, &argv); // why after calling this command PHP stops getting output? Have tested by putting printf statements before and after init call pfd = pango_font_description_from_string(fontname); width = char_width_from_layout(pfd, inputtext); /* Never get this output */ printf("Got char width of %d\n", width); return 0; }

« previous php.gtk.general (#3891) next »