[evolution-patches] gtkhtml, mail content should be read line by line(update)



Hi rodo,
  This is a patch for bug #55250. With the help of your advice, I have
rewritten the patch. And now it works well on my box (but it still can't
read the the whole line's text if the line has a inlined image, because 
the image will break the line into two seperate HTMLText Object, then
gnopernicus can only read one by one), would you please give it a
review? Thanks!
 
Some information about this bug:
    The bug's reason is that gail_text_util doesn't know how lines are
broken in gtkhtml, so gail_text_util_get_text function will treat the
whole paragraph as a single line. In this patch, we implement the
function when boundary_type is ATK_TEXT_BOUNDARY_LINE_START or
ATK_TEXT_BOUNDARY_LINE_END, and leave the rest to gail_text_util.

--
Regards,
Eric.

   
Index: text.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/text.c,v
retrieving revision 1.7
diff -u -r1.7 text.c
--- text.c	16 Sep 2003 21:05:38 -0000	1.7
+++ text.c	27 Apr 2004 13:26:58 -0000
@@ -365,22 +365,95 @@
 				      gint *start_offset, gint *end_offset)
 {
 	HTMLText *to = HTML_TEXT (HTML_A11Y_HTML (text));
+	HTMLTextSlave *start_slave, *end_slave;
 
-	gail_text_util_text_setup (HTML_A11Y_TEXT (text)->util, to->text);
-	return gail_text_util_get_text (HTML_A11Y_TEXT (text)->util, NULL, GAIL_AFTER_OFFSET, boundary_type, offset, 
+	g_return_val_if_fail (to, NULL);
+	g_return_val_if_fail (start_offset && end_offset, NULL);
+
+	switch (boundary_type) {
+	case ATK_TEXT_BOUNDARY_LINE_START:
+		end_slave = html_text_get_slave_at_offset (HTML_OBJECT (to), offset);
+		g_return_val_if_fail (end_slave, NULL);
+		start_slave = (HTMLTextSlave *) HTML_OBJECT (end_slave)->next;
+
+		if (start_slave && HTML_IS_TEXT_SLAVE (start_slave)) {
+			*start_offset = start_slave->posStart;
+			end_slave = (HTMLTextSlave *) HTML_OBJECT (start_slave)->next;
+			if (end_slave && HTML_IS_TEXT_SLAVE (end_slave)) 
+				*end_offset = end_slave->posStart;
+			else 
+				*end_offset = start_slave->posStart + start_slave->posLen;
+
+		} else { /* we are on the last line. */
+			*start_offset = *end_offset = html_a11y_text_get_character_count (text);
+		}
+
+		return html_a11y_text_get_text (text, *start_offset, *end_offset);
+
+	case ATK_TEXT_BOUNDARY_LINE_END:
+		start_slave = html_text_get_slave_at_offset (HTML_OBJECT (to), offset);
+		g_return_val_if_fail (start_slave, NULL);
+
+		*start_offset = start_slave->posStart + start_slave->posLen;
+		end_slave = (HTMLTextSlave *) HTML_OBJECT (start_slave)->next;
+		if (end_slave && HTML_IS_TEXT_SLAVE (end_slave))
+			*end_offset = end_slave->posStart + end_slave->posLen;
+		else
+			*end_offset = *start_offset;
+		
+		return html_a11y_text_get_text (text, *start_offset, *end_offset);
+
+	default:
+		gail_text_util_text_setup (HTML_A11Y_TEXT (text)->util, to->text);
+		return gail_text_util_get_text (HTML_A11Y_TEXT (text)->util, NULL, GAIL_AFTER_OFFSET, boundary_type, offset, 
 					start_offset, end_offset);
+	}
 }
 
 static gchar *
 html_a11y_text_get_text_at_offset (AtkText *text, gint offset, AtkTextBoundary boundary_type,
 				   gint *start_offset, gint *end_offset)
 {
-	gchar * ret;
 	HTMLText *to = HTML_TEXT (HTML_A11Y_HTML (text));
+	HTMLTextSlave *start_slave, *end_slave;
 
-	gail_text_util_text_setup (HTML_A11Y_TEXT (text)->util, to->text);
-	return gail_text_util_get_text (HTML_A11Y_TEXT (text)->util, NULL, GAIL_AT_OFFSET, boundary_type, offset, 
+	g_return_val_if_fail (to, NULL);
+	g_return_val_if_fail (start_offset && end_offset, NULL);
+
+	switch (boundary_type) {
+	case ATK_TEXT_BOUNDARY_LINE_START:
+		start_slave = html_text_get_slave_at_offset (HTML_OBJECT (to), offset);
+		g_return_val_if_fail (start_slave, NULL);
+		end_slave = (HTMLTextSlave *) HTML_OBJECT (start_slave)->next;
+
+		if (end_slave && HTML_IS_TEXT_SLAVE (end_slave)) {
+			*end_offset = end_slave->posStart;
+		} else {
+			*end_offset = start_slave->posStart + start_slave->posLen;
+		}
+		*start_offset = start_slave->posStart;
+
+		return html_a11y_text_get_text (text, *start_offset, *end_offset);
+
+	case ATK_TEXT_BOUNDARY_LINE_END:
+		end_slave = html_text_get_slave_at_offset (HTML_OBJECT (to), offset);
+		g_return_val_if_fail (end_slave, NULL);
+		start_slave = (HTMLTextSlave *) HTML_OBJECT (end_slave)->prev;
+
+		if (start_slave && HTML_IS_TEXT_SLAVE (start_slave)) {
+			*start_offset = start_slave->posStart + start_slave->posLen;
+		} else {
+			*start_offset = end_slave->posStart;
+		}
+		*end_offset = end_slave->posStart + end_slave->posLen;
+
+		return html_a11y_text_get_text (text, *start_offset, *end_offset);
+
+	default:
+		gail_text_util_text_setup (HTML_A11Y_TEXT (text)->util, to->text);
+		return gail_text_util_get_text (HTML_A11Y_TEXT (text)->util, NULL, GAIL_AT_OFFSET, boundary_type, offset, 
 					start_offset, end_offset);
+	}
 	
 }
 
@@ -399,13 +472,49 @@
 				       gint *start_offset, gint *end_offset)
 {
 	HTMLText *to = HTML_TEXT (HTML_A11Y_HTML (text));
+	HTMLTextSlave *start_slave, *end_slave;
 
 	g_return_val_if_fail (to, NULL);
+	g_return_val_if_fail (start_offset && end_offset, NULL);
 
-	gail_text_util_text_setup (HTML_A11Y_TEXT (text)->util, to->text);
-	
-	return gail_text_util_get_text (HTML_A11Y_TEXT (text)->util, NULL, GAIL_BEFORE_OFFSET, boundary_type, offset, 
+	switch (boundary_type) {
+	case ATK_TEXT_BOUNDARY_LINE_START:
+		end_slave = html_text_get_slave_at_offset (HTML_OBJECT (to), offset);
+		g_return_val_if_fail (end_slave, NULL);
+		start_slave = (HTMLTextSlave *) HTML_OBJECT (end_slave)->prev;
+
+		*end_offset = end_slave->posStart;
+		if (start_slave && HTML_IS_TEXT_SLAVE (start_slave)) {
+			*start_offset = start_slave->posStart;
+		} else 
+			*start_offset = *end_offset;
+
+		return html_a11y_text_get_text (text, *start_offset, *end_offset);
+
+	case ATK_TEXT_BOUNDARY_LINE_END:
+		start_slave = html_text_get_slave_at_offset (HTML_OBJECT (to), offset);
+		g_return_val_if_fail (start_slave, NULL);
+		end_slave = (HTMLTextSlave *) HTML_OBJECT (start_slave)->prev;
+
+		if (end_slave && HTML_IS_TEXT_SLAVE (end_slave)) {
+			*end_offset = end_slave->posStart + end_slave->posLen;
+			start_slave = (HTMLTextSlave *) HTML_OBJECT (end_slave)->prev;
+			if (start_slave && HTML_IS_TEXT_SLAVE (start_slave))
+				*start_offset = start_slave->posStart + start_slave->posLen;
+			else 
+				*start_offset = end_slave->posStart;
+
+		} else {
+			*start_offset = *end_offset = 0;	/* on the first line */
+		}
+
+		return html_a11y_text_get_text (text, *start_offset, *end_offset);
+
+	default:
+		gail_text_util_text_setup (HTML_A11Y_TEXT (text)->util, to->text);
+		return gail_text_util_get_text (HTML_A11Y_TEXT (text)->util, NULL, GAIL_BEFORE_OFFSET, boundary_type, offset, 
 					start_offset, end_offset);
+	}
 }
 
 static gint
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/a11y/ChangeLog,v
retrieving revision 1.6
diff -u -r1.6 ChangeLog
--- ChangeLog	8 Sep 2003 09:02:55 -0000	1.6
+++ ChangeLog	27 Apr 2004 13:26:58 -0000
@@ -1,3 +1,13 @@
+2004-04-27  Eric Zhao  <eric zhao sun com>
+
+	fixes #55250.
+
+	* text.c: (html_a11y_text_get_text_after_offset),
+	(html_a11y_text_get_text_at_offset),
+	(html_a11y_text_get_text_before_offset): the gail_text_util doesn't
+	know how we break lines in gtkhtml, so we should implement them by
+	ourselves.
+
 2003-09-05  Yuedong Du  <yuedong du sun com>
 
 	* text.c: (html_a11y_text_get_text_after_offset),


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