Re: A new type of pango underlining for underlining errors



> 
> I think that's fine -- keeps things simple for now.


Here are two patches that implement the "wavy" underlining.

The first patch (pango-wave-underline.diff) implements the new pango
attribute for underlining (called PANGO_UNDERLINE_WAVE).

The second patch (gtk-wave-underline.diff) contains the corresponding
changes in the display of the text_view, and a modification in the
"testtext" program to make use of this new attribute. (To see it in
action, use the menu Test->Examples).

Best regards,

Nico, for the GtkAda team.
Index: tests/testtext.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/testtext.c,v
retrieving revision 1.73
diff -u -r1.73 testtext.c
--- tests/testtext.c	26 Sep 2003 23:33:45 -0000	1.73
+++ tests/testtext.c	31 Oct 2003 14:00:37 -0000
@@ -493,6 +493,13 @@
                 "strikethrough", TRUE,
                 NULL);
 
+  tag = gtk_text_buffer_create_tag (buffer, "underline_wave", NULL);
+
+  setup_tag (tag);
+      
+  g_object_set (tag,
+                "underline", PANGO_UNDERLINE_WAVE,
+                NULL);
 
   tag = gtk_text_buffer_create_tag (buffer, "underline", NULL);
 
@@ -580,6 +587,11 @@
 
       gtk_text_buffer_apply_tag_by_name (buffer, "underline", &iter, &iter2);
 
+      gtk_text_buffer_get_iter_at_line_offset (buffer, &iter, 1, 4);
+      gtk_text_buffer_get_iter_at_line_offset (buffer, &iter2, 1, 7);
+
+      gtk_text_buffer_apply_tag_by_name (buffer, "underline_wave", &iter, &iter2);
+
       gtk_text_buffer_get_iter_at_line_offset (buffer, &iter, 1, 14);
       gtk_text_buffer_get_iter_at_line_offset (buffer, &iter2, 1, 24);
 
Index: gtk/gtktextdisplay.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextdisplay.c,v
retrieving revision 1.42
diff -u -r1.42 gtktextdisplay.c
--- gtk/gtktextdisplay.c	4 Jun 2003 23:26:51 -0000	1.42
+++ gtk/gtktextdisplay.c	31 Oct 2003 14:00:37 -0000
@@ -92,6 +92,7 @@
   GtkTextAppearance *last_bg_appearance;
   GdkGC *fg_gc;
   GdkGC *bg_gc;
+  GdkGC *error_gc;
   GdkRectangle clip_rect;
 };
 
@@ -112,10 +113,22 @@
                            GdkRectangle *clip_rect)
 {
   GtkTextRenderState *state = g_new0 (GtkTextRenderState, 1);
+  GdkColor red_color;
 
   state->widget = widget;
   state->fg_gc = gdk_gc_new (drawable);
   state->bg_gc = gdk_gc_new (drawable);
+  state->error_gc = gdk_gc_new (drawable);
+
+  /* FIXME: here, it would be nice to cache the GC in the style.
+     See bug 73310 for what is needed to do that.  */
+
+  if (gdk_color_parse ("red", &red_color))
+  {
+    gdk_colormap_alloc_color (gtk_widget_get_colormap (widget), &red_color, FALSE, TRUE);
+    gdk_gc_set_foreground (state->error_gc, &red_color);
+  }   
+
   state->clip_rect = *clip_rect;
 
   return state;
@@ -126,6 +139,7 @@
 {
   g_object_unref (state->fg_gc);
   g_object_unref (state->bg_gc);
+  g_object_unref (state->error_gc);
 
   g_free (state);
 }
@@ -423,6 +437,27 @@
                          x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE,
                          risen_y + 1);
           break;
