示例#1
0
static gint
gtk_hex_entry_motion (GtkWidget *widget, GdkEventMotion *event)
{
	GtkHexEntry *hex_entry;
	gint x;
		
	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (GTK_IS_HEX_ENTRY (widget), FALSE);

	hex_entry = GTK_HEX_ENTRY (widget);

	if (hex_entry->button == 0) return FALSE;

	x = event->x;
	if (event->is_hint || (widget->window != event->window))
		gdk_window_get_pointer (widget->window, &x, NULL, NULL);

	hex_entry->cursor_position = x / gdk_char_width (hex_entry->font,'0');
	hex_entry->selection_end_pos = hex_entry->cursor_position;

	if (hex_entry->selection_end_pos < hex_entry->selection_start_pos)
	{
		hex_entry->selection_end_pos = hex_entry->selection_start_pos;
		hex_entry->selection_start_pos = hex_entry->cursor_position;
	}

	queue_draw (hex_entry);

	return TRUE;
}
示例#2
0
static void
gtk_hex_entry_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
	GtkHexEntry *hex_entry;

	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_IS_HEX_ENTRY (widget));
	g_return_if_fail (requisition != NULL);

	hex_entry = GTK_HEX_ENTRY (widget);

	requisition->width = (hex_entry->digits * gdk_char_width (hex_entry->font,'1'));
	requisition->height = hex_entry->font->ascent + hex_entry->font->descent;
}
示例#3
0
文件: gdkfont.c 项目: amery/clip-itk
/* Determine the width of a given character. */
int
clip_GDK_CHARWIDTH(ClipMachine * cm)
{
	C_object      *cfont = _fetch_co_opt(cm);
	gchar * string = _clip_parc(cm,2);
	CHECKCOBJOPT(cfont,GDK_IS_FONT(cfont));
	CHECKARG(2,CHARACTER_t);
	LOCALE_TO_UTF(string);
	_clip_retni(cm,gdk_char_width(GDK_FONT(cfont->object), *string));
	FREE_TEXT(string);
	return 0;
err:
	return 1;
}
示例#4
0
/**
 * Allocate memory for list status view structure and initialize it with
 * correct values.
 *
 * \todo: All of the values are hardcoded now, but it should be possible to make
 * them used settable through configuration storage. It would mean to refactor
 * the configuration storage though (flag option list won't be sufficient
 * anymore, especially for colors).
 *
 * \return pointer to image display specific data
 */
ViewListStatus* view_lsv_create(ViewGeneric *parent) {
	const ConfigStorage* conf;
	ViewListStatus *result = NULL;
	GdkFont* font = NULL;

	ASSERT( NULL != parent );

	font = gdk_font_load(DEFAULT_FONT_NAME);
	if ( NULL == font ) {
		ERROR_SET(ERROR.INVALID_PARAM);
		ERROR_NOTE("Font %s does not load", DEFAULT_FONT_NAME);
		return  result;
	}

	if ( NULL == ( result = (ViewListStatus*) g_try_malloc0(sizeof(ViewListStatus))) ) {
		ERROR_SET(ERROR.MEMORY_FAILURE);
		return result;
	}

	result->border_size.x = 5;
	result->border_size.y = 2;

	/// \todo for now, we assume that the font is monospace and does not contain
	// wide characters
	result->text_size.x = gdk_char_width(font, 'A');
	result->text_size.y = gdk_char_height(font, 'A');

	result->color.fg.red = 65535;
	result->color.fg.green = 65535;
	result->color.fg.blue = 65535;

	result->color.bg.red = 0;
	result->color.bg.green = 0;
	result->color.bg.blue = 0;

	result->font = font;

	parent->region_hint.y = result->text_size.y + 2 * result->border_size.y;

	return result;
}
示例#5
0
static gint
gtk_hex_entry_button_press (GtkWidget *widget, GdkEventButton *event)
{
	GtkHexEntry *hex_entry;

	g_return_val_if_fail (widget != NULL, FALSE);
	g_return_val_if_fail (GTK_IS_HEX_ENTRY (widget), FALSE);

	hex_entry = GTK_HEX_ENTRY (widget);
	hex_entry->button = event->button;

	if (!GTK_WIDGET_HAS_FOCUS (widget))
		gtk_widget_grab_focus (widget);

	if (event->button==1)
	{
		switch (event->type)
		{
			case GDK_BUTTON_PRESS:
				gtk_grab_add (widget);
				hex_entry->has_selection = TRUE;
				hex_entry->cursor_position = event->x / gdk_char_width (hex_entry->font,'0');
				hex_entry->selection_end_pos =
				hex_entry->selection_start_pos = hex_entry->cursor_position;
				break;
			case GDK_2BUTTON_PRESS:
				hex_entry->selected ^= 1;
				break;
			
			default:
				break;
		}
	}

	return TRUE;
}
示例#6
0
GtkWidget *setupLCD(GtkWidget *parent, int rows, int cols, char *font){
   int i;
   int width;
   int wid, hgt;
#ifdef GTK_VER_1_1
   static GtkTargetEntry targetlist[] = {
     /* Target          Flags  Info      */
     { "STRING",        0,     TARGET_STRING },
     { "TEXT",          0,     TARGET_TEXT },
     { "COMPOUND_TEXT", 0,     TARGET_COMPOUND_TEXT } 
   };
   static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]);
