From 909b23ec197d270fc2e664e47d35d62fbdcd601e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 23 Feb 2009 16:51:31 +0000 Subject: fix splitting on spaces svn path=/trunk/netsurf/; revision=6609 --- framebuffer/fb_font_freetype.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/framebuffer/fb_font_freetype.c b/framebuffer/fb_font_freetype.c index ea0bbb954..fbc3dc339 100644 --- a/framebuffer/fb_font_freetype.c +++ b/framebuffer/fb_font_freetype.c @@ -70,7 +70,7 @@ bool fb_font_init(void) } /* set the default render mode */ - // ft_load_type = FT_LOAD_MONOCHROME; + //ft_load_type = FT_LOAD_MONOCHROME; /* faster but less pretty */ ft_load_type = 0; return true; @@ -217,17 +217,13 @@ static bool nsfont_split(const struct css_style *style, FT_UInt glyph_index; FT_Face face = fb_get_face(style); FT_Error error; - int last_space_x = -1; - int last_space_idx = -1; + int last_space_x = 0; + int last_space_idx = 0; *actual_x = 0; while (nxtchr < length) { ucs4 = utf8_to_ucs4(string + nxtchr, length - nxtchr); - if (ucs4 == 0x20) { - last_space_x = *actual_x; - last_space_idx = nxtchr; - } glyph_index = FT_Get_Char_Index(face, ucs4); @@ -235,19 +231,26 @@ static bool nsfont_split(const struct css_style *style, if (error) continue; + if (ucs4 == 0x20) { + last_space_x = *actual_x; + last_space_idx = nxtchr; + } + *actual_x += face->glyph->advance.x >> 6; - if (*actual_x > x) - break; + if (*actual_x > x) { + /* string has exceeded available width return previous + * space + */ + *actual_x = last_space_x; + *char_offset = last_space_idx; + return true; + } nxtchr = utf8_next(string, length, nxtchr); } - if (last_space_x == -1) { - *char_offset = nxtchr; - } else { - *actual_x = last_space_x; - *char_offset = last_space_idx; - } + *char_offset = nxtchr; + return true; } -- cgit v1.2.3