Factor out wxTextMeasureBase::GetEmptyLineHeight()

No real changes, just refactor to extract a trivial helper function.
This commit is contained in:
Vadim Zeitlin
2020-07-15 01:16:23 +02:00
parent db556fc388
commit 2280e43fe9
2 changed files with 13 additions and 5 deletions

View File

@@ -128,6 +128,10 @@ protected:
wxCoord *descent = NULL, wxCoord *descent = NULL,
wxCoord *externalLeading = NULL); wxCoord *externalLeading = NULL);
// Get line height: used when the line is empty because CallGetTextExtent()
// would just return (0, 0) in this case.
int GetEmptyLineHeight();
// Return a valid font: if one was given to us in the ctor, use this one, // Return a valid font: if one was given to us in the ctor, use this one,
// otherwise use the current font of the associated wxDC or wxWindow. // otherwise use the current font of the associated wxDC or wxWindow.
wxFont GetFont() const; wxFont GetFont() const;

View File

@@ -100,6 +100,13 @@ void wxTextMeasureBase::GetTextExtent(const wxString& string,
CallGetTextExtent(string, width, height, descent, externalLeading); CallGetTextExtent(string, width, height, descent, externalLeading);
} }
int wxTextMeasureBase::GetEmptyLineHeight()
{
int dummy, height;
CallGetTextExtent(wxS("W"), &dummy, &height);
return height;
}
void wxTextMeasureBase::GetMultiLineTextExtent(const wxString& text, void wxTextMeasureBase::GetMultiLineTextExtent(const wxString& text,
wxCoord *width, wxCoord *width,
wxCoord *height, wxCoord *height,
@@ -136,12 +143,9 @@ void wxTextMeasureBase::GetMultiLineTextExtent(const wxString& text,
if ( !heightLineDefault ) if ( !heightLineDefault )
heightLineDefault = heightLine; heightLineDefault = heightLine;
// and if we hadn't had any previous one neither, compute it now
if ( !heightLineDefault ) if ( !heightLineDefault )
{ heightLineDefault = GetEmptyLineHeight();
// but we don't know it yet - choose something reasonable
int dummy;
CallGetTextExtent(wxS("W"), &dummy, &heightLineDefault);
}
heightTextTotal += heightLineDefault; heightTextTotal += heightLineDefault;
} }