comparison src/gtkimhtml.c @ 8309:f694277e8341

[gaim-migrate @ 9033] Better parsing; Font sizes scale with the GTK theme; More to come... committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Sat, 21 Feb 2004 20:26:46 +0000
parents b248c1f4efbd
children 6f549c1d0829
comparison
equal deleted inserted replaced
8308:34e8ad866f12 8309:f694277e8341
68 68
69 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a 69 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a
70 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ 70 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */
71 #define MAX_FONT_SIZE 7 71 #define MAX_FONT_SIZE 7
72 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) 72 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1])
73 static gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 }; 73 static gdouble _point_sizes [] = { .5, .75, 1, 1.5, 2, 3, 4};
74 74
75 enum { 75 enum {
76 TARGET_HTML, 76 TARGET_HTML,
77 TARGET_UTF8_STRING, 77 TARGET_UTF8_STRING,
78 TARGET_COMPOUND_TEXT, 78 TARGET_COMPOUND_TEXT,
226 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); 226 G_CALLBACK (gtk_imhtml_tip_paint), imhtml);
227 227
228 gtk_widget_ensure_style (imhtml->tip_window); 228 gtk_widget_ensure_style (imhtml->tip_window);
229 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); 229 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip);
230 font = pango_font_get_metrics(pango_context_load_font(pango_layout_get_context(layout), 230 font = pango_font_get_metrics(pango_context_load_font(pango_layout_get_context(layout),
231 imhtml->tip_window->style->font_desc), 231 imhtml->tip_window->style->font_desc),
232 NULL); 232 NULL);
233 233
234 234
235 pango_layout_get_pixel_size(layout, &scr_w, NULL); 235 pango_layout_get_pixel_size(layout, &scr_w, NULL);
236 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font) + 236 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font) +
237 pango_font_metrics_get_descent(font))/ 4); 237 pango_font_metrics_get_descent(font))/ 4);
238 238
1467 gtk_imhtml_insert_link(imhtml, url, ws); 1467 gtk_imhtml_insert_link(imhtml, url, ws);
1468 else 1468 else
1469 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); 1469 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos);
1470 ws[0] = '\0'; wpos = 0; 1470 ws[0] = '\0'; wpos = 0;
1471 /* NEW_BIT (NEW_TEXT_BIT); */ 1471 /* NEW_BIT (NEW_TEXT_BIT); */
1472 fonts = g_slist_remove (fonts, font); 1472
1473 if (font->face) { 1473 if (font->face) {
1474 gtk_imhtml_toggle_fontface(imhtml, NULL); 1474 gtk_imhtml_toggle_fontface(imhtml, NULL);
1475 g_free (font->face); 1475 g_free (font->face);
1476 } 1476 }
1477 if (font->fore) { 1477 if (font->fore) {
1483 g_free (font->back); 1483 g_free (font->back);
1484 } 1484 }
1485 if (font->sml) 1485 if (font->sml)
1486 g_free (font->sml); 1486 g_free (font->sml);
1487 g_free (font); 1487 g_free (font);
1488
1489 if (font->size != 3)
1490 gtk_imhtml_font_set_size(imhtml, 3);
1491
1492 fonts = fonts->next;
1493 if (fonts) {
1494 GtkIMHtmlFontDetail *font = fonts->data;
1495
1496 if (font->face)
1497 gtk_imhtml_toggle_fontface(imhtml, font->face);
1498 if (font->fore)
1499 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
1500 if (font->back)
1501 gtk_imhtml_toggle_backcolor(imhtml, font->back);
1502 if (font->size != 3)
1503 gtk_imhtml_font_set_size(imhtml, font->size);
1504 }
1488 } 1505 }
1489 break; 1506 break;
1490 case 28: /* /A */ 1507 case 28: /* /A */
1491 if (url) { 1508 if (url) {
1492 gtk_imhtml_insert_link(imhtml, url, ws); 1509 gtk_imhtml_insert_link(imhtml, url, ws);
1493 g_free(url); 1510 g_free(url);
1494 ws[0] = '\0'; wpos = 0; 1511 ws[0] = '\0'; wpos = 0;
1532 1549
1533 font = g_new0 (GtkIMHtmlFontDetail, 1); 1550 font = g_new0 (GtkIMHtmlFontDetail, 1);
1534 if (fonts) 1551 if (fonts)
1535 oldfont = fonts->data; 1552 oldfont = fonts->data;
1536 1553
1537 if (color && !(options & GTK_IMHTML_NO_COLOURS)) 1554 if (color && !(options & GTK_IMHTML_NO_COLOURS)) {
1538 font->fore = color; 1555 font->fore = color;
1539 else if (oldfont && oldfont->fore)
1540 font->fore = g_strdup(oldfont->fore);
1541 if (font->fore)
1542 gtk_imhtml_toggle_forecolor(imhtml, font->fore); 1556 gtk_imhtml_toggle_forecolor(imhtml, font->fore);
1543 1557 }
1544 if (back && !(options & GTK_IMHTML_NO_COLOURS)) 1558 //else if (oldfont && oldfont->fore)
1559 // font->fore = g_strdup(oldfont->fore);
1560
1561 if (back && !(options & GTK_IMHTML_NO_COLOURS)) {
1545 font->back = back; 1562 font->back = back;
1546 else if (oldfont && oldfont->back)
1547 font->back = g_strdup(oldfont->back);
1548 if (font->back)
1549 gtk_imhtml_toggle_backcolor(imhtml, font->back); 1563 gtk_imhtml_toggle_backcolor(imhtml, font->back);
1550 1564 }
1551 if (face && !(options & GTK_IMHTML_NO_FONTS)) 1565 //else if (oldfont && oldfont->back)
1566 // font->back = g_strdup(oldfont->back);
1567
1568 if (face && !(options & GTK_IMHTML_NO_FONTS)) {
1552 font->face = face; 1569 font->face = face;
1553 else if (oldfont && oldfont->face)
1554 font->face = g_strdup(oldfont->face);
1555 if (font->face)
1556 gtk_imhtml_toggle_fontface(imhtml, font->face); 1570 gtk_imhtml_toggle_fontface(imhtml, font->face);
1571 }
1572 //else if (oldfont && oldfont->face)
1573 // font->face = g_strdup(oldfont->face);
1557 1574
1558 if (sml) 1575 if (sml)
1559 font->sml = sml; 1576 font->sml = sml;
1560 else if (oldfont && oldfont->sml) 1577 else if (oldfont && oldfont->sml)
1561 font->sml = g_strdup(oldfont->sml); 1578 font->sml = g_strdup(oldfont->sml);
1572 } 1589 }
1573 if (font->size > 100) 1590 if (font->size > 100)
1574 font->size = 100; 1591 font->size = 100;
1575 } else if (oldfont) 1592 } else if (oldfont)
1576 font->size = oldfont->size; 1593 font->size = oldfont->size;
1577 /* gtk_imhtml_font_set_size(imhtml, font->size); */ 1594 else
1595 font->size = 3;
1596 gtk_imhtml_font_set_size(imhtml, font->size);
1578 g_free(size); 1597 g_free(size);
1579 fonts = g_slist_prepend (fonts, font); 1598 fonts = g_slist_prepend (fonts, font);
1580 } 1599 }
1581 break; 1600 break;
1582 case 44: /* BODY (opt) */ 1601 case 44: /* BODY (opt) */
2311 GtkTextIter size; 2330 GtkTextIter size;
2312 /* We create the tags here so that one can grow font or shrink font several times 2331 /* We create the tags here so that one can grow font or shrink font several times
2313 * in a row without creating unnecessary tags */ 2332 * in a row without creating unnecessary tags */
2314 if (span->tag == NULL) { 2333 if (span->tag == NULL) {
2315 span->tag = gtk_text_buffer_create_tag 2334 span->tag = gtk_text_buffer_create_tag
2316 (imhtml->text_buffer, NULL, "size-points", (double)_point_sizes [imhtml->edit.fontsize-1], NULL); 2335 (imhtml->text_buffer, NULL, "scale", (double)_point_sizes [imhtml->edit.fontsize-1], NULL);
2317 span->start_tag = g_strdup_printf("<font size=\"%d\">", imhtml->edit.fontsize); 2336 span->start_tag = g_strdup_printf("<font size=\"%d\">", imhtml->edit.fontsize);
2318 span->end_tag = g_strdup("</font>"); 2337 span->end_tag = g_strdup("</font>");
2319 } 2338 }
2320 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &size, span->start); 2339 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &size, span->start);
2321 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &size, iter); 2340 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &size, iter);
2500 { 2519 {
2501 GtkIMHtmlFormatSpan *span; 2520 GtkIMHtmlFormatSpan *span;
2502 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); 2521 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
2503 GtkTextIter iter; 2522 GtkTextIter iter;
2504 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); 2523 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
2505 if (!imhtml->edit.forecolor) { 2524 if (color) { //!imhtml->edit.forecolor) {
2506 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); 2525 span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
2507 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); 2526 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2508 span->start_tag = g_strdup_printf("<font color=\"%s\">", color); 2527 span->start_tag = g_strdup_printf("<font color=\"%s\">", color);
2509 span->end = NULL; 2528 span->end = NULL;
2510 span->end_tag = g_strdup("</font>"); 2529 span->end_tag = g_strdup("</font>");
2526 { 2545 {
2527 GtkIMHtmlFormatSpan *span; 2546 GtkIMHtmlFormatSpan *span;
2528 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); 2547 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
2529 GtkTextIter iter; 2548 GtkTextIter iter;
2530 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); 2549 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
2531 if (!imhtml->edit.backcolor) { 2550 if (color) { //!imhtml->edit.backcolor) {
2532 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); 2551 span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
2533 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); 2552 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2534 span->start_tag = g_strdup_printf("<font back=\"%s\">", color); 2553 span->start_tag = g_strdup_printf("<font back=\"%s\">", color);
2535 span->end = NULL; 2554 span->end = NULL;
2536 span->end_tag = g_strdup("</font>"); 2555 span->end_tag = g_strdup("</font>");
2550 { 2569 {
2551 GtkIMHtmlFormatSpan *span; 2570 GtkIMHtmlFormatSpan *span;
2552 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); 2571 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
2553 GtkTextIter iter; 2572 GtkTextIter iter;
2554 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); 2573 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
2555 if (!imhtml->edit.fontface) { 2574 if (face) { //!imhtml->edit.fontface) {
2556 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); 2575 span = g_malloc(sizeof(GtkIMHtmlFormatSpan));
2557 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); 2576 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE);
2558 span->start_tag = g_strdup_printf("<font face=\"%s\">", face); 2577 span->start_tag = g_strdup_printf("<font face=\"%s\">", face);
2559 span->end = NULL; 2578 span->end = NULL;
2560 span->end_tag = g_strdup("</font>"); 2579 span->end_tag = g_strdup("</font>");