Re: Pango Integration?
- From: Noah Levitt <nlevitt columbia edu>
- To: Zitan Broth <zitan mediasculpt net>
- Cc: gtk-i18n-list gnome org
- Subject: Re: Pango Integration?
- Date: Thu, 18 Sep 2003 23:01:46 -0400
gtk_init tries to open the X display.
You don't need to use gtk+ for this program at all (neither
does Attin Cotteral). You can create a PangoContext the way
pangoft2topgm.c does:
fontmap = pango_ft2_font_map_new ();
pango_ft2_font_map_set_resolution (PANGO_FT2_FONT_MAP (fontmap), 96, 96);
context = pango_ft2_font_map_create_context (PANGO_FT2_FONT_MAP (fontmap));
Noah
On Fri, Sep 19, 2003 at 14:45:23 -0700, Zitan Broth wrote:
> Greetings All,
>
> I'm having a problem calling Pango from PHP, which is most likely PHP related, but I thought you all might be able to help me - at least interpret the error I am getting. The php-gtk project haven't worked with GTK 2.0 yet so ....
>
> I have some c code (a **special** thanks to Attin Cotteral for this) 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, and I've included the code and compile instructions below :-)
>
> When I call this program from PHP it gives me the output:
> ./pango/pango_get_width "arial 12" "bumpylove"
> (pango_get_width:5039): Gtk-WARNING **: cannot open display:
> Got fontname 'arial 12'
> Got input text 'bumpylove'
>
> What I'm wondering is what the Gtk-WARNING means? This has been rather a large headache so any help is **hugely** appreciated :-)
>
> 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);
>
> pfd = pango_font_description_from_string(fontname);
>
> width = char_width_from_layout(pfd, inputtext);
>
> printf("Got char width of %d\n", width);
>
> return 0;
> }
>
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]