Re: [PATCH to 1.2.8] gdk_text_width_wc was broked



On Tue, 22 Aug 2000, Vlad Harchev wrote:

 Guys, why don't you apply this patch to 1.2 branch? It's a bugfix, and should
go in. I'm asking you to allow applying it since 22 Aug. Shame to you!


>  Hi,
> 
>  Here is a patch to fix broken behaviour of gdk_text_width_wc. If the font
> passed to it is of type GDK_FONT_FONT (i.e. not a fontset) it converts wcs
> to char[] using plain assignment, rather than using gdk_wcstombs). This breaks
> horribly for russian strings - the characters get shifted by 128 after such
> conversion, thus leading to measuring the width of completely different string
> (it always shorter, so all strings in russian appear truncated by a half of a
> letter in average).
> 
>  Best regards,
>   -Vlad
> 
> diff -ru gtk+-1.2.5-was/gdk/gdkfont.c gtk+-1.2.5/gdk/gdkfont.c
> --- gtk+-1.2.5-was/gdk/gdkfont.c	Mon Aug 21 11:40:39 2000
> +++ gtk+-1.2.5/gdk/gdkfont.c	Tue Aug 22 18:48:55 2000
> @@ -388,12 +388,18 @@
>        xfont = (XFontStruct *) private->xfont;
>        if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
>          {
> -          gchar *text_8bit;
> -          gint i;
> -          text_8bit = g_new (gchar, text_length);
> -          for (i=0; i<text_length; i++) text_8bit[i] = text[i];
> -          width = XTextWidth (xfont, text_8bit, text_length);
> -          g_free (text_8bit);
> +          GdkWChar* wc_tmp;
> +          gchar* mbtext;
> +          gint mblen;
> +	  
> +          wc_tmp = g_new(GdkWChar,text_length+1);
> +          memcpy(wc_tmp,text,sizeof(GdkWChar)*text_length);
> +          wc_tmp[text_length] = (GdkWChar)0;
> +          mbtext = gdk_wcstombs(wc_tmp);
> +          mblen = strlen(mbtext);
> +          width = XTextWidth (xfont, mbtext, mblen);
> +          g_free(mbtext);
> +          g_free(wc_tmp);
>          }
>        else
>          {
> 
> 
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list
> 

 Best regards,
  -Vlad





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