00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 # include <config.h>
00024 #endif
00025
00026 #include "intl.h"
00027 #include <gtk/gtk.h>
00028 #include <string.h>
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include <ctype.h>
00032 #include "pixmaps/aol_icon.xpm"
00033 #include "pixmaps/free_icon.xpm"
00034 #include "pixmaps/dt_icon.xpm"
00035 #include "pixmaps/admin_icon.xpm"
00036 #include "pixmaps/no_such_smiley.xpm"
00037 #include "extgtktext.h"
00038 #include "browser.h"
00039 #include "globals.h"
00040 #include "smileys.h"
00041
00042 #ifdef HAVE_LIBXFT
00043 #include <gdk/gdkprivate.h>
00044 #include <X11/Xft/Xft.h>
00045 #endif
00046
00047 static GData * font_cache;
00048 static gboolean cache_init = FALSE;
00049
00050 extern gint font_size;
00051
00052
00053
00054
00055
00056 #define DEBUG
00057
00058 int _adjust_font_metrics(int size)
00059 {
00060 #ifndef HAVE_LIBXFT
00061 size = font_size + 2 + (size*2);
00062 if(size > 60)
00063 {
00064 size = 60;
00065 }
00066 #else
00067 size = font_size + (size*2);
00068 if(size > 60)
00069 {
00070 size = 60;
00071 }
00072 #endif
00073
00074 return size;
00075 }
00076
00077 char * _unescape_string(char * input)
00078 {
00079 int i = 0;
00080 int j = 0;
00081 for(i = 0; input[i]; )
00082 {
00083 if(input[i] == '&')
00084 {
00085 if(!g_strncasecmp(input+i+1, "gt;", 3))
00086 {
00087 input[j++] = '>';
00088 i+=4;
00089 }
00090 else if(!g_strncasecmp(input+i+1, "lt;", 3))
00091 {
00092 input[j++] = '<';
00093 i+=4;
00094 }
00095 else if(!g_strncasecmp(input+i+1, "amp;", 4))
00096 {
00097 input[j++] = '&';
00098 i+=5;
00099 }
00100 else if(!g_strncasecmp(input+i+1, "#8212;", 6))
00101 {
00102 input[j++] = '-';
00103 input[j++] = '-';
00104 i+=7;
00105 }
00106 else if(!g_strncasecmp(input+i+1, "nbsp;", 5))
00107 {
00108 input[j++] = ' ';
00109 i+=6;
00110 }
00111 else
00112 {
00113 input[j++] = '&';
00114 i++;
00115 }
00116 }
00117 else
00118 {
00119 input[j++] = input[i++];
00120 }
00121 }
00122 input[j] = '\0';
00123 return input;
00124 }
00125
00126
00127 #ifndef HAVE_LIBXFT
00128 static GdkFont * _getfont(char * font, int bold, int italic, int size, int ptsize)
00129 {
00130 gchar font_name[1024] = "-*-";
00131 GdkFont * my_font;
00132
00133 if(!cache_init)
00134 {
00135 g_datalist_init(&font_cache);
00136 cache_init = TRUE;
00137 }
00138
00139
00140
00141 if(strlen(font))
00142 {
00143 strcat( font_name, font );
00144 }
00145 else
00146 {
00147 strcat( font_name, "*" );
00148 }
00149 strcat( font_name, "-" );
00150
00151 if(bold)
00152 {
00153 strcat( font_name, "bold");
00154 }
00155 else
00156 {
00157 strcat( font_name, "medium");
00158 }
00159 strcat( font_name, "-" );
00160
00161
00162
00163
00164
00165
00166
00167 if( italic == 1 )
00168 {
00169 strcat( font_name, "i");
00170 }
00171 else if( italic == 2 )
00172 {
00173 strcat( font_name, "o" );
00174 }
00175 else
00176 {
00177 strcat( font_name, "r");
00178 }
00179 strcat( font_name, "-*-*-");
00180 {
00181 char buff[256];
00182 if(size != -1)
00183 {
00184 int size2 = 0;
00185 size2 = _adjust_font_metrics(size);
00186 sprintf(buff, "%d-*-*-*-*-*-*-*", size2);
00187 }
00188 else
00189 {
00190 sprintf(buff, "*-%d-*-*-*-*-*-*", (ptsize+font_size-6)*10);
00191 }
00192
00193 strcat( font_name, buff );
00194 }
00195
00196 eb_debug(DBG_HTML, "Wanting font %s\n", font_name);
00197
00198 g_strdown(font_name);
00199
00200 if(( my_font =
00201 g_datalist_id_get_data(&font_cache, g_quark_from_string(font_name)) ))
00202 {
00203 return my_font;
00204 }
00205 my_font = gdk_font_load(font_name);
00206 if( !my_font )
00207 {
00208 if( italic == 1 )
00209 {
00210 my_font = _getfont(font, bold, 2, size, ptsize );
00211 }
00212 else if(strcmp(font, "helvetica"))
00213 {
00214 my_font = _getfont("helvetica", bold, italic, size, ptsize );
00215 }
00216 else
00217 {
00218 my_font = _getfont("fixed", bold, italic, size, ptsize );
00219 }
00220 }
00221 g_datalist_id_set_data( &font_cache,
00222 g_quark_from_string(font_name),
00223 my_font );
00224 return my_font;
00225 }
00226 #else
00227 static XftFont * _getfont(char * font, int bold, int italic, int size, int ptsize)
00228 {
00229 XftFont * xftfont;
00230 XftPattern * pattern;
00231 gchar font_name[1024] = "";
00232
00233 if(!cache_init)
00234 {
00235 g_datalist_init(&font_cache);
00236 cache_init = TRUE;
00237 }
00238
00239
00240 sprintf(font_name, "%s,helvetica,arial", font);
00241 if(size != -1)
00242 {
00243 int size2 = 0;
00244 char buff[256] = "";
00245
00246 eb_debug(DBG_HTML, "Size param = %d\n", size);
00247 eb_debug(DBG_HTML, "fontsize adjust = %d\n", font_size);
00248 size2 = _adjust_font_metrics(size);
00249 sprintf(buff, "-%d", size2);
00250 strcat(font_name, buff);
00251 }
00252 else
00253 {
00254 int size2 = ptsize+(font_size-6);
00255 char buff[256] = "";
00256 sprintf(buff, "-%d", size2);
00257 strcat(font_name, buff);
00258 }
00259 if(bold)
00260 {
00261 strcat(font_name, ":bold");
00262 }
00263 if(italic)
00264 {
00265 strcat(font_name, ":slant=italic,oblique");
00266 }
00267 if(( xftfont =
00268 g_datalist_id_get_data(&font_cache, g_quark_from_string(font_name)) ))
00269 {
00270 return xftfont;
00271 }
00272
00273 eb_debug(DBG_HTML, "Wanting font %s\n", font_name);
00274
00275 pattern = XftNameParse(font_name);
00276 xftfont = XftFontOpenName(gdk_display, DefaultScreen(gdk_display), font_name);
00277
00278 if(xftfont == NULL)
00279 {
00280 eb_debug(DBG_HTML, "font %s Not Found!!!\n", font_name);
00281 }
00282
00283 g_datalist_id_set_data( &font_cache,
00284 g_quark_from_string(font_name),
00285 xftfont);
00286 return xftfont;
00287 }
00288 #endif
00289
00290 static GdkColor * _getcolor(GdkColormap * map, char * name)
00291 {
00292 GdkColor * color;
00293
00294 color = (GdkColor *)g_new0(GdkColor, 1);
00295 gdk_color_parse(name, color);
00296 gdk_color_alloc(map, color);
00297
00298 return color;
00299 }
00300
00301 static void _extract_parameter(char * parm, char * buffer, int buffer_size)
00302 {
00303
00304
00305
00306
00307
00308 if(*parm == '\"')
00309 {
00310 int cnt = 0;
00311 parm += 1;
00312
00313 for(cnt = 0; *parm && *parm != '\"' && cnt < buffer_size-1;
00314 parm++, cnt++)
00315 {
00316 buffer[cnt] = *parm;
00317 }
00318 buffer[cnt] = '\0';
00319 }
00320 else
00321 {
00322 int cnt = 0;
00323
00324 for(cnt = 0; *parm && !isspace(*parm) && *parm != '>' && cnt < buffer_size-1;
00325 parm++, cnt++)
00326 {
00327 buffer[cnt] = *parm;
00328 }
00329 buffer[cnt] = '\0';
00330 }
00331 }
00332
00333 typedef struct _font_stack
00334 {
00335 GdkColor * fore;
00336 GdkColor * back;
00337 char font_name[255];
00338 int font_size;
00339 int font_ptsize;
00340 struct _font_stack * next;
00341 } font_stack;
00342
00343 static font_stack * _font_stack_init()
00344 {
00345 font_stack * fs = g_new0(font_stack, 1);
00346
00347 fs->font_size = 3;
00348 fs->font_ptsize = font_size + 5;
00349
00350 strcpy(fs->font_name, "helvetica");
00351 return fs;
00352 }
00353
00354 static font_stack * _font_stack_push(font_stack * fs)
00355 {
00356 font_stack * fs2 = g_new0(font_stack, 1);
00357 memcpy(fs2, fs, sizeof(font_stack));
00358 fs2->next = fs;
00359
00360 if(fs2->fore)
00361 {
00362 fs2->fore = g_new0(GdkColor, 1);
00363 memcpy(fs2->fore, fs->fore, sizeof(GdkColor));
00364 }
00365
00366 if(fs2->back)
00367 {
00368 fs2->back = g_new0(GdkColor, 1);
00369 memcpy(fs2->back, fs->back, sizeof(GdkColor));
00370 }
00371
00372 return fs2;
00373 }
00374
00375 static font_stack * _font_stack_pop(font_stack * fs)
00376 {
00377
00378 font_stack * fs2 = fs->next;
00379 if(fs->fore)
00380 g_free(fs->fore);
00381 if(fs->back)
00382 g_free(fs->back);
00383 g_free(fs);
00384
00385 return fs2;
00386 }
00387
00388 static void handle_click(GdkWindow *widget, gpointer data)
00389 {
00390 if(data && strlen(data) > 1 && strcmp(data, "\n"))
00391 {
00392 #ifdef __MINGW32__
00393 open_url_nw(widget, data);
00394 #else
00395 open_url_nw(NULL, data);
00396 #endif
00397 }
00398 }
00399
00400 void gtk_eb_html_init(ExtGtkText * widget)
00401 {
00402 gtk_signal_connect_after(GTK_OBJECT(widget), "button_press_event",
00403 GTK_SIGNAL_FUNC(handle_click), NULL);
00404 ext_gtk_text_set_editable(EXT_GTK_TEXT(widget), FALSE);
00405 ext_gtk_text_set_line_wrap(EXT_GTK_TEXT(widget), TRUE);
00406 ext_gtk_text_set_word_wrap(EXT_GTK_TEXT(widget), TRUE);
00407
00408
00409
00410 }
00411
00412 static int _lighten(int color)
00413 {
00414 if(color < 0x80)
00415 {
00416 return color + 0x80;
00417 }
00418 return 0xFF;
00419 }
00420
00421 static int _darken(int color)
00422 {
00423 if(color > 0x80)
00424 {
00425 return color - 0x80;
00426 }
00427 return 0x00;
00428 }
00429
00430 static int _is_dark(int r, int g, int b)
00431 {
00432 if((r+g+b)<(0x80*3))
00433 {
00434 return 1;
00435 }
00436 return 0;
00437 }
00438
00439 static void _adjust_colors(int*fg_r, int*fg_g, int*fg_b,
00440 int r, int g, int b)
00441 {
00442 int bg_dark = _is_dark(r,g,b);
00443 int fg_dark = _is_dark(*fg_r, *fg_g, *fg_b);
00444
00445 eb_debug(DBG_HTML, "adjusting color %x %x %x", *fg_r, *fg_g, *fg_b);
00446
00447 if(bg_dark && fg_dark)
00448 {
00449 *fg_r = _lighten(*fg_r);
00450 *fg_g = _lighten(*fg_g);
00451 *fg_b = _lighten(*fg_b);
00452 }
00453 else if(!bg_dark && !fg_dark)
00454 {
00455 *fg_r = _darken(*fg_r);
00456 *fg_g = _darken(*fg_g);
00457 *fg_b = _darken(*fg_b);
00458 }
00459 }
00460
00461
00462
00463 void gtk_eb_html_add(ExtGtkText* widget, char * text,
00464 int ignore_bgcolor, int ignore_fgcolor, int ignore_font)
00465 {
00466 gchar ** tokens;
00467 int i = 0;
00468 #ifndef HAVE_LIBXFT
00469 GdkFont * font = NULL;
00470 #else
00471 XftFont * font = NULL;
00472 #endif
00473
00474
00475
00476
00477
00478
00479 int font_bold = 0;
00480 int font_italic = 0;
00481 char * url = NULL;
00482
00483 int first = 0;
00484
00485
00486
00487
00488
00489
00490
00491
00492 int ignore = 0;
00493
00494 font_stack * fs = _font_stack_init();
00495
00496 fs->fore = g_new0(GdkColor, 1);
00497 memcpy(fs->fore, >K_WIDGET (widget)->style->fg[0],
00498 sizeof(GdkColor));
00499
00500
00501 font = _getfont(fs->font_name, font_bold, font_italic,
00502 fs->font_size, fs->font_ptsize);
00503
00504
00505
00506
00507
00508
00509
00510
00511 if(*text != '<')
00512 {
00513 first = 1;
00514 }
00515
00516
00517
00518
00519
00520
00521
00522
00523 if(strstr(text, "<br>") || strstr(text, "<BR>"))
00524 {
00525 char * c = text;
00526 while((c = strstr(c, "\n")) != 0)
00527 {
00528 *c = ' ';
00529 }
00530 c = text;
00531 while((c = strstr(c, "\r")) != 0)
00532 {
00533 *c = ' ';
00534 }
00535 }
00536 else if(strstr(text, "\r"))
00537 { char * c = text;
00538 if(strstr(text, "\n"))
00539 {
00540 while((c = strstr(c,"\r")) != 0)
00541 {
00542 *c = ' ';
00543 }
00544 }
00545 else
00546 {
00547 while((c = strstr(c,"\r")) != 0)
00548 {
00549 *c = '\n';
00550 }
00551 }
00552 }
00553
00554 tokens = g_strsplit(text, "<", 0);
00555
00556
00557
00558
00559
00560
00561
00562 for( i = first?0:1; tokens[i]; i++ )
00563 {
00564
00565
00566 eb_debug(DBG_HTML, "Part %d: %s\n", i, tokens[i]);
00567
00568 if(!first && strstr(tokens[i], ">"))
00569 {
00570 char * copy = strdup(tokens[i]);
00571 #ifdef __MINGW32__
00572 gchar ** tags = g_strsplit(tokens[i], ">", 2);
00573 #else
00574 gchar ** tags = g_strsplit(tokens[i], ">", 1);
00575 #endif
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 eb_debug(DBG_HTML, "\t Part a: %s\n", tags[0]);
00586 eb_debug(DBG_HTML, "\t Part b: %s\n", tags[1]);
00587 g_strstrip(tags[0]);
00588 g_strdown(tags[0]);
00589
00590 if(!strncmp(tags[0], "font", strlen("font")))
00591 {
00592 char * data = tags[0] + strlen("font");
00593 char * parm;
00594
00595 fs = _font_stack_push(fs);
00596
00597 if((parm = strstr(data, "face=")) != NULL)
00598 {
00599 parm += strlen("face=");
00600 _extract_parameter(parm, fs->font_name, 255);
00601 }
00602
00603 if((parm = strstr(data, "ptsize=")) != NULL)
00604 {
00605 char size[25];
00606 parm += strlen("ptsize=");
00607 _extract_parameter(parm, size, 25);
00608 fs->font_size = -1;
00609 fs->font_ptsize = atoi(size);
00610 eb_debug(DBG_HTML, "got a ptsize of %d\n", fs->font_ptsize);
00611 }
00612 else if((parm = strstr(data, "absz=")) != NULL)
00613 {
00614 char size[25];
00615 parm += strlen("absz=");
00616 _extract_parameter(parm, size, 25);
00617 fs->font_size = -1;
00618 fs->font_ptsize = atoi(size);
00619 eb_debug(DBG_HTML, "got a ptsize of %d\n", fs->font_ptsize);
00620 }
00621 else if((parm = strstr(data, "size=")) != NULL)
00622 {
00623 char size[25];
00624 parm += strlen("size=");
00625 _extract_parameter(parm, size, 25);
00626
00627 if(*size == '+')
00628 {
00629 fs->font_size += atoi(size+1);
00630 }
00631 else if(*size == '-')
00632 {
00633 fs->font_size -= atoi(size+1);
00634 }
00635 else
00636 {
00637 fs->font_size = atoi(size);
00638 }
00639 }
00640 if((parm = strstr(data, "color=")) != NULL)
00641 {
00642 char color[255];
00643 parm += strlen("color=");
00644 _extract_parameter(parm, color, 255);
00645 if(fs->fore)
00646 {
00647 g_free(fs->fore);
00648 fs->fore = NULL;
00649 }
00650 if(!ignore_fgcolor)
00651 {
00652
00653
00654
00655 if(!fs->back)
00656 {
00657 GdkColor * bg = >K_WIDGET(widget)->style->base[GTK_STATE_NORMAL];
00658 int r, g, b;
00659 char color2[20];
00660 int fg_r, fg_g, fg_b;
00661 if(!sscanf(color, "#%02x%02x%02x", &fg_r, &fg_g, &fg_b))
00662 {
00663 GdkColor *tmpColor = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color);
00664 fg_r = (tmpColor->red >> 8)&0xFF;
00665 fg_g = (tmpColor->green >> 8)&0xFF;
00666 fg_b = (tmpColor->blue >> 8)&0xFF;
00667 g_free(tmpColor);
00668
00669 }
00670
00671
00672 r = (bg->red >> 8)&0xFF;
00673 g = (bg->green >> 8)&0xFF;
00674 b = (bg->blue >> 8)&0xFF;
00675
00676 _adjust_colors(&fg_r, &fg_g, &fg_b,
00677 r, g, b);
00678
00679 sprintf(color2, "#%02x%02x%02x",fg_r, fg_g,fg_b);
00680
00681 fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color2);
00682 }
00683 else
00684 {
00685 fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color);
00686 }
00687 }
00688 else
00689 {
00690 if(!fs->back && !ignore_bgcolor)
00691 {
00692 fs->fore = g_new0(GdkColor, 1);
00693 memcpy(fs->fore, >K_WIDGET (widget)->style->fg[0],
00694 sizeof(GdkColor));
00695 }
00696 else
00697 {
00698 fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), "black");
00699 }
00700 }
00701
00702 }
00703
00704 if(!ignore_font)
00705 {
00706 font = _getfont(fs->font_name, font_bold, font_italic,
00707 fs->font_size, fs->font_ptsize);
00708 }
00709 else
00710 {
00711 #ifndef HAVE_LIBXFT
00712 font = NULL;
00713 #endif
00714 }
00715 }
00716 else if(!strncmp(tags[0], "img ", strlen("img ")))
00717 {
00718 char * parm;
00719 if((parm = strstr(copy, "src=")) != NULL
00720 ||(parm = strstr(copy, "SRC=")) != NULL)
00721 {
00722 char tmp_url[1024];
00723 GdkPixmap *icon;
00724 GdkBitmap *mask;
00725 parm += strlen("src=");
00726
00727 _extract_parameter(parm,
00728 tmp_url, 1024);
00729
00730 if(!strcmp(tmp_url, "aol_icon.gif"))
00731 {
00732 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, aol_icon_xpm);
00733 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00734 icon, mask, "aol_icon", 0);
00735
00736 }
00737 else if(!strcmp(tmp_url, "free_icon.gif"))
00738 {
00739 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, free_icon_xpm);
00740 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00741 icon, mask, "free_icon", 0);
00742
00743 }
00744 else if(!strcmp(tmp_url, "dt_icon.gif"))
00745 {
00746 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, dt_icon_xpm);
00747 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00748 icon, mask, "dt_icon", 0);
00749
00750 }
00751 else if(!strcmp(tmp_url, "admin_icon.gif"))
00752 {
00753 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, admin_icon_xpm);
00754 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00755 icon, mask, "admin_icon", 0);
00756
00757 }
00758 }
00759 }
00760 else if(!strncmp(tags[0], "smiley ", strlen("smiley ")))
00761 {
00762 char * parm;
00763 if((parm = strstr(copy, "name=")) != NULL
00764 ||(parm = strstr(copy, "NAME=")) != NULL)
00765 {
00766 char tmp_sname[64];
00767 GdkPixmap *icon;
00768 GdkBitmap *mask;
00769 GList * slist=smileys;
00770 smiley * smile;
00771
00772 parm += strlen("name=");
00773
00774 _extract_parameter(parm, tmp_sname, 64);
00775
00776 while(slist!=NULL)
00777 {
00778 smile=(smiley *)slist->data;
00779 if(!strcmp(smile->name, tmp_sname))
00780 {
00781 icon = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, smile->pixmap);
00782 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00783 icon, mask, "smiley", strlen("smiley"));
00784 break;
00785 }
00786 slist=slist->next;
00787 }
00788 if(slist==NULL)
00789 {
00790 if((parm = strstr(copy, "alt=")) != NULL
00791 || (parm = strstr(copy, "ALT=")) != NULL)
00792 {
00793 parm += strlen("alt=");
00794 _extract_parameter(parm, tmp_sname, 64);
00795 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
00796 tmp_sname, strlen(tmp_sname));
00797 }
00798 else
00799 {
00800 icon =gdk_pixmap_create_from_xpm_d(GTK_WIDGET(widget)->window, &mask, NULL, no_such_smiley_xpm);
00801 ext_gtk_text_insert_pixmap(widget, font, fs->fore, fs->back,
00802 icon, mask, "smiley", strlen("smiley"));
00803 }
00804 }
00805 }
00806 }
00807 else if(!strncmp(tags[0], "a ", strlen("a ")))
00808 {
00809
00810 char * parm;
00811
00812 fs = _font_stack_push(fs);
00813
00814 if((parm = strstr(copy, "href=")) != NULL
00815 ||(parm = strstr(copy, "HREF=")) != NULL
00816 )
00817 {
00818 char tmp_url[1024];
00819 int r=0, g=0, b=0xFF;
00820 GdkColor * bg = >K_WIDGET(widget)->style->base[GTK_STATE_NORMAL];
00821 char color[20];
00822 int bg_r, bg_g, bg_b;
00823
00824
00825 bg_r = (bg->red >> 8)&0xFF;
00826 bg_g = (bg->green >> 8)&0xFF;
00827 bg_b = (bg->blue >> 8)&0xFF;
00828
00829 _adjust_colors(&r, &g, &b, bg_r, bg_g, bg_b);
00830 sprintf(color, "#%02x%02x%02x", r, g, b);
00831 fs->fore = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color);
00832
00833 parm += strlen("href=");
00834
00835 _extract_parameter(parm,
00836 tmp_url, 1024);
00837 if(url)
00838 {
00839 g_free(url);
00840 }
00841 url = strdup(tmp_url);
00842
00843
00844 }
00845 }
00846 else if(!strcmp(tags[0], "/a"))
00847 {
00848 fs = _font_stack_pop(fs);
00849 if(url)
00850 {
00851 g_free(url);
00852 }
00853 url = NULL;
00854
00855 if(!fs)
00856 {
00857 fs = _font_stack_init();
00858 fs->fore = g_new0(GdkColor, 1);
00859 memcpy(fs->fore, >K_WIDGET (widget)->style->fg[0],
00860 sizeof(GdkColor));
00861 }
00862 if(!ignore_font)
00863 {
00864 font = _getfont(fs->font_name, font_bold, font_italic,
00865 fs->font_size, fs->font_ptsize);
00866 }
00867 else
00868 {
00869 #ifndef HAVE_LIBXFT
00870 font = NULL;
00871 #endif
00872 }
00873 }
00874 else if(!strcmp(tags[0], "b"))
00875 {
00876 font_bold = 1;
00877 if(!ignore_font)
00878 {
00879 font = _getfont(fs->font_name, font_bold, font_italic,
00880 fs->font_size, fs->font_ptsize);
00881 }
00882 else
00883 {
00884 #ifndef HAVE_LIBXFT
00885 font = NULL;
00886 #endif
00887 }
00888
00889 }
00890 else if(!strcmp(tags[0], "u"))
00891 {
00892 eb_debug(DBG_HTML, "Underline tag found\n");
00893 if(!url)
00894 {
00895 url = strdup("");
00896 }
00897 else
00898 {
00899 eb_debug(DBG_HTML, "Underline tag ignored\n");
00900 }
00901 }
00902 else if(!strcmp(tags[0], "/u"))
00903 {
00904
00905
00906
00907
00908 if(url)
00909 {
00910 g_free(url);
00911 url = NULL;
00912 }
00913 }
00914 else if(!strcmp(tags[0], "/b"))
00915 {
00916 font_bold = 0;
00917 if(!ignore_font)
00918 {
00919 font = _getfont(fs->font_name, font_bold, font_italic,
00920 fs->font_size, fs->font_ptsize);
00921 }
00922 else
00923 {
00924 #ifndef HAVE_LIBXFT
00925 font = NULL;
00926 #endif
00927 }
00928 }
00929 else if(!strcmp(tags[0], "i"))
00930 {
00931 font_italic = 1;
00932 if(!ignore_font)
00933 {
00934 font = _getfont(fs->font_name, font_bold, font_italic,
00935 fs->font_size, fs->font_ptsize);
00936 }
00937 else
00938 {
00939 #ifndef HAVE_LIBXFT
00940 font = NULL;
00941 #endif
00942 }
00943 }
00944 else if(!strcmp(tags[0], "/i"))
00945 {
00946 font_italic = 0;
00947 if(!ignore_font)
00948 {
00949 font = _getfont(fs->font_name, font_bold, font_italic,
00950 fs->font_size, fs->font_ptsize);
00951 }
00952 else
00953 {
00954 #ifndef HAVE_LIBXFT
00955 font = NULL;
00956 #endif
00957 }
00958 }
00959 else if(!strcmp(tags[0], "br"))
00960 {
00961 if(url)
00962 {
00963 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
00964 url, strlen(url)+1, handle_click, "\n", strlen("\n"));
00965 }
00966 else
00967 {
00968 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
00969 "\n", strlen("\n"));
00970 }
00971 }
00972 else if(!strcmp(tags[0], "html")
00973 | !strcmp(tags[0], "/html")
00974 | !strcmp(tags[0], "/p")
00975 | !strcmp(tags[0], "p")
00976 | !strcmp(tags[0], "title")
00977 | !strcmp(tags[0], "/title")
00978 | !strcmp(tags[0], "pre")
00979 | !strcmp(tags[0], "/pre")
00980 | !strncmp(tags[0], "img", strlen("img")))
00981 {
00982 }
00983 else if(!strcmp(tags[0], "hr")
00984 || !strncmp(tags[0], "hr ", strlen("hr ")))
00985 {
00986 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
00987 "\n", strlen("\n"));
00988 ext_gtk_text_insert_divider(widget, font, fs->fore, fs->back,
00989 " \n", strlen(" \n"));
00990
00991
00992 }
00993 else if(!strcmp(tags[0], "/font")
00994 || !strcmp(tags[0], "/body"))
00995 {
00996 fs = _font_stack_pop(fs);
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006 if(!fs)
01007 {
01008 fs = _font_stack_init();
01009 fs->fore = g_new0(GdkColor, 1);
01010 memcpy(fs->fore, >K_WIDGET (widget)->style->fg[0],
01011 sizeof(GdkColor));
01012 }
01013 if(!ignore_font)
01014 {
01015 font = _getfont(fs->font_name, font_bold, font_italic,
01016 fs->font_size, fs->font_ptsize);
01017 }
01018 else
01019 {
01020 #ifndef HAVE_LIBXFT
01021 font = NULL;
01022 #endif
01023 }
01024 }
01025 else if(!strncmp(tags[0], "head", strlen("head")))
01026 {
01027
01028
01029
01030
01031 ignore = 1;
01032 }
01033 else if(!strncmp(tags[0], "body", strlen("body")))
01034 {
01035 char * data = tags[0] + strlen("body");
01036 char * parm;
01037
01038 ignore = 0;
01039
01040
01041 fs = _font_stack_push(fs);
01042
01043 if((parm = strstr(data, "bgcolor=")) != NULL)
01044 {
01045 char color[255];
01046 parm += strlen("bgcolor=");
01047 _extract_parameter(parm, color, 255);
01048 if(fs->back)
01049 {
01050 g_free(fs->back);
01051 }
01052 if(!ignore_bgcolor)
01053 {
01054 fs->back = _getcolor(gdk_window_get_colormap(GTK_WIDGET(widget)->window), color);
01055
01056 }
01057 else
01058 {
01059 fs->back = NULL;
01060 }
01061 }
01062 }
01063 else
01064 {
01065 _unescape_string(copy);
01066 if(url)
01067 {
01068 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
01069 url, strlen(url)+1, handle_click, "<", 1);
01070 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
01071 url, strlen(url)+1, handle_click, copy, strlen(copy));
01072 }
01073 else
01074 {
01075 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
01076 "<", 1);
01077 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
01078 copy, strlen(copy));
01079 }
01080 g_strfreev(tags);
01081 free(copy);
01082 first = 0;
01083 continue;
01084
01085 }
01086
01087 if(tags[1] && !ignore)
01088 {
01089 _unescape_string(tags[1]);
01090
01091 if(url)
01092 {
01093 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
01094 url, strlen(url)+1, handle_click, tags[1], strlen(tags[1]));
01095 eb_debug(DBG_HTML, "Underlined text inserted\n");
01096 }
01097 else
01098 {
01099 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
01100 tags[1], strlen(tags[1]));
01101 }
01102 }
01103 g_strfreev(tags);
01104 free(copy);
01105 }
01106 else
01107 {
01108
01109
01110
01111
01112
01113
01114
01115
01116 if(!ignore)
01117 {
01118 if(!first)
01119 {
01120 if(url)
01121 {
01122 ext_gtk_text_insert_data_underlined( widget, font, fs->fore,
01123 fs->back, url, strlen(url)+1, handle_click, "<", strlen("<") );
01124 }
01125 else
01126 {
01127 ext_gtk_text_insert( widget, font, fs->fore,
01128 fs->back, "<", strlen("<") );
01129 }
01130 }
01131
01132 _unescape_string(tokens[i]);
01133 if(url)
01134 {
01135 ext_gtk_text_insert_data_underlined(widget, font, fs->fore, fs->back,
01136 url, strlen(url)+1, handle_click, tokens[i], strlen(tokens[i]));
01137 }
01138 else
01139 {
01140 ext_gtk_text_insert(widget, font, fs->fore, fs->back,
01141 tokens[i], strlen(tokens[i]));
01142 }
01143 }
01144
01145 }
01146 first = 0;
01147 }
01148
01149
01150
01151
01152
01153
01154 if(text[strlen(text)-1] == '<')
01155 {
01156 if(url)
01157 {
01158 ext_gtk_text_insert_data_underlined( widget, font, fs->fore,
01159 fs->back, url, strlen(url)+1, handle_click, "<", strlen("<") );
01160 }
01161 else
01162 {
01163 ext_gtk_text_insert( widget, font, fs->fore,
01164 fs->back, "<", strlen("<") );
01165 }
01166 }
01167
01168 g_strfreev(tokens);
01169
01170 while(fs)
01171 {
01172 fs = _font_stack_pop(fs);
01173 }
01174 }