comparison src/gtkimhtml.c @ 3470:2f8f4f1dac98

[gaim-migrate @ 3521] Thanks Faceprint. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 29 Aug 2002 18:18:41 +0000
parents 15089f9d3431
children 7fb93ecd631c
comparison
equal deleted inserted replaced
3469:15089f9d3431 3470:2f8f4f1dac98
277 gchar *text; 277 gchar *text;
278 struct im_image *img; 278 struct im_image *img;
279 GdkPixmap *pm; 279 GdkPixmap *pm;
280 GdkBitmap *bm; 280 GdkBitmap *bm;
281 281
282 GdkFont *font; 282 PangoLayout *layout;
283 GdkColor *fore; 283 GdkColor *fore;
284 GdkColor *back; 284 GdkColor *back;
285 GdkColor *bg; 285 GdkColor *bg;
286 gboolean underline; 286 gboolean underline;
287 gboolean strike; 287 gboolean strike;
498 if (!line->text) { 498 if (!line->text) {
499 gdk_gc_unref (gc); 499 gdk_gc_unref (gc);
500 return; 500 return;
501 } 501 }
502 502
503 if (bit->back != NULL) {
504 gdk_color_alloc (cmap, bit->back);
505 gdk_gc_set_foreground (gc, bit->back);
506 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, line->y - yoff,
507 gdk_string_width (bit->font, line->text), line->height);
508 bg = bit->back;
509 }
510
511 bg = gdk_color_copy (bg);
512
513 if (line->selected) { 503 if (line->selected) {
514 gint width, x; 504 gint width, x;
515 505
516 if ((line->sel_start > line->sel_end) && (line->sel_end != NULL)) { 506 if ((line->sel_start > line->sel_end) && (line->sel_end != NULL)) {
517 start = line->sel_end; 507 start = line->sel_end;
522 } 512 }
523 513
524 if (start == NULL) 514 if (start == NULL)
525 x = 0; 515 x = 0;
526 else 516 else
527 x = gdk_text_width (bit->font, line->text, start - line->text); 517 x = 100; //gdk_text_width (bit->font, line->text, start - line->text);
528 518
529 if (end == NULL) 519 if (end == NULL)
530 end = strchr(line->text, '\0'); 520 end = strchr(line->text, '\0');
531 521
532 width = gdk_text_width (bit->font, line->text, end - line->text) - x; 522 width = 100; //gdk_text_width (bit->font, line->text, end - line->text) - x;
533 523
534 gdk_gc_set_foreground (gc, imhtml->default_hl_color); 524 gdk_gc_set_foreground (gc, imhtml->default_hl_color);
535 525
536 gdk_draw_rectangle (window, gc, TRUE, x + line->x - xoff, line->y - yoff, 526 gdk_draw_rectangle (window, gc, TRUE, x + line->x - xoff, line->y - yoff,
537 width, line->height); 527 width, line->height);
557 if (similar_colors (bg, fg)) { 547 if (similar_colors (bg, fg)) {
558 gdk_color_alloc (cmap, fg); 548 gdk_color_alloc (cmap, fg);
559 gdk_gc_set_foreground (gc, fg); 549 gdk_gc_set_foreground (gc, fg);
560 } 550 }
561 551
562 if (start) { 552 //if (start) {
563 int offset = 0; 553 //int offset = 0;
564 gdk_draw_text (window, bit->font, gc, line->x - xoff, 554 // gdk_draw_layout (window, *gc, line->x - xoff,
565 line->y - yoff + line->ascent, line->text, start - line->text); 555 // line->y - yoff + line->ascent, line->text,
566 offset = gdk_text_width(bit->font, line->text, start - line->text); 556 // bit->layout);
567 if (bit->underline || bit->url) 557 // offset = gdk_text_width(bit->font, line->text, start - line->text);
568 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, 558 // if (bit->underline || bit->url)
569 line->y - yoff + line->ascent + 1, 559 // gdk_draw_rectangle (window, gc, TRUE, line->x - xoff,
570 offset, 1); 560 // line->y - yoff + line->ascent + 1,
571 if (bit->strike) 561 // offset, 1);
572 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, 562 //if (bit->strike)
573 line->y - yoff + line->ascent - (bit->font->ascent / 2), 563 // gdk_draw_rectangle (window, gc, TRUE, line->x - xoff,
574 offset, 1); 564 // line->y - yoff + line->ascent - (bit->font->ascent / 2),
575 gdk_gc_set_foreground (gc, imhtml->default_hlfg_color); 565 // offset, 1);
576 gdk_draw_text (window, bit->font, gc, line->x - xoff + offset, 566 // gdk_gc_set_foreground (gc, imhtml->default_hlfg_color);
577 line->y - yoff + line->ascent, start, end - start); 567 //gdk_draw_layout (window, bit->font, gc, line->x - xoff + offset,
578 if (bit->underline || bit->url) 568 // line->y - yoff + line->ascent, start, end - start);
579 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff + offset, 569 //if (bit->underline || bit->url)
580 line->y - yoff + line->ascent + 1, 570 //gdk_draw_rectangle (window, gc, TRUE, line->x - xoff + offset,
581 gdk_text_width(bit->font, line->text, end - start), 1); 571 // line->y - yoff + line->ascent + 1,
582 if (bit->strike) 572 // gdk_text_width(bit->font, line->text, end - start), 1);
583 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff + offset, 573 // if (bit->strike)
584 line->y - yoff + line->ascent - (bit->font->ascent / 2), 574 //gdk_draw_rectangle (window, gc, TRUE, line->x - xoff + offset,
585 gdk_text_width(bit->font, line->text, end - start), 1); 575 // line->y - yoff + line->ascent - (bit->font->ascent / 2),
586 offset = gdk_text_width(bit->font, line->text, end - line->text); 576 // gdk_text_width(bit->font, line->text, end - start), 1);
587 gdk_gc_set_foreground (gc, fg); 577 //offset = gdk_text_width(bit->font, line->text, end - line->text);
588 gdk_draw_string (window, bit->font, gc, line->x - xoff + offset, 578 // gdk_gc_set_foreground (gc, fg);
589 line->y - yoff + line->ascent, end); 579 //gdk_draw_string (window, bit->font, gc, line->x - xoff + offset,
590 if (bit->underline || bit->url) 580 // line->y - yoff + line->ascent, end);
591 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff + offset, 581 //if (bit->underline || bit->url)
592 line->y - yoff + line->ascent + 1, 582 //gdk_draw_rectangle (window, gc, TRUE, line->x - xoff + offset,
593 gdk_string_width(bit->font, end), 1); 583 // line->y - yoff + line->ascent + 1,
594 if (bit->strike) 584 // gdk_string_width(bit->font, end), 1);
595 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff + offset, 585 //if (bit->strike)
596 line->y - yoff + line->ascent - (bit->font->ascent / 2), 586 // gdk_draw_rectangle (window, gc, TRUE, line->x - xoff + offset,
597 gdk_string_width(bit->font, end), 1); 587 // line->y - yoff + line->ascent - (bit->font->ascent / 2),
598 } else { 588 // gdk_string_width(bit->font, end), 1);
599 gdk_draw_string (window, bit->font, gc, line->x - xoff, 589 //} else {
600 line->y - yoff + line->ascent, line->text); 590 gdk_draw_layout (window, gc, line->x - xoff,
591 line->y - yoff + line->ascent, bit->layout);
601 592
602 if (bit->underline || bit->url) 593 //if (bit->underline || bit->url)
603 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, line->y - yoff + line->ascent + 1, 594 // gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, line->y - yoff + line->ascent + 1,
604 gdk_string_width (bit->font, line->text), 1); 595 // gdk_string_width (bit->font, line->text), 1);
605 if (bit->strike) 596 //if (bit->strike)
606 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, 597 // gdk_draw_rectangle (window, gc, TRUE, line->x - xoff,
607 line->y - yoff + line->ascent - (bit->font->ascent / 2), 598 // line->y - yoff + line->ascent - (bit->font->ascent / 2),
608 gdk_string_width (bit->font, line->text), 1); 599 // gdk_string_width (bit->font, line->text), 1);
609 } 600 }
610 601
611 gdk_color_free (bg); 602 gdk_color_free (bg);
612 gdk_color_free (fg); 603 gdk_color_free (fg);
613 604
1099 1090
1100 if (width <= 0) 1091 if (width <= 0)
1101 return text; 1092 return text;
1102 1093
1103 for (pos = text; *pos != '\0'; pos++) { 1094 for (pos = text; *pos != '\0'; pos++) {
1104 gint char_width = gdk_text_width (chunk->bit->font, pos, 1); 1095 gint char_width = 7;//gdk_text_width (chunk->bit->font, pos, 1);
1105 if ((width > total) && (width <= total + char_width)) { 1096 if ((width > total) && (width <= total + char_width)) {
1106 if (width < total + (char_width / 2)) 1097 if (width < total + (char_width / 2))
1107 return pos; 1098 return pos;
1108 else 1099 else
1109 return ++pos; 1100 return ++pos;
2063 gtk_imhtml_get_font_name (GdkFont *font) 2054 gtk_imhtml_get_font_name (GdkFont *font)
2064 { 2055 {
2065 return gdk_x11_font_get_name(font); 2056 return gdk_x11_font_get_name(font);
2066 } 2057 }
2067 2058
2068 static GdkFont* 2059 static PangoLayout*
2069 gtk_imhtml_font_load (GtkIMHtml *imhtml, 2060 gtk_imhtml_font_load (const char *text,
2061 GtkIMHtml *imhtml,
2070 gchar *name, 2062 gchar *name,
2071 gboolean bold, 2063 gboolean bold,
2072 gboolean italics, 2064 gboolean italics,
2073 gint fontsize) 2065 gint fontsize)
2074 { 2066 {
2075 GdkFont *default_font = imhtml->default_font; 2067 PangoLayout *layout = gtk_widget_create_pango_layout(GTK_WIDGET(imhtml), text);
2076 const gchar *default_name; 2068 PangoAttrList *list = pango_layout_get_attributes (layout);
2077 gchar **xnames; 2069 PangoAttribute *attr;
2078 gchar **pos; 2070
2079 gchar *tmp = NULL; 2071 if (name) {
2080 GdkFont *ret_font; 2072 attr = pango_attr_family_new (name);
2081 gchar *xname; 2073 pango_attr_list_insert (list, attr);
2082 gchar **xflds; 2074 }
2083 gchar **newvals; 2075
2084 gchar **names = NULL; 2076 if (bold) {
2085 2077 attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
2086 char *italicstrings[] = {"i","o","*"}; 2078 pango_attr_list_insert (list, attr);
2087 int italicsind = 0, nameind = 0; 2079 }
2088 gboolean usebold = TRUE, usesize = TRUE, useregenc = TRUE;
2089 2080
2090 /* if we're not changing anything, use the default. this is the common case */ 2081 if (italics) {
2091 if (!name && !bold && !italics && !fontsize) 2082 attr = pango_attr_style_new (PANGO_STYLE_ITALIC);
2092 return gdk_font_ref (default_font); 2083 pango_attr_list_insert (list, attr);
2084 }
2093 2085
2094 /* base things off of the default font name */ 2086 if (fontsize) {
2095 default_name = gtk_imhtml_get_font_name (default_font); 2087 attr = pango_attr_size_new (POINT_SIZE(fontsize) * 1000);
2096 /* the default font name can actually be several names separated by ','. 2088 pango_attr_list_insert (list, attr);
2097 * This is a fontset... used in foreign encodings. */ 2089 }
2098 do { 2090
2099 xnames = g_strsplit (default_name, ",", -1); 2091 pango_layout_set_attributes(layout, list);
2100 for (pos = xnames; pos && *pos; pos++) { 2092 pango_attr_list_unref(list);
2101 gint i, j; 2093 return layout;
2102 gchar fs[10];
2103 gchar *garbage;
2104 xname = *pos;
2105 xname = g_strchomp (xname);
2106 xname = g_strchug (xname);
2107
2108 xflds = g_strsplit (xname, "-", -1);
2109
2110 /* figure out if we have a valid name. i wish there were an
2111 * easier way for determining how many values g_strplit gave */
2112 for (i = 0; xflds [i]; i++);
2113 if (i != 15) {
2114 int tmp;
2115 newvals = g_malloc0 (16 * sizeof (gchar *));
2116 newvals [0] = "";
2117 for (tmp = 1; tmp < 15; tmp++)
2118 newvals [tmp] = "*";
2119 } else
2120 newvals = g_memdup (xflds, 16 * sizeof (xflds));
2121
2122 /* we force foundry as "*" because i hate them. i should give a better reason. */
2123 newvals [FNDRY] = "*";
2124
2125 /* if it's "*" then it defaults to (nil) anyway. some fonts don't want (nil) */
2126 if ((i > ADSTYL) && !xflds [ADSTYL][0])
2127 newvals [ADSTYL] = "*";
2128
2129 /* If the font doesn't work the first time, we try it with
2130 * registry and encoding as "*" */
2131 if (!useregenc) {
2132 newvals [RGSTRY] = "*";
2133 newvals [ENCDNG] = "*";
2134 }
2135 /* right. */
2136 if (usebold && bold)
2137 newvals [WGHT] = "bold";
2138 else if (!usebold)
2139 newvals [WGHT] = "*";
2140
2141 if (italics)
2142 /* We'll try "i" "o" to get italics and then just use "*" */
2143 newvals [SLANT] = italicstrings[italicsind];
2144
2145 if (usesize && fontsize) {
2146 g_snprintf (fs, sizeof (fs), "%d", POINT_SIZE (fontsize));
2147 newvals [PTSZ] = fs;
2148 newvals [PXLSZ] = "*";
2149 } else if (!usesize) {
2150 newvals [PTSZ] = "*";
2151 newvals [PXLSZ] = "*";
2152 }
2153
2154 if (name) {
2155 /* we got passed a name. it might be a list of names. */
2156 gchar **tmp_nms = g_strsplit (name, ",", -1);
2157 for (j = 0; tmp_nms [j]; j++);
2158 names = g_new0 (char *, j + 2);
2159 for (j = 0; tmp_nms [j]; j++)
2160 names [j] = tmp_nms [j];
2161 g_free (tmp_nms);
2162 /* Put the default font on the array. */
2163 if (i > FMLY) {
2164 names [j] = g_strdup (xflds [FMLY]);
2165 }
2166 newvals [FMLY] = names[nameind];
2167 } else if (i > FMLY) {
2168 /* we didn't get a name. we come here if the gtk font name is valid */
2169 names = g_new0 (gchar *, 2);
2170 names [0] = g_strdup (xflds [FMLY]);
2171 } else {
2172 /* we got fucked */
2173 names = g_new0 (gchar *, 2);
2174 names [0] = g_strdup ("*");
2175 }
2176 if (!tmp)
2177 tmp = g_strjoinv("-", newvals);
2178 else {
2179 /* We have to concat the xlfds in the fontset */
2180 garbage = tmp;
2181 tmp = g_strconcat(garbage, ",",
2182 g_strjoinv ("-", newvals), NULL);
2183 g_free(garbage);
2184 }
2185 g_free (newvals);
2186 g_strfreev (xflds);
2187 }
2188 g_strfreev (xnames);
2189
2190 if (default_font->type == GDK_FONT_FONT)
2191 ret_font = gdk_font_load (tmp);
2192 else {
2193 /* For some reason, fontsets must end with a single * as an xlfd */
2194 gchar *garbage = tmp;
2195 tmp = g_strconcat(garbage, ",*", NULL);
2196 ret_font = gdk_fontset_load (tmp);
2197 }
2198 /* If the font didn't load, we change some of the xlfds one by one
2199 * to get the closest we can. */
2200 if (!ret_font) {
2201 if (useregenc) {
2202 useregenc = FALSE;
2203 } else if (italics && italicsind != 2) {
2204 useregenc = TRUE;
2205 italicsind++;
2206 } else if (bold && usebold) {
2207 useregenc = TRUE;
2208 italicsind=0;
2209 usebold = FALSE;
2210 } else if (usesize) {
2211 useregenc = TRUE;
2212 italicsind = 0;
2213 usebold = TRUE;
2214 usesize = FALSE;
2215 } else if (names && names[nameind++]) {
2216 useregenc = TRUE;
2217 italicsind = 0;
2218 usebold = TRUE;
2219 usesize = TRUE;
2220 } else {
2221 ret_font = gdk_font_ref(default_font);
2222 }
2223 }
2224 g_strfreev (names);
2225 names = NULL;
2226 g_free(tmp);
2227 tmp=NULL;
2228 } while (!ret_font); /* Loop with the new options */
2229 return ret_font;
2230 } 2094 }
2231 2095
2232 static void 2096 static void
2233 gtk_imhtml_init (GtkIMHtml *imhtml) 2097 gtk_imhtml_init (GtkIMHtml *imhtml)
2234 { 2098 {
2499 struct line_info *li; 2363 struct line_info *li;
2500 struct clickable *uw; 2364 struct clickable *uw;
2501 gint width; 2365 gint width;
2502 2366
2503 if (text) 2367 if (text)
2504 width = gdk_string_width (bit->font, text); 2368 pango_layout_get_size(layout, &width, NULL);
2369 width = PANGO_PIXELS(width);
2505 else 2370 else
2506 width = 0; 2371 width = 0;
2507 2372
2508 li = g_new0 (struct line_info, 1); 2373 li = g_new0 (struct line_info, 1);
2509 li->x = imhtml->x; 2374 li->x = imhtml->x;
2510 li->y = imhtml->y; 2375 li->y = imhtml->y;
2511 li->width = width; 2376 li->width = width;
2512 li->height = imhtml->llheight; 2377 li->height = imhtml->llheight;
2513 if (text) 2378 if (text)
2514 li->ascent = MAX (imhtml->llascent, bit->font->ascent); 2379 li->ascent = imhtml->llascent;
2515 else 2380 else
2516 li->ascent = 0; 2381 li->ascent = 0;
2517 li->text = text; 2382 li->text = text;
2518 li->bit = bit; 2383 li->bit = bit;
2519 2384
2585 gchar *copy = g_strdup (bit->text); 2450 gchar *copy = g_strdup (bit->text);
2586 gint pos = 0; 2451 gint pos = 0;
2587 gboolean seenspace = FALSE; 2452 gboolean seenspace = FALSE;
2588 gchar *tmp; 2453 gchar *tmp;
2589 2454
2590 height = bit->font->ascent + bit->font->descent; 2455 pango_layout_get_size (bit->layout, &width, &height);
2591 width = gdk_string_width (bit->font, bit->text); 2456 width = PANGO_PIXELS(width);
2457 height = PANGO_PIXELS(height);
2592 2458
2593 if ((imhtml->x != 0) && ((imhtml->x + width) > imhtml->xsize)) { 2459 if ((imhtml->x != 0) && ((imhtml->x + width) > imhtml->xsize)) {
2594 gint remain = imhtml->xsize - imhtml->x; 2460 gint remain = imhtml->xsize - imhtml->x;
2595 while (gdk_text_width (bit->font, copy, pos) < remain) { 2461 //while (gdk_text_width (bit->font, copy, pos) < remain) {
2596 if (copy [pos] == ' ') 2462 // if (copy [pos] == ' ')
2597 seenspace = TRUE; 2463 // seenspace = TRUE;
2598 pos++; 2464 // pos++;
2599 } 2465 }
2600 if (seenspace) { 2466 if (seenspace) {
2601 while (copy [pos - 1] != ' ') pos--; 2467 while (copy [pos - 1] != ' ') pos--;
2602 2468
2603 tmp = g_strndup (copy, pos); 2469 tmp = g_strndup (copy, pos);
2604 2470
2605 backwards_update (imhtml, bit, height, bit->font->ascent); 2471 backwards_update (imhtml, bit, height, 0); //bit->font->ascent);
2606 add_text_renderer (imhtml, bit, tmp); 2472 add_text_renderer (imhtml, bit, tmp);
2607 } else 2473 } else
2608 pos = 0; 2474 pos = 0;
2609 seenspace = FALSE; 2475 seenspace = FALSE;
2610 new_line (imhtml); 2476 new_line (imhtml);
2611 } 2477 }
2612 2478
2613 backwards_update (imhtml, bit, height, bit->font->ascent); 2479 backwards_update (imhtml, bit, height, 0); //bit->font->ascent);
2614 2480
2615 while (pos < strlen (bit->text)) { 2481 while (pos < strlen (bit->text)) {
2616 width = gdk_string_width (bit->font, copy + pos); 2482 pango_layout_get_size(bit->layout, &width, NULL);
2483 width = PANGO_PIXELS(width);
2617 if (imhtml->x + width > imhtml->xsize) { 2484 if (imhtml->x + width > imhtml->xsize) {
2618 gint newpos = 0; 2485 gint newpos = 0;
2619 gint remain = imhtml->xsize - imhtml->x; 2486 gint remain = imhtml->xsize - imhtml->x;
2620 while (gdk_text_width (bit->font, copy + pos, newpos) < remain) { 2487 //while (gdk_text_width (bit->font, copy + pos, newpos) < remain) {
2621 if (copy [pos + newpos] == ' ') 2488 // if (copy [pos + newpos] == ' ')
2622 seenspace = TRUE; 2489 // seenspace = TRUE;
2623 newpos++; 2490 // newpos++;
2624 } 2491 //}
2625 2492
2626 if (seenspace) 2493 if (seenspace)
2627 while (copy [pos + newpos - 1] != ' ') newpos--; 2494 while (copy [pos + newpos - 1] != ' ') newpos--;
2628 2495
2629 if (newpos == 0) 2496 if (newpos == 0)
2630 break; 2497 break;
2631 2498
2632 tmp = g_strndup (copy + pos, newpos); 2499 tmp = g_strndup (copy + pos, newpos);
2633 pos += newpos; 2500 pos += newpos;
2634 2501
2635 backwards_update (imhtml, bit, height, bit->font->ascent); 2502 backwards_update (imhtml, bit, height, 0); //bit->font->ascent);
2636 add_text_renderer (imhtml, bit, tmp); 2503 add_text_renderer (imhtml, bit, tmp);
2637 2504
2638 seenspace = FALSE; 2505 seenspace = FALSE;
2639 new_line (imhtml); 2506 new_line (imhtml);
2640 } else { 2507 } else {
2641 tmp = g_strdup (copy + pos); 2508 tmp = g_strdup (copy + pos);
2642 2509
2643 backwards_update (imhtml, bit, height, bit->font->ascent); 2510 backwards_update (imhtml, bit, height, 0); //bit->font->ascent);
2644 add_text_renderer (imhtml, bit, tmp); 2511 add_text_renderer (imhtml, bit, tmp);
2645 2512
2646 pos = strlen (bit->text); 2513 pos = strlen (bit->text);
2647 2514
2648 imhtml->x += width; 2515 imhtml->x += width;
2790 bit->text = g_strdup (text); 2657 bit->text = g_strdup (text);
2791 2658
2792 if ((font != NULL) || bold || italics || pre) { 2659 if ((font != NULL) || bold || italics || pre) {
2793 if (font && (bold || italics || font->size || font->face || pre)) { 2660 if (font && (bold || italics || font->size || font->face || pre)) {
2794 if (pre) { 2661 if (pre) {
2795 bit->font = gtk_imhtml_font_load (imhtml, DEFAULT_PRE_FACE, bold, italics, font->size); 2662 bit->layout = gtk_imhtml_font_load (bit->text, imhtml, DEFAULT_PRE_FACE, bold, italics, font->size);
2796 } else { 2663 } else {
2797 bit->font = gtk_imhtml_font_load (imhtml, font->face, bold, italics, font->size); 2664 bit->layout = gtk_imhtml_font_load (bit->text, imhtml, font->face, bold, italics, font->size);
2798 } 2665 }
2799 } else if (bold || italics || pre) { 2666 } else if (bold || italics || pre) {
2800 if (pre) { 2667 if (pre) {
2801 bit->font = gtk_imhtml_font_load (imhtml, DEFAULT_PRE_FACE, bold, italics, 0); 2668 bit->layout = gtk_imhtml_font_load (bit->text, imhtml, DEFAULT_PRE_FACE, bold, italics, 0);
2802 } else { 2669 } else {
2803 bit->font = gtk_imhtml_font_load (imhtml, NULL, bold, italics, 0); 2670 bit->layout = gtk_imhtml_font_load (bit->text, imhtml, NULL, bold, italics, 0);
2804 } 2671 }
2805 } 2672 }
2806 2673
2807 if (font && (type != TYPE_BR)) { 2674 if (font && (type != TYPE_BR)) {
2808 if (font->fore != NULL) 2675 if (font->fore != NULL)
2812 bit->back = gdk_color_copy (font->back); 2679 bit->back = gdk_color_copy (font->back);
2813 } 2680 }
2814 } 2681 }
2815 2682
2816 if (((bit->type == TYPE_TEXT) || (bit->type == TYPE_SMILEY) || (bit->type == TYPE_COMMENT)) && 2683 if (((bit->type == TYPE_TEXT) || (bit->type == TYPE_SMILEY) || (bit->type == TYPE_COMMENT)) &&
2817 (bit->font == NULL)) 2684 (bit->layout == NULL))
2818 bit->font = gdk_font_ref (imhtml->default_font); 2685 return NULL;
2819 2686
2820 if (bg != NULL) 2687 if (bg != NULL)
2821 bit->bg = gdk_color_copy (bg); 2688 bit->bg = gdk_color_copy (bg);
2822 2689
2823 bit->underline = underline; 2690 bit->underline = underline;
3648 while (imhtml->bits) { 3515 while (imhtml->bits) {
3649 GtkIMHtmlBit *bit = imhtml->bits->data; 3516 GtkIMHtmlBit *bit = imhtml->bits->data;
3650 imhtml->bits = g_list_remove (imhtml->bits, bit); 3517 imhtml->bits = g_list_remove (imhtml->bits, bit);
3651 if (bit->text) 3518 if (bit->text)
3652 g_free (bit->text); 3519 g_free (bit->text);
3653 if (bit->font) 3520 if (bit->layout)
3654 gdk_font_unref (bit->font); 3521 g_object_unref (bit->layout);
3655 if (bit->fore) 3522 if (bit->fore)
3656 gdk_color_free (bit->fore); 3523 gdk_color_free (bit->fore);
3657 if (bit->back) 3524 if (bit->back)
3658 gdk_color_free (bit->back); 3525 gdk_color_free (bit->back);
3659 if (bit->bg) 3526 if (bit->bg)