+void wxPostScriptDC::DoDrawRotatedText( const wxString& text, wxCoord x, wxCoord y, double angle )
+{
+ if (angle == 0.0)
+ {
+ DoDrawText(text, x, y);
+ return;
+ }
+
+ wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
+
+ SetFont( m_font );
+
+ if (m_textForegroundColour.Ok())
+ {
+ unsigned char red = m_textForegroundColour.Red();
+ unsigned char blue = m_textForegroundColour.Blue();
+ unsigned char green = m_textForegroundColour.Green();
+
+ if (!m_colour)
+ {
+ // Anything not white is black
+ if (! (red == (unsigned char) 255 &&
+ blue == (unsigned char) 255 &&
+ green == (unsigned char) 255))
+ {
+ red = (unsigned char) 0;
+ green = (unsigned char) 0;
+ blue = (unsigned char) 0;
+ }
+ }
+
+ // maybe setgray here ?
+ if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))
+ {
+ double redPS = (double)(red) / 255.0;
+ double bluePS = (double)(blue) / 255.0;
+ double greenPS = (double)(green) / 255.0;
+
+ char buffer[100];
+ sprintf( buffer,
+ "%.8f %.8f %.8f setrgbcolor\n",
+ redPS, greenPS, bluePS );
+ for (int i = 0; i < 100; i++)
+ if (buffer[i] == ',') buffer[i] = '.';
+ fprintf( m_pstream, buffer );
+
+ m_currentRed = red;
+ m_currentBlue = blue;
+ m_currentGreen = green;
+ }
+ }
+
+ int size = m_font.GetPointSize();
+
+ long by = y + (long)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
+
+ // FIXME only correct for 90 degrees
+ fprintf(m_pstream, "%d %d moveto\n",
+ XLOG2DEV((wxCoord)(x + size)), YLOG2DEV((wxCoord)by) );
+
+ char buffer[100];
+ sprintf(buffer, "%.8f rotate\n", angle);
+ size_t i;
+ for (i = 0; i < 100; i++)
+ if (buffer[i] == ',') buffer[i] = '.';
+ fprintf(m_pstream, buffer);
+
+ fprintf( m_pstream, "(" );
+ const wxWX2MBbuf textbuf = text.mb_str();
+ size_t len = strlen(textbuf);
+ for (i = 0; i < len; i++)
+ {
+ int c = (unsigned char) textbuf[i];
+ if (c == ')' || c == '(' || c == '\\')
+ {
+ /* Cope with special characters */
+ fprintf( m_pstream, "\\" );
+ fputc(c, m_pstream);
+ }
+ else if ( c >= 128 )
+ {
+ /* Cope with character codes > 127 */
+ fprintf(m_pstream, "\\%o", c);
+ }
+ else
+ {
+ fputc(c, m_pstream);
+ }
+ }
+
+ fprintf( m_pstream, ") show\n" );
+
+ sprintf( buffer, "%.8f rotate\n", -angle );
+ for (i = 0; i < 100; i++)
+ if (buffer[i] == ',') buffer[i] = '.';
+ fprintf( m_pstream, buffer );
+
+ if (m_font.GetUnderlined())
+ {
+ wxCoord uy = (wxCoord)(y + size - m_underlinePosition);
+ wxCoord w, h;
+ char buffer[100];
+ GetTextExtent(text, &w, &h);
+
+ sprintf( buffer,
+ "gsave\n"
+ "%d %d moveto\n"
+ "%f setlinewidth\n"
+ "%d %d lineto\n"
+ "stroke\n"
+ "grestore\n",
+ XLOG2DEV(x), YLOG2DEV(uy),
+ m_underlineThickness,
+ XLOG2DEV(x + w), YLOG2DEV(uy) );
+ for (i = 0; i < 100; i++)
+ if (buffer[i] == ',') buffer[i] = '.';
+ fprintf( m_pstream, buffer );
+ }
+
+ CalcBoundingBox( x, y );
+ CalcBoundingBox( x + size * text.Length() * 2/3 , y );
+}