Factor out text measurement from wxDC and wxWindow into wxTextMeasure.
Add a new private wxTextMeasure class implementing methods for measuring text and move the often duplicated (but not always identically) code for doing the same from wxDC and wxWindow into it. Currently this class is only really implemented in wxMSW and wxGTK. Also extend the test for text measuring functions and rename it to MeasuringTextTestCase from MeasuringContextTestCase as it's not wxGC-specific any more. Closes #14705. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72699 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -81,6 +81,7 @@
|
||||
#include "wx/msw/private.h"
|
||||
#include "wx/msw/private/keyboard.h"
|
||||
#include "wx/msw/dcclient.h"
|
||||
#include "wx/private/textmeasure.h"
|
||||
|
||||
#if wxUSE_TOOLTIPS
|
||||
#include "wx/tooltip.h"
|
||||
@@ -2164,31 +2165,18 @@ void wxWindowMSW::DoGetTextExtent(const wxString& string,
|
||||
int *externalLeading,
|
||||
const wxFont *fontToUse) const
|
||||
{
|
||||
wxASSERT_MSG( !fontToUse || fontToUse->IsOk(),
|
||||
wxT("invalid font in GetTextExtent()") );
|
||||
|
||||
HFONT hfontToUse;
|
||||
if ( fontToUse )
|
||||
hfontToUse = GetHfontOf(*fontToUse);
|
||||
// ensure we work with a valid font
|
||||
wxFont font;
|
||||
if ( !fontToUse || !fontToUse->IsOk() )
|
||||
font = GetFont();
|
||||
else
|
||||
hfontToUse = GetHfontOf(GetFont());
|
||||
font = *fontToUse;
|
||||
|
||||
WindowHDC hdc(GetHwnd());
|
||||
SelectInHDC selectFont(hdc, hfontToUse);
|
||||
wxCHECK_RET( font.IsOk(), wxT("invalid font in GetTextExtent()") );
|
||||
|
||||
SIZE sizeRect;
|
||||
TEXTMETRIC tm;
|
||||
::GetTextExtentPoint32(hdc, string.t_str(), string.length(), &sizeRect);
|
||||
GetTextMetrics(hdc, &tm);
|
||||
|
||||
if ( x )
|
||||
*x = sizeRect.cx;
|
||||
if ( y )
|
||||
*y = sizeRect.cy;
|
||||
if ( descent )
|
||||
*descent = tm.tmDescent;
|
||||
if ( externalLeading )
|
||||
*externalLeading = tm.tmExternalLeading;
|
||||
const wxWindow* win = static_cast<const wxWindow*>(this);
|
||||
wxTextMeasure txm(win, &font);
|
||||
txm.GetTextExtent(string, x, y, descent, externalLeading);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user