[pango: 2/4] [pango-view] Add an extra level of mild annotation



commit 56ff9ed93d1cc9fd091da609304bd153d706d818
Author: Behdad Esfahbod <behdad behdad org>
Date:   Mon Mar 16 16:33:48 2009 -0400

    [pango-view] Add an extra level of mild annotation to cairo backend
---
 pango-view/viewer-main.c       |    2 +-
 pango-view/viewer-pangocairo.c |  133 ++++++++++++++++++++-------------------
 pango-view/viewer-x.c          |   15 ++---
 3 files changed, 74 insertions(+), 76 deletions(-)

diff --git a/pango-view/viewer-main.c b/pango-view/viewer-main.c
index 611a4fb..61c43ee 100644
--- a/pango-view/viewer-main.c
+++ b/pango-view/viewer-main.c
@@ -128,7 +128,7 @@ main (int    argc,
 	  while (1)
 	    {
 	      state = view->display (instance, surface, window, width, height, state);
-	      if (!state)
+	      if (state == GINT_TO_POINTER (-1))
 		break;
 
 	      view->render (instance, surface, context, &width, &height, state);
diff --git a/pango-view/viewer-pangocairo.c b/pango-view/viewer-pangocairo.c
index bed0f38..e834540 100644
--- a/pango-view/viewer-pangocairo.c
+++ b/pango-view/viewer-pangocairo.c
@@ -133,15 +133,15 @@ render_callback (PangoLayout *layout,
 		 int          x,
 		 int          y,
 		 gpointer     context,
-		 gpointer     data)
+		 gpointer     state)
 {
   cairo_t *cr = (cairo_t *) context;
-  gboolean show_borders = GPOINTER_TO_UINT (data) == 0xdeadbeef;
+  int annotate = GPOINTER_TO_INT (state) % 3;
 
   cairo_save (cr);
   cairo_translate (cr, x, y);
 
-  if (show_borders)
+  if (annotate)
     {
       cairo_pattern_t *pattern;
       PangoRectangle ink, logical;
@@ -150,68 +150,71 @@ render_callback (PangoLayout *layout,
 
       pango_layout_get_extents (layout, &ink, &logical);
 
-      /* draw resolved gravity "roof" in blue */
-      cairo_save (cr);
-      cairo_translate (cr,
-		       (double)logical.x / PANGO_SCALE,
-		       (double)logical.y / PANGO_SCALE);
-      cairo_scale     (cr,
-		       (double)logical.width / PANGO_SCALE * 0.5,
-		       (double)logical.height / PANGO_SCALE * 0.5);
-      cairo_translate   (cr,  1.0,  1.0);
-      cairo_rotate (cr,
-	pango_gravity_to_rotation (
-	  pango_context_get_gravity (
-	    pango_layout_get_context (layout))));
-      cairo_move_to     (cr, -1.0, -1.0);
-      cairo_rel_line_to (cr, +1.0, -0.2); /* /   */
-      cairo_rel_line_to (cr, +1.0, +0.2); /*   \ */
-      cairo_close_path  (cr);             /*  -  */
-      pattern = cairo_pattern_create_linear (0, -1.0, 0, -1.2);
-      cairo_pattern_add_color_stop_rgba (pattern, 0.0, 0.0, 0.0, 1.0, 0.0);
-      cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0.0, 0.0, 1.0, 0.15);
-      cairo_set_source (cr, pattern);
-      cairo_fill (cr);
-      /* once more, without close_path this time */
-      cairo_move_to     (cr, -1.0, -1.0);
-      cairo_rel_line_to (cr, +1.0, -0.2); /* /   */
-      cairo_rel_line_to (cr, +1.0, +0.2); /*   \ */
-      /* silly line_width is not locked :(. get rid of scale. */
-      cairo_restore (cr);
-      cairo_save (cr);
-      cairo_set_source_rgba (cr, 0.0, 0.0, 0.7, 0.2);
-      cairo_stroke (cr);
-      cairo_restore (cr);
+      if (annotate >= 2)
+        {
+	  /* draw resolved gravity "roof" in blue */
+	  cairo_save (cr);
+	  cairo_translate (cr,
+			   (double)logical.x / PANGO_SCALE,
+			   (double)logical.y / PANGO_SCALE);
+	  cairo_scale     (cr,
+			   (double)logical.width / PANGO_SCALE * 0.5,
+			   (double)logical.height / PANGO_SCALE * 0.5);
+	  cairo_translate   (cr,  1.0,  1.0);
+	  cairo_rotate (cr,
+	    pango_gravity_to_rotation (
+	      pango_context_get_gravity (
+		pango_layout_get_context (layout))));
+	  cairo_move_to     (cr, -1.0, -1.0);
+	  cairo_rel_line_to (cr, +1.0, -0.2); /* /   */
+	  cairo_rel_line_to (cr, +1.0, +0.2); /*   \ */
+	  cairo_close_path  (cr);             /*  -  */
+	  pattern = cairo_pattern_create_linear (0, -1.0, 0, -1.2);
+	  cairo_pattern_add_color_stop_rgba (pattern, 0.0, 0.0, 0.0, 1.0, 0.0);
+	  cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0.0, 0.0, 1.0, 0.15);
+	  cairo_set_source (cr, pattern);
+	  cairo_fill (cr);
+	  /* once more, without close_path this time */
+	  cairo_move_to     (cr, -1.0, -1.0);
+	  cairo_rel_line_to (cr, +1.0, -0.2); /* /   */
+	  cairo_rel_line_to (cr, +1.0, +0.2); /*   \ */
+	  /* silly line_width is not locked :(. get rid of scale. */
+	  cairo_restore (cr);
+	  cairo_save (cr);
+	  cairo_set_source_rgba (cr, 0.0, 0.0, 0.7, 0.2);
+	  cairo_stroke (cr);
+	  cairo_restore (cr);
 
 
-      /* draw block progression arrow in green */
-      cairo_save (cr);
-      cairo_translate (cr,
-		       (double)logical.x / PANGO_SCALE,
-		       (double)logical.y / PANGO_SCALE);
-      cairo_scale     (cr,
-		       (double)logical.width / PANGO_SCALE * 0.5,
-		       (double)logical.height / PANGO_SCALE * 0.5);
-      cairo_translate   (cr,  1.0,  1.0);
-      cairo_move_to     (cr, -0.4, -0.7);
-      cairo_rel_line_to (cr, +0.8,  0.0); /*  --   */
-      cairo_rel_line_to (cr,  0.0, +0.9); /*    |  */
-      cairo_rel_line_to (cr, +0.4,  0.0); /*     - */
-      cairo_rel_line_to (cr, -0.8, +0.5); /*    /  */
-      cairo_rel_line_to (cr, -0.8, -0.5); /*  \    */
-      cairo_rel_line_to (cr, +0.4,  0.0); /* -     */
-      cairo_close_path  (cr);             /*  |    */
-      pattern = cairo_pattern_create_linear (0, -0.7, 0, 0.7);
-      cairo_pattern_add_color_stop_rgba (pattern, 0.0, 0.0, 1.0, 0.0, 0.0);
-      cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0.0, 1.0, 0.0, 0.15);
-      cairo_set_source (cr, pattern);
-      cairo_fill_preserve (cr);
-      /* silly line_width is not locked :(. get rid of scale. */
-      cairo_restore (cr);
-      cairo_save (cr);
-      cairo_set_source_rgba (cr, 0.0, 0.7, 0.0, 0.2);
-      cairo_stroke (cr);
-      cairo_restore (cr);
+	  /* draw block progression arrow in green */
+	  cairo_save (cr);
+	  cairo_translate (cr,
+			   (double)logical.x / PANGO_SCALE,
+			   (double)logical.y / PANGO_SCALE);
+	  cairo_scale     (cr,
+			   (double)logical.width / PANGO_SCALE * 0.5,
+			   (double)logical.height / PANGO_SCALE * 0.5);
+	  cairo_translate   (cr,  1.0,  1.0);
+	  cairo_move_to     (cr, -0.4, -0.7);
+	  cairo_rel_line_to (cr, +0.8,  0.0); /*  --   */
+	  cairo_rel_line_to (cr,  0.0, +0.9); /*    |  */
+	  cairo_rel_line_to (cr, +0.4,  0.0); /*     - */
+	  cairo_rel_line_to (cr, -0.8, +0.5); /*    /  */
+	  cairo_rel_line_to (cr, -0.8, -0.5); /*  \    */
+	  cairo_rel_line_to (cr, +0.4,  0.0); /* -     */
+	  cairo_close_path  (cr);             /*  |    */
+	  pattern = cairo_pattern_create_linear (0, -0.7, 0, 0.7);
+	  cairo_pattern_add_color_stop_rgba (pattern, 0.0, 0.0, 1.0, 0.0, 0.0);
+	  cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0.0, 1.0, 0.0, 0.15);
+	  cairo_set_source (cr, pattern);
+	  cairo_fill_preserve (cr);
+	  /* silly line_width is not locked :(. get rid of scale. */
+	  cairo_restore (cr);
+	  cairo_save (cr);
+	  cairo_set_source_rgba (cr, 0.0, 0.7, 0.0, 0.2);
+	  cairo_stroke (cr);
+	  cairo_restore (cr);
+	}
 
       /* draw baselines with line direction arrow in orange */
       cairo_save (cr);
