diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index 675447f..eedf917 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -1710,9 +1710,10 @@ wxCoord wxMSWDCImpl::GetCharWidth() const return lpTextMetric.tmAveCharWidth; } -void wxMSWDCImpl::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, - wxCoord *descent, wxCoord *externalLeading, - const wxFont *font) const +void wxMSWDCImpl::DoGetTextExtent(const wxString& stringOrig, + wxCoord *x, wxCoord *y, + wxCoord *descent, wxCoord *externalLeading, + const wxFont *font) const { #ifdef __WXMICROWIN__ if (!GetHDC()) @@ -1737,6 +1738,14 @@ void wxMSWDCImpl::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y hfontOld = 0; } + // GetTextExtentPoint32() doesn't handle TABs correctly so expand them + // manually or the returned string would be too small + // + // notice that MSW allows changing the number of spaces per TAB (e.g. using + // DT_TABSTOP flag of DrawText()) but wx API does not so we can safely + // assume that TABs are always rendered as 8 spaces + wxString string(stringOrig); + string.Replace(wxT("\t"), wxT(" ")); SIZE sizeRect; const size_t len = string.length(); if ( !::GetTextExtentPoint32(GetHdc(), string.wx_str(), len, &sizeRect) )