From bd7f0529df20a3268815da365944979af441cd3a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 30 Apr 2007 23:09:47 +0000 Subject: Move PANGO_UNITS_ROUND here... ...from here. 2007-04-30 Behdad Esfahbod * pango/pango-types.h: Move PANGO_UNITS_ROUND here... * pango/pangofc-private.h: ...from here. * pango/pango-gravity.c: Document that pango_gravity_to_rotation() returns angle in radians but pango_matrix_rotate() takes degrees. * pango/pango-layout.c (pango_layout_run_get_extents): * pango/pango-renderer.c (pango_renderer_draw_layout_line): Retain metrics hinting when centering baseline (used for Latin, etc in vertical mode). * pango/pangocairo-fcfont.c (pango_cairo_fc_font_get_metrics), (pango_cairo_fc_font_glyph_extents_cache_init): Respect metrics hinting setting when moving glyphs around for vertical writing. * pango/pangocairo-fcfont.c (_pango_cairo_fc_font_new): Apply the gravity rotation before the pattern's matrix, such that vertical text gets correct italic direction. * pango/pangocairo-font.c (_pango_cairo_font_get_hex_box_info): Make hexbox font inherit most properties from the current font. That is, bold hexbox digits for a bold font, etc. svn path=/trunk/; revision=2238 --- pango/pango-gravity.c | 6 +++++- pango/pango-layout.c | 10 +++++++++- pango/pango-renderer.c | 10 +++++++++- pango/pango-types.h | 4 ++++ pango/pangocairo-fcfont.c | 37 +++++++++++++++++++++++++++---------- pango/pangocairo-font.c | 28 +++++++++++++++++++--------- pango/pangofc-private.h | 3 --- 7 files changed, 73 insertions(+), 25 deletions(-) (limited to 'pango') diff --git a/pango/pango-gravity.c b/pango/pango-gravity.c index 1b59a500..1c2d8b0d 100644 --- a/pango/pango-gravity.c +++ b/pango/pango-gravity.c @@ -29,9 +29,13 @@ * pango_gravity_to_rotation: * @gravity: gravity to query * - * Converts a #PangoGravity value to its rotation value. + * Converts a #PangoGravity value to its natural rotation in radians. * @gravity should not be %PANGO_GRAVITY_AUTO. * + * Note that pango_matrix_rotate() takes angle in degrees, not radians. + * So, to call pango_matrix_rotate() with the output of this function + * you should multiply it by (180. / G_PI). + * * Return value: the rotation value corresponding to @gravity. * * Since: 1.16 diff --git a/pango/pango-layout.c b/pango/pango-layout.c index 18b67e1e..4c6eca0a 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -4309,7 +4309,15 @@ pango_layout_run_get_extents (PangoLayoutRun *run, } if (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_CENTERED_BASELINE) - properties.rise += run_logical->y + run_logical->height / 2; + { + gboolean is_hinted = (run_logical->y & run_logical->height & (PANGO_SCALE - 1)) == 0; + int adjustment = run_logical->y + run_logical->height / 2; + + if (is_hinted) + adjustment = PANGO_UNITS_ROUND (adjustment); + + properties.rise += adjustment; + } if (properties.rise != 0) { diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c index daa877fb..02b8f479 100644 --- a/pango/pango-renderer.c +++ b/pango/pango-renderer.c @@ -516,7 +516,15 @@ pango_renderer_draw_layout_line (PangoRenderer *renderer, state.logical_rect_end = x + x_off + glyph_string_width; if (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_CENTERED_BASELINE) - rise += logical_rect.y + logical_rect.height / 2; + { + gboolean is_hinted = (logical_rect.y & logical_rect.height & (PANGO_SCALE - 1)) == 0; + int adjustment = logical_rect.y + logical_rect.height / 2; + + if (is_hinted) + adjustment = PANGO_UNITS_ROUND (adjustment); + + rise += adjustment; + } if (renderer->priv->color_set[PANGO_RENDER_PART_BACKGROUND]) diff --git a/pango/pango-types.h b/pango/pango-types.h index 59ecac0c..1b08f8ff 100644 --- a/pango/pango-types.h +++ b/pango/pango-types.h @@ -57,6 +57,10 @@ typedef guint32 PangoGlyph; * PANGO_PIXELS also behaves differently for +512 and -512. */ +#define PANGO_UNITS_ROUND(d) \ + (((d) + (PANGO_SCALE >> 1)) & ~(PANGO_SCALE - 1)) + + int pango_units_from_double (double d) G_GNUC_CONST; double pango_units_to_double (int i) G_GNUC_CONST; diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c index 65b9e038..8c44b2a0 100644 --- a/pango/pangocairo-fcfont.c +++ b/pango/pangocairo-fcfont.c @@ -245,11 +245,14 @@ pango_cairo_fc_font_get_metrics (PangoFont *font, break; case PANGO_GRAVITY_EAST: case PANGO_GRAVITY_WEST: - info->metrics->ascent = height / 2; + { + int ascent = height / 2; + if (fcfont->is_hinted) + ascent = PANGO_UNITS_ROUND (ascent); + info->metrics->ascent = 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; @@ -307,7 +310,13 @@ pango_cairo_fc_font_glyph_extents_cache_init (PangoCairoFcFont *cffont) break; case PANGO_GRAVITY_EAST: case PANGO_GRAVITY_WEST: - cffont->font_extents.y = - pango_units_from_double ((font_extents.ascent + font_extents.descent) * 0.5); + { + PangoFcFont *fcfont = (PangoFcFont *) (cffont); + int ascent = pango_units_from_double (font_extents.ascent + font_extents.descent) / 2; + if (fcfont->is_hinted) + ascent = PANGO_UNITS_ROUND (ascent); + cffont->font_extents.y = - ascent; + } } cffont->glyph_extents_cache = g_new0 (GlyphExtentsCacheEntry, GLYPH_CACHE_NUM_ENTRIES); @@ -507,21 +516,29 @@ _pango_cairo_fc_font_new (PangoCairoFcFontMap *cffontmap, cffont->gravity = pango_font_description_get_gravity (desc); + /* first apply gravity rotation, then pattern matrix, such that + * vertical italic text comes out "correct". we don't do anything + * like baseline adjustment etc though. should be specially + * handled when we support italic correction. */ + cairo_matrix_init_rotate(&cffont->font_matrix, + pango_gravity_to_rotation (cffont->gravity)); + if (FcPatternGetMatrix (pattern, FC_MATRIX, 0, &fc_matrix) == FcResultMatch) { - cairo_matrix_init (&cffont->font_matrix, + cairo_matrix_t matrix; + + cairo_matrix_init (&matrix, fc_matrix->xx, - fc_matrix->yx, - fc_matrix->xy, fc_matrix->yy, 0., 0.); - } - else - cairo_matrix_init_identity (&cffont->font_matrix); - cairo_matrix_rotate(&cffont->font_matrix, - pango_gravity_to_rotation (cffont->gravity)); + cairo_matrix_multiply (&cffont->font_matrix, + &matrix, + &cffont->font_matrix); + } pango_ctm = pango_context_get_matrix (context); diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c index d779b983..a8d011f2 100644 --- a/pango/pangocairo-font.c +++ b/pango/pangocairo-font.c @@ -142,10 +142,11 @@ _pango_cairo_font_get_hex_box_info (PangoCairoFont *cfont) cairo_font_options_t *font_options; cairo_font_extents_t font_extents; double size, mini_size; - PangoFontDescription *desc, *mini_desc; + PangoFontDescription *desc; cairo_scaled_font_t *scaled_font, *scaled_mini_font; PangoMatrix pango_ctm; cairo_matrix_t cairo_ctm; + PangoGravity gravity; if (!cfont) return NULL; @@ -164,8 +165,16 @@ _pango_cairo_font_get_hex_box_info (PangoCairoFont *cfont) font_options = cairo_font_options_create (); cairo_scaled_font_get_font_options (scaled_font, font_options); is_hinted = (cairo_font_options_get_hint_metrics(font_options) != CAIRO_HINT_METRICS_OFF); + desc = pango_font_describe_with_absolute_size ((PangoFont *)cfont); + size = pango_font_description_get_size (desc) / (1.*PANGO_SCALE); + gravity = pango_font_description_get_gravity (desc); cairo_scaled_font_get_ctm (scaled_font, &cairo_ctm); + /* I started adding support for vertical hexboxes here, but it's too much + * work. Easier to do with cairo user fonts and vertical writing mode + * support in cairo. + */ + /*cairo_matrix_rotate (&cairo_ctm, pango_gravity_to_rotation (gravity));*/ pango_ctm.xx = cairo_ctm.xx; pango_ctm.yx = cairo_ctm.yx; pango_ctm.xy = cairo_ctm.xy; @@ -201,12 +210,15 @@ _pango_cairo_font_get_hex_box_info (PangoCairoFont *cfont) fontmap = pango_font_get_font_map ((PangoFont *)cfont); - desc = pango_font_describe_with_absolute_size ((PangoFont *)cfont); - size = pango_font_description_get_size (desc) / (1.*PANGO_SCALE); + /* we inherit most font properties for the mini font. just + * change family and size. means, you get bold hex digits + * in the hexbox for a bold font. + */ - mini_desc = pango_font_description_new (); - pango_font_description_set_family_static (mini_desc, "monospace"); + /* We should rotate the box, not glyphs */ + pango_font_description_unset_fields (desc, PANGO_FONT_MASK_GRAVITY); + pango_font_description_set_family_static (desc, "monospace"); rows = 2; mini_size = size / 2.4; @@ -221,7 +233,7 @@ _pango_cairo_font_get_hex_box_info (PangoCairoFont *cfont) } } - pango_font_description_set_absolute_size (mini_desc, mini_size * PANGO_SCALE); + pango_font_description_set_absolute_size (desc, mini_size * PANGO_SCALE); /* load mini_font */ @@ -231,10 +243,8 @@ _pango_cairo_font_get_hex_box_info (PangoCairoFont *cfont) pango_context_set_matrix (context, &pango_ctm); pango_context_set_language (context, pango_language_from_string ("en")); pango_cairo_context_set_font_options (context, font_options); - mini_font = pango_font_map_load_font (fontmap, context, mini_desc); - pango_font_description_free (mini_desc); + mini_font = pango_font_map_load_font (fontmap, context, desc); - pango_font_description_free (desc); g_object_unref (context); } diff --git a/pango/pangofc-private.h b/pango/pangofc-private.h index 09406d13..27ad5769 100644 --- a/pango/pangofc-private.h +++ b/pango/pangofc-private.h @@ -42,9 +42,6 @@ struct _PangoFcMetricsInfo ((d) - PANGO_SCALE_26_6 / 2) / PANGO_SCALE_26_6) #define PANGO_UNITS_26_6(d) (PANGO_SCALE_26_6 * (d)) -#define PANGO_UNITS_ROUND(d) \ - (((d) + (PANGO_SCALE >> 1)) & ~(PANGO_SCALE - 1)) - #define PANGO_FC_GRAVITY "pangogravity" void _pango_fc_font_shutdown (PangoFcFont *fcfont); -- cgit v1.2.1