Implemented DoDrawRotatedText() by way of a
rotation of a alpha blended text bitmap. It would be better if Pango could draw directly into an wxImage (as FreeType) can, but that is for later.. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30605 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
6408deedee
commit
f1c72f0ca0
@ -1635,9 +1635,10 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
||||
wxMemoryDC dc;
|
||||
dc.SelectObject(src);
|
||||
dc.SetFont(GetFont());
|
||||
dc.SetBackground(*wxWHITE_BRUSH);
|
||||
dc.SetBackground(*wxBLACK_BRUSH);
|
||||
dc.SetBrush(*wxBLACK_BRUSH);
|
||||
dc.Clear();
|
||||
dc.SetTextForeground( *wxWHITE );
|
||||
dc.DrawText(text, 0, 0);
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
|
||||
@ -1661,47 +1662,17 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
||||
minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5),
|
||||
minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
|
||||
|
||||
// prepare to blit-with-rotate the bitmap to the DC
|
||||
|
||||
wxImage image = src.ConvertToImage();
|
||||
|
||||
GdkColor *colText = m_textForegroundColour.GetColor(),
|
||||
*colBack = m_textBackgroundColour.GetColor();
|
||||
image.ConvertColourToAlpha( m_textForegroundColour.Red(),
|
||||
m_textForegroundColour.Green(),
|
||||
m_textForegroundColour.Blue() );
|
||||
image = image.Rotate( rad, wxPoint(0,0) );
|
||||
|
||||
bool textColSet = TRUE;
|
||||
src = image;
|
||||
DoDrawBitmap( src, x /*- (int)(sin(rad)*h)*/ , y-image.GetHeight()+h, true );
|
||||
|
||||
unsigned char *data = image.GetData();
|
||||
|
||||
// paint pixel by pixel
|
||||
for ( wxCoord srcX = 0; srcX < w; srcX++ )
|
||||
{
|
||||
for ( wxCoord srcY = 0; srcY < h; srcY++ )
|
||||
{
|
||||
// transform source coords to dest coords
|
||||
double r = sqrt((double)srcX*srcX + srcY*srcY);
|
||||
double angleOrig = atan2((double)srcY, (double)srcX) - rad;
|
||||
wxCoord dstX = (wxCoord)(r*cos(angleOrig) + 0.5),
|
||||
dstY = (wxCoord)(r*sin(angleOrig) + 0.5);
|
||||
|
||||
// non-white pixel?
|
||||
bool textPixel = data[(srcY*w + srcX)*3] != 0xff;
|
||||
if ( textPixel || (m_backgroundMode == wxSOLID) )
|
||||
{
|
||||
// change colour if needed
|
||||
if ( textPixel != textColSet )
|
||||
{
|
||||
gdk_gc_set_foreground( m_textGC, textPixel ? colText
|
||||
: colBack );
|
||||
|
||||
textColSet = textPixel;
|
||||
}
|
||||
|
||||
// don't use DrawPoint() because it uses the current pen
|
||||
// colour, and we don't need it here
|
||||
gdk_draw_point( m_window, m_textGC,
|
||||
XLOG2DEV(x) + dstX, YLOG2DEV(y) + dstY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// it would be better to draw with non underlined font and draw the line
|
||||
// manually here (it would be more straight...)
|
||||
@ -1714,9 +1685,6 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
// restore the font colour
|
||||
gdk_gc_set_foreground( m_textGC, colText );
|
||||
|
||||
// update the bounding box
|
||||
CalcBoundingBox(x + minX, y + minY);
|
||||
CalcBoundingBox(x + maxX, y + maxY);
|
||||
|
@ -1635,9 +1635,10 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
||||
wxMemoryDC dc;
|
||||
dc.SelectObject(src);
|
||||
dc.SetFont(GetFont());
|
||||
dc.SetBackground(*wxWHITE_BRUSH);
|
||||
dc.SetBackground(*wxBLACK_BRUSH);
|
||||
dc.SetBrush(*wxBLACK_BRUSH);
|
||||
dc.Clear();
|
||||
dc.SetTextForeground( *wxWHITE );
|
||||
dc.DrawText(text, 0, 0);
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
|
||||
@ -1661,47 +1662,17 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
||||
minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5),
|
||||
minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
|
||||
|
||||
// prepare to blit-with-rotate the bitmap to the DC
|
||||
|
||||
wxImage image = src.ConvertToImage();
|
||||
|
||||
GdkColor *colText = m_textForegroundColour.GetColor(),
|
||||
*colBack = m_textBackgroundColour.GetColor();
|
||||
image.ConvertColourToAlpha( m_textForegroundColour.Red(),
|
||||
m_textForegroundColour.Green(),
|
||||
m_textForegroundColour.Blue() );
|
||||
image = image.Rotate( rad, wxPoint(0,0) );
|
||||
|
||||
bool textColSet = TRUE;
|
||||
src = image;
|
||||
DoDrawBitmap( src, x /*- (int)(sin(rad)*h)*/ , y-image.GetHeight()+h, true );
|
||||
|
||||
unsigned char *data = image.GetData();
|
||||
|
||||
// paint pixel by pixel
|
||||
for ( wxCoord srcX = 0; srcX < w; srcX++ )
|
||||
{
|
||||
for ( wxCoord srcY = 0; srcY < h; srcY++ )
|
||||
{
|
||||
// transform source coords to dest coords
|
||||
double r = sqrt((double)srcX*srcX + srcY*srcY);
|
||||
double angleOrig = atan2((double)srcY, (double)srcX) - rad;
|
||||
wxCoord dstX = (wxCoord)(r*cos(angleOrig) + 0.5),
|
||||
dstY = (wxCoord)(r*sin(angleOrig) + 0.5);
|
||||
|
||||
// non-white pixel?
|
||||
bool textPixel = data[(srcY*w + srcX)*3] != 0xff;
|
||||
if ( textPixel || (m_backgroundMode == wxSOLID) )
|
||||
{
|
||||
// change colour if needed
|
||||
if ( textPixel != textColSet )
|
||||
{
|
||||
gdk_gc_set_foreground( m_textGC, textPixel ? colText
|
||||
: colBack );
|
||||
|
||||
textColSet = textPixel;
|
||||
}
|
||||
|
||||
// don't use DrawPoint() because it uses the current pen
|
||||
// colour, and we don't need it here
|
||||
gdk_draw_point( m_window, m_textGC,
|
||||
XLOG2DEV(x) + dstX, YLOG2DEV(y) + dstY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// it would be better to draw with non underlined font and draw the line
|
||||
// manually here (it would be more straight...)
|
||||
@ -1714,9 +1685,6 @@ void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y,
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
// restore the font colour
|
||||
gdk_gc_set_foreground( m_textGC, colText );
|
||||
|
||||
// update the bounding box
|
||||
CalcBoundingBox(x + minX, y + minY);
|
||||
CalcBoundingBox(x + maxX, y + maxY);
|
||||
|
Loading…
Reference in New Issue
Block a user