#endif

   /* store arguments */
   lcdWidth = cols;
   lcdHeight = rows;

#ifdef USE_PANGO
   lcdDA = gtk_drawing_area_new();
   pango_layout = gtk_widget_create_pango_layout(lcdDA, NULL);
   pango_desc = pango_font_description_from_string(font?font:"Liberation Mono 16");
   pango_fontmap = pango_cairo_font_map_get_default();
   pango_context = pango_cairo_font_map_create_context( (PangoCairoFontMap *)pango_fontmap );
   pango_font = pango_context_load_font(pango_context, pango_desc);
   pango_metrics =
      pango_context_get_metrics(pango_context, pango_desc, pango_language_get_default());

   fontW = (pango_font_metrics_get_approximate_digit_width(pango_metrics))/PANGO_SCALE;
   fontH = (pango_font_metrics_get_ascent(pango_metrics) + pango_font_metrics_get_descent(pango_metrics))/PANGO_SCALE;
   fontD = pango_font_metrics_get_descent(pango_metrics)/PANGO_SCALE;

   gtk_widget_modify_font(lcdDA, pango_desc);
#else
   fontW = 0;
   fontH = 0;
   fontD = 0;

   /* get a font for the main window */
   if(font != NULL){
      if(NULL == (lcdFont = gdk_font_load(font))){
         fprintf(stderr, "Unable to load font %s.\n", font);
         exit(0);
      }
   } else if(NULL == (lcdFont = gdk_font_load(FONT1)) &&
      NULL == (lcdFont = gdk_font_load(FONT2)) &&
      NULL == (lcdFont = gdk_font_load(FONT3)) &&
      NULL == (lcdFont = gdk_font_load(FONT4)) &&
      NULL == (lcdFont = gdk_font_load(FONT5)) &&
      NULL == (lcdFont = gdk_font_load(FONT6))){

      fprintf(stderr, "Unable to load a font.\n");
      exit(0);
   }

   /* find max font width */
   for(i=0; i<256; i++){
      width = gdk_char_width(lcdFont, (gchar)i);
      if(width < 50 && width > fontW) fontW = width;
   }

   /* globals we use all over the place */
   fontH = lcdFont->ascent + lcdFont->descent;
   fontD = lcdFont->descent;
#endif

   if(fontW == 0 || fontH == 0){
      fprintf(stderr, "Error: can not determine font dimentions.\n");
      exit(0);
   }

   wid = (2 * BORDER) + (lcdWidth * fontW);
   hgt = (2 * BORDER) + (lcdHeight * fontH);

