made width computation in GetTextExtent() more precise, especially for italics fonts (based on the code from Wlodek Szafran)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38743 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
968f291be6
commit
481203cb23
@ -175,6 +175,7 @@ wxMSW:
|
||||
- Fixed wxChoice/wxComboBox slow appending and infinite recursion
|
||||
if its size is set within a paint handler (for example when embedded in a
|
||||
wxHtmlWindow). [Now reverted due to problems in W2K and below.]
|
||||
- wxDC::GetTextExtent() width calculation is more precise for italics fonts now
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@ -1753,10 +1753,39 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
|
||||
}
|
||||
|
||||
SIZE sizeRect;
|
||||
TEXTMETRIC tm;
|
||||
const size_t len = string.length();
|
||||
if ( !::GetTextExtentPoint32(GetHdc(), string, len, &sizeRect) )
|
||||
{
|
||||
wxLogLastError(_T("GetTextExtentPoint32()"));
|
||||
}
|
||||
|
||||
::GetTextExtentPoint32(GetHdc(), string, string.length(), &sizeRect);
|
||||
GetTextMetrics(GetHdc(), &tm);
|
||||
// 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
|
||||
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?
|
||||
}
|
||||
|
||||
TEXTMETRIC tm;
|
||||
::GetTextMetrics(GetHdc(), &tm);
|
||||
|
||||
if (x)
|
||||
*x = sizeRect.cx;
|
||||
|
Loading…
Reference in New Issue
Block a user