# HG changeset patch # User Richard Laager # Date 1130315712 0 # Node ID 047f85200139fcbbeacf23aaeeb4656dca8c90e2 # Parent 216a05e0a6f10f27124d52d0913fdff56a97db99 [gaim-migrate @ 14131] SF Patch #1338002 from sadrul "When an image in a non-editable GtkIMHtml is just enough wide/long to cause the imhtml to have a scrollbar, the size-allocate callback for the imhtml falls into an infinite loop. Bleeter hit this bug with the profile of a specific yahoo-id. So did I. This patch prevents such lockups." committer: Tailor Script diff -r 216a05e0a6f1 -r 047f85200139 src/gtkimhtml.c --- a/src/gtkimhtml.c Wed Oct 26 05:59:26 2005 +0000 +++ b/src/gtkimhtml.c Wed Oct 26 08:35:12 2005 +0000 @@ -381,7 +381,7 @@ } } -static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) +static void gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) { GdkRectangle rect; int xminus; @@ -403,7 +403,7 @@ } widget->old_rect = rect; - return FALSE; + return; } static gint @@ -3152,22 +3152,19 @@ GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; if(image->width > width || image->height > height){ + double ratio_w, ratio_h, ratio; + int new_h, new_w; GdkPixbuf *new_image = NULL; - float factor; - int new_width = image->width, new_height = image->height; - - if(image->width > (width - 2)){ - factor = (float)(width)/image->width; - new_width = width; - new_height = image->height * factor; - } - if(new_height >= (height - 2)){ - factor = (float)(height)/new_height; - new_height = height; - new_width = new_width * factor; - } - - new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR); + + ratio_w = ((double)width - 2) / image->width; + ratio_h = ((double)height - 2) / image->height; + + ratio = (ratio_w < ratio_h) ? ratio_w : ratio_h; + + new_w = (int)(image->width * ratio); + new_h = (int)(image->height * ratio); + + new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_w, new_h, GDK_INTERP_BILINEAR); gtk_image_set_from_pixbuf(image->image, new_image); g_object_unref(G_OBJECT(new_image)); }