#ifndef USE_PANGO
   lcdDA = gtk_drawing_area_new();
#endif

   gtk_drawing_area_size(GTK_DRAWING_AREA(lcdDA), wid, hgt);
   gtk_box_pack_start(GTK_BOX(parent), lcdDA, TRUE, TRUE, 0);

   /* Signals used to handle window ops */
   gtk_signal_connect(GTK_OBJECT(lcdDA), "expose_event",
		     (GtkSignalFunc)lcdExposeCB, NULL);
   gtk_signal_connect(GTK_OBJECT(lcdDA),"configure_event",
		     (GtkSignalFunc)lcdResizeCB, NULL);

   /* Event signals (Selection) */
   gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_received",
                     (GtkSignalFunc)lcdPasteCB, NULL);
   gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_clear_event",
                     (GtkSignalFunc)loseSelection, NULL);
   /*
   gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_request_event",
                     (GtkSignalFunc)convertSelection, NULL);
   */
#ifdef GTK_VER_1_1
   gtk_selection_add_targets(lcdDA,
      GDK_SELECTION_PRIMARY, targetlist, ntargets);

   gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_get",
      (GtkSignalFunc)convertSelection, NULL);
#else
   gtk_selection_add_handler(lcdDA, GDK_SELECTION_PRIMARY,
      GDK_SELECTION_TYPE_STRING, convertSelection, NULL);
