+ wxColour oldPenColour = m_currentColour;
+ m_currentColour = m_textBackgroundColour;
+ bool sameColour = (oldPenColour.Ok () && m_textBackgroundColour.Ok () &&
+ (oldPenColour.Red () == m_textBackgroundColour.Red ()) &&
+ (oldPenColour.Blue () == m_textBackgroundColour.Blue ()) &&
+ (oldPenColour.Green () == m_textBackgroundColour.Green ()));
+
+ // This separation of the big && test required for gcc2.7/HP UX 9.02
+ // or pixel value can be corrupted!
+ sameColour = (sameColour &&
+ (oldPenColour.GetPixel() == m_textBackgroundColour.GetPixel()));
+
+ if (!sameColour || !GetOptimization())
+ {
+ int pixel = m_textBackgroundColour.AllocColour(m_display);
+ m_currentColour = m_textBackgroundColour;
+
+ // Set the GC to the required colour
+ if (pixel > -1)
+ {
+ XSetForeground ((Display*) m_display, (GC) m_gc, pixel);
+ if (m_window && m_window->GetBackingPixmap())
+ XSetForeground ((Display*) m_display,(GC) m_gcBacking, pixel);
+ }
+ }
+ else
+ m_textBackgroundColour = oldPenColour ;
+
+ XFillRectangle ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, XLOG2DEV (x), YLOG2DEV (y), cx, cy);
+ if (m_window && m_window->GetBackingPixmap())
+ XFillRectangle ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking,
+ XLOG2DEV_2 (x), YLOG2DEV_2 (y), cx, cy);
+ }
+
+ // Now set the text foreground and draw the text
+ if (m_textForegroundColour.Ok ())
+ {
+ wxColour oldPenColour = m_currentColour;
+ m_currentColour = m_textForegroundColour;
+ bool sameColour = (oldPenColour.Ok () && m_currentColour.Ok () &&
+ (oldPenColour.Red () == m_currentColour.Red ()) &&
+ (oldPenColour.Blue () == m_currentColour.Blue ()) &&
+ (oldPenColour.Green () == m_currentColour.Green ()) &&
+ (oldPenColour.GetPixel() == m_currentColour.GetPixel()));
+
+ if (!sameColour || !GetOptimization())
+ {
+ int pixel = -1;
+ if (!m_colour) // Mono display
+ {
+ // Unless foreground is really white, draw it in black
+ unsigned char red = m_textForegroundColour.Red ();
+ unsigned char blue = m_textForegroundColour.Blue ();
+ unsigned char green = m_textForegroundColour.Green ();
+ if (red == (unsigned char) 255 && blue == (unsigned char) 255
+ && green == (unsigned char) 255)
+ {
+ m_currentColour = *wxWHITE;
+ pixel = (int) WhitePixel ((Display*) m_display, DefaultScreen ((Display*) m_display));
+ m_currentColour.SetPixel(pixel);
+ m_textForegroundColour.SetPixel(pixel);
+ }
+ else
+ {
+ m_currentColour = *wxBLACK;
+ pixel = (int) BlackPixel ((Display*) m_display, DefaultScreen ((Display*) m_display));
+ m_currentColour.SetPixel(pixel);
+ m_textForegroundColour.SetPixel(pixel);
+ }
+ }
+ else
+ {
+ pixel = m_textForegroundColour.AllocColour((Display*) m_display);
+ m_currentColour.SetPixel(pixel);
+ }
+
+ // Set the GC to the required colour
+ if (pixel > -1)
+ {
+ XSetForeground ((Display*) m_display, (GC) m_gc, pixel);
+ if (m_window && m_window->GetBackingPixmap())
+ XSetForeground ((Display*) m_display,(GC) m_gcBacking, pixel);
+ }
+ }
+ else
+ m_textForegroundColour = oldPenColour;
+ }
+
+ // We need to add the ascent, not the whole height, since X draws at the
+ // point above the descender.
+#if 0
+ if (use16)
+ XDrawString16((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, XLOG2DEV (x), YLOG2DEV (y) + ascent,
+ (XChar2b *)(char*) (const char*) text, slen);
+ else
+#endif // 0
+ XDrawString((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, XLOG2DEV (x), YLOG2DEV (y) + ascent, text, slen);
+
+ if (m_window && m_window->GetBackingPixmap()) {
+#if 0
+ if (use16)
+ XDrawString16((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(), (GC) m_gcBacking,
+ XLOG2DEV_2 (x), YLOG2DEV_2 (y) + ascent,
+ (XChar2b *)(char*) (const char*) text, slen);
+ else
+#endif // 0
+ XDrawString((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(), (GC) m_gcBacking,
+ XLOG2DEV_2 (x), YLOG2DEV_2 (y) + ascent, (char*) (const char*) text, slen);
+ }
+
+ wxCoord w, h;
+ GetTextExtent (text, &w, &h);
+ CalcBoundingBox (x + w, y + h);
+ CalcBoundingBox (x, y);
+}
+
+void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
+{
+ if (angle == 0.0)
+ {
+ DrawText(text, x, y);
+ return;
+ }
+
+ wxCHECK_RET( Ok(), "invalid dc" );
+
+ // Since X draws from the baseline of the text, must add the text height
+ int cx = 0;
+ int cy = 0;
+ int ascent = 0;
+ int slen;
+
+ slen = strlen(text);
+
+ if (m_font.Ok())
+ {
+ // Calculate text extent.
+ WXFontStructPtr pFontStruct = m_font.GetFontStruct(m_userScaleY*m_logicalScaleY, m_display);
+ int direction, descent;
+ XCharStruct overall_return;
+#if 0
+ if (use16)
+ (void)XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *)(const char*) text, slen, &direction,
+ &ascent, &descent, &overall_return);
+ else
+#endif // 0
+ (void)XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) text, slen, &direction,
+ &ascent, &descent, &overall_return);
+
+ cx = overall_return.width;
+ cy = ascent + descent;
+ }
+
+ wxBitmap src(cx, cy);
+ 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);
+
+ // Calculate the size of the rotated bounding box.
+ double dx = cos(angle / 180.0 * M_PI);
+ double dy = sin(angle / 180.0 * M_PI);
+ double x4 = -cy * dy;
+ double y4 = cy * dx;
+ double x3 = cx * dx;
+ double y3 = cx * dy;
+ double x2 = x3 + x4;
+ double y2 = y3 + y4;
+ double x1 = x;
+ double y1 = y;
+
+ // Create image from the source bitmap after writing the text into it.
+ wxImage image(src);
+
+ int minx = roundmin(0, roundmin(x4, roundmin(x2, x3)));
+ int miny = roundmin(0, roundmin(y4, roundmin(y2, y3)));
+ int maxx = roundmax(0, roundmax(x4, roundmax(x2, x3)));
+ int maxy = roundmax(0, roundmax(y4, roundmax(y2, y3)));
+
+ // This rotates counterclockwise around the top left corner.
+ for (int rx = minx; rx < maxx; rx++)
+ {
+ for (int ry = miny; ry < maxy; ry++)
+ {
+ // transform dest coords to source coords
+ int sx = (int) (rx * dx + ry * dy + 0.5);
+ int sy = (int) (ry * dx - rx * dy + 0.5);
+ if (sx >= 0 && sx < cx && sy >= 0 && sy < cy)
+ {
+ // draw black pixels, ignore white ones (i.e. transparent b/g)
+ if (image.GetRed(sx, sy) == 0)
+ {
+ DrawPoint((wxCoord) (x1 + maxx - rx), (wxCoord) (cy + y1 - ry));
+ }
+ else
+ {
+ // Background
+ //DrawPoint(x1 + maxx - rx, cy + y1 + maxy - ry);
+ }
+ }
+ }
+ }
+
+#if 0
+ // First draw a rectangle representing the text background, if a text
+ // background is specified
+ if (m_textBackgroundColour.Ok () && (m_backgroundMode != wxTRANSPARENT))
+ {
+ wxColour oldPenColour = m_currentColour;
+ m_currentColour = m_textBackgroundColour;
+ bool sameColour = (oldPenColour.Ok () && m_textBackgroundColour.Ok () &&
+ (oldPenColour.Red () == m_textBackgroundColour.Red ()) &&
+ (oldPenColour.Blue () == m_textBackgroundColour.Blue ()) &&
+ (oldPenColour.Green () == m_textBackgroundColour.Green ()));
+
+ // This separation of the big && test required for gcc2.7/HP UX 9.02
+ // or pixel value can be corrupted!
+ sameColour = (sameColour &&
+ (oldPenColour.GetPixel() == m_textBackgroundColour.GetPixel()));
+
+ if (!sameColour || !GetOptimization())
+ {
+ int pixel = m_textBackgroundColour.AllocColour(m_display);
+ m_currentColour = m_textBackgroundColour;
+
+ // Set the GC to the required colour
+ if (pixel > -1)
+ {
+ XSetForeground ((Display*) m_display, (GC) m_gc, pixel);
+ if (m_window && m_window->GetBackingPixmap())
+ XSetForeground ((Display*) m_display,(GC) m_gcBacking, pixel);
+ }
+ }
+ else
+ m_textBackgroundColour = oldPenColour ;
+
+ XFillRectangle ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, XLOG2DEV (x), YLOG2DEV (y), cx, cy);
+ if (m_window && m_window->GetBackingPixmap())
+ XFillRectangle ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking,
+ XLOG2DEV_2 (x), YLOG2DEV_2 (y), cx, cy);
+ }
+#endif
+
+ long w, h;
+ // XXX use pixmap size
+ GetTextExtent (text, &w, &h);
+ CalcBoundingBox (x + w, y + h);
+ CalcBoundingBox (x, y);
+}
+
+bool wxWindowDC::CanGetTextExtent() const
+{
+ return TRUE;
+}
+
+void wxWindowDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height,
+ wxCoord *descent, wxCoord *externalLeading,
+ wxFont *font ) const
+{
+ wxCHECK_RET( Ok(), "invalid dc" );
+
+ wxFont* theFont = font;
+ if (!theFont)
+ theFont = (wxFont *)&m_font; // const_cast
+
+ if (!theFont->Ok())
+ {
+ // TODO: this should be an error log function
+ wxFAIL_MSG("set a valid font before calling GetTextExtent!");
+
+ if (width) *width = -1;
+ if (height) *height = -1;
+ return;
+ }
+
+ WXFontStructPtr pFontStruct = theFont->GetFontStruct(m_userScaleY*m_logicalScaleY, m_display);
+
+ int direction, ascent, descent2;
+ XCharStruct overall;
+ int slen;
+
+#if 0
+ if (use16)
+ slen = str16len(string);
+ else
+#endif // 0
+ slen = strlen(string);
+
+#if 0
+ if (use16)
+ XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction,
+ &ascent, &descent2, &overall);
+ else
+#endif // 0
+ XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) string, slen, &direction,
+ &ascent, &descent2, &overall);
+
+ if (width) *width = XDEV2LOGREL (overall.width);
+ if (height) *height = YDEV2LOGREL (ascent + descent2);
+ if (descent)
+ *descent = descent2;
+ if (externalLeading)
+ *externalLeading = 0;
+}
+
+wxCoord wxWindowDC::GetCharWidth() const
+{
+ wxCHECK_MSG( Ok(), 0, "invalid dc" );
+ wxCHECK_MSG( m_font.Ok(), 0, "invalid font" );
+
+ WXFontStructPtr pFontStruct = m_font.GetFontStruct(m_userScaleY * m_logicalScaleY, m_display);
+
+ int direction, ascent, descent;
+ XCharStruct overall;
+ XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
+ &descent, &overall);
+ return XDEV2LOGREL(overall.width);
+}
+
+wxCoord wxWindowDC::GetCharHeight() const
+{
+ wxCHECK_MSG( Ok(), 0, "invalid dc" );
+ wxCHECK_MSG( m_font.Ok(), 0, "invalid font" );
+
+ WXFontStructPtr pFontStruct = m_font.GetFontStruct(m_userScaleY*m_logicalScaleY, m_display);
+
+ int direction, ascent, descent;
+ XCharStruct overall;
+ XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
+ &descent, &overall);
+ // return XDEV2LOGREL(overall.ascent + overall.descent);
+ return XDEV2LOGREL(ascent + descent);
+}
+
+void wxWindowDC::Clear()
+{
+ wxCHECK_RET( Ok(), "invalid dc" );
+
+ int w, h;
+ if (m_window)
+ {
+ m_window->GetSize(&w, &h);
+
+ if (m_window && m_window->GetBackingPixmap())