Verified and applied [ 1042133 ] GTK2.0: DrawRotatedText dumb implementation
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29703 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1589,6 +1589,11 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
CalcBoundingBox (x, y);
|
CalcBoundingBox (x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: There is an example of rotating text with GTK2 that would probably be
|
||||||
|
// a better approach here:
|
||||||
|
// http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
|
||||||
|
|
||||||
void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
|
void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
|
||||||
{
|
{
|
||||||
if (angle == 0.0)
|
if (angle == 0.0)
|
||||||
@@ -1601,18 +1606,22 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
|||||||
|
|
||||||
if (!m_window) return;
|
if (!m_window) return;
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
wxCoord w;
|
||||||
|
wxCoord h;
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
// implement later without GdkFont for GTK 2.0
|
// implement later without GdkFont for GTK 2.0
|
||||||
return;
|
GetTextExtent(text, &w, &h, NULL,NULL, &m_font);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
GdkFont *font = m_font.GetInternalFont( m_scaleY );
|
GdkFont *font = m_font.GetInternalFont( m_scaleY );
|
||||||
|
|
||||||
wxCHECK_RET( font, wxT("invalid font") );
|
wxCHECK_RET( font, wxT("invalid font") );
|
||||||
|
|
||||||
// the size of the text
|
// the size of the text
|
||||||
wxCoord w = gdk_string_width( font, text.mbc_str() );
|
w = gdk_string_width( font, text.mbc_str() );
|
||||||
wxCoord h = font->ascent + font->descent;
|
h = font->ascent + font->descent;
|
||||||
|
#endif
|
||||||
// draw the string normally
|
// draw the string normally
|
||||||
wxBitmap src(w, h);
|
wxBitmap src(w, h);
|
||||||
wxMemoryDC dc;
|
wxMemoryDC dc;
|
||||||
@@ -1665,8 +1674,8 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
|||||||
wxCoord dstX = (wxCoord)(r*cos(angleOrig) + 0.5),
|
wxCoord dstX = (wxCoord)(r*cos(angleOrig) + 0.5),
|
||||||
dstY = (wxCoord)(r*sin(angleOrig) + 0.5);
|
dstY = (wxCoord)(r*sin(angleOrig) + 0.5);
|
||||||
|
|
||||||
// black pixel?
|
// non-white pixel?
|
||||||
bool textPixel = data[(srcY*w + srcX)*3] == 0;
|
bool textPixel = data[(srcY*w + srcX)*3] != 0xff;
|
||||||
if ( textPixel || (m_backgroundMode == wxSOLID) )
|
if ( textPixel || (m_backgroundMode == wxSOLID) )
|
||||||
{
|
{
|
||||||
// change colour if needed
|
// change colour if needed
|
||||||
@@ -1703,7 +1712,6 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
|||||||
// update the bounding box
|
// update the bounding box
|
||||||
CalcBoundingBox(x + minX, y + minY);
|
CalcBoundingBox(x + minX, y + minY);
|
||||||
CalcBoundingBox(x + maxX, y + maxY);
|
CalcBoundingBox(x + maxX, y + maxY);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindowDC::DoGetTextExtent(const wxString &string,
|
void wxWindowDC::DoGetTextExtent(const wxString &string,
|
||||||
|
@@ -1589,6 +1589,11 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
|
|||||||
CalcBoundingBox (x, y);
|
CalcBoundingBox (x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: There is an example of rotating text with GTK2 that would probably be
|
||||||
|
// a better approach here:
|
||||||
|
// http://www.daa.com.au/pipermail/pygtk/2003-April/005052.html
|
||||||
|
|
||||||
void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
|
void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
|
||||||
{
|
{
|
||||||
if (angle == 0.0)
|
if (angle == 0.0)
|
||||||
@@ -1601,18 +1606,22 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
|||||||
|
|
||||||
if (!m_window) return;
|
if (!m_window) return;
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
wxCoord w;
|
||||||
|
wxCoord h;
|
||||||
|
|
||||||
|
#ifdef __WXGTK20__
|
||||||
// implement later without GdkFont for GTK 2.0
|
// implement later without GdkFont for GTK 2.0
|
||||||
return;
|
GetTextExtent(text, &w, &h, NULL,NULL, &m_font);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
GdkFont *font = m_font.GetInternalFont( m_scaleY );
|
GdkFont *font = m_font.GetInternalFont( m_scaleY );
|
||||||
|
|
||||||
wxCHECK_RET( font, wxT("invalid font") );
|
wxCHECK_RET( font, wxT("invalid font") );
|
||||||
|
|
||||||
// the size of the text
|
// the size of the text
|
||||||
wxCoord w = gdk_string_width( font, text.mbc_str() );
|
w = gdk_string_width( font, text.mbc_str() );
|
||||||
wxCoord h = font->ascent + font->descent;
|
h = font->ascent + font->descent;
|
||||||
|
#endif
|
||||||
// draw the string normally
|
// draw the string normally
|
||||||
wxBitmap src(w, h);
|
wxBitmap src(w, h);
|
||||||
wxMemoryDC dc;
|
wxMemoryDC dc;
|
||||||
@@ -1665,8 +1674,8 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
|||||||
wxCoord dstX = (wxCoord)(r*cos(angleOrig) + 0.5),
|
wxCoord dstX = (wxCoord)(r*cos(angleOrig) + 0.5),
|
||||||
dstY = (wxCoord)(r*sin(angleOrig) + 0.5);
|
dstY = (wxCoord)(r*sin(angleOrig) + 0.5);
|
||||||
|
|
||||||
// black pixel?
|
// non-white pixel?
|
||||||
bool textPixel = data[(srcY*w + srcX)*3] == 0;
|
bool textPixel = data[(srcY*w + srcX)*3] != 0xff;
|
||||||
if ( textPixel || (m_backgroundMode == wxSOLID) )
|
if ( textPixel || (m_backgroundMode == wxSOLID) )
|
||||||
{
|
{
|
||||||
// change colour if needed
|
// change colour if needed
|
||||||
@@ -1703,7 +1712,6 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
|||||||
// update the bounding box
|
// update the bounding box
|
||||||
CalcBoundingBox(x + minX, y + minY);
|
CalcBoundingBox(x + minX, y + minY);
|
||||||
CalcBoundingBox(x + maxX, y + maxY);
|
CalcBoundingBox(x + maxX, y + maxY);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindowDC::DoGetTextExtent(const wxString &string,
|
void wxWindowDC::DoGetTextExtent(const wxString &string,
|
||||||
|
Reference in New Issue
Block a user