Pango Integration?



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.
 
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]