summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--docs/tmpl/main.sgml2
-rw-r--r--pango/glyphstring.c3
-rw-r--r--pango/pango-context.c8
-rw-r--r--pango/pango-item.h6
-rw-r--r--pango/pango-layout.c10
-rw-r--r--pango/pango-renderer.c21
-rw-r--r--pango/pangocairo-fcfont.c10
8 files changed, 72 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 1734a26d..78b5c9e3 100644
--- 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.
diff --git a/docs/tmpl/main.sgml b/docs/tmpl/main.sgml
index 0751fc77..4444b786 100644
--- a/docs/tmpl/main.sgml
+++ b/docs/tmpl/main.sgml
@@ -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.
diff --git a/pango/glyphstring.c b/pango/glyphstring.c
index 353fa2a4..2247d034 100644
--- a/pango/glyphstring.c
+++ b/pango/glyphstring.c
@@ -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;
diff --git a/pango/pango-context.c b/pango/pango-context.c
index c0e20420..31953c71 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -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)
diff --git a/pango/pango-item.h b/pango/pango-item.h
index 90b9b614..638bc0d1 100644
--- a/pango/pango-item.h
+++ b/pango/pango-item.h
@@ -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;
};
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index db2c870c..cb6e14d7 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -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)
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index c53f645d..f54e1282 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -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)
diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c
index 5ca9bcb2..0e503061 100644
--- a/pango/pangocairo-fcfont.c
+++ b/pango/pangocairo-fcfont.c
@@ -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);
}