gtkhtml r8862 - branches/gnome-2-22/gtkhtml



Author: mcrha
Date: Mon Jun  9 14:52:33 2008
New Revision: 8862
URL: http://svn.gnome.org/viewvc/gtkhtml?rev=8862&view=rev

Log:
2008-06-09  Milan Crha  <mcrha redhat com>

	** Fix for bug #533741 (Patch by Vaclav Slavik.)

	* gtkhtml.c: (get_selection_string), (gtk_html_get_selection_html),
	(gtk_html_get_selection_plain_text), (utf8_filter_out_bom),
	(clipboard_paste_received_cb), (create_clipboard_contents),
	(update_primary_selection): Don't insert BOM into UTF-8 text when
	copying to clipboard; filter it out when pasting from clipboard.



Modified:
   branches/gnome-2-22/gtkhtml/ChangeLog
   branches/gnome-2-22/gtkhtml/gtkhtml.c

Modified: branches/gnome-2-22/gtkhtml/gtkhtml.c
==============================================================================
--- branches/gnome-2-22/gtkhtml/gtkhtml.c	(original)
+++ branches/gnome-2-22/gtkhtml/gtkhtml.c	Mon Jun  9 14:52:33 2008
@@ -2094,7 +2094,7 @@
 }
 
 static char *
-get_selection_string (GtkHTML *html, int *len, gboolean selection, gboolean primary, gboolean html_format, gboolean order_marker)
+get_selection_string (GtkHTML *html, int *len, gboolean selection, gboolean primary, gboolean html_format)
 {
 	HTMLObject *selection_object = NULL;
 	char *selection_string = NULL;
@@ -2124,11 +2124,6 @@
 			state = html_engine_save_buffer_new (html->engine, TRUE);
   			buffer = (GString *)state->user_data;
 
-			if (order_marker) {
-				/* prepend a byte order marker (ZWNBSP) to the selection */
-				g_string_append_unichar (buffer, 0xfeff);
-			}
-
        			html_object_save (selection_object, state);
 			g_string_append_unichar (buffer, 0x0000);
 
@@ -2153,14 +2148,14 @@
 char *
 gtk_html_get_selection_html (GtkHTML *html, int *len)
 {
-	return get_selection_string (html, len, TRUE, FALSE, TRUE, FALSE);
+	return get_selection_string (html, len, TRUE, FALSE, TRUE);
 }
 
 /* returned pointer should be freed with g_free */
 char *
 gtk_html_get_selection_plain_text (GtkHTML *html, int *len)
 {
-	return get_selection_string (html, len, TRUE, FALSE, FALSE, FALSE);
+	return get_selection_string (html, len, TRUE, FALSE, FALSE);
 }
 
 static gchar *
@@ -2201,6 +2196,23 @@
 	return (utf8_ret);
 }
 
+/* removes useless leading BOM from UTF-8 string if present */
+static gchar *
+utf8_filter_out_bom (gchar *str) {
+	if (!str)
+		return NULL;
+
+	/* input is always valid, NUL-terminated UTF-8 sequence, we don't need
+	 * to validated it again */
+	if (g_utf8_get_char (str) == 0xfeff) {
+		gchar *out = g_strdup (g_utf8_next_char (str));
+		g_free (str);
+		return out;
+	}
+
+	return str;
+}
+
 static void
 set_adjustments (GtkLayout     *layout,
 		 GtkAdjustment *hadj,
@@ -4252,7 +4264,7 @@
 				utf8 = utf16_to_utf8_with_bom_check (selection_data->data, selection_data->length);
 
 			} else {
-				utf8 = g_strndup ((const gchar *) selection_data->data, selection_data->length);
+				utf8 = utf8_filter_out_bom (g_strndup ((const gchar *)selection_data->data, selection_data->length));
 			}
 
 			if (as_cite && utf8) {
@@ -4268,6 +4280,7 @@
 			else
 				g_warning ("selection was empty");
 		} else if ((utf8 = (gchar *) gtk_selection_data_get_text (selection_data))) {
+			utf8 = utf8_filter_out_bom (utf8);
 			if (as_cite) {
 				char *encoded;
 
@@ -4316,10 +4329,10 @@
 	contents = g_new0 (ClipboardContents, 1);
 
 	/* set html text */
-	contents->html_text = get_selection_string (html, &html_len, FALSE, FALSE, TRUE, TRUE);
+	contents->html_text = get_selection_string (html, &html_len, FALSE, FALSE, TRUE);
 
 	/* set plain text */
-	contents->plain_text = get_selection_string (html, &text_len, FALSE, FALSE, FALSE, FALSE);
+	contents->plain_text = get_selection_string (html, &text_len, FALSE, FALSE, FALSE);
 
 	return contents;
 }
@@ -4408,7 +4421,7 @@
 
 	clipboard = gtk_widget_get_clipboard (GTK_WIDGET (html), GDK_SELECTION_PRIMARY);
 
-	text = get_selection_string (html, &text_len, FALSE, TRUE, FALSE, FALSE);
+	text = get_selection_string (html, &text_len, FALSE, TRUE, FALSE);
 	if (!text)
 		return;
 



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