PROGRAM(GdkFont);
FUNCTION(create, "function(string|void:void)");
NAME_ARGS(font_name);
// Create a new font. The string is the font string. 
{
  char *n;
  if(args)
  {
    get_all_args("Gdk.Font", args, "%s", &n);
    THIS->obj = (void*)gdk_font_load( n );
    if(!THIS->obj)
      error("Failed to load font.\n");
  } else { 
  }
}
FUNCTION(destroy, "function(void:void)");
// Free the font, called automatically by pike when the object is destroyed.
{
  if(THIS->obj)
    gdk_font_unref( (GdkFont*)THIS->obj );
}
FUNCTION(text_width, "function(string,int|void:int)")
NAME_ARGS(text,force_16bitwidestring);
// Gives the width, in pixels, of the text. If force_wide is true, the 
// text will be padded or shrunk to 16bit characters, no matter what
// the original width of the text was. This is useful when the font is 
// a X 16bit wide font.
{
  struct pike_string *s;
  char *swapped;
  get_all_args("text_width", args, "%W", &s);
  if(swapped = get_swapped_string( s,args>1 ))
  {
    push_int(gdk_text_width((GdkFont*)THIS->obj,
			    swapped,s->len<<s->size_shift));
    free(swapped);
  } else {
    push_int(gdk_text_width((GdkFont*)THIS->obj,
			    s->str,s->len<<s->size_shift));
  }
}
FUNCTION(char_width, "function(int:int)")
NAME_ARGS(character);
{
  push_int(gdk_char_width((GdkFont*)THIS->obj, sp[-args].u.integer));
}