diff --git a/pango-view/viewer-x.c b/pango-view/viewer-x.c
index 25492f3..ad1c9a8 100644
--- a/pango-view/viewer-x.c
+++ b/pango-view/viewer-x.c
@@ -182,11 +182,7 @@ x_view_display (gpointer instance,
   XRectangle  r;
   Region update_region;
   unsigned int quit_keycode;
-  unsigned int borders_keycode;
-  gboolean show_borders = FALSE;
-
-  if (state)
-    show_borders = GPOINTER_TO_UINT (state) == 0xdeadbeef;
+  unsigned int annotate_keycode;
 
   /* force a full redraw */
   update_region = XCreateRegion ();
@@ -196,7 +192,7 @@ x_view_display (gpointer instance,
   r.height = height;
   XUnionRectWithRegion (&r, update_region, update_region);
 
-  borders_keycode = XKeysymToKeycode(x->display, 'B');
+  annotate_keycode = XKeysymToKeycode(x->display, 'B');
   quit_keycode = XKeysymToKeycode(x->display, 'Q');
 
   while (1)
@@ -208,11 +204,10 @@ x_view_display (gpointer instance,
       switch (xev.xany.type) {
       case KeyPress:
 	if (xev.xkey.keycode == quit_keycode)
-	  return NULL;
-	else if (xev.xkey.keycode == borders_keycode)
+	  return GINT_TO_POINTER (-1);
+	else if (xev.xkey.keycode == annotate_keycode)
 	  {
-	    show_borders = !show_borders;
-	    return GUINT_TO_POINTER (show_borders ? 0xdeadbeef : 0xbe);
+	    return GUINT_TO_POINTER (GPOINTER_TO_INT (state) + 1);
 	  }
 	break;
       case Expose:



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