X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/93da796db4fdeeba8b2370cbc864b74b769126d5..20c81bed846981e90769826b94a91eebb91158f1:/src/gtk/dcclient.cpp diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 77ed883565..c79e4175d6 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -391,6 +391,8 @@ void wxWindowDC::SetUpDC() gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); gdk_gc_set_fill( m_textGC, GDK_SOLID ); + + gdk_gc_set_colormap( m_textGC, m_cmap ); /* m_penGC */ m_pen.GetColour().CalcPixel( m_cmap ); @@ -1769,10 +1771,54 @@ void wxWindowDC::DoGetTextExtent(const wxString &string, } // Reset old font description - if (theFont) + if (theFont->IsOk()) pango_layout_set_font_description( m_layout, m_fontdesc ); } + +bool wxWindowDC::DoGetPartialTextExtents(const wxString& text, + wxArrayInt& widths) const +{ + const size_t len = text.length(); + widths.Empty(); + widths.Add(0, len); + + if (text.empty()) + return true; + + // Set layout's text + const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(text, m_font); + if ( !dataUTF8 ) + { + // hardly ideal, but what else can we do if conversion failed? + wxLogLastError(wxT("DoGetPartialTextExtents")); + return false; + } + + pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); + + // Calculate the position of each character based on the widths of + // the previous characters + + // Code borrowed from Scintilla's PlatGTK + PangoLayoutIter *iter = pango_layout_get_iter(m_layout); + PangoRectangle pos; + pango_layout_iter_get_cluster_extents(iter, NULL, &pos); + size_t i = 0; + while (pango_layout_iter_next_cluster(iter)) + { + pango_layout_iter_get_cluster_extents(iter, NULL, &pos); + int position = PANGO_PIXELS(pos.x); + widths[i++] = position; + } + while (i < len) + widths[i++] = PANGO_PIXELS(pos.x + pos.width); + pango_layout_iter_free(iter); + + return true; +} + + wxCoord wxWindowDC::GetCharWidth() const { pango_layout_set_text( m_layout, "H", 1 );