a5bd9f6
From 5d4c7b334f440e337abf83b29408e06474497655 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Colin Watson <cjwatson@ubuntu.com>
a5bd9f6
Date: Mon, 21 Jan 2013 21:03:26 +0000
a5bd9f6
Subject: [PATCH 137/364] * grub-core/font/font.c (blit_comb: do_blit): Make
a5bd9f6
 static instead of nested. (blit_comb: add_device_width): Likewise.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog             |   6 +++
a5bd9f6
 grub-core/font/font.c | 133 ++++++++++++++++++++++++++++----------------------
a5bd9f6
 2 files changed, 80 insertions(+), 59 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 08c2c9f..a2edbc5 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,5 +1,11 @@
a5bd9f6
 2013-01-21  Colin Watson  <cjwatson@ubuntu.com>
a5bd9f6
 
a5bd9f6
+	* grub-core/font/font.c (blit_comb: do_blit): Make static instead of
a5bd9f6
+	nested.
a5bd9f6
+	(blit_comb: add_device_width): Likewise.
a5bd9f6
+
a5bd9f6
+2013-01-21  Colin Watson  <cjwatson@ubuntu.com>
a5bd9f6
+
a5bd9f6
 	Remove nested functions from USB iterators.
a5bd9f6
 
a5bd9f6
 	* include/grub/usb.h (grub_usb_iterate_hook_t): New type.