+        case PANGO_UNDERLINE_WAVE:
+          g_assert (need_ink);
+          {
+            int point_x;
+            int counter = 0;
+
+            for (point_x = x + (x_off + ink_rect.x) / PANGO_SCALE - 1;
+                 point_x <= x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE;
+                 point_x++)
+            {
+              if (counter < 2)
+                gdk_draw_point 
+                 (drawable, render_state->error_gc, point_x, risen_y + 1);
+              else
+                gdk_draw_point 
+                 (drawable, render_state->error_gc, point_x, risen_y + 2);
+
+              counter = (counter + 1) % 4;
+            }
+          }
+          break;
         case PANGO_UNDERLINE_LOW:
           g_assert (need_ink);
           gdk_draw_line (drawable, fg_gc,
Index: gdk/gdkpango.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkpango.c,v
retrieving revision 1.27
diff -u -r1.27 gdkpango.c
--- gdk/gdkpango.c	11 Sep 2003 22:09:37 -0000	1.27
+++ gdk/gdkpango.c	31 Oct 2003 14:00:38 -0000
@@ -186,6 +186,26 @@
 		     start_x, baseline_y + 1,
 		     end_x,   baseline_y + 1);
       break;
+    case PANGO_UNDERLINE_WAVE:
+      {
+        int point_x;
+        int counter = 0;
+
+        for (point_x = start_x;
+             point_x <= end_x;
+             point_x++)
+        {
+          if (counter < 2)
+            gdk_draw_point 
+             (drawable, gc, point_x, baseline_y + 1);
+          else
+            gdk_draw_point 
+             (drawable, gc, point_x, baseline_y + 2);
+
+          counter = (counter + 1) % 4;
+        }
+      }
+      break;
     case PANGO_UNDERLINE_LOW:
       gdk_draw_line (drawable, gc,
 		     start_x, low_y + 1,
Index: pango/pango-attributes.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-attributes.h,v
retrieving revision 1.20
diff -u -r1.20 pango-attributes.h
--- pango/pango-attributes.h	10 Dec 2002 23:45:26 -0000	1.20
+++ pango/pango-attributes.h	31 Oct 2003 14:06:33 -0000
@@ -87,6 +87,7 @@
   PANGO_UNDERLINE_NONE,
   PANGO_UNDERLINE_SINGLE,
   PANGO_UNDERLINE_DOUBLE,
+  PANGO_UNDERLINE_WAVE,
   PANGO_UNDERLINE_LOW
 } PangoUnderline;
 
Index: pango/pango-layout.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-layout.c,v
retrieving revision 1.104
diff -u -r1.104 pango-layout.c
--- pango/pango-layout.c	3 Aug 2003 21:57:33 -0000	1.104
+++ pango/pango-layout.c	31 Oct 2003 14:06:34 -0000
@@ -3577,6 +3577,12 @@
     {
     case PANGO_UNDERLINE_NONE:
       break;
+    case PANGO_UNDERLINE_WAVE:
+      if (run_ink)
+        run_ink->height = MAX (run_ink->height, 3 * PANGO_SCALE - run_ink->y);
+      if (run_logical)
+	 run_logical->height = MAX (run_logical->height, 3 * PANGO_SCALE - run_logical->y);
+      break;
     case PANGO_UNDERLINE_SINGLE:
       if (run_ink)
         run_ink->height = MAX (run_ink->height, 2 * PANGO_SCALE - run_ink->y);
Index: pango/pango-markup.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-markup.c,v
retrieving revision 1.16
diff -u -r1.16 pango-markup.c
--- pango/pango-markup.c	2 Jul 2002 17:15:22 -0000	1.16
+++ pango/pango-markup.c	31 Oct 2003 14:06:34 -0000
@@ -1133,6 +1133,8 @@
         ul = PANGO_UNDERLINE_DOUBLE;
       else if (strcmp (underline, "low") == 0)
         ul = PANGO_UNDERLINE_LOW;
+      else if (strcmp (underline, "wave") == 0)
+        ul = PANGO_UNDERLINE_WAVE;
       else if (strcmp (underline, "none") == 0)
         ul = PANGO_UNDERLINE_NONE;
       else
Index: pango/pangoft2.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangoft2.c,v
retrieving revision 1.60
diff -u -r1.60 pangoft2.c
--- pango/pangoft2.c	3 Aug 2003 02:35:20 -0000	1.60
+++ pango/pangoft2.c	31 Oct 2003 14:06:35 -0000
@@ -840,6 +840,28 @@
 				x + PANGO_PIXELS (x_off + ink_rect.x),
 				x + PANGO_PIXELS (x_off + ink_rect.x + ink_rect.width));
 	  break;
