diff options
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | pango/pango-utils.c | 34 | ||||
-rw-r--r-- | pango/pango-utils.h | 3 | ||||
-rw-r--r-- | pango/pango.def | 1 | ||||
-rw-r--r-- | pango/pangocairo-win32font.c | 5 | ||||
-rw-r--r-- | pango/pangofc-font.c | 28 |
6 files changed, 66 insertions, 24 deletions
@@ -1,3 +1,22 @@ +2006-03-30 Tor Lillqvist <tml@novell.com> + + Fix blurred underlines on Win32 (#332656): + + * pango/pango-utils.c (pango_quantize_line_geometry): + New public function. Used to be the static quantize_position() in + pangofc-font.c + + * pango/pango-utils.h: Declare it. + + * pango/pango.def: Here, too. + + * pango/pangofc-font.c (quantize_position): Remove. + (get_face_metrics): Use pango_quantize_line_geometry() instead. + + * pango/pangocairo-win32font.c (create_metrics_for_context): Call + pango_quantize_line_geometry() for underline and strikethrough + geometries. + 2006-03-25 Behdad Esfahbod <behdad@gnome.org> * pango/opentype/ottest.c: Don't err on Table_Missing. diff --git a/pango/pango-utils.c b/pango/pango-utils.c index 7758c27f..5f7a206f 100644 --- a/pango/pango-utils.c +++ b/pango/pango-utils.c @@ -1806,3 +1806,37 @@ pango_is_zero_width (gunichar ch) (ch >= 0x202A && ch <= 0x202E) )) || ch == 0xFEFF; } + +/** + * pango_quantize_line_geometry: + * @thickness: pointer to the thickness of a line, in Pango scaled units + * @position: corresponding position + * + * Quantizes the thickness and position of a line, typically an + * underline or strikethrough, to whole device pixels, that is + * multiplies of PANGO_SCALE. The purpose of this function is to avoid + * such lines looking blurry. + * + * Since: 1.12 + */ +void +pango_quantize_line_geometry (int *thickness, + int *position) +{ + int thickness_pixels = (*thickness + PANGO_SCALE / 2) / PANGO_SCALE; + if (thickness_pixels == 0) + thickness_pixels = 1; + + if (thickness_pixels & 1) + { + int new_center = ((*position - *thickness / 2) & ~(PANGO_SCALE - 1)) + PANGO_SCALE / 2; + *position = new_center + (PANGO_SCALE * thickness_pixels) / 2; + } + else + { + int new_center = ((*position - *thickness / 2 + PANGO_SCALE / 2) & ~(PANGO_SCALE - 1)); + *position = new_center + (PANGO_SCALE * thickness_pixels) / 2; + } + + *thickness = thickness_pixels * PANGO_SCALE; +} diff --git a/pango/pango-utils.h b/pango/pango-utils.h index 00d4889e..bc130532 100644 --- a/pango/pango-utils.h +++ b/pango/pango-utils.h @@ -102,6 +102,9 @@ gboolean pango_is_zero_width (gunichar ch) G_GNUC_CONST; /* String interning for static strings */ #define I_(string) g_intern_static_string (string) +void pango_quantize_line_geometry (int *thickness, + int *position); + G_END_DECLS #endif /* __PANGO_UTILS_H__ */ diff --git a/pango/pango.def b/pango/pango.def index ee8c6856..cb88c903 100644 --- a/pango/pango.def +++ b/pango/pango.def @@ -278,6 +278,7 @@ EXPORTS pango_parse_style pango_parse_variant pango_parse_weight + pango_quantize_line_geometry pango_read_line pango_render_part_get_type pango_renderer_activate diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c index 40e5be85..67c71202 100644 --- a/pango/pangocairo-win32font.c +++ b/pango/pangocairo-win32font.c @@ -302,6 +302,11 @@ create_metrics_for_context (PangoFont *font, metrics->strikethrough_thickness = metrics->underline_thickness; metrics->strikethrough_position = height / 4; + pango_quantize_line_geometry (&metrics->underline_thickness, + &metrics->underline_position); + pango_quantize_line_geometry (&metrics->strikethrough_thickness, + &metrics->strikethrough_position); + layout = pango_layout_new (context); font_desc = pango_font_describe (font); pango_layout_set_font_description (layout, font_desc); diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c index d6e2d8fd..1724f12f 100644 --- a/pango/pangofc-font.c +++ b/pango/pangofc-font.c @@ -252,28 +252,6 @@ pango_fc_font_get_coverage (PangoFont *font, fcfont); } -static void -quantize_position (int *thickness, - int *position) -{ - int thickness_pixels = (*thickness + PANGO_SCALE / 2) / PANGO_SCALE; - if (thickness_pixels == 0) - thickness_pixels = 1; - - if (thickness_pixels & 1) - { - int new_center = ((*position - *thickness / 2) & ~(PANGO_SCALE - 1)) + PANGO_SCALE / 2; - *position = new_center + (PANGO_SCALE * thickness_pixels) / 2; - } - else - { - int new_center = ((*position - *thickness / 2 + PANGO_SCALE / 2) & ~(PANGO_SCALE - 1)); - *position = new_center + (PANGO_SCALE * thickness_pixels) / 2; - } - - *thickness = thickness_pixels * PANGO_SCALE; -} - /* For Xft, it would be slightly more efficient to simply to * call Xft, and also more robust against changes in Xft. * But for now, we simply use the same code for all backends. @@ -386,8 +364,10 @@ get_face_metrics (PangoFcFont *fcfont, */ if (fcfont->is_hinted) { - quantize_position (&metrics->underline_thickness, &metrics->underline_position); - quantize_position (&metrics->strikethrough_thickness, &metrics->strikethrough_position); + pango_quantize_line_geometry (&metrics->underline_thickness, + &metrics->underline_position); + pango_quantize_line_geometry (&metrics->strikethrough_thickness, + &metrics->strikethrough_position); } PANGO_FC_FONT_UNLOCK_FACE (fcfont); |