[evolution/wip/webkit2] Check for UTF-16 HTML in emfe_text_html_format() when printing



commit 3cd8d1fa16a6bb4d5e25c5f545ca4038399f1e3d
Author: Milan Crha <mcrha redhat com>
Date:   Wed Aug 12 11:48:19 2015 +0200

    Check for UTF-16 HTML in emfe_text_html_format() when printing
    
    If there is a UTF-16 HTML content in a text/html part, then it is
    shown fine in UI, because that part is an iframe, but when it's
    printed, then everything is one long HTML, where the UTF-16 data
    does not make any good, because the main document is UTF-8.

 em-format/e-mail-formatter-text-html.c |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/em-format/e-mail-formatter-text-html.c b/em-format/e-mail-formatter-text-html.c
index 61b98cc..4bb6178 100644
--- a/em-format/e-mail-formatter-text-html.c
+++ b/em-format/e-mail-formatter-text-html.c
@@ -144,7 +144,7 @@ emfe_text_html_format (EMailFormatterExtension *extension,
 
        } else if (context->mode == E_MAIL_FORMATTER_MODE_PRINTING) {
                GOutputStream *decoded_stream;
-               GString *string;
+               GString *string = NULL;
                gchar *pos;
                GList *tags, *iter;
                gboolean valid;
@@ -165,7 +165,32 @@ emfe_text_html_format (EMailFormatterExtension *extension,
                length = g_memory_output_stream_get_data_size (
                        G_MEMORY_OUTPUT_STREAM (decoded_stream));
 
-               string = g_string_new_len ((gchar *) data, length);
+               if (length > 2 && data) {
+                       gunichar2 *maybe_utf16 = data;
+
+                       if (*maybe_utf16 == (gunichar2) 0xFFFE) {
+                               gunichar2 *ptr;
+
+                               for (ptr = maybe_utf16; i < length / 2; i++, ptr++) {
+                                       *ptr = GUINT16_SWAP_LE_BE (*ptr);
+                               }
+                       }
+
+                       if (*maybe_utf16 == (gunichar2) 0xFEFF) {
+                               gchar *utf8;
+
+                               maybe_utf16++;
+                               utf8 = g_utf16_to_utf8 (maybe_utf16, length / 2, NULL, NULL, NULL);
+
+                               if (utf8 && *utf8)
+                                       string = g_string_new (utf8);
+
+                               g_free (utf8);
+                       }
+               }
+
+               if (!string)
+                       string = g_string_new_len ((gchar *) data, length);
 
                g_object_unref (decoded_stream);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]