Bug 469049 – Fix all compiler warnings
authorBehdad Esfahbod <behdad@gnome.org>
Fri, 26 Dec 2008 02:31:47 +0000 (02:31 +0000)
committerBehdad Esfahbod <behdad@src.gnome.org>
Fri, 26 Dec 2008 02:31:47 +0000 (02:31 +0000)
2008-12-25  Behdad Esfahbod  <behdad@gnome.org>

        Bug 469049 – Fix all compiler warnings

        * pango-view/viewer-pangocairo.c (render_callback):
        * pango/fonts.c (append_field), (pango_font_description_to_string):
        * pango/opentype/harfbuzz-dump.c:
        * pango/pango-bidi-type.c (pango_log2vis_get_embedding_levels):
        * pango/pango-coverage.c (pango_coverage_set):
        * pango/pango-markup.c (span_parse_func):
        * pango/pango-renderer.c
        (pango_renderer_default_draw_error_underline):
        * pango/pango-utils.c (pango_scan_string):
        * pango/pangocairo-render.c (pango_cairo_renderer_draw_trapezoid),
        (draw_error_underline), (pango_cairo_renderer_class_init):
        Fix all the remaining warnings.

svn path=/trunk/; revision=2767

ChangeLog
pango-view/viewer-pangocairo.c
pango/fonts.c
pango/opentype/harfbuzz-dump.c
pango/pango-bidi-type.c
pango/pango-coverage.c
pango/pango-markup.c
pango/pango-renderer.c
pango/pango-utils.c
pango/pangocairo-render.c

index 4e5af33..bbfcd19 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
 2008-12-25  Behdad Esfahbod  <behdad@gnome.org>
 
+       Bug 469049 – Fix all compiler warnings
+
+       * pango-view/viewer-pangocairo.c (render_callback):
+       * pango/fonts.c (append_field), (pango_font_description_to_string):
+       * pango/opentype/harfbuzz-dump.c:
+       * pango/pango-bidi-type.c (pango_log2vis_get_embedding_levels):
+       * pango/pango-coverage.c (pango_coverage_set):
+       * pango/pango-markup.c (span_parse_func):
+       * pango/pango-renderer.c
+       (pango_renderer_default_draw_error_underline):
+       * pango/pango-utils.c (pango_scan_string):
+       * pango/pangocairo-render.c (pango_cairo_renderer_draw_trapezoid),
+       (draw_error_underline), (pango_cairo_renderer_class_init):
+       Fix all the remaining warnings.
+
+2008-12-25  Behdad Esfahbod  <behdad@gnome.org>
+
        * pango/modules.c (pango_module_load), (script_info_free):
        * pango/opentype/harfbuzz-gpos.c (HB_Load_GPOS_Table):
        * pango/pango-bidi-type.c:
index de3fc89..97946eb 100644 (file)
@@ -269,6 +269,7 @@ render_callback (PangoLayout *layout,
       cairo_restore (cr);
     }
 
+  cairo_move_to (cr, 0, 0);
   pango_cairo_show_layout (cr, layout);
 
   cairo_restore (cr);
index 74b36ab..d7d59bc 100644 (file)
@@ -1120,19 +1120,19 @@ append_field (GString *str, const FieldMap *map, int n_elements, int val)
   int i;
   for (i=0; i<n_elements; i++)
     {
-      if (map[i].value == val)
+      if (map[i].value != val)
+        continue;
+
+      if (G_LIKELY (map[i].str && map[i].str[0]))
        {
-         if (map[i].str && map[i].str[0])
-           {
-             if (str->len > 0 && str->str[str->len -1] != ' ')
-               g_string_append_c (str, ' ');
-             g_string_append (str, map[i].str);
-           }
-         return;
+         if (G_LIKELY (str->len > 0 && str->str[str->len -1] != ' '))
+           g_string_append_c (str, ' ');
+         g_string_append (str, map[i].str);
        }
+      return;
     }
 
-  if (str->len > 0 || str->str[str->len -1] != ' ')
+  if (G_LIKELY (str->len > 0 || str->str[str->len -1] != ' '))
     g_string_append_c (str, ' ');
   g_string_append_printf (str, "%d", val);
 }
@@ -1158,7 +1158,7 @@ pango_font_description_to_string (const PangoFontDescription  *desc)
 
   result = g_string_new (NULL);
 
-  if (desc->family_name && desc->mask & PANGO_FONT_MASK_FAMILY)
+  if (G_LIKELY (desc->family_name && desc->mask & PANGO_FONT_MASK_FAMILY))
     {
       const char *p;
       size_t wordlen;
index 8c81da1..8611664 100644 (file)
@@ -54,6 +54,9 @@ do_indent (FILE *stream, int indent)
   fprintf (stream, "%*s", indent * 3, "");
 }
 
