- HFONT hfontOld;
- if ( font )
- {
- wxASSERT_MSG( font->IsOk(), wxT("invalid font in wxMSWDCImpl::GetTextExtent") );
-
- hfontOld = (HFONT)::SelectObject(GetHdc(), GetHfontOf(*font));
- }
- else // don't change the font
- {
- hfontOld = 0;
- }
-
- SIZE sizeRect;
- const size_t len = string.length();
- if ( !::GetTextExtentPoint32(GetHdc(), string.wx_str(), len, &sizeRect) )
- {
- wxLogLastError(wxT("GetTextExtentPoint32()"));
- }
-
-#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
- // the result computed by GetTextExtentPoint32() may be too small as it
- // accounts for under/overhang of the first/last character while we want
- // just the bounding rect for this string so adjust the width as needed
- // (using API not available in 2002 SDKs of WinCE)
- if ( len > 0 )
- {
- ABC width;
- const wxChar chFirst = *string.begin();
- if ( ::GetCharABCWidths(GetHdc(), chFirst, chFirst, &width) )
- {
- if ( width.abcA < 0 )
- sizeRect.cx -= width.abcA;
-
- if ( len > 1 )
- {
- const wxChar chLast = *string.rbegin();
- ::GetCharABCWidths(GetHdc(), chLast, chLast, &width);
- }
- //else: we already have the width of the last character
-
- if ( width.abcC < 0 )
- sizeRect.cx -= width.abcC;
- }
- //else: GetCharABCWidths() failed, not a TrueType font?
- }
-#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
-
- if (x)
- *x = sizeRect.cx;
- if (y)
- *y = sizeRect.cy;