From e7a991687844342152ffc0c57174b68ecb1b306f Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 17 Mar 2016 21:06:25 +0100 Subject: [PATCH] Fixed calculating widths in wxCairoContext::GetPartialTextExtents (wxMSW). Widths from the beginning of text to the corresponding character should be calculated instead of widths of individual characters. --- src/generic/graphicc.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index ac67883705..b486d4f75f 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -2333,24 +2333,14 @@ void wxCairoContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& while (i++ < len) widths.Add(PANGO_PIXELS(w)); #else - const wxCharBuffer data = text.utf8_str(); - for (size_t i = 0; i < data.length(); i++) + for (size_t i = 0; i < text.Length(); i++) { + const wxCharBuffer data = text.SubString(0, i).utf8_str(); + cairo_text_extents_t te; - char ch[2]; + cairo_text_extents(m_context, (const char*)data, &te); - ch[0] = data[i]; - ch[1] = '\0'; - cairo_text_extents(m_context, ch, &te); - - double w; - // Last character is interpreted in a different way. - if( i == data.length()-1 ) - w = te.width; - else - w = te.x_advance; - - widths.push_back(w); + widths.push_back(te.width); } #endif }