+#if __GNUC__ >= 3
+__attribute__((__format__(__printf__, 3, 4)))
+#endif
 static void
 dump (FILE *stream, int indent, const char *format, ...)
 {
index 990c4d2..9c37ef7 100644 (file)
@@ -131,7 +131,7 @@ pango_log2vis_get_embedding_levels (const gchar    *text,
   {
     if (length < 0)
       length = strlen (text);
-    embedding_levels_list = fribidi_log2vis_get_embedding_levels_new_utf8 (text, length, &fribidi_base_dir);
+    embedding_levels_list = (guint8 *) fribidi_log2vis_get_embedding_levels_new_utf8 (text, length, &fribidi_base_dir);
   }
 #else
   {
index 4e47c24..73fb147 100644 (file)
@@ -212,7 +212,7 @@ pango_coverage_set (PangoCoverage     *coverage,
 
   g_return_if_fail (coverage != NULL);
   g_return_if_fail (index >= 0);
-  g_return_if_fail (level >= 0 && level <= 3);
+  g_return_if_fail ((guint) level <= 3);
 
   block_index = index / 256;
 
index f5c9649..b1a8c9c 100644 (file)
@@ -1244,7 +1244,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
     {
       PangoUnderline ul = PANGO_UNDERLINE_NONE;
 
-      if (!span_parse_enum ("underline", underline, PANGO_TYPE_UNDERLINE, (int *) &ul, line_number, error))
+      if (!span_parse_enum ("underline", underline, PANGO_TYPE_UNDERLINE, (int*)(void*)&ul, line_number, error))
        goto error;
 
       add_attribute (tag, pango_attr_underline_new (ul));
@@ -1264,7 +1264,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
     {
       PangoGravity gr = PANGO_GRAVITY_SOUTH;
 
-      if (!span_parse_enum ("gravity", gravity, PANGO_TYPE_GRAVITY, (int *) &gr, line_number, error))
+      if (!span_parse_enum ("gravity", gravity, PANGO_TYPE_GRAVITY, (int*)(void*)&gr, line_number, error))
        goto error;
 
       add_attribute (tag, pango_attr_gravity_new (gr));
@@ -1274,7 +1274,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
     {
       PangoGravityHint hint = PANGO_GRAVITY_HINT_NATURAL;
 
-      if (!span_parse_enum ("gravity_hint", gravity_hint, PANGO_TYPE_GRAVITY_HINT, (int *) &hint, line_number, error))
+      if (!span_parse_enum ("gravity_hint", gravity_hint, PANGO_TYPE_GRAVITY_HINT, (int*)(void*)&hint, line_number, error))
        goto error;
 
       add_attribute (tag, pango_attr_gravity_hint_new (hint));
index d89d53f..ac83388 100644 (file)
@@ -975,6 +975,7 @@ pango_renderer_default_draw_error_underline (PangoRenderer *renderer,
   const PangoMatrix *matrix;
   double dx, dx0, dy0;
   PangoMatrix total;
+  int i;
 
   x += (width - width_units * unit_width) / 2;
   width = width_units * unit_width;
@@ -989,27 +990,25 @@ pango_renderer_default_draw_error_underline (PangoRenderer *renderer,
   dx0 = (matrix->xx * dx) / PANGO_SCALE;
   dy0 = (matrix->yx * dx) / PANGO_SCALE;
 
+  i = (width_units - 1) / 2;
   while (TRUE)
     {
-
       draw_rectangle (renderer, &total, PANGO_RENDER_PART_UNDERLINE, /* A */
                      0,                      0,
                      HEIGHT_SQUARES * 2 - 1, 1);
 
-      if (width_units > 2)
-       {
-         draw_rectangle (renderer, &total, PANGO_RENDER_PART_UNDERLINE, /* B */
-                         HEIGHT_SQUARES * 2 - 2, - (HEIGHT_SQUARES * 2 - 3),
-                         1,                      HEIGHT_SQUARES * 2 - 3);
-         width_units -= 2;
+      if (i <= 0)
+        break;
+      i--;
 
-         total.x0 += dx0;
-         total.y0 += dy0;
-       }
-      else
-       break;
+      draw_rectangle (renderer, &total, PANGO_RENDER_PART_UNDERLINE, /* B */
+                     HEIGHT_SQUARES * 2 - 2, - (HEIGHT_SQUARES * 2 - 3),
+                     1,                      HEIGHT_SQUARES * 2 - 3);
+
+      total.x0 += dx0;
+      total.y0 += dy0;
     }
-  if (width_units == 2)
+  if (width_units % 2 == 0)
     {
       draw_rectangle (renderer, &total, PANGO_RENDER_PART_UNDERLINE, /* C */
                      HEIGHT_SQUARES * 2 - 2, - (HEIGHT_SQUARES * 2 - 2),
index e9018fb..78e969f 100644 (file)
@@ -425,7 +425,7 @@ pango_scan_string (const char **pos, GString *out)
   while (g_ascii_isspace (*p))
     p++;
 
-  if (!*p)
+  if (G_UNLIKELY (!*p))
     return FALSE;
   else if (*p == '"')
     {
index 8be2614..006c8b5 100644 (file)
@@ -498,6 +498,45 @@ pango_cairo_renderer_draw_rectangle (PangoRenderer     *renderer,
     }
 }
 
+static void
+pango_cairo_renderer_draw_trapezoid (PangoRenderer     *renderer,
+                                    PangoRenderPart    part,
+                                    double             y1_,
+                                    double             x11,
+                                    double             x21,
+                                    double             y2,
+                                    double             x12,
+                                    double             x22)
+{
+  PangoCairoRenderer *crenderer = (PangoCairoRenderer *) (renderer);
+  cairo_t *cr;
+  double x, y;
+
+  cr = crenderer->cr;
+
+  cairo_save (cr);
+
+  if (!crenderer->do_path)
+    set_color (crenderer, part);
+
+  x = crenderer->x_offset,
+  y = crenderer->y_offset;
+  cairo_user_to_device_distance (cr, &x, &y);
+  cairo_identity_matrix (cr);
+  cairo_translate (cr, x, y);
+
+  cairo_move_to (cr, x11, y1_);
+  cairo_line_to (cr, x21, y1_);
+  cairo_line_to (cr, x22, y2);
+  cairo_line_to (cr, x12, y2);
+  cairo_close_path (cr);
+
+  if (!crenderer->do_path)
+    cairo_fill (cr);
+
+  cairo_restore (cr);
+}
+
 /* Draws an error underline that looks like one of:
  *              H       E                H
  *     /\      /\      /\        /\      /\               -
@@ -527,8 +566,10 @@ draw_error_underline (cairo_t *cr,
 {
   double square = height / HEIGHT_SQUARES;
   double unit_width = (HEIGHT_SQUARES - 1) * square;
+  double double_width = 2 * unit_width;
   int width_units = (width + unit_width / 2) / unit_width;
   double y_top, y_bottom;
+  double x_left, x_middle, x_right;
   int i;
 
   x += (width - width_units * unit_width) / 2;
@@ -538,38 +579,35 @@ draw_error_underline (cairo_t *cr,
   y_bottom = y + height;
 
   /* Bottom of squiggle */
+  x_middle = x + unit_width;
+  x_right  = x + double_width;
   cairo_move_to (cr, x - square / 2, y_top + square / 2); /* A */
-  for (i = 0; i < width_units; i += 2)
+  for (i = 0; i < width_units-2; i += 2)
     {
-      double x_middle = x + (i + 1) * unit_width;
-      double x_right = x + (i + 2) * unit_width;
-
       cairo_line_to (cr, x_middle, y_bottom); /* B */
+      cairo_line_to (cr, x_right, y_top + square); /* C */
 
-      if (i + 1 == width_units)
-       /* Nothing */;
-      else if (i + 2 == width_units)
-       cairo_line_to (cr, x_right + square / 2, y_top + square / 2); /* D */
-      else
-       cairo_line_to (cr, x_right, y_top + square); /* C */
+      x_middle += double_width;
+      x_right  += double_width;
     }
+  cairo_line_to (cr, x_middle, y_bottom); /* B */
+
+  if (i + 1 == width_units)
+    cairo_line_to (cr, x_middle + square / 2, y_bottom - square / 2); /* G */
+  else if (i + 2 == width_units) {
+    cairo_line_to (cr, x_right + square / 2, y_top + square / 2); /* D */
+    cairo_line_to (cr, x_right, y_top); /* E */
+  }
 
   /* Top of squiggle */
-  for (i -= 2; i >= 0; i -= 2)
+  x_left = x_middle - unit_width;
+  for (; i >= 0; i -= 2)
     {
-      double x_left = x + i * unit_width;
-      double x_middle = x + (i + 1) * unit_width;
-      double x_right = x + (i + 2) * unit_width;
-
-      if (i + 1 == width_units)
-       cairo_line_to (cr, x_middle + square / 2, y_bottom - square / 2); /* G */
-      else {
-       if (i + 2 == width_units)
-         cairo_line_to (cr, x_right, y_top); /* E */
-       cairo_line_to (cr, x_middle, y_bottom - square); /* F */
-      }
-
+      cairo_line_to (cr, x_middle, y_bottom - square); /* F */
       cairo_line_to (cr, x_left, y_top);   /* H */
+
+      x_left   -= double_width;
+      x_middle -= double_width;
     }
 }
 
@@ -656,6 +694,7 @@ pango_cairo_renderer_class_init (PangoCairoRendererClass *klass)
   renderer_class->draw_glyphs = pango_cairo_renderer_draw_glyphs;
   renderer_class->draw_glyph_item = pango_cairo_renderer_draw_glyph_item;
   renderer_class->draw_rectangle = pango_cairo_renderer_draw_rectangle;
+  renderer_class->draw_trapezoid = pango_cairo_renderer_draw_trapezoid;
   renderer_class->draw_error_underline = pango_cairo_renderer_draw_error_underline;
   renderer_class->draw_shape = pango_cairo_renderer_draw_shape;
 }