From 748c727a414e12443622accd3fe5bffd5846e374 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 28 Oct 2007 20:24:55 +0100 Subject: fscalc: Support for UTF-8 strings. fscalc: Fixed the get_line_height() function. --- fscalc.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fscalc.cpp b/fscalc.cpp index 6842a65..83ec5da 100644 --- a/fscalc.cpp +++ b/fscalc.cpp @@ -87,7 +87,18 @@ unsigned int Font::get_text_width(std::string s) { bool kerning = FT_HAS_KERNING(face); double width = 0; for(std::string::iterator c = s.begin(); c < s.end(); c++) { - int i = FT_Get_Char_Index(face, *c); + FT_UInt character; + unsigned char first; + first = character = *c; + if(first & 0x80) { + character += *(++c) << 8; + if((first & 0xf0) == 0xe0) { + character += *(++c) << 16; + if((first & 0xf8) == 0xf0) + character += *(++c) << 24; + } + } + int i = FT_Get_Char_Index(face, character); if(kerning && prev && i) width += get_kerning(prev, i); if(FT_Load_Char(face, *c, 0)) @@ -98,5 +109,5 @@ unsigned int Font::get_text_width(std::string s) { } unsigned int Font::get_line_height() { - return face->bbox.yMax - face->bbox.yMin; + return (face->size->metrics.ascender - face->size->metrics.descender) / 64; } -- cgit v1.2.3