+ wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") );
+
+ if (angle == 0.0)
+ {
+ DrawText(text, x, y);
+ return;
+ }
+
+ MacInstallFont();
+
+ // the size of the text
+ wxCoord w, h;
+ GetTextExtent(text, &w, &h);
+
+ // draw the string normally
+ wxBitmap src(w, h);
+ wxMemoryDC dc;
+ dc.SelectObject(src);
+ dc.SetFont(GetFont());
+ dc.SetBackground(*wxWHITE_BRUSH);
+ dc.SetBrush(*wxBLACK_BRUSH);
+ dc.Clear();
+ dc.DrawText(text, 0, 0);
+ dc.SetFont(wxNullFont);
+ dc.SelectObject(wxNullBitmap);
+
+ wxMacPortSetter helper(this) ;
+
+ // Calculate the size of the rotated bounding box.
+ double rad = DegToRad(angle);
+ double dx = cos(rad);
+ double dy = sin(rad);
+
+ // the rectngle vertices are counted clockwise with the first one being at
+ // (0, 0) (or, rather, at (x, y))
+ double x2 = w * dx;
+ double y2 = -w * dy; // y axis points to the bottom, hence minus
+ double x4 = h * dy;
+ double y4 = h * dx;
+ double x3 = x4 + x2;
+ double y3 = y4 + y2;
+
+ // calc max and min
+ wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5);
+ wxCoord maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5);
+ wxCoord minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5);
+ wxCoord minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
+
+ // prepare to blit-with-rotate the bitmap to the DC
+ wxImage image(src);
+
+ RGBColor colText = m_textForegroundColour.GetPixel();
+ RGBColor colBack = m_textBackgroundColour.GetPixel();
+
+ unsigned char *data = image.GetData();
+
+ wxCoord dstX, dstY;
+ double r, angleOrig;
+ bool textPixel;
+
+ // paint pixel by pixel
+ for ( wxCoord srcX = 0; srcX < w; srcX++ )
+ {
+ for ( wxCoord srcY = 0; srcY < h; srcY++ )
+ {
+ // transform source coords to dest coords
+ r = sqrt( (double)(srcX * srcX + srcY * srcY) );
+ angleOrig = atan2((double)srcY, (double)srcX) - rad;
+ dstX = (wxCoord)(r * cos(angleOrig) + 0.5);
+ dstY = (wxCoord)(r * sin(angleOrig) + 0.5);
+
+ // black pixel?
+ textPixel = data[(srcY*w + srcX)*3] == 0;
+ if ( textPixel || (m_backgroundMode == wxSOLID) )
+ {
+ SetCPixel(XLOG2DEVMAC(x + dstX), YLOG2DEVMAC(y + dstY),
+ textPixel ? &colText : &colBack);
+ }
+ }
+ }
+
+ // it would be better to draw with non underlined font and draw the line
+ // manually here (it would be more straight...)
+#if 0
+ if ( m_font.GetUnderlined() )
+ {
+ ::MoveTo(XLOG2DEVMAC(x + x4), YLOG2DEVMAC(y + y4 + font->descent));
+ ::LineTo(XLOG2DEVMAC(x + x3), YLOG2DEVMAC(y + y3 + font->descent));
+ }
+#endif // 0
+
+ // update the bounding box
+ CalcBoundingBox(x + minX, y + minY);
+ CalcBoundingBox(x + maxX, y + maxY);