diff options
author | Tor Lillqvist <tml@novell.com> | 2006-03-31 00:21:30 +0000 |
---|---|---|
committer | Tor Lillqvist <tml@src.gnome.org> | 2006-03-31 00:21:30 +0000 |
commit | a2d9f1a92b48b9a878f8bd2f9be5fd8f3c7b4c82 (patch) | |
tree | c668a9b5cb1627d209f23880ab22f5bbe390173a /pango/pango-utils.c | |
parent | c4a19d3bf7a470605e86158f9c45fc3e630cd060 (diff) | |
download | pango-a2d9f1a92b48b9a878f8bd2f9be5fd8f3c7b4c82.tar.gz |
Fix blurred underlines on Win32 (#332656):
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.
Diffstat (limited to 'pango/pango-utils.c')
-rw-r--r-- | pango/pango-utils.c | 34 |
1 files changed, 34 insertions, 0 deletions
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; +} |