diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2007-04-30 23:09:47 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2007-04-30 23:09:47 +0000 |
commit | bd7f0529df20a3268815da365944979af441cd3a (patch) | |
tree | fb8ed8d2a77ed919f180f7197f89695b6fd8af84 | |
parent | 69bcc7f2e5ca2c7135e7ba558c85fffbce2426cb (diff) | |
download | pango-bd7f0529df20a3268815da365944979af441cd3a.tar.gz |
Move PANGO_UNITS_ROUND here... ...from here.
2007-04-30 Behdad Esfahbod <behdad@gnome.org>
* 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
-rw-r--r-- | ChangeLog | 25 | ||||
-rw-r--r-- | pango-view/viewer-pangocairo.c | 2 | ||||
-rw-r--r-- | pango/pango-gravity.c | 6 | ||||
-rw-r--r-- | pango/pango-layout.c | 10 | ||||
-rw-r--r-- | pango/pango-renderer.c | 10 | ||||
-rw-r--r-- | pango/pango-types.h | 4 | ||||
-rw-r--r-- | pango/pangocairo-fcfont.c | 37 | ||||
-rw-r--r-- | pango/pangocairo-font.c | 28 | ||||
-rw-r--r-- | pango/pangofc-private.h | 3 |
9 files changed, 100 insertions, 25 deletions
@@ -1,3 +1,28 @@ +2007-04-30 Behdad Esfahbod <behdad@gnome.org> + + * 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. + 2007-04-30 Tor Lillqvist <tml@novell.com> * pango/pangowin32-fontmap.c (get_family_nameA, get_family_nameW): diff --git a/pango-view/viewer-pangocairo.c b/pango-view/viewer-pangocairo.c index 10aaccc4..09f205c0 100644 --- a/pango-view/viewer-pangocairo.c +++ b/pango-view/viewer-pangocairo.c @@ -319,6 +319,8 @@ pangocairo_view_render (gpointer instance, /* This is annoying ... we have to create a temporary surface just to * get the extents of the text. */ + /* image surface here is not good as it may have font options different + * from the target surface */ cs = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1); cr = cairo_create (cs); cairo_surface_destroy (cs); 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); |