Re: GTk Related Question
| From: | Steph | Date: | Mon, 15 Sep 2003 02:58:51 +0000 |
| Subject: | Re: GTk Related Question | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-3892@lists.php.net to get a copy of this message | ||
We don't have PHP bindings for GTK2 yet, and Pango isn't assimilated
into GTK1.
Try the Python guys (and don't tell anyone I said so ;)
----- Original Message -----
From: "Zitan Broth" <zitan@mediasculpt.net>
To: <php-gtk-general@lists.php.net>
Sent: Monday, September 15, 2003 8:40 PM
Subject: [PHP-GTK] GTk Related Question
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;
}