Re: [evolution-patches] [gtkhtml] RTL plain saving indentation fix



Please ignore previous patch. The right one is attached to this message.

Radek

On Thu, 2005-02-10 at 18:32 +0100, Radek Doulík wrote:
Attached patch fixes plain text saving for RTL paragraphs. It also adds new tests to regression test suite.
--
Radek Doulík <rodo novell com>
Novell, Inc.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.2090
diff -u -p -r1.2090 ChangeLog
--- ChangeLog	9 Feb 2005 14:36:59 -0000	1.2090
+++ ChangeLog	10 Feb 2005 17:25:27 -0000
@@ -1,3 +1,9 @@
+2005-02-10  Radek Doulik  <rodo novell com>
+
+	* test-suite.c: added tests for plain save indentation
+
+	* htmlclueflow.c (save_plain): fixed plain padding for RTL
+
 2005-02-09  Radek Doulik  <rodo novell com>
 
 	* test-suite.c: added test for outer quotes inside table
Index: htmlclueflow.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlclueflow.c,v
retrieving revision 1.318
diff -u -p -r1.318 htmlclueflow.c
--- htmlclueflow.c	9 Feb 2005 14:21:27 -0000	1.318
+++ htmlclueflow.c	10 Feb 2005 17:25:37 -0000
@@ -1879,6 +1879,7 @@ save_plain (HTMLObject *self,
 {
 	HTMLClueFlow *flow;
 	HTMLEngineSaveState *buffer_state;
+	HTMLDirection dir = html_object_get_direction (self);
 	GString *out = g_string_new ("");
 	gint pad;
 	gint align_pad;
@@ -2008,13 +2009,19 @@ save_plain (HTMLObject *self,
 
 				switch (html_clueflow_get_halignment (flow)) {
 				case HTML_HALIGN_RIGHT:
-					align_pad = max_width - width;
+					if (dir != HTML_DIRECTION_RTL)
+						align_pad = max_width - width;
+					else
+						align_pad = 0;
 					break;
 				case HTML_HALIGN_CENTER:
 					align_pad = (max_width - width) / 2;
 					break;
 				default:
-					align_pad = 0;
+					if (dir != HTML_DIRECTION_RTL)
+						align_pad = 0;
+					else
+						align_pad = max_width - width;
 					break;
 				}
 			
Index: test-suite.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/test-suite.c,v
retrieving revision 1.8
diff -u -p -r1.8 test-suite.c
--- test-suite.c	9 Feb 2005 14:21:27 -0000	1.8
+++ test-suite.c	10 Feb 2005 17:25:37 -0000
@@ -1,5 +1,6 @@
 #include <string.h>
 #include <stdio.h>
+#include <glib/gstring.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtkwindow.h>
 #include "gtkhtml.h"
@@ -12,6 +13,8 @@
 #include "htmlengine-edit-cut-and-paste.h"
 #include "htmlengine-edit-movement.h"
 #include "htmlengine-edit-text.h"
+#include "htmlengine-save.h"
+#include "htmlselection.h"
 #include "htmltable.h"
 #include "htmltablecell.h"
 #include "htmltext.h"
@@ -32,6 +35,8 @@ static int test_quotes_in_div_block (Gtk
 static int test_quotes_in_table (GtkHTML *html);
 static int test_capitalize_upcase_lowcase_word (GtkHTML *html);
 static int test_delete_nested_cluevs_and_undo (GtkHTML *html);
+static int test_indentation_plain_text (GtkHTML *html);
+static int test_indentation_plain_text_rtl (GtkHTML *html);
 
 static Test tests[] = {
 	{ "cursor movement", NULL },
@@ -46,6 +51,8 @@ static Test tests[] = {
 	{ "outer quotes inside table", test_quotes_in_table },
 	{ "capitalize, upcase/lowcase word", test_capitalize_upcase_lowcase_word },
 	{ "delete across nested cluev's and undo", test_delete_nested_cluevs_and_undo },
+	{ "indentation in plain text", test_indentation_plain_text },
+	{ "indentation in plain text (RTL)", test_indentation_plain_text_rtl },
 	{ NULL, NULL }
 };
 
@@ -57,6 +64,30 @@ static void load_editable (GtkHTML *html
 	gtk_html_set_editable (html, TRUE);
 }
 
+static gboolean
+plain_save_receiver (gpointer engine, const char *data, unsigned int len, gpointer user_data)
+{
+	GString *str = (GString *) user_data;
+
+	g_string_append_len (str, data, len);
+
+	return TRUE;
+}
+
+static char *
+get_plain (GtkHTML *html)
+{
+	GString *str = g_string_new (0);
+	char *rv;
+
+	html_engine_save_plain (html->engine, plain_save_receiver, str);
+
+	rv = str->str;
+	g_string_free (str, FALSE);
+
+	return rv;
+}
+
 static int test_delete_nested_cluevs_and_undo (GtkHTML *html)
 {
 	load_editable (html, "<div>abc</div><div>efg</div>");
@@ -85,6 +116,36 @@ static int test_delete_nested_cluevs_and
 	if (html->engine->cursor->offset != 3
 	    || html->engine->cursor->position != 7)
 		return FALSE;
+
+	return TRUE;
+}
+
+static int test_indentation_plain_text (GtkHTML *html)
+{
+	char *str;
+
+	load_editable (html, "abc<div align=right>abc</div>");
+
+	str = get_plain (html);
+	if (!str || strcmp (str, "abc\n                                                                     abc\n"))
+		return FALSE;
+
+	g_free (str);
+
+	return TRUE;
+}
+
+static int test_indentation_plain_text_rtl (GtkHTML *html)
+{
+	char *str;
+
+	load_editable (html, "׊נ×?×?ק×?ע×?<div align=left>׊נ×?×?ק×?ע×?</div>");
+
+	str = get_plain (html);
+	if (!str || strcmp (str, "׊נ×?×?ק×?ע×?\n                                                                ׊נ×?×?ק×?ע×?\n"))
+		return FALSE;
+
+	g_free (str);
 
 	return TRUE;
 }


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