diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2006-08-15 19:26:40 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2006-08-15 19:26:40 +0000 |
commit | 099d3b8efa4b04c8d578aa9e1de3e108ef4c77a9 (patch) | |
tree | b9dd21fb459506b945fcf43032c2acd7b7ff3f2c | |
parent | 9f96e87af64452c67466dc48636d7df77cdd5cd4 (diff) | |
download | pango-099d3b8efa4b04c8d578aa9e1de3e108ef4c77a9.tar.gz |
Fix handling of WEST and EAST gravity effect on bidi level.
2006-08-15 Behdad Esfahbod <behdad@gnome.org>
* pango/pango-context.c (itemize_state_add_character):
Fix handling of WEST and EAST gravity effect on bidi level.
* pango/pangocairo-fcfont.c
(pango_cairo_fc_font_glyph_extents_cache_init):
For NORTH gravity (upside down text), swap ascent and descent,
and for EAST/WEST, center baseline between ascent/descent.
* pango/shape.c (pango_shape): If glyph width is negative, negate
it and shift glyph by that amount. This allows having font matrices
that essentially move the glyph origin to the right of the glyph to
still work.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | pango/pango-context.c | 18 | ||||
-rw-r--r-- | pango/pangocairo-fcfont.c | 22 | ||||
-rw-r--r-- | pango/shape.c | 15 |
4 files changed, 60 insertions, 10 deletions
@@ -1,5 +1,20 @@ 2006-08-15 Behdad Esfahbod <behdad@gnome.org> + * pango/pango-context.c (itemize_state_add_character): + Fix handling of WEST and EAST gravity effect on bidi level. + + * pango/pangocairo-fcfont.c + (pango_cairo_fc_font_glyph_extents_cache_init): + For NORTH gravity (upside down text), swap ascent and descent, + and for EAST/WEST, center baseline between ascent/descent. + + * pango/shape.c (pango_shape): If glyph width is negative, negate + it and shift glyph by that amount. This allows having font matrices + that essentially move the glyph origin to the right of the glyph to + still work. + +2006-08-15 Behdad Esfahbod <behdad@gnome.org> + * pango/pangocairo-fcfont.c (pango_cairo_fc_font_get_scaled_font), (_pango_cairo_fc_font_new): Move font_matrix rotation into font_new as we use only rotation and no translation anymore. diff --git a/pango/pango-context.c b/pango/pango-context.c index f0fae76d..c538d3e9 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -875,25 +875,31 @@ itemize_state_add_character (ItemizeState *state, state->item->analysis.level = state->embedding; state->item->analysis.gravity = state->gravity; /* The level vs. gravity dance: - * - If gravity is NORTH, leave level untouched - * - If gravity is SOUTH, step level one up, to + * - If gravity is SOUTH, leave level untouched + * - If gravity is NORTH, step level one up, to * not get mirrored upside-down text - * - If gravity is WEST, leave level untouched, as + * - If gravity is EAST, step up to an even level, as * it's a clockwise-rotated layout, so the rotated * top is unrotated left. - * - If gravity is EAST, step level one up to get, as + * - If gravity is WEST, step up to an odd level, as * it's a counter-clockwise-rotated layout, so the rotated * top is unrotated right. */ switch (state->item->analysis.gravity) { case PANGO_GRAVITY_SOUTH: - case PANGO_GRAVITY_EAST: default: break; case PANGO_GRAVITY_NORTH: - case PANGO_GRAVITY_WEST: state->item->analysis.level++; + break; + case PANGO_GRAVITY_EAST: + state->item->analysis.level += 1; + state->item->analysis.level &= ~1; + break; + case PANGO_GRAVITY_WEST: + state->item->analysis.level |= 1; + break; } state->item->analysis.language = state->derived_lang; diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c index 1b5a56fe..1af98e11 100644 --- a/pango/pangocairo-fcfont.c +++ b/pango/pangocairo-fcfont.c @@ -270,9 +270,27 @@ pango_cairo_fc_font_glyph_extents_cache_init (PangoCairoFcFont *cffont) cairo_scaled_font_extents (scaled_font, &font_extents); cffont->font_extents.x = 0; - cffont->font_extents.y = - PANGO_UNITS (font_extents.ascent); - cffont->font_extents.height = PANGO_UNITS (font_extents.ascent + font_extents.descent); cffont->font_extents.width = 0; + cffont->font_extents.height = PANGO_UNITS (font_extents.ascent + font_extents.descent); + switch (cffont->gravity) + { + default: + case PANGO_GRAVITY_SOUTH: + cffont->font_extents.y = - PANGO_UNITS (font_extents.ascent); + break; + case PANGO_GRAVITY_NORTH: + cffont->font_extents.y = - PANGO_UNITS (font_extents.descent); + break; + /* The case of EAST/WEST is tricky. In vertical layout, ascent/descent + * are useless. I'm trying to get a patch into cairo to use + * max_x_advance*0.5 for ascent and descent for vertical fonts. That's + * at least more useful. But with or without it, doesn't harm to center + * ourselves here. + */ + case PANGO_GRAVITY_EAST: + case PANGO_GRAVITY_WEST: + cffont->font_extents.y = - PANGO_UNITS ((font_extents.ascent + font_extents.descent) * 0.5); + } cffont->glyph_extents_cache = g_new0 (GlyphExtentsCacheEntry, GLYPH_CACHE_NUM_ENTRIES); /* Make sure all cache entries are invalid initially */ diff --git a/pango/shape.c b/pango/shape.c index 50479b5e..96abd21b 100644 --- a/pango/shape.c +++ b/pango/shape.c @@ -109,10 +109,10 @@ pango_shape (const gchar *text, text, length, analysis, glyphs); } - /* Set glyphs[i].attr.is_cluster_start based on log_clusters[] - */ for (i = 0; i < glyphs->num_glyphs; i++) { + /* Set glyphs[i].attr.is_cluster_start based on log_clusters[] + */ if (glyphs->log_clusters[i] != last_cluster) { glyphs->glyphs[i].attr.is_cluster_start = TRUE; @@ -120,5 +120,16 @@ pango_shape (const gchar *text, } else glyphs->glyphs[i].attr.is_cluster_start = FALSE; + + + /* Shift glyph if width is negative, and negate width. + * This is useful for rotated font matrices and shouldn't + * harm in normal cases. + */ + if (glyphs->glyphs[i].geometry.width < 0) + { + glyphs->glyphs[i].geometry.width = -glyphs->glyphs[i].geometry.width; + glyphs->glyphs[i].geometry.x_offset += glyphs->glyphs[i].geometry.width; + } } } |