a5bd9f6
diff --git a/grub-core/font/font.c b/grub-core/font/font.c
a5bd9f6
index fca8c8d..6b54a84 100644
a5bd9f6
--- a/grub-core/font/font.c
a5bd9f6
+++ b/grub-core/font/font.c
a5bd9f6
@@ -1143,6 +1143,49 @@ grub_font_blit_glyph_mirror (struct grub_font_glyph *target,
a5bd9f6
     }
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
+/* Context for blit_comb.  */
a5bd9f6
+struct blit_comb_ctx
a5bd9f6
+{
a5bd9f6
+  struct grub_font_glyph *glyph;
a5bd9f6
+  int *device_width;
a5bd9f6
+  struct grub_video_signed_rect bounds;
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
+/* Helper for blit_comb.  */
a5bd9f6
+static void
a5bd9f6
+do_blit (struct grub_font_glyph *src, signed dx, signed dy,
a5bd9f6
+	 struct blit_comb_ctx *ctx)
a5bd9f6
+{
a5bd9f6
+  if (ctx->glyph)
a5bd9f6
+    grub_font_blit_glyph (ctx->glyph, src, dx - ctx->glyph->offset_x,
a5bd9f6
+			  (ctx->glyph->height + ctx->glyph->offset_y) + dy);
a5bd9f6
+  if (dx < ctx->bounds.x)
a5bd9f6
+    {
a5bd9f6
+      ctx->bounds.width += ctx->bounds.x - dx;
a5bd9f6
+      ctx->bounds.x = dx;
a5bd9f6
+    }
a5bd9f6
+  if (ctx->bounds.y > -src->height - dy)
a5bd9f6
+    {
a5bd9f6
+      ctx->bounds.height += ctx->bounds.y - (-src->height - dy);
a5bd9f6
+      ctx->bounds.y = (-src->height - dy);
a5bd9f6
+    }
a5bd9f6
+  if (dx + src->width - ctx->bounds.x >= (signed) ctx->bounds.width)
a5bd9f6
+    ctx->bounds.width = dx + src->width - ctx->bounds.x + 1;
a5bd9f6
+  if ((signed) ctx->bounds.height < src->height + (-src->height - dy)
a5bd9f6
+      - ctx->bounds.y)
a5bd9f6
+    ctx->bounds.height = src->height + (-src->height - dy) - ctx->bounds.y;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+/* Helper for blit_comb.  */
a5bd9f6
+static inline void
a5bd9f6
+add_device_width (int val, struct blit_comb_ctx *ctx)
a5bd9f6
+{
a5bd9f6
+  if (ctx->glyph)
a5bd9f6
+    ctx->glyph->device_width += val;
a5bd9f6
+  if (ctx->device_width)
a5bd9f6
+    *ctx->device_width += val;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
 static void
a5bd9f6
 blit_comb (const struct grub_unicode_glyph *glyph_id,
a5bd9f6
 	   struct grub_font_glyph *glyph,
a5bd9f6
@@ -1150,63 +1193,34 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
a5bd9f6
 	   struct grub_font_glyph *main_glyph,
a5bd9f6
 	   struct grub_font_glyph **combining_glyphs, int *device_width)
a5bd9f6
 {
a5bd9f6
-  struct grub_video_signed_rect bounds;
a5bd9f6
+  struct blit_comb_ctx ctx = {
a5bd9f6
+    .glyph = glyph,
a5bd9f6
+    .device_width = device_width
a5bd9f6
+  };
a5bd9f6
   unsigned i;
a5bd9f6
   signed above_rightx, above_righty;
a5bd9f6
   signed above_leftx, above_lefty;
a5bd9f6
   signed below_rightx, below_righty;
a5bd9f6
   signed min_devwidth = 0;
a5bd9f6
-  auto void NESTED_FUNC_ATTR do_blit (struct grub_font_glyph *src,
a5bd9f6
-				      signed dx, signed dy);
a5bd9f6
-  void NESTED_FUNC_ATTR do_blit (struct grub_font_glyph *src,
a5bd9f6
-				 signed dx, signed dy)
a5bd9f6
-  {
a5bd9f6
-    if (glyph)
a5bd9f6
-      grub_font_blit_glyph (glyph, src, dx - glyph->offset_x,
a5bd9f6
-			    (glyph->height + glyph->offset_y) + dy);
a5bd9f6
-    if (dx < bounds.x)
a5bd9f6
-      {
a5bd9f6
-	bounds.width += bounds.x - dx;
a5bd9f6
-	bounds.x = dx;
a5bd9f6
-      }
a5bd9f6
-    if (bounds.y > -src->height - dy)
a5bd9f6
-      {
a5bd9f6
-	bounds.height += bounds.y - (-src->height - dy);
a5bd9f6
-	bounds.y = (-src->height - dy);
a5bd9f6
-      }
a5bd9f6
-    if (dx + src->width - bounds.x >= (signed) bounds.width)
a5bd9f6
-      bounds.width = dx + src->width - bounds.x + 1;
a5bd9f6
-    if ((signed) bounds.height < src->height + (-src->height - dy) - bounds.y)
a5bd9f6
-      bounds.height = src->height + (-src->height - dy) - bounds.y;
a5bd9f6
-  }
a5bd9f6
-
a5bd9f6
-  auto void add_device_width (int val);
a5bd9f6
-  void add_device_width (int val)
a5bd9f6
-  {
a5bd9f6
-    if (glyph)
a5bd9f6
-      glyph->device_width += val;
a5bd9f6
-    if (device_width)
a5bd9f6
-      *device_width += val;
a5bd9f6
-  }
a5bd9f6
 
a5bd9f6
   if (glyph)
a5bd9f6
     glyph->device_width = main_glyph->device_width;
a5bd9f6
   if (device_width)
a5bd9f6
     *device_width = main_glyph->device_width;
a5bd9f6
 
a5bd9f6
-  bounds.x = main_glyph->offset_x;
a5bd9f6
-  bounds.y = main_glyph->offset_y;
a5bd9f6
-  bounds.width = main_glyph->width;
a5bd9f6
-  bounds.height = main_glyph->height;
a5bd9f6
+  ctx.bounds.x = main_glyph->offset_x;
a5bd9f6
+  ctx.bounds.y = main_glyph->offset_y;
a5bd9f6
+  ctx.bounds.width = main_glyph->width;
a5bd9f6
+  ctx.bounds.height = main_glyph->height;
a5bd9f6
 
a5bd9f6
   above_rightx = main_glyph->offset_x + main_glyph->width;
a5bd9f6
-  above_righty = bounds.y + bounds.height;
a5bd9f6
+  above_righty = ctx.bounds.y + ctx.bounds.height;
a5bd9f6
 
a5bd9f6
   above_leftx = main_glyph->offset_x;
a5bd9f6
-  above_lefty = bounds.y + bounds.height;
a5bd9f6
+  above_lefty = ctx.bounds.y + ctx.bounds.height;
a5bd9f6
 
a5bd9f6
-  below_rightx = bounds.x + bounds.width;
a5bd9f6
-  below_righty = bounds.y;
a5bd9f6
+  below_rightx = ctx.bounds.x + ctx.bounds.width;
a5bd9f6
+  below_righty = ctx.bounds.y;
a5bd9f6
 
a5bd9f6
   for (i = 0; i < glyph_id->ncomb; i++)
a5bd9f6
     {
a5bd9f6
@@ -1216,7 +1230,7 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
a5bd9f6
 
a5bd9f6
       if (!combining_glyphs[i])
a5bd9f6
 	continue;
a5bd9f6
-      targetx = (bounds.width - combining_glyphs[i]->width) / 2 + bounds.x;
a5bd9f6
+      targetx = (ctx.bounds.width - combining_glyphs[i]->width) / 2 + ctx.bounds.x;
a5bd9f6
       /* CGJ is to avoid diacritics reordering. */
a5bd9f6
       if (glyph_id->combining[i].code
a5bd9f6
 	  == GRUB_UNICODE_COMBINING_GRAPHEME_JOINER)
a5bd9f6
@@ -1226,31 +1240,31 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
a5bd9f6
 	case GRUB_UNICODE_COMB_OVERLAY:
a5bd9f6
 	  do_blit (combining_glyphs[i],
a5bd9f6
 		   targetx,
a5bd9f6
-		   (bounds.height - combining_glyphs[i]->height) / 2
a5bd9f6
-		   - (bounds.height + bounds.y));
a5bd9f6
+		   (ctx.bounds.height - combining_glyphs[i]->height) / 2
a5bd9f6
+		   - (ctx.bounds.height + ctx.bounds.y), &ctx;;
a5bd9f6
 	  if (min_devwidth < combining_glyphs[i]->width)
a5bd9f6
 	    min_devwidth = combining_glyphs[i]->width;
a5bd9f6
 	  break;
a5bd9f6
 
a5bd9f6
 	case GRUB_UNICODE_COMB_ATTACHED_ABOVE_RIGHT:
a5bd9f6
-	  do_blit (combining_glyphs[i], above_rightx, -above_righty);
a5bd9f6
+	  do_blit (combining_glyphs[i], above_rightx, -above_righty, &ctx;;
a5bd9f6
 	  above_rightx += combining_glyphs[i]->width;
a5bd9f6
 	  break;
a5bd9f6
 
a5bd9f6
 	case GRUB_UNICODE_COMB_ABOVE_RIGHT:
a5bd9f6
 	  do_blit (combining_glyphs[i], above_rightx,
a5bd9f6
-		   -(above_righty + combining_glyphs[i]->height));
a5bd9f6
+		   -(above_righty + combining_glyphs[i]->height), &ctx;;
a5bd9f6
 	  above_rightx += combining_glyphs[i]->width;
a5bd9f6
 	  break;
a5bd9f6
 
a5bd9f6
 	case GRUB_UNICODE_COMB_ABOVE_LEFT:
a5bd9f6
 	  above_leftx -= combining_glyphs[i]->width;
a5bd9f6
 	  do_blit (combining_glyphs[i], above_leftx,
a5bd9f6
-		   -(above_lefty + combining_glyphs[i]->height));
a5bd9f6
+		   -(above_lefty + combining_glyphs[i]->height), &ctx;;
a5bd9f6
 	  break;
a5bd9f6
 
a5bd9f6
 	case GRUB_UNICODE_COMB_BELOW_RIGHT:
a5bd9f6
-	  do_blit (combining_glyphs[i], below_rightx, below_righty);
a5bd9f6
+	  do_blit (combining_glyphs[i], below_rightx, below_righty, &ctx;;
a5bd9f6
 	  below_rightx += combining_glyphs[i]->width;
a5bd9f6
 	  break;
a5bd9f6
 
a5bd9f6
@@ -1276,7 +1290,7 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
a5bd9f6
 	    space = 1 + (grub_font_get_xheight (main_glyph->font)) / 8;
a5bd9f6
 	  do_blit (combining_glyphs[i], targetx,
a5bd9f6
 		   -(main_glyph->height + main_glyph->offset_y + space
a5bd9f6
-		     + combining_glyphs[i]->height));
a5bd9f6
+		     + combining_glyphs[i]->height), &ctx;;
a5bd9f6
 	  if (min_devwidth < combining_glyphs[i]->width)
a5bd9f6
 	    min_devwidth = combining_glyphs[i]->width;
a5bd9f6
 	  break;
a5bd9f6
@@ -1300,16 +1314,16 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
a5bd9f6
 
a5bd9f6
 	case GRUB_UNICODE_STACK_ATTACHED_ABOVE:
a5bd9f6
 	  do_blit (combining_glyphs[i], targetx,
a5bd9f6
-		   -(bounds.height + bounds.y + space
a5bd9f6
-		     + combining_glyphs[i]->height));
a5bd9f6
+		   -(ctx.bounds.height + ctx.bounds.y + space
a5bd9f6
+		     + combining_glyphs[i]->height), &ctx;;
a5bd9f6
 	  if (min_devwidth < combining_glyphs[i]->width)
a5bd9f6
 	    min_devwidth = combining_glyphs[i]->width;
a5bd9f6
 	  break;
a5bd9f6
 
a5bd9f6
 	case GRUB_UNICODE_COMB_HEBREW_DAGESH:
a5bd9f6
 	  do_blit (combining_glyphs[i], targetx,
a5bd9f6
-		   -(bounds.height / 2 + bounds.y
a5bd9f6
-		     + combining_glyphs[i]->height / 2));
a5bd9f6
+		   -(ctx.bounds.height / 2 + ctx.bounds.y
a5bd9f6
+		     + combining_glyphs[i]->height / 2), &ctx;;
a5bd9f6
 	  if (min_devwidth < combining_glyphs[i]->width)
a5bd9f6
 	    min_devwidth = combining_glyphs[i]->width;
a5bd9f6
 	  break;
a5bd9f6
@@ -1340,7 +1354,8 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
a5bd9f6
 	    space = 1 + (grub_font_get_xheight (main_glyph->font)) / 8;
a5bd9f6
 
a5bd9f6
 	case GRUB_UNICODE_STACK_ATTACHED_BELOW:
a5bd9f6
-	  do_blit (combining_glyphs[i], targetx, -(bounds.y - space));
a5bd9f6
+	  do_blit (combining_glyphs[i], targetx, -(ctx.bounds.y - space),
a5bd9f6
+		   &ctx;;
a5bd9f6
 	  if (min_devwidth < combining_glyphs[i]->width)
a5bd9f6
 	    min_devwidth = combining_glyphs[i]->width;
a5bd9f6
 	  break;
a5bd9f6
@@ -1373,22 +1388,22 @@ blit_comb (const struct grub_unicode_glyph *glyph_id,
a5bd9f6
 		     main_glyph->device_width
a5bd9f6
 		     + combining_glyphs[i]->offset_x,
a5bd9f6
 		     -(combining_glyphs[i]->height
a5bd9f6
-		       + combining_glyphs[i]->offset_y));
a5bd9f6
-	    add_device_width (combining_glyphs[i]->device_width);
a5bd9f6
+		       + combining_glyphs[i]->offset_y), &ctx;;
a5bd9f6
+	    add_device_width (combining_glyphs[i]->device_width, &ctx;;
a5bd9f6
 	  }
a5bd9f6
 	}
a5bd9f6
     }
a5bd9f6
   add_device_width ((above_rightx >
a5bd9f6
 		     below_rightx ? above_rightx : below_rightx) -
a5bd9f6
-		    (main_glyph->offset_x + main_glyph->width));
a5bd9f6
-  add_device_width (above_leftx - main_glyph->offset_x);
a5bd9f6
+		    (main_glyph->offset_x + main_glyph->width), &ctx;;
a5bd9f6
+  add_device_width (above_leftx - main_glyph->offset_x, &ctx;;
a5bd9f6
   if (glyph && glyph->device_width < min_devwidth)
a5bd9f6
     glyph->device_width = min_devwidth;
a5bd9f6
   if (device_width && *device_width < min_devwidth)
a5bd9f6
     *device_width = min_devwidth;
a5bd9f6
 
a5bd9f6
   if (bounds_out)
a5bd9f6
-    *bounds_out = bounds;
a5bd9f6
+    *bounds_out = ctx.bounds;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static struct grub_font_glyph *
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6