Mercurial > pidgin
changeset 956:0f9fc69a1f3b
[gaim-migrate @ 966]
gdb is a wonderful tool ;)
committer: Tailor Script <tailor@pidgin.im>
author | Todd Kulesza <fflewddur> |
---|---|
date | Sun, 08 Oct 2000 04:29:34 +0000 |
parents | 889e5026fd98 |
children | 032a6e1553c1 |
files | src/gtkhtml.c |
diffstat | 1 files changed, 114 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkhtml.c Sun Oct 08 01:52:44 2000 +0000 +++ b/src/gtkhtml.c Sun Oct 08 04:29:34 2000 +0000 @@ -44,7 +44,7 @@ #include "pixmaps/admin_icon.xpm" #include "pixmaps/free_icon.xpm" #include "pixmaps/dt_icon.xpm" -#define MAX_SIZE 7 +#define MAX_SIZE 7 #define MIN_HTML_WIDTH_LINES 20 #define MIN_HTML_HEIGHT_LINES 10 #define BORDER_WIDTH 2 @@ -53,6 +53,7 @@ #define KEY_SCROLL_PIXELS 10 int font_sizes[] = { 80, 100, 120, 140, 200, 300, 400 }; +GtkHtmlBit *start_of_line = NULL; /* GdkFont *fixed_font[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; @@ -168,7 +169,8 @@ static void draw_cursor(GtkHtml * html); static void undraw_cursor(GtkHtml * html); -static int get_line_height(GtkHtml *, GtkHtmlBit *); +static int get_line_max_height(GtkHtml *, GtkHtmlBit *); +static void get_line_max_extents(GtkHtml *, GtkHtmlBit *, int *, int *); static GtkWidgetClass *parent_class = NULL; @@ -1844,8 +1846,6 @@ if (html->frozen > 0) return; - hbits = g_list_find(html->html_bits, hb); - if (hb->type == HTML_BIT_TEXT) { @@ -2046,22 +2046,43 @@ /*end my stuff*/ if (hb->text && hb->back != NULL) { - int hwidth, hheight, hei, tmpcnt; - hei = get_line_height(html, hb); + int hwidth, hheight, tmpcnt, max_ascent, max_descent; + + /* get the gtkhtmlbit at the start of each line, and use it as the starting point to calculate the + max height of each line and set the background-rectangle's size accordingly */ + /* FIXME: should also include a method of eliminating 'gaps' between different line using + different text sizes */ + if (!start_of_line) + start_of_line = hb; + else + { + hbits = g_list_find(html->html_bits, hb); + if (hbits->prev) + { + hbit = hbits->prev->data; + if (hbit && hbit->newline) + start_of_line = hb; + } + else + start_of_line = hb; + } + + get_line_max_extents(html, start_of_line, &max_ascent, &max_descent); gdk_window_get_size(html->html_area, &hwidth, &hheight); gdk_gc_set_foreground(gc, hb->back); /* we use a 2-pixel window border */ if (hb->x < 2) hb->x = 2; + gdk_draw_rectangle(html->html_area, gc, TRUE /* filled */, - hb->x, hb->y - html->yoffset - hei - 6, - hwidth - shift - hb->x + 1, hei + hei + 2); + hb->x, hb->y - html->yoffset - max_ascent - max_descent - 2, + hwidth - shift - hb->x + 1, max_ascent + max_descent + 8); for (tmpcnt = 1; tmpcnt < hb->newline; tmpcnt++) { - int eoff = hei + hei + 2; + int eoff = max_ascent + max_descent + 2; eoff *= tmpcnt; gdk_draw_rectangle(html->html_area, gc, TRUE, - 2, hb->y - html->yoffset - hei - 6 + eoff, - hwidth, hei + hei + 2); + 2, hb->y - html->yoffset - max_ascent - max_descent - 2 + eoff, + hwidth, max_ascent + max_descent + 2); } } @@ -2074,6 +2095,7 @@ gdk_draw_string(html->html_area, hb->font, gc, shift + hb->x, hb->y - html->yoffset, hb->text); + if (hb->uline) gdk_draw_line(html->html_area, gc, shift + hb->x, hb->y - html->yoffset, @@ -2092,7 +2114,24 @@ { if (hb->back != NULL) { int hwidth, hheight, hei, tmpcnt; - hei = get_line_height(html, hb); + + if (!start_of_line) + start_of_line = hb; + else + { + hbits = g_list_find(html->html_bits, hb); + if (hbits && hbits->prev) + { + hbit = hbits->prev->data; + if (hbit && hbit->newline) + start_of_line = hb; + } + else + start_of_line = hb; + } + + hei = get_line_max_height(html, start_of_line); + gdk_window_get_size(html->html_area, &hwidth, &hheight); gdk_gc_set_foreground(gc, hb->back); gdk_draw_rectangle(html->html_area, gc, TRUE, @@ -2128,7 +2167,24 @@ clear_area(html, &area); if (hb->back != NULL) { int hwidth, hheight, hei, tmpcnt; - hei = get_line_height(html, hb); + + if (!start_of_line) + start_of_line = hb; + else + { + hbits = g_list_find(html->html_bits, hb); + if (hbits && hbits->prev) + { + hbit = hbits->prev->data; + if (hbit && hbit->newline) + start_of_line = hb; + } + else + start_of_line = hb; + } + + hei = get_line_max_height(html, start_of_line); + gdk_window_get_size(html->html_area, &hwidth, &hheight); gdk_gc_set_foreground(gc, hb->back); for (tmpcnt = 0; tmpcnt < hb->newline; tmpcnt++) { @@ -2857,7 +2913,7 @@ GdkGC *gc; int nl = 0, nl2 = 0; - int maxwidth; + int maxwidth, ascent, descent; gint lb; GList *hbits; size_t num = 0; @@ -2975,7 +3031,8 @@ if (!count) { /* FIXME : sometimes we need to add newline, sometimes we don't */ hbits = g_list_last(html->html_bits); - if (!hbits) return; /* does this ever happen? */ + if (!hbits) + return; /* does this ever happen? */ hb = (GtkHtmlBit *)hbits->data; hb->newline++; } @@ -3005,9 +3062,9 @@ } - height = cfont->ascent + cfont->descent + 2; - - + gdk_text_extents(cfont, "yG", strlen("yG"), NULL, NULL, NULL, &ascent, &descent); + height = ascent + descent + 2; + if ((int) (html->vadj->upper - html->current_y) < (int) (height * 2)) { int val; @@ -3019,7 +3076,7 @@ if (html->current_x == 0) { - html->current_y += height + 3; + html->current_y += height + 6; gdk_text_extents(cfont, text, 1, &lb, NULL, NULL, NULL, NULL); html->current_x += (2 - lb); } @@ -3431,9 +3488,7 @@ { d += strlen("COLOR="); if (*d == '\"') - { d++; - } if (*d == '#') d++; if (d[strlen(d) - 1] == '\"') @@ -3444,17 +3499,12 @@ current->color = get_color(colorv, map); current->owncolor = 1; } - else - { - } } if (!strncasecmp(d, "FACE=", strlen("FACE="))) { d += strlen("FACE="); if (*d == '\"') - { d++; - } if (d[strlen(d) - 1] == '\"') d[strlen(d) - 1] = 0; strcpy(current->font, d); @@ -3474,9 +3524,6 @@ current->bgcol = get_color(colorv, map); current->ownbg = 1; } - else - { - } } else if (!strncasecmp(d, "SIZE=", strlen("SIZE="))) { @@ -3486,12 +3533,7 @@ if (*d == '+') d++; if (sscanf(d, "%d", &colorv)) - { current->size = colorv; - } - else - { - } } else if (strncasecmp(d, "PTSIZE=", strlen("PTSIZE="))) { @@ -3500,7 +3542,6 @@ } else if (!strncasecmp(tag, "BODY", strlen("BODY"))) { - char *d; current = push_state(current); html_strtok(tag, ' '); @@ -4391,7 +4432,7 @@ } } -static int get_line_height(GtkHtml *html, GtkHtmlBit *start) +static int get_line_max_height(GtkHtml *html, GtkHtmlBit *start) { int height, max_height = 0; GList *hbits = html->html_bits; @@ -4401,7 +4442,7 @@ while (hbits) { - hbit = hbits->data; + hbit = (GtkHtmlBit *)hbits->data; if (hbit->font) height = gdk_text_height(hbit->font, "C", 1); @@ -4412,8 +4453,42 @@ hbits = hbits->next; } - if (max_height == 0) + if (!max_height) max_height = gdk_text_height(hbit->font, "C", 1); - + return max_height; } + +static void get_line_max_extents(GtkHtml *html, GtkHtmlBit *start, int *max_acsent, int *max_descent) +{ + int acsent, descent; + GList *hbits = html->html_bits; + GtkHtmlBit *hbit = start; /* default this in case hbits is NULL */ + + *max_acsent = 0; + *max_descent = 0; + + hbits = g_list_find(hbits, start); + + while (hbits) + { + hbit = (GtkHtmlBit *)hbits->data; + if (hbit->font) + gdk_text_extents(hbit->font, "yG", strlen("yG"), NULL, NULL, NULL, &acsent, &descent); + + if (*max_acsent < acsent) + *max_acsent = acsent; + if (*max_descent < descent) + *max_descent =descent; + if (hbit->newline) + break; + hbits = hbits->next; + } + + if (!*max_acsent) + gdk_text_extents(hbit->font, "yG", strlen("yG"), NULL, NULL, NULL, max_acsent, NULL); + if (!*max_descent) + gdk_text_extents(hbit->font, "yG", strlen("yG"), NULL, NULL, NULL, NULL, max_descent); + + return; +} \ No newline at end of file