+	case PANGO_UNDERLINE_WAVE:
+          {
+            int point_x;
+            int counter = 0;
+
+            for (point_x = x + PANGO_PIXELS (x_off + ink_rect.x) - 1;
+                 point_x < x + PANGO_PIXELS (x_off + ink_rect.x + ink_rect.width);
+                 point_x = point_x + 2)
+            {
+              if (counter)
+	        pango_ft2_draw_hline (bitmap,
+				      risen_y + 2,
+				      point_x, point_x + 1);
+              else
+	        pango_ft2_draw_hline (bitmap,
+				      risen_y + 3,
+				      point_x, point_x + 1);
+
+              counter = (counter + 1) % 2;
+            }
+          }
+	  break;
 	case PANGO_UNDERLINE_LOW:
 	  pango_ft2_draw_hline (bitmap,
 				risen_y + PANGO_PIXELS (ink_rect.y + ink_rect.height),
Index: pango/pangowin32.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangowin32.c,v
retrieving revision 1.43
diff -u -r1.43 pangowin32.c
--- pango/pangowin32.c	2 Apr 2003 18:25:34 -0000	1.43
+++ pango/pangowin32.c	31 Oct 2003 14:06:36 -0000
@@ -780,6 +780,28 @@
 	  points[0].y = points[1].y = y + 2;
 	  Polyline (hdc, points, 2);
 	  break;
+	case PANGO_UNDERLINE_WAVE:
+          {
+            int point_x;
+            int counter = 0;
+
+            for (point_x = x + PANGO_PIXELS (x_off + ink_rect.x) - 1;
+                 point_x < x + PANGO_PIXELS (x_off + ink_rect.x + ink_rect.width);
+                 point_x = point_x + 2)
+            {
+	      points[0].x = point_x;
+	      points[1].x = point_x + 1;
+
+              if (counter)
+	         points[0].y = points[1].y = y + 2;
+              else
+	         points[0].y = points[1].y = y + 3;
+
+	      Polyline (hdc, points, 2);
+              counter = (counter + 1) % 2;
+            }
+          }
+	  break;
 	case PANGO_UNDERLINE_LOW:
 	  points[0].x = x + PANGO_PIXELS (x_off + ink_rect.x) - 1;
 	  points[0].y = points[1].y = y + PANGO_PIXELS (ink_rect.y + ink_rect.height) + 2;
Index: pango/pangox.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangox.c,v
retrieving revision 1.81
diff -u -r1.81 pangox.c
--- pango/pangox.c	2 Aug 2003 18:18:30 -0000	1.81
+++ pango/pangox.c	31 Oct 2003 14:06:37 -0000
@@ -1500,6 +1500,26 @@
 		     x + (x_off + ink_rect.x) / PANGO_SCALE - 1, y + 2,
 		     x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE, y + 2);
 	  break;
+	case PANGO_UNDERLINE_WAVE:
+          {
+            int point_x;
+            int counter = 0;
+
+            for (point_x = x + (x_off + ink_rect.x) / PANGO_SCALE - 1;
+                 point_x < x + (x_off + ink_rect.x + ink_rect.width) / PANGO_SCALE;
+                 point_x++)
+            {
+              if (counter < 2)
+                XDrawPoint
+                 (display, drawable, fg_gc, point_x, y + 2);
+              else
+                XDrawPoint
+                 (display, drawable, fg_gc, point_x, y + 3);
+
+              counter = (counter + 1) % 4;
+            }
+          }
+	  break;
 	case PANGO_UNDERLINE_LOW:
 	  XDrawLine (display, drawable, fg_gc,
 		     x + (x_off + ink_rect.x) / PANGO_SCALE - 1, y + (ink_rect.y + ink_rect.height) / PANGO_SCALE + 2,


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