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.
@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.
*/
g_return_if_fail (start <= end);
+ if (G_UNLIKELY (!ink_rect && !logical_rect))
+ return;
+
if (ink_rect)
{
ink_rect->x = 0;
const char *embedding_end;
guint8 embedding;
PangoGravity gravity;
+ gboolean centered_baseline;
PangoAttrIterator *attr_iter;
gboolean free_attr_iter;
* 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)
break;
}
+ state->item->analysis.centered_baseline = state->centered_baseline;
+
state->item->analysis.language = state->derived_lang;
if (state->copy_extra_attrs)
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;
};
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,
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)
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);
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)
if (!tmp_list)
{
PangoContext *context;
- int height;
+ int height, shift;
if (!fcfont->fontmap)
return pango_font_metrics_new ();
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);
}