summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2012-08-01 23:58:54 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2012-08-01 23:58:54 +0100
commitc0bfe7dfdff84f5072975d38263b6fa8d6594f9a (patch)
tree87c21be14cd39b3bbefe56159a70fdcfd20ada73
parenta92f2aa0a6405682084fe040960e710fd3c3179d (diff)
downloadnetsurf-c0bfe7dfdff84f5072975d38263b6fa8d6594f9a.tar.gz
netsurf-c0bfe7dfdff84f5072975d38263b6fa8d6594f9a.tar.bz2
Fix freetype nsfont_position_in_string to return nearest, rather than next.
-rw-r--r--framebuffer/font_freetype.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/framebuffer/font_freetype.c b/framebuffer/font_freetype.c
index b3c993f40..581fd9a3d 100644
--- a/framebuffer/font_freetype.c
+++ b/framebuffer/font_freetype.c
@@ -462,6 +462,7 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
uint32_t ucs4;
size_t nxtchr = 0;
FT_Glyph glyph;
+ int prev_x = 0;
*actual_x = 0;
while (nxtchr < length) {
@@ -475,9 +476,14 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
if (*actual_x > x)
break;
+ prev_x = *actual_x;
nxtchr = utf8_next(string, length, nxtchr);
}
+ /* choose nearest of previous and last x */
+ if (abs(*actual_x - x) > abs(prev_x - x))
+ *actual_x = prev_x;
+
*char_offset = nxtchr;
return true;
}