--- src/message.c | 27 ++++++++++++++++----------- test/automatic/message2.c | 14 +++++++------- test/automatic/script/20-messages.scr | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/src/message.c b/src/message.c index 7c35cb1..ab43bbd 100644 --- a/src/message.c +++ b/src/message.c @@ -394,6 +394,7 @@ size_t gg_message_text_to_html(char *dst, const char *src, gg_encoding_t encodin size_t char_pos = 0; unsigned char old_attr = 0; const unsigned char default_color[] = {'\x00', '\x00', '\x00'}; + const unsigned char *old_color = NULL; int in_span = 0; unsigned int i; size_t len = 0; @@ -455,14 +456,9 @@ size_t gg_message_text_to_html(char *dst, const char *src, gg_encoding_t encodin if ((old_attr & GG_FONT_BOLD) != 0) gg_append(dst, &len, "</b>", 4); - if ((attr & (GG_FONT_BOLD | GG_FONT_ITALIC | GG_FONT_UNDERLINE | GG_FONT_COLOR)) != 0 || (attr == 0 && old_attr != 0)) { + if ((attr & (GG_FONT_BOLD | GG_FONT_ITALIC | GG_FONT_UNDERLINE | GG_FONT_COLOR)) != 0) { const unsigned char *color; - if (in_span) { - gg_append(dst, &len, "</span>", 7); - in_span = 0; - } - if (((attr & GG_FONT_COLOR) != 0) && (format_idx + 3 <= format_len)) { color = &format_[format_idx]; format_idx += 3; @@ -470,12 +466,20 @@ size_t gg_message_text_to_html(char *dst, const char *src, gg_encoding_t encodin color = default_color; } - if (src[i] != 0) { - if (dst != NULL) - sprintf(&dst[len], span_fmt, color[0], color[1], color[2]); + if (old_color == NULL || memcmp(color, old_color, 3) != 0) { + if (in_span) { + gg_append(dst, &len, "</span>", 7); + in_span = 0; + } + + if (src[i] != 0) { + if (dst != NULL) + sprintf(&dst[len], span_fmt, color[0], color[1], color[2]); - len += span_len; - in_span = 1; + len += span_len; + in_span = 1; + old_color = color; + } } } @@ -529,6 +533,7 @@ size_t gg_message_text_to_html(char *dst, const char *src, gg_encoding_t encodin len += span_len; in_span = 1; + old_color = default_color; } /* Doklej znak zachowując htmlowe escapowanie. */ diff --git a/test/automatic/message2.c b/test/automatic/message2.c index 5c34c40..6d92c7f 100644 --- a/test/automatic/message2.c +++ b/test/automatic/message2.c @@ -41,10 +41,10 @@ const struct test_data text_to_html[] = { "test test", SPAN("test<img name=\"8877665544332211\">test"), GG_ENCODING_UTF8, "\x04\x00\x80\x09\x01\x11\x22\x33\x44\x55\x66\x77\x88", 13 }, /* Obrazek w środku tekstu, tekst na końcu formatowany */ - { "test test foo", SPAN("test<img name=\"8877665544332211\">test ") SPAN("<b>foo</b>"), GG_ENCODING_UTF8, "\x04\x00\x80\x09\x01\x11\x22\x33\x44\x55\x66\x77\x88\x0a\x00\x01", 16 }, + { "test test foo", SPAN("test<img name=\"8877665544332211\">test <b>foo</b>"), GG_ENCODING_UTF8, "\x04\x00\x80\x09\x01\x11\x22\x33\x44\x55\x66\x77\x88\x0a\x00\x01", 16 }, /* Obrazek w środku tekstu, tekst na końcu formatowany, dokładnie tak jak wysyła oryginalny klient */ - { "test\xa0test foo", SPAN("test<img name=\"8877665544332211\">") SPAN("test ") SPAN("<b>foo</b>"), GG_ENCODING_CP1250, "\x00\x00\x08\x00\x00\x00\x05\x00\x08\x00\x00\x00\x0a\x00\x09\x00\x00\x00\x04\x00\x80\x09\x01\x11\x22\x33\x44\x55\x66\x77\x88", 31 }, + { "test\xa0test foo", SPAN("test<img name=\"8877665544332211\">test <b>foo</b>"), GG_ENCODING_CP1250, "\x00\x00\x08\x00\x00\x00\x05\x00\x08\x00\x00\x00\x0a\x00\x09\x00\x00\x00\x04\x00\x80\x09\x01\x11\x22\x33\x44\x55\x66\x77\x88", 31 }, /* Obrazek poza tekstem */ { "test", SPAN("test"), GG_ENCODING_UTF8, "\x05\x00\x80\x09\x01\x11\x22\x33\x44\x55\x66\x77\x88", 13 }, @@ -68,10 +68,10 @@ const struct test_data text_to_html[] = { "", "<img name=\"8877665544332211\">", GG_ENCODING_UTF8, "\x00\x00\x80\x09\x01\x11\x22\x33\x44\x55\x66\x77\x88\x01\x00\x80\x09\x01\x88\x77\x66\x55\x44\x33\x22\x11", 26 }, /* Atrybuty na początku, w środku i na końcu tekstu */ - { "foobarbaz", SPAN("<b>foo</b>") SPAN("<i>bar</i>") SPAN("<u>baz</u>"), GG_ENCODING_UTF8, "\x00\x00\x01\x03\x00\x02\x06\x00\x04", 9 }, + { "foobarbaz", SPAN("<b>foo</b><i>bar</i><u>baz</u>"), GG_ENCODING_UTF8, "\x00\x00\x01\x03\x00\x02\x06\x00\x04", 9 }, /* Mieszane atrybuty */ - { "foobarbaz", SPAN("<b><i>foo</i></b>") SPAN("<b><u>bar</u></b>") SPAN("<i><u>baz</u></i>"), GG_ENCODING_UTF8, "\x00\x00\x03\x03\x00\x05\x06\x00\x06", 9 }, + { "foobarbaz", SPAN("<b><i>foo</i></b><b><u>bar</u></b><i><u>baz</u></i>"), GG_ENCODING_UTF8, "\x00\x00\x03\x03\x00\x05\x06\x00\x06", 9 }, /* Wszystkie atrybuty */ { "test", SPAN("<b><i><u>test</u></i></b>"), GG_ENCODING_UTF8, "\x00\x00\x07", 3 }, @@ -110,13 +110,13 @@ const struct test_data text_to_html[] = { "test", SPAN("test"), GG_ENCODING_UTF8, "\x04\x00\x80\x09\x01\x11\x22\x33\x44\x55\x66\x77", 12 }, /* Atrybut w środku znaku unikodowego */ - { "żółć", SPAN("<b>ż</b>") SPAN("<i>ółć</i>"), GG_ENCODING_UTF8, "\x00\x00\x01\x01\x00\x02", 6 }, + { "żółć", SPAN("<b>ż</b><i>ółć</i>"), GG_ENCODING_UTF8, "\x00\x00\x01\x01\x00\x02", 6 }, /* To samo co wyżej, ale kodowanie CP1250 */ - { "\xbf\xf4\xb3\xe6", SPAN("<b>\xbf</b>") SPAN("<i>\xf4\xb3\xe6</i>"), GG_ENCODING_CP1250, "\x00\x00\x01\x01\x00\x02", 6 }, + { "\xbf\xf4\xb3\xe6", SPAN("<b>\xbf</b><i>\xf4\xb3\xe6</i>"), GG_ENCODING_CP1250, "\x00\x00\x01\x01\x00\x02", 6 }, /* Błąd zgłoszony na ekg-users <5b601e1c.7feabed5.4bfaf8b6.14...@o2.pl> */ - { "testboldatest", SPAN("test") SPAN("<b>bolda</b>") SPAN("test"), GG_ENCODING_UTF8, "\x04\x00\x01\x09\x00\x00", 6 }, + { "testboldatest", SPAN("test<b>bolda</b>test"), GG_ENCODING_UTF8, "\x04\x00\x01\x09\x00\x00", 6 }, /* Pusty tekst. Oryginalny klient co prawda nie wysyła pustego tekstu, * ale przy wiadomości zawierającej jedynie obrazek, nie dokleja tagów diff --git a/test/automatic/script/20-messages.scr b/test/automatic/script/20-messages.scr index 3916c88..c659b33 100644 --- a/test/automatic/script/20-messages.scr +++ b/test/automatic/script/20-messages.scr @@ -26,7 +26,7 @@ call { } #expect data (0b 00 00 00, auto, 56 34 12 00, xx xx xx xx, 28 00 00 00, "Test" 00, 02, 0f 00, 00 00 01, 01 00 02, 02 00 04, 03 00 08 12 34 56) -expect data (2d 00 00 00, auto, 56 34 12 00, xx xx xx xx, 28 00 00 00, 76 01 00 00, 7b 01 00 00, "<span" 20 "style=" 22 "color:#000000;" 20 "font-family:'MS" 20 "Shell" 20 "Dlg" 20 "2';" 20 "font-size:9pt;" 20 22 "><b>T</b></span><span" 20 "style=" 22 "color:#000000;" 20 "font-family:'MS" 20 "Shell" 20 "Dlg" 20 "2';" 20 "font-size:9pt;" 20 22 "><i>e</i></span><span" 20 "style=" 22 "color:#000000;" 20 "font-family:'MS" 20 "Shell" 20 "Dlg" 20 "2';" 20 "font-size:9pt;" 20 22 "><u>s</u></span><span" 20 "style=" 22 "color:#123456;" 20 "font-family:'MS" 20 "Shell" 20 "Dlg" 20 "2';" 20 "font-size:9pt;" 20 22 ">t</span>" 00, "Test" 00, 02, 0f 00, 00 00 01, 01 00 02, 02 00 04, 03 00 08 12 34 56) +expect data (2d 00 00 00, auto, 56 34 12 00, xx xx xx xx, 28 00 00 00, d2 00 00 00, d7 00 00 00, "<span" 20 "style=" 22 "color:#000000;" 20 "font-family:'MS" 20 "Shell" 20 "Dlg" 20 "2';" 20 "font-size:9pt;" 20 22 "><b>T</b><i>e</i><u>s</u></span><span" 20 "style=" 22 "color:#123456;" 20 "font-family:'MS" 20 "Shell" 20 "Dlg" 20 "2';" 20 "font-size:9pt;" 20 22 ">t</span>" 00, "Test" 00, 02, 0f 00, 00 00 01, 01 00 02, 02 00 04, 03 00 08 12 34 56) #----------------------------------------------------------------------------- # Sending conference message -- 1.7.6.1 _______________________________________________ libgadu-devel mailing list libgadu-devel@lists.ziew.org http://lists.ziew.org/mailman/listinfo/libgadu-devel