Use automatic resource management in wxMSW wxDC::DrawRotatedText().
No real changes, just simplify the code by using RAII classes. Also avoid unnecessary indentation by returning after checking for the special cases. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75751 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
130
src/msw/dc.cpp
130
src/msw/dc.cpp
@@ -1483,78 +1483,72 @@ void wxMSWDCImpl::DoDrawRotatedText(const wxString& text,
|
|||||||
DoDrawText(text, x, y);
|
DoDrawText(text, x, y);
|
||||||
|
|
||||||
// Bounding box already updated by DoDrawText(), no need to do it again.
|
// Bounding box already updated by DoDrawText(), no need to do it again.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __WXMICROWIN__
|
#ifndef __WXMICROWIN__
|
||||||
else
|
// NB: don't take DEFAULT_GUI_FONT (a.k.a. wxSYS_DEFAULT_GUI_FONT)
|
||||||
|
// because it's not TrueType and so can't have non zero
|
||||||
|
// orientation/escapement under Win9x
|
||||||
|
wxFont font = m_font.IsOk() ? m_font : *wxSWISS_FONT;
|
||||||
|
LOGFONT lf;
|
||||||
|
if ( ::GetObject(GetHfontOf(font), sizeof(lf), &lf) == 0 )
|
||||||
{
|
{
|
||||||
// NB: don't take DEFAULT_GUI_FONT (a.k.a. wxSYS_DEFAULT_GUI_FONT)
|
wxLogLastError(wxT("GetObject(hfont)"));
|
||||||
// because it's not TrueType and so can't have non zero
|
|
||||||
// orientation/escapement under Win9x
|
|
||||||
wxFont font = m_font.IsOk() ? m_font : *wxSWISS_FONT;
|
|
||||||
HFONT hfont = (HFONT)font.GetResourceHandle();
|
|
||||||
LOGFONT lf;
|
|
||||||
if ( ::GetObject(hfont, sizeof(lf), &lf) == 0 )
|
|
||||||
{
|
|
||||||
wxLogLastError(wxT("GetObject(hfont)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// GDI wants the angle in tenth of degree
|
|
||||||
long angle10 = (long)(angle * 10);
|
|
||||||
lf.lfEscapement = angle10;
|
|
||||||
lf.lfOrientation = angle10;
|
|
||||||
|
|
||||||
hfont = ::CreateFontIndirect(&lf);
|
|
||||||
if ( !hfont )
|
|
||||||
{
|
|
||||||
wxLogLastError(wxT("CreateFont"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HFONT hfontOld = (HFONT)::SelectObject(GetHdc(), hfont);
|
|
||||||
|
|
||||||
// Get extent of whole text.
|
|
||||||
wxCoord w, h, heightLine;
|
|
||||||
GetOwner()->GetMultiLineTextExtent(text, &w, &h, &heightLine);
|
|
||||||
|
|
||||||
// Prepare for drawing the text
|
|
||||||
wxTextColoursChanger textCol(GetHdc(), *this);
|
|
||||||
wxBkModeChanger bkMode(GetHdc(), m_backgroundMode);
|
|
||||||
|
|
||||||
// Compute the shift for the origin of the next line.
|
|
||||||
const double rad = DegToRad(angle);
|
|
||||||
const double dx = heightLine * sin(rad);
|
|
||||||
const double dy = heightLine * cos(rad);
|
|
||||||
|
|
||||||
// Draw all text line by line
|
|
||||||
const wxArrayString lines = wxSplit(text, '\n', '\0');
|
|
||||||
for ( size_t lineNum = 0; lineNum < lines.size(); lineNum++ )
|
|
||||||
{
|
|
||||||
// Calculate origin for each line to avoid accumulation of
|
|
||||||
// rounding errors.
|
|
||||||
DrawAnyText(lines[lineNum],
|
|
||||||
x + wxRound(lineNum*dx),
|
|
||||||
y + wxRound(lineNum*dy));
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)::SelectObject(GetHdc(), hfontOld);
|
|
||||||
(void)::DeleteObject(hfont);
|
|
||||||
|
|
||||||
// call the bounding box by adding all four vertices of the rectangle
|
|
||||||
// containing the text to it (simpler and probably not slower than
|
|
||||||
// determining which of them is really topmost/leftmost/...)
|
|
||||||
|
|
||||||
// "upper left" and "upper right"
|
|
||||||
CalcBoundingBox(x, y);
|
|
||||||
CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(w*sin(rad)));
|
|
||||||
|
|
||||||
// "bottom left" and "bottom right"
|
|
||||||
x += (wxCoord)(h*sin(rad));
|
|
||||||
y += (wxCoord)(h*cos(rad));
|
|
||||||
CalcBoundingBox(x, y);
|
|
||||||
CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(w*sin(rad)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GDI wants the angle in tenth of degree
|
||||||
|
long angle10 = (long)(angle * 10);
|
||||||
|
lf.lfEscapement = angle10;
|
||||||
|
lf.lfOrientation = angle10;
|
||||||
|
|
||||||
|
AutoHFONT hfont(lf);
|
||||||
|
if ( !hfont )
|
||||||
|
{
|
||||||
|
wxLogLastError(wxT("CreateFont"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectInHDC selRotatedFont(GetHdc(), hfont);
|
||||||
|
|
||||||
|
// Get extent of whole text.
|
||||||
|
wxCoord w, h, heightLine;
|
||||||
|
GetOwner()->GetMultiLineTextExtent(text, &w, &h, &heightLine);
|
||||||
|
|
||||||
|
// Prepare for drawing the text
|
||||||
|
wxTextColoursChanger textCol(GetHdc(), *this);
|
||||||
|
wxBkModeChanger bkMode(GetHdc(), m_backgroundMode);
|
||||||
|
|
||||||
|
// Compute the shift for the origin of the next line.
|
||||||
|
const double rad = DegToRad(angle);
|
||||||
|
const double dx = heightLine * sin(rad);
|
||||||
|
const double dy = heightLine * cos(rad);
|
||||||
|
|
||||||
|
// Draw all text line by line
|
||||||
|
const wxArrayString lines = wxSplit(text, '\n', '\0');
|
||||||
|
for ( size_t lineNum = 0; lineNum < lines.size(); lineNum++ )
|
||||||
|
{
|
||||||
|
// Calculate origin for each line to avoid accumulation of
|
||||||
|
// rounding errors.
|
||||||
|
DrawAnyText(lines[lineNum],
|
||||||
|
x + wxRound(lineNum*dx),
|
||||||
|
y + wxRound(lineNum*dy));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// call the bounding box by adding all four vertices of the rectangle
|
||||||
|
// containing the text to it (simpler and probably not slower than
|
||||||
|
// determining which of them is really topmost/leftmost/...)
|
||||||
|
|
||||||
|
// "upper left" and "upper right"
|
||||||
|
CalcBoundingBox(x, y);
|
||||||
|
CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(w*sin(rad)));
|
||||||
|
|
||||||
|
// "bottom left" and "bottom right"
|
||||||
|
x += (wxCoord)(h*sin(rad));
|
||||||
|
y += (wxCoord)(h*cos(rad));
|
||||||
|
CalcBoundingBox(x, y);
|
||||||
|
CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(w*sin(rad)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user