#endif


   /* Event signals (Input) */
   gtk_signal_connect(GTK_OBJECT(lcdDA), "motion_notify_event",
		     (GtkSignalFunc)lcdMotionEvnt, NULL);
   gtk_signal_connect(GTK_OBJECT(lcdDA), "button_press_event",
		     (GtkSignalFunc)lcdButtonPressEvnt, NULL);
   gtk_signal_connect(GTK_OBJECT(lcdDA), "button_release_event",
		     (GtkSignalFunc)lcdButtonReleaseEvnt, NULL);
   gtk_signal_connect_after(GTK_OBJECT(lcdDA), "key_press_event",
		     (GtkSignalFunc)lcdKeyPressEvnt, NULL);
   gtk_signal_connect_after(GTK_OBJECT(lcdDA), "key_release_event",
		     (GtkSignalFunc)lcdKeyReleaseEvnt, NULL);

   gtk_widget_set_events(lcdDA, 
      GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK |
      GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
      GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
      GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);

   GTK_WIDGET_SET_FLAGS(lcdDA, GTK_CAN_FOCUS);
   gtk_widget_show(lcdDA);
   gtk_widget_grab_focus(lcdDA);


   return lcdDA;
}
示例#7
0
static void
gtk_hex_entry_paint (GtkWidget *widget,
	GdkRectangle *area)
{
	GtkHexEntry *hex_entry;
	GdkRectangle def_area;

	g_return_if_fail (widget != NULL);
	g_return_if_fail (GTK_IS_HEX_ENTRY (widget));

	hex_entry = GTK_HEX_ENTRY (widget);

	if (area == NULL)
	{
		area = &def_area;
		area->x = area->y = 0;
		area->width = widget->allocation.width;
		area->height = widget->allocation.height;
	}

	if (hex_entry->pixmap==NULL)
		hex_entry->pixmap = gdk_pixmap_new (widget->window,
			widget->allocation.width, widget->allocation.height, -1);

	if (GTK_WIDGET_DRAWABLE (widget))
	{
		gint w,h;

		w = gdk_char_width (hex_entry->font,'0');
		h = hex_entry->font->ascent + hex_entry->font->descent;

		if (hex_entry->selected)
		{
			gdk_draw_rectangle (hex_entry->pixmap,widget->style->white_gc,TRUE,
			0,0,widget->allocation.width,widget->allocation.height);
		}
		else
		{
			gdk_draw_rectangle (hex_entry->pixmap,widget->style->bg_gc[GTK_WIDGET_STATE (widget)],TRUE,
			0,0,widget->allocation.width,widget->allocation.height);
		}
/*
		if (hex_entry->has_selection)
		{
			g_print ("%d, %d\n",hex_entry->selection_start_pos,hex_entry->selection_end_pos);

			gdk_draw_rectangle (hex_entry->pixmap,widget->style->black_gc,TRUE,
			(hex_entry->selection_start_pos*w),0,
			((hex_entry->selection_end_pos-hex_entry->selection_start_pos)*w),h);
		}
*/
		if (GTK_WIDGET_HAS_FOCUS(widget))
		{
			if ( (hex_entry->cursor_position>=0) &&
				(hex_entry->cursor_position<hex_entry->digits) )
			{
				gdk_draw_rectangle (hex_entry->pixmap,hex_entry->gc,TRUE,
				(hex_entry->cursor_position*w),
				0,w,h);
			}
		}

		gdk_draw_string (hex_entry->pixmap,
			hex_entry->font,
			widget->style->fg_gc[hex_entry->modified ? GTK_STATE_SELECTED : GTK_WIDGET_STATE (widget)],
			0,
			hex_entry->font->ascent,
			hex_entry->buffer);

		gdk_draw_pixmap (widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
			hex_entry->pixmap, area->x, area->y, area->x, area->y, area->width, area->height);
	}
}
示例#8
0
static int
gtk_initialize_font_instance (struct Lisp_Font_Instance *f, Lisp_Object name,
			      Lisp_Object device, Error_behavior errb)
{
  GdkFont *gf;
  XFontStruct *xf;
  const char *extname;

  TO_EXTERNAL_FORMAT (LISP_STRING, f->name, C_STRING_ALLOCA, extname, Qctext);

  gf = gdk_font_load (extname);

  if (!gf)
    {
      maybe_signal_simple_error ("couldn't load font", f->name,
				 Qfont, errb);
      return 0;
    }

  xf = GDK_FONT_XFONT (gf);

  /* Don't allocate the data until we're sure that we will succeed,
     or the finalize method may get f****d. */
  f->data = xnew (struct gtk_font_instance_data);
  FONT_INSTANCE_GTK_TRUENAME (f) = Qnil;
  FONT_INSTANCE_GTK_FONT (f) = gf;
  f->ascent = gf->ascent;
  f->descent = gf->descent;
  f->height = gf->ascent + gf->descent;

  /* Now lets figure out the width of the font */
  {
    /* following change suggested by Ted Phelps <*****@*****.**> */
    unsigned int def_char = 'n'; /*xf->default_char;*/
    unsigned int byte1, byte2;

  once_more:
    byte1 = def_char >> 8;
    byte2 = def_char & 0xFF;

    if (xf->per_char)
      {
	/* Old versions of the R5 font server have garbage (>63k) as
	   def_char. 'n' might not be a valid character. */
	if (byte1 < xf->min_byte1         ||
	    byte1 > xf->max_byte1         ||
	    byte2 < xf->min_char_or_byte2 ||
	    byte2 > xf->max_char_or_byte2)
	  f->width = 0;
	else
	  f->width = xf->per_char[(byte1 - xf->min_byte1) *
				  (xf->max_char_or_byte2 -
				   xf->min_char_or_byte2 + 1) +
				  (byte2 - xf->min_char_or_byte2)].width;
      }
    else
      f->width = xf->max_bounds.width;

    /* Some fonts have a default char whose width is 0.  This is no good.
       If that's the case, first try 'n' as the default char, and if n has
       0 width too (unlikely) then just use the max width. */
    if (f->width == 0)
      {
	if (def_char == xf->default_char)
	  f->width = xf->max_bounds.width;
	else
	  {
	    def_char = xf->default_char;
	    goto once_more;
	  }
      }
  }

  /* If all characters don't exist then there could potentially be
     0-width characters lurking out there.  Not setting this flag
     trips an optimization that would make them appear to have width
     to redisplay.  This is bad.  So we set it if not all characters
     have the same width or if not all characters are defined.
     */
  /* #### This sucks.  There is a measurable performance increase
     when using proportional width fonts if this flag is not set.
     Unfortunately so many of the f*****g X fonts are not fully
     defined that we could almost just get rid of this damn flag and
     make it an assertion. */
  f->proportional_p = (xf->min_bounds.width != xf->max_bounds.width ||
		       (/* x_handle_non_fully_specified_fonts */ 0 &&
			!xf->all_chars_exist));
#if 0
  f->width = gdk_char_width (gf, 'n');
  f->proportional_p = (gdk_char_width (gf, '|') != gdk_char_width (gf, 'W')) ? 1 : 0;
#endif
  return 1;
}
示例#9
0
文件: gtkplotgdk.c 项目: deweerdt/TSP
static void 
gtk_plot_gdk_draw_string                        (GtkPlotPC *pc,
                                                gint tx, gint ty,
                                                gint angle,
                                                const GdkColor *fg,
                                                const GdkColor *bg,
                                                gboolean transparent,
                                                gint border,
                                                gint border_space,
                                                gint border_width,
                                                gint shadow_width,
                                                const gchar *font_name,
                                                gint font_height,
                                                GtkJustification just,
                                                const gchar *text)
{
  GdkBitmap *text_bitmap;
  GdkPixmap *text_pixmap;
  GdkBitmap *text_mask;
  GdkImage *image;
  GdkGC *gc, *bitmap_gc;
  GdkColormap *colormap;
  GdkColor white, black, mask_color;
  GList *family = NULL;
  gint y0;
  gint old_width, old_height;
  gboolean bold, italic;
  gint fontsize;
  gint ascent, descent;
  gint numf;
  gint xp = 0, yp = 0;
  gint width, height;
  gint x, y;
  gint i;
  GdkFont *font, *latin_font, *dfont;
  GtkPSFont *psfont, *base_psfont, *latin_psfont;
  gchar subs[2], insert_char;
  GdkWChar *aux, *wtext, *lastchar = NULL, *xaux;
  gchar num[4];

  if(!GTK_PLOT_GDK(pc)->drawable) return;
  if(!GTK_PLOT_GDK(pc)->window) return;
  if(!GTK_PLOT_GDK(pc)->gc) return;
  if(!text || strlen(text) == 0) return;

  colormap = gdk_colormap_get_system ();
  gc = GTK_PLOT_GDK(pc)->gc;

  if(!gc) return;

  gtk_plot_text_get_size(text, angle, font_name, font_height, &width, &height, &ascent, &descent);

  if(height == 0 || width == 0) return;

  old_width = width;
  old_height = height;
  if(angle == 90 || angle == 270)
    {
      old_width = height;
      old_height = width;
    }

  gtk_psfont_get_families(&family, &numf);
  font = gtk_psfont_get_gdkfont(font_name, font_height);
  base_psfont = psfont = gtk_psfont_get_font(font_name);
  italic = psfont->italic;
  bold = psfont->bold;
  fontsize = font_height;
  x = 0;
  y0 = y = ascent;

  if (psfont->i18n_latinfamily) {
    latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily, italic,
					     bold);
    latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname, fontsize);
  } else {
    latin_psfont = NULL;
    latin_font = NULL;
  }

  i = strlen(text) + 2;
  aux = wtext = g_malloc0(sizeof(GdkWChar) * i);
  gdk_mbstowcs(wtext, text, i - 1);

  /* initializing text bitmap - ajd */
  text_bitmap = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window,
                              old_width, old_height, 1);
  bitmap_gc = gdk_gc_new(text_bitmap);
  gdk_color_white (colormap, &white);
  gdk_gc_set_foreground(bitmap_gc, &white);
  gdk_draw_rectangle(text_bitmap, bitmap_gc, TRUE,
                     0, 0, -1, -1);
  gdk_color_black (colormap, &black);
  gdk_gc_set_foreground(bitmap_gc, &black);

  while(aux && *aux != '\0' && *aux != '\n'){
   if(*aux == '\\'){
     aux++;
     switch(*aux){
       case '0': case '1': case '2': case '3':
       case '4': case '5': case '6': case '7': case '9':
           psfont = gtk_psfont_find_by_family((gchar *)g_list_nth_data(family, *aux-'0'), italic, bold);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
           aux++;
           break;
       case '8': case 'g':
           psfont = gtk_psfont_find_by_family("Symbol", italic, bold);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
           aux++;
           break;
       case 'B':
           bold = TRUE;
           psfont = gtk_psfont_find_by_family(psfont->family, italic, bold);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 'x':
           xaux = aux + 1;
           for (i=0; i<3; i++){
            if (xaux[i] >= '0' && xaux[i] <= '9')
              num[i] = xaux[i];
            else
              break;
           }
           if (i < 3){
              aux++;
              break;
           }
           num[3] = '\0';
           insert_char = (gchar)atoi(num);
           subs[0] = insert_char;
           subs[1] = '\0';
	   /* \xNNN is always outputted with latin fonts. */
	   dfont = (psfont->i18n_latinfamily != NULL) ? latin_font : font;
           gdk_draw_string (text_bitmap, dfont,
                            bitmap_gc,
                            x, y,
                            subs);

           x += gdk_char_width(font, insert_char);
           aux += 4;
           lastchar = aux - 1;
           break;
       case 'i':
           italic = TRUE;
           psfont = gtk_psfont_find_by_family(psfont->family, italic, bold);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 'S': case '^':
           fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
           y -= font->ascent;
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 's': case '_':
           fontsize = (int)((gdouble)fontsize * 0.6 + 0.5);
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
           y += font->descent;
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case '+':
           fontsize += 3;
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case '-':
           fontsize -= 3;
           gdk_font_unref(font);
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 'N':
	   psfont = base_psfont;
           gdk_font_unref(font);
           fontsize = font_height;
           font = gtk_psfont_get_gdkfont(psfont->psname, fontsize);
           y = y0;
           italic = psfont->italic;
           bold = psfont->bold;
	   if (latin_font) {
	     gdk_font_unref(latin_font);
	     latin_font = NULL;
	   }
	   if (psfont->i18n_latinfamily) {
	     latin_psfont = gtk_psfont_find_by_family(psfont->i18n_latinfamily,
						      italic, bold);
	     latin_font = gtk_psfont_get_gdkfont(latin_psfont->psname,
						 fontsize);
	   }
           aux++;
           break;
       case 'b':
	   if (lastchar) {
	     gtk_psfont_get_char_size(psfont, font, latin_font, *lastchar, &i,
				    NULL, NULL);
	     x -= i;

	     if (lastchar == wtext)
	       lastchar = NULL;
	     else
	       lastchar--;
	   } else {
	     gtk_psfont_get_char_size(psfont, font, latin_font, 'X', &i, NULL,
				    NULL);
	     x -= i;
	   }
           aux++;
           break;
       default:
           if(aux && *aux != '\0' && *aux !='\n'){
	     x += drawstring(pc, text_bitmap, bitmap_gc, &black, &white, x, y,
			     psfont, font, latin_font, *aux);
	     lastchar = aux;
	     aux++;
	   }
	   break;
     }
   } else {
     if(aux && *aux != '\0' && *aux !='\n'){
       x += drawstring(pc, text_bitmap, bitmap_gc, &black, &white, x, y,
		       psfont, font, latin_font, *aux);
       lastchar = aux;
       aux++;
     }
   }
  }

  g_free(wtext);

  /* initializing clip mask bitmap - ajd */
  text_mask = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window, width, height, 1);
  mask_color = white;
  mask_color.pixel = 0;
  gdk_gc_set_foreground(bitmap_gc, &mask_color);
  gdk_draw_rectangle(text_mask, bitmap_gc, TRUE, 0, 0, -1, -1);
  mask_color = black;
  mask_color.pixel = 1;
  gdk_gc_set_foreground(bitmap_gc, &mask_color);

  /* performing text rotation and saving it onto clip mask bitmap - ajd */
  image = gdk_image_get(text_bitmap, 0, 0, old_width, old_height);
  for(y = 0; y < old_height; y++)
      for(x = 0; x < old_width; x++)
         {
           if( black.pixel == gdk_image_get_pixel(image, x, y) ){
           switch(angle){
            case 0:
                xp = x;
                yp = y;
                break;
            case 90:
                xp = y;
                yp = old_width - x;
                break;
            case 180:
                xp = old_width - x;
                yp = old_height - y;
                break;
            case 270:
                xp = old_height - y;
                yp = x;
                break;
            }
            gdk_draw_point(text_mask, bitmap_gc, xp, yp);
           }
         }
  gdk_image_destroy(image);


  /* initializing text pixmap - ajd */
  text_pixmap = gdk_pixmap_new(GTK_PLOT_GDK(pc)->window, width, height, -1);
  gdk_gc_set_foreground(gc, (GdkColor *) bg);
  gdk_draw_rectangle(text_pixmap, gc, TRUE, 0, 0, -1, -1);
  gdk_gc_set_foreground(gc, (GdkColor *) fg);

  /* copying clip mask bitmap onto text pixmap - ajd */
  gdk_gc_set_clip_mask(gc, text_mask);
  gdk_gc_set_clip_origin(gc, 0, 0);
  gdk_draw_rectangle(text_pixmap, gc, TRUE, 0, 0, -1, -1);
  gdk_gc_set_clip_mask(gc, NULL);

  gtk_plot_text_get_area(text, angle, just, font_name, font_height,
                         &x, &y, &width, &height);
  tx += x;
  ty += y;

  if(transparent){
    gdk_gc_set_clip_mask (gc, text_mask);
    gdk_gc_set_clip_origin (gc, tx, ty);
  } else {
    gdk_gc_set_foreground(gc, (GdkColor *) bg);
    gtk_plot_pc_draw_rectangle(pc,
   		         TRUE, 
                         tx - border_space, ty - border_space, 
                         width + 2*border_space, height + 2*border_space);
  }

  gdk_draw_pixmap(GTK_PLOT_GDK(pc)->drawable, gc,
                  text_pixmap, 0, 0,
                  tx, ty, -1, -1);
  gdk_gc_set_clip_mask(gc, NULL);

  gdk_pixmap_unref(text_pixmap);
  gdk_bitmap_unref(text_mask);
  gdk_font_unref(font);
  if (latin_font) gdk_font_unref(latin_font);
  gdk_gc_unref(bitmap_gc);
  gdk_pixmap_unref(text_bitmap);


/* border */

  gdk_gc_set_foreground(gc, (GdkColor *) fg);
  gtk_plot_pc_set_dash(pc, 0, NULL, 0);
  gtk_plot_pc_set_lineattr(pc, border_width, 0, 0, 0);
  switch(border){
    case GTK_PLOT_BORDER_SHADOW: 
      gtk_plot_pc_draw_rectangle(pc,
   		         TRUE, 
                         tx - border_space + shadow_width, 
                         ty + height + border_space, 
                         width + 2 * border_space, shadow_width);
      gtk_plot_pc_draw_rectangle(pc,
   		         TRUE, 
                         tx + width + border_space, 
                         ty - border_space + shadow_width, 
                         shadow_width, height + 2 * border_space);
    case GTK_PLOT_BORDER_LINE: 
      gtk_plot_pc_draw_rectangle(pc,
   		         FALSE, 
                         tx - border_space, ty - border_space, 
                         width + 2*border_space, height + 2*border_space);
    case GTK_PLOT_BORDER_NONE: 
    default:
	break; 
  }

  return;
}