Return if none of logical_rect or ink_rect is non-NULL.
authorBehdad Esfahbod <behdad@gnome.org>
Wed, 16 Aug 2006 02:01:17 +0000 (02:01 +0000)
committerBehdad Esfahbod <behdad@src.gnome.org>
Wed, 16 Aug 2006 02:01:17 +0000 (02:01 +0000)
2006-08-15  Behdad Esfahbod  <behdad@gnome.org>

        * pango/pango-layout.c (pango_layout_run_get_extents):
        * pango/glyphstring.c (pango_glyph_string_extents_range):
        Return if none of logical_rect or ink_rect is non-NULL.

        * pango/pango-item.h (PangoAnalysis): Add new member centered_baseline
        which if set, makes item rendered such that ascent == descent.

        * pango/pango-context.c (itemize_state_init),
        (itemize_state_add_character):
        * pango/pango-renderer.c (pango_renderer_draw_layout_line):
        Implement centered_baseline.

        * pango/pangocairo-fcfont.c (pango_cairo_fc_font_get_metrics): When
        adjusting ascent/descent for vertical fonts, adjust strikethrough and
        underline position too.

        * docs/tmpl/main.sgml: Document new struct member.

ChangeLog
docs/tmpl/main.sgml
pango/glyphstring.c
pango/pango-context.c
pango/pango-item.h
pango/pango-layout.c
pango/pango-renderer.c
pango/pangocairo-fcfont.c

index 1734a26..78b5c9e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2006-08-15  Behdad Esfahbod  <behdad@gnome.org>
 
+       * pango/pango-layout.c (pango_layout_run_get_extents):
+       * pango/glyphstring.c (pango_glyph_string_extents_range):
+       Return if none of logical_rect or ink_rect is non-NULL.
+
+       * pango/pango-item.h (PangoAnalysis): Add new member centered_baseline
+       which if set, makes item rendered such that ascent == descent.
+
+       * pango/pango-context.c (itemize_state_init),
+       (itemize_state_add_character):
+       * pango/pango-renderer.c (pango_renderer_draw_layout_line):
+       Implement centered_baseline.
+
+       * pango/pangocairo-fcfont.c (pango_cairo_fc_font_get_metrics): When
+       adjusting ascent/descent for vertical fonts, adjust strikethrough and
+       underline position too.
+
+       * docs/tmpl/main.sgml: Document new struct member.
+
+2006-08-15  Behdad Esfahbod  <behdad@gnome.org>
+
        * modules/basic/basic-fc.c (basic_engine_shape): Use analysis->gravity
        to detect vertical fonts, instead of poking into the font_pattern.
 
index 0751fc7..4444b78 100644 (file)
@@ -51,6 +51,8 @@ fields:
 @font: the font for this segment.
 @level: the bidrectional level for this segment.
 @gravity: the glyph orientation for this segment.
+@centered_baseline: whether this segment should be shifted to center around
+the baseline.
 @language: the detected language for this segment.
 @extra_attrs: extra attributes for this segment.
 
