From d78777276cd0f8dba502f7c108dbcfb038783eb6 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 10 Feb 2013 23:24:04 +0000 Subject: Bring nsfont_split up to core expectations. Slightly bodged. --- amiga/font.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'amiga/font.c') diff --git a/amiga/font.c b/amiga/font.c index 33f71a926..ef89e5f26 100644 --- a/amiga/font.c +++ b/amiga/font.c @@ -131,13 +131,10 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { - struct TextExtent extent; - struct TextFont *tfont; uint16 *utf16 = NULL, *outf16 = NULL; uint16 utf16next = 0; FIXED kern = 0; struct OutlineFont *ofont, *ufont = NULL; - struct GlyphMap *glyph; uint32 tx=0,i=0; size_t len, utf8len = 0; uint8 *utf8; @@ -222,33 +219,38 @@ bool nsfont_position_in_string(const plot_font_style_t *fstyle, * \param string UTF-8 string to measure * \param length length of string * \param x width available - * \param char_offset updated to offset in string of actual_x, [0..length] + * \param char_offset updated to offset in string of actual_x, [1..length] * \param actual_x updated to x coordinate of character closest to x * \return true on success, false on error and error reported * - * On exit, [char_offset == 0 || - * string[char_offset] == ' ' || - * char_offset == length] + * On exit, char_offset indicates first character after split point. + * + * Note: char_offset of 0 should never be returned. + * + * Returns: + * char_offset giving split point closest to x, where actual_x <= x + * else + * char_offset giving split point closest to x, where actual_x > x + * + * Returning char_offset == length means no split possible */ bool nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x) { - struct TextExtent extent; ULONG co; char *ostr = (char *)string; - struct TextFont *tfont; uint16 *utf16 = NULL,*outf16 = NULL; uint16 utf16next = 0; FIXED kern = 0; int utf16charlen = 0; struct OutlineFont *ofont, *ufont = NULL; - struct GlyphMap *glyph; uint32 tx=0,i=0; size_t len; int utf8len, utf8clen = 0; int32 tempx = 0; + size_t coffset = 0; ULONG emwidth = (ULONG)NSA_FONT_EMWIDTH(fstyle->size); len = utf8_bounded_length(string, length); @@ -270,16 +272,18 @@ bool nsfont_split(const plot_font_style_t *fstyle, utf16next = utf16[utf16charlen]; - if(x < tx) - { - i = length+1; - } - else - { - if(string[utf8clen] == ' ') //*utf16 == 0x0020) - { + if(x < tx) { + /* If we've run out of space, and no space has been found, tell the core to split here. + * This shouldn't work, but it does. Without it we randomly get non-split lines. */ + if(coffset == 0) { *actual_x = tx; - *char_offset = utf8clen; + coffset = utf8clen; + } + break; + } else { + if(*utf16 == 0x0020) { + *actual_x = tx; + coffset = utf8clen; } } @@ -311,6 +315,12 @@ bool nsfont_split(const plot_font_style_t *fstyle, free(outf16); + if(coffset == 0) { + *char_offset = length; + } else { + *char_offset = coffset; + } + return true; } -- cgit v1.2.3