]> Pileus Git - ~andy/gtk/commitdiff
do right thing in one-character lines and at paragraph end (#448313).
authorYevgen Muntyan <muntyan@tamu.edu>
Thu, 28 Jun 2007 06:30:21 +0000 (06:30 +0000)
committerYevgen Muntyan <muntyan@src.gnome.org>
Thu, 28 Jun 2007 06:30:21 +0000 (06:30 +0000)
2007-06-28  Yevgen Muntyan  <muntyan@tamu.edu>

* gtk/gtktextutil.c (_gtk_text_util_get_block_cursor_location):
do right thing in one-character lines and at paragraph end (#448313).

* configure.in: require pango-1.17.3 to get fixed pango_layout_index_to_line_x()
(pango #448342).

svn path=/trunk/; revision=18273

ChangeLog
configure.in
gtk/gtktextutil.c

index 195b0c43a354c47cf647ec50369543ec2bb87656..d530463109269178a04a101e5ac8148851c5541f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-06-28  Yevgen Muntyan  <muntyan@tamu.edu>
+
+       * gtk/gtktextutil.c (_gtk_text_util_get_block_cursor_location):
+       do right thing in one-character lines and at paragraph end (#448313).
+
+       * configure.in: require pango-1.17.3 to get fixed pango_layout_index_to_line_x()
+       (pango #448342).
+
 2007-06-27  Johan Dahlin  <jdahlin@async.com.br>
 
        * gtk/gtkbuilderparser.c (parse_property): Use
index d03f9dfb67de8c6d7d80ee9b1958710604fabc10..27cdb5f03aeb8875be107af51f6e77179a0a2300 100644 (file)
@@ -32,7 +32,7 @@ m4_define([gtk_binary_version], [2.10.0])
 
 # required versions of other packages
 m4_define([glib_required_version], [2.13.5])
-m4_define([pango_required_version], [1.15.3])
+m4_define([pango_required_version], [1.17.3])
 m4_define([atk_required_version], [1.9.0])
 m4_define([cairo_required_version], [1.2.0])
 
index f601e2f9bd9206ab52080734173fe338026b1dd4..dbeb4086f71f8e0325b6dcfd95d3dc34b1444cb2 100644 (file)
@@ -387,7 +387,9 @@ layout_get_char_width (PangoLayout *layout)
  * _gtk_text_util_get_block_cursor_location
  * @layout: a #PangoLayout
  * @index: index at which cursor is located
- * @rect: cursor location
+ * @pos: cursor location
+ * @at_line_end: whether cursor i sdrawn at line end, not over some
+ * character
  *
  * Returns: whether cursor should actually be drawn as a rectangle.
  * It may not be the case if character at index is invisible.
@@ -402,6 +404,7 @@ _gtk_text_util_get_block_cursor_location (PangoLayout    *layout,
   PangoLayoutLine *layout_line;
   gboolean rtl;
   gint line_no;
+  const gchar *text;
 
   g_return_val_if_fail (layout != NULL, FALSE);
   g_return_val_if_fail (index >= 0, FALSE);
@@ -423,23 +426,23 @@ _gtk_text_util_get_block_cursor_location (PangoLayout    *layout,
     }
 
   pango_layout_index_to_line_x (layout, index, FALSE, &line_no, NULL);
-  g_return_val_if_fail (line_no >= 0, FALSE);
   layout_line = pango_layout_get_line_readonly (layout, line_no);
-
-  /* end of layout, get last line */
-  if (!layout_line)
-    {
-      line_no -= 1;
-      layout_line = pango_layout_get_line_readonly (layout, line_no);
-    }
-
   g_return_val_if_fail (layout_line != NULL, FALSE);
 
+  text = pango_layout_get_text (layout);
+
   if (index < layout_line->start_index + layout_line->length)
     {
-      /* cursor points to some zero-width character, do not
-       * bother with block cursor */
-      return FALSE;
+      /* this may be a zero-width character in the middle of the line,
+       * or it could be a character where line is wrapped, we do want
+       * block cursor in latter case */
+      if (g_utf8_next_char (text + index) - text !=
+         layout_line->start_index + layout_line->length)
+       {
+         /* zero-width character in the middle of the line, do not
+          * bother with block cursor */
+         return FALSE;
+       }
     }
 
   /* Cursor is at the line end. It may be an empty line, or it could
@@ -459,23 +462,19 @@ _gtk_text_util_get_block_cursor_location (PangoLayout    *layout,
    * pixel of the layout line, so we need to correct it for RTL text. */
   if (layout_line->length)
     {
-      gint left, right;
-      const gchar *text;
-      const gchar *p;
-
-      text = pango_layout_get_text (layout);
-      p = g_utf8_prev_char (text + index);
-
-      pango_layout_line_index_to_x (layout_line, p - text, FALSE, &left);
-      pango_layout_line_index_to_x (layout_line, p - text, TRUE, &right);
-
-      if (MIN (left, right) <= 0)
+      if (layout_line->resolved_dir == PANGO_DIRECTION_RTL)
        {
-          /* last character is on the left, RTL */
-
          PangoLayoutIter *iter;
          PangoRectangle line_rect;
          gint i;
+         gint left, right;
+         const gchar *p;
+
+         p = g_utf8_prev_char (text + index);
+
+         pango_layout_line_index_to_x (layout_line, p - text, FALSE, &left);
+         pango_layout_line_index_to_x (layout_line, p - text, TRUE, &right);
+         pos->x = MIN (left, right);
 
          iter = pango_layout_get_iter (layout);
          for (i = 0; i < line_no; i++)
@@ -484,7 +483,7 @@ _gtk_text_util_get_block_cursor_location (PangoLayout    *layout,
          pango_layout_iter_free (iter);
 
           rtl = TRUE;
-         pos->x = MIN (left, right) + line_rect.x;
+         pos->x += line_rect.x;
        }
       else
        rtl = FALSE;