Re: [patch] Re: bug in gtk_label




a-higuti@math.sci.hokudai.ac.jp (Akira Higuchi) writes:

> In article <199812161928.UAA20787@loki.gams.co.at>
> mla@gams.co.at writes:
> 
> >gtk_label_set_text() calls gdk_mbstowcs and uses it's return value as
> >an index into label->label_wc.
> >
> >gdk_mbstowcs can return -1 (it does it on my setup because
> >XwcTextPropertyToTextList return a failure code) but this error is not 
> >checked.
> 
> This bug seems to be fixed in gtk+-1.1.9, but I think the following
> way is better than checking for glibc2 mb functions. Please apply
> the following patch. This patch is against gtk+-1.1.8 (not 1.1.9).

I don't think this patch is a full solution, because 
while I think it is safe to assume:

 multi-byte encoding => need fontset to draw

we can't assume:

 have fontset => have multi-byte encoding.

If somebody specifies a fontset in their gtkrc, they
shouldn't get garbage or empty labels as the result.

So, I think I'm going to leave in the check for glibc.  But 
your patch, is , also worth applying since it should speed up 
the common case quite a bit by bypassing X's locale-conversion 
routines.

Regards,
                                        Owen

> --- gtklabel.c.old	Thu Dec 17 16:07:41 1998
> +++ gtklabel.c	Thu Dec 17 17:24:33 1998
> @@ -192,6 +192,7 @@
>    GTK_WIDGET_SET_FLAGS (label, GTK_NO_WINDOW);
>    
>    label->label = NULL;
> +  label->label_wc = NULL;
>    label->words = NULL;
>    label->max_width = 0;
>    label->jtype = GTK_JUSTIFY_CENTER;
> @@ -219,6 +220,7 @@
>  gtk_label_set_text (GtkLabel *label,
>  		    const char *str)
>  {
> +  GtkWidget *widget = GTK_WIDGET (label);
>    guint len;
>    guint wc_len;
>    
> @@ -231,10 +233,23 @@
>    label->label = g_strdup (str);
>  
>    /* Convert text to wide characters */
> +  if (label->label_wc)
> +    g_free (label->label_wc);
>    len = strlen (str);
>    label->label_wc = g_new (GdkWChar, len + 1);
> -  wc_len = gdk_mbstowcs (label->label_wc, str, len + 1);
> -  label->label_wc[wc_len] = '\0';
> +  gtk_widget_ensure_style (widget);
> +  if ((widget->style) && (widget->style->font->type == GDK_FONT_FONTSET))
> +    {
> +      wc_len = gdk_mbstowcs (label->label_wc, str, len + 1);
> +      if (wc_len < 0) wc_len = 0;
> +      label->label_wc[wc_len] = '\0';
> +    }
> +  else
> +    {
> +      guint i;
> +      for (i = 0; i <= len; i++)
> +	label->label_wc[i] = label->label[i];
> +    }
>  
>    gtk_label_free_words (label);
>  
> @@ -334,6 +349,8 @@
>    g_free (label->label);
>    if (label->pattern) 
>      g_free (label->pattern);
> +  if (label->label_wc)
> +    g_free (label->label_wc);
>    gtk_label_free_words (label);
>    (* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
>  }
> @@ -847,15 +864,27 @@
>  {
>    GtkWidget *widget = GTK_WIDGET (label);
>    GtkLabelULine *uline;
> -  gchar *tmp_str;
> +  guchar *tmp_str;
>  
> -  tmp_str = gdk_wcstombs (word->beginning);
> -  gtk_paint_string (widget->style, widget->window, widget->state,
> -		    area, widget, "label", 
> -		    x + word->x,
> -		    y + word->y,
> -		    tmp_str);
> -  g_free (tmp_str);
> +  if ((widget->style) && (widget->style->font->type == GDK_FONT_FONTSET))
> +    tmp_str = gdk_wcstombs (word->beginning);
> +  else
> +    {
> +      guint i, len;
> +      for (len = 0; word->beginning[len]; len++);
> +      tmp_str = g_new (guchar, len + 1);
> +      for (i = 0; i <= len; i++)
> +	tmp_str[i] = word->beginning[i];
> +    }
> +  if (tmp_str)
> +    {
> +      gtk_paint_string (widget->style, widget->window, widget->state,
> +			area, widget, "label", 
> +			x + word->x,
> +			y + word->y,
> +			tmp_str);
> +      g_free (tmp_str);
> +    }
>    
>    for (uline = word->uline;uline;uline = uline->next)
>      gtk_paint_hline (widget->style, widget->window, 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]