From c53833d1e4b209819cc9cfe688539ca4c158d103 Mon Sep 17 00:00:00 2001 From: David Haywood Date: Thu, 31 Mar 2016 17:26:35 +0100 Subject: [PATCH] attempt to fix hap issue (nw) --- src/emu/rendfont.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/emu/rendfont.cpp b/src/emu/rendfont.cpp index 0c5e5d1a51e..8697e681cd2 100644 --- a/src/emu/rendfont.cpp +++ b/src/emu/rendfont.cpp @@ -416,8 +416,19 @@ float render_font::string_width(float height, float aspect, const char *string) { // loop over the string and accumulate widths int totwidth = 0; - for (const unsigned char *ptr = (const unsigned char *)string; *ptr != 0; ptr++) - totwidth += get_char(*ptr).width; + + const char *ends = string + strlen(string); + const char *s = string; + unicode_char schar; + + // loop over characters + while (*s != 0) + { + int scharcount = uchar_from_utf8(&schar, s, ends - s); + totwidth += get_char(schar).width; + s += scharcount; + } + // scale the final result based on height return float(totwidth) * m_scale * height * aspect;