# HG changeset patch # User Eric Warmenhoven # Date 968189443 0 # Node ID 2804dc8e9ba0adc81e77476defb1c6e17fb13f54 # Parent 3b09dd3796004ee56770fc32a6ba42b971588d25 [gaim-migrate @ 852] HTML widget is faster, more stable :) oh my cs teacher would be so proud. here's a description of the old algorithm and my new improved one: old algorithm: print as much text as we can. then try printing the rest of it. with at 4000 character message, this usually leads to a stack about 200 functions deep. depending on the amound of memory you have, this may have lead to a segfault. new algorithm: if we can print it all, print it all. if we can't { if we've already printed stuff on this line then finish printing the line. print the first half of the stuff, then the second half. } this usually leads to a stack no deeper than about 20 functions. it also causes the widget to be much faster. committer: Tailor Script diff -r 3b09dd379600 -r 2804dc8e9ba0 ChangeLog --- a/ChangeLog Tue Sep 05 03:17:37 2000 +0000 +++ b/ChangeLog Tue Sep 05 21:30:43 2000 +0000 @@ -29,6 +29,7 @@ * New icons for panel (depends on some GNOME pixmaps) * Perl scripting. See plugins/PERL-HOWTO for how to write perl scripts. All .pl files in ~/.gaim are autoloaded when gaim starts. + * HTML widget is faster, more stable version 0.9.20 (07/14/2000): * More plugin events, more plugin features diff -r 3b09dd379600 -r 2804dc8e9ba0 src/gtkhtml.c --- a/src/gtkhtml.c Tue Sep 05 03:17:37 2000 +0000 +++ b/src/gtkhtml.c Tue Sep 05 21:30:43 2000 +0000 @@ -2782,7 +2782,6 @@ } - static void gtk_html_add_text(GtkHtml * html, GdkFont * cfont, GdkColor * fore, @@ -2896,9 +2895,29 @@ * HTK_SCROLLED_WINDOW(GTK_WIDGET(layout)->parent)->vscrollbar->allocation.width) - 8; */ - /* FIXME: gtk_text_measure can overflow if the text is too long. hopefully that will - * never happen though. but it is very possible. NOTE: this is not a buffer overflow, - * it just means it won't display text properly. */ + if ((maxwidth == (hwidth - 8) && gdk_text_measure(cfont, text, num) > maxwidth) || gdk_text_measure(cfont, text, num) < 0) { + char *tmp1, *tmp2; + static int count = 0; + count ++; + tmp1 = g_malloc(num / 2 + 1); + tmp2 = g_malloc(num / 2 + 2); + g_snprintf(tmp1, num / 2 + 1, "%s", text); + g_snprintf(tmp2, num / 2 + 2, "%s", text + num / 2); + gtk_html_add_text(html, cfont, fore, back, tmp1, num / 2 + 1, uline, strike, url); + gtk_html_add_text(html, cfont, fore, back, tmp2, num / 2 + 2, uline, strike, url); + g_free(tmp1); + g_free(tmp2); + g_free(text); + count--; + if (!count) { + hbits = g_list_last(html->html_bits); + if (!hbits) return; /* does this ever happen? */ + hb = (GtkHtmlBit *)hbits->data; + hb->newline = 1; + } + return; + } + while (gdk_text_measure(cfont, text, num) > maxwidth) { if (num > 1) @@ -2975,7 +2994,7 @@ * * much better lookin */ - for (i=2; (num - i > 0); i++) { + for (i=2; (num > i); i++) { if (text[num - i] == ' ') { num = num - (i - 1); nl2 = 1;