From 3bf30d14fd20bb82fc6459c12379355e378bf12e Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 16 Mar 2016 21:42:37 +0100 Subject: [PATCH] Implemented GetPartialTextExtents for Cairo context (wxMSW). This implementation should work fine not only for wxMSW port. --- src/generic/graphicc.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 8618313770..b380054c51 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -2330,7 +2330,25 @@ void wxCairoContext::GetPartialTextExtents(const wxString& text, wxArrayDouble& while (i++ < len) widths.Add(PANGO_PIXELS(w)); #else - // TODO + const wxCharBuffer data = text.utf8_str(); + for (size_t i = 0; i < data.length(); i++) + { + cairo_text_extents_t te; + char ch[2]; + + 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); + } #endif }