index 353fa2a..2247d03 100644 (file)
@@ -166,6 +166,9 @@ pango_glyph_string_extents_range (PangoGlyphString *glyphs,
    */
   g_return_if_fail (start <= end);
 
+  if (G_UNLIKELY (!ink_rect && !logical_rect))
+    return;
+
   if (ink_rect)
     {
       ink_rect->x = 0;
index c0e2042..31953c7 100644 (file)
@@ -577,6 +577,7 @@ struct _ItemizeState
   const char *embedding_end;
   guint8 embedding;
   PangoGravity gravity;
+  gboolean centered_baseline;
 
   PangoAttrIterator *attr_iter;
   gboolean free_attr_iter;
@@ -707,7 +708,10 @@ itemize_state_init (ItemizeState      *state,
    * proper gravity assignment.
    */
   state->gravity = context->base_gravity;
-  
+
+  state->centered_baseline = context->base_gravity == PANGO_GRAVITY_EAST
+                         || context->base_gravity == PANGO_GRAVITY_WEST;
+
   /* Initialize the attribute iterator
    */
   if (cached_iter)
@@ -902,6 +906,8 @@ itemize_state_add_character (ItemizeState     *state,
        break;
     }
 
+  state->item->analysis.centered_baseline = state->centered_baseline;
+
   state->item->analysis.language = state->derived_lang;
   
   if (state->copy_extra_attrs)
index 90b9b61..638bc0d 100644 (file)
@@ -34,8 +34,12 @@ struct _PangoAnalysis
   PangoEngineShape *shape_engine;
   PangoEngineLang  *lang_engine;
   PangoFont *font;
+
   guint8 level;
-  PangoGravity gravity : 8; /* nastiest hack ever.  stuff gravity in the padding after the guint8 */
+  /* nastiest hack ever.  stuff new items in the padding after the guint8 */
+  PangoGravity gravity       : 8;
+  gboolean centered_baseline : 1;
+
   PangoLanguage *language;
   GSList *extra_attrs;
 };
index db2c870..cb6e14d 100644 (file)
@@ -3910,10 +3910,17 @@ pango_layout_run_get_extents (PangoLayoutRun *run,
                               PangoRectangle *run_ink,
                               PangoRectangle *run_logical)
 {
+  PangoRectangle logical;
   ItemProperties properties;
 
+  if (G_UNLIKELY (!run_ink && !run_logical))
+    return;
+
   pango_layout_get_item_properties (run->item, &properties);
 
+  if (!run_logical && run->item->analysis.centered_baseline)
+    run_logical = &logical;
+
   if (properties.shape_set)
     imposed_extents (run->item->num_chars,
                     properties.shape_ink_rect,
@@ -3959,6 +3966,9 @@ pango_layout_run_get_extents (PangoLayoutRun *run,
       pango_font_metrics_unref (metrics);
     }
 
+  if (run->item->analysis.centered_baseline)
+    properties.rise += run_logical->y + run_logical->height / 2;
+
   if (properties.rise != 0)
     {
       if (run_ink)
index c53f645..f54e128 100644 (file)
@@ -479,7 +479,11 @@ pango_renderer_draw_layout_line (PangoRenderer    *renderer,
       gint rise;
       PangoLayoutRun *run = l->data;
       PangoAttrShape *shape_attr;
-      PangoRectangle ink_rect;
+      PangoRectangle ink_rect, *ink = NULL;
+      PangoRectangle logical_rect, *logical = NULL;
+
+      if (run->item->analysis.centered_baseline)
+        logical = &logical_rect;
 
       pango_renderer_prepare_run (renderer, run);
       
@@ -488,19 +492,28 @@ pango_renderer_draw_layout_line (PangoRenderer    *renderer,
       if (shape_attr)
        {
          ink_rect = shape_attr->ink_rect;
+         logical_rect = shape_attr->logical_rect;
          glyph_string_width = shape_attr->logical_rect.width;
        }
       else
        {
          if (renderer->underline != PANGO_UNDERLINE_NONE ||
              renderer->strikethrough)
-             pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
-                                         &ink_rect, NULL);
-         glyph_string_width = pango_glyph_string_get_width (run->glyphs);
+           ink = &ink_rect;
+         pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
+                                     ink, logical);
+         if (logical)
+           glyph_string_width = logical_rect.width;
+         else
+           glyph_string_width = pango_glyph_string_get_width (run->glyphs);
        }
 
       state.logical_rect_end = x + x_off + glyph_string_width;
 
+      if (run->item->analysis.centered_baseline)
+        rise += logical_rect.y + logical_rect.height / 2;
+
+
       if (renderer->priv->color_set[PANGO_RENDER_PART_BACKGROUND])
        {
          if (!got_overall)
index 5ca9bcb..0e50306 100644 (file)
@@ -216,7 +216,7 @@ pango_cairo_fc_font_get_metrics (PangoFont     *font,
   if (!tmp_list)
     {
       PangoContext *context;
-      int height;
+      int height, shift;
 
       if (!fcfont->fontmap)
        return pango_font_metrics_new ();
@@ -248,7 +248,13 @@ pango_cairo_fc_font_get_metrics (PangoFont     *font,
          case PANGO_GRAVITY_WEST:
            info->metrics->ascent = height / 2;
        }
-      info->metrics->descent = height - info->metrics->ascent;
+      shift = (height - info->metrics->ascent) - info->metrics->descent;
+      if (fcfont->is_hinted)
+        shift &= ~(PANGO_SCALE - 1);
+      info->metrics->descent += shift;
+      info->metrics->underline_position -= shift;
+      info->metrics->strikethrough_position -= shift;
+      info->metrics->ascent = height - info->metrics->descent;
 
       g_object_unref (context);
     }