+ SetLogicalFunction( old_logical_func );
+
+ return true;
+}
+
+void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
+{
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (!m_window) return;
+
+ if (text.empty()) return;
+
+#ifndef __WXGTK20__
+ GdkFont *font = m_font.GetInternalFont( m_scaleY );
+
+ wxCHECK_RET( font, wxT("invalid font") );
+#endif
+
+ x = XLOG2DEV(x);
+ y = YLOG2DEV(y);
+
+#ifdef __WXGTK20__
+ wxCHECK_RET( m_context, wxT("no Pango context") );
+ wxCHECK_RET( m_layout, wxT("no Pango layout") );
+ wxCHECK_RET( m_fontdesc, wxT("no Pango font description") );
+
+ bool underlined = m_font.Ok() && m_font.GetUnderlined();
+
+#if wxUSE_UNICODE
+ const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
+#else
+ const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
+ if ( !wdata )
+ return;
+ const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
+#endif
+ size_t datalen = strlen((const char*)data);
+ pango_layout_set_text( m_layout, (const char*) data, datalen);
+
+ if (underlined)
+ {
+ PangoAttrList *attrs = pango_attr_list_new();
+ PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
+ a->start_index = 0;
+ a->end_index = datalen;
+ pango_attr_list_insert(attrs, a);
+ pango_layout_set_attributes(m_layout, attrs);
+ pango_attr_list_unref(attrs);
+ }
+
+ int w,h;
+
+ if (fabs(m_scaleY - 1.0) > 0.00001)
+ {
+ // If there is a user or actually any scale applied to
+ // the device context, scale the font.
+
+ // scale font description
+ gint oldSize = pango_font_description_get_size( m_fontdesc );
+ double size = oldSize;
+ size = size * m_scaleY;
+ pango_font_description_set_size( m_fontdesc, (gint)size );
+
+ // actually apply scaled font
+ pango_layout_set_font_description( m_layout, m_fontdesc );
+
+ pango_layout_get_pixel_size( m_layout, &w, &h );
+ if ( m_backgroundMode == wxSOLID )
+ {
+ gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
+ gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
+ gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
+ }
+
+ // Draw layout.
+ gdk_draw_layout( m_window, m_textGC, x, y, m_layout );
+
+ // reset unscaled size
+ pango_font_description_set_size( m_fontdesc, oldSize );
+
+ // actually apply unscaled font
+ pango_layout_set_font_description( m_layout, m_fontdesc );
+ }
+ else
+ {
+ pango_layout_get_pixel_size( m_layout, &w, &h );
+ if ( m_backgroundMode == wxSOLID )
+ {
+ gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());
+ gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);
+ gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());
+ }
+ // Draw layout.
+ gdk_draw_layout( m_window, m_textGC, x, y, m_layout );
+ }
+
+ if (underlined)
+ {
+ // undo underline attributes setting:
+ pango_layout_set_attributes(m_layout, NULL);
+ }
+
+ wxCoord width = w;
+ wxCoord height = h;
+
+#else // GTK+ 1.x
+ wxCoord width = gdk_string_width( font, text.mbc_str() );
+ wxCoord height = font->ascent + font->descent;
+
+ if ( m_backgroundMode == wxSOLID )
+ {
+ gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() );
+ gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height );
+ gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() );
+ }
+ gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() );
+
+ /* CMB 17/7/98: simple underline: ignores scaling and underlying
+ X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
+ properties (see wxXt implementation) */
+ if (m_font.GetUnderlined())
+ {
+ wxCoord ul_y = y + font->ascent;
+ if (font->descent > 0) ul_y++;
+ gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y);
+ }
+#endif // GTK+ 2.0/1.x
+
+ width = wxCoord(width / m_scaleX);
+ height = wxCoord(height / m_scaleY);
+ CalcBoundingBox (x + width, y + height);
+ 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 )
+{
+ if ( wxIsNullDouble(angle) )
+ {
+ DrawText(text, x, y);
+ return;
+ }
+
+ wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+ if (!m_window) return;
+
+ wxCoord w;
+ wxCoord h;
+
+#ifdef __WXGTK20__
+ // implement later without GdkFont for GTK 2.0
+ GetTextExtent(text, &w, &h, NULL,NULL, &m_font);
+
+#else
+ GdkFont *font = m_font.GetInternalFont( m_scaleY );
+
+ wxCHECK_RET( font, wxT("invalid font") );
+
+ // the size of the text
+ w = gdk_string_width( font, text.mbc_str() );
+ h = font->ascent + font->descent;
+#endif
+ // draw the string normally
+ wxBitmap src(w, h);
+ wxMemoryDC dc;
+ dc.SelectObject(src);
+ dc.SetFont(GetFont());
+ dc.SetBackground(*wxBLACK_BRUSH);
+ dc.SetBrush(*wxBLACK_BRUSH);
+ dc.Clear();
+ dc.SetTextForeground( *wxWHITE );
+ dc.DrawText(text, 0, 0);
+ dc.SelectObject(wxNullBitmap);
+
+ // Calculate the size of the rotated bounding box.
+ double rad = DegToRad(angle);
+ double dx = cos(rad),
+ 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,
+ y2 = -w*dy; // y axis points to the bottom, hence minus
+ double x4 = h*dy,
+ y4 = h*dx;
+ double x3 = x4 + x2,
+ y3 = y4 + y2;
+
+ // calc max and min
+ wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5),
+ maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5),
+ minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5),
+ minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5);
+
+
+ wxImage image = src.ConvertToImage();
+
+ image.ConvertColourToAlpha( m_textForegroundColour.Red(),
+ m_textForegroundColour.Green(),
+ m_textForegroundColour.Blue() );
+ image = image.Rotate( rad, wxPoint(0,0) );
+
+ int i_angle = (int) angle;
+ i_angle = i_angle % 360;
+ if (i_angle < 0)
+ i_angle += 360;
+ int xoffset = 0;
+ if ((i_angle >= 90.0) && (i_angle < 270.0))
+ xoffset = image.GetWidth();
+ int yoffset = 0;
+ if ((i_angle >= 0.0) && (i_angle < 180.0))
+ yoffset = image.GetHeight();
+
+ if ((i_angle >= 0) && (i_angle < 90))
+ yoffset -= (int)( cos(rad)*h );
+ if ((i_angle >= 90) && (i_angle < 180))
+ xoffset -= (int)( sin(rad)*h );
+ if ((i_angle >= 180) && (i_angle < 270))
+ yoffset -= (int)( cos(rad)*h );
+ if ((i_angle >= 270) && (i_angle < 360))
+ xoffset -= (int)( sin(rad)*h );
+
+ int i_x = x - xoffset;
+ int i_y = y - yoffset;
+
+ src = image;
+ DoDrawBitmap( src, i_x, i_y, true );
+
+
+ // 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() )
+ {
+ gdk_draw_line( m_window, m_textGC,
+ XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent),
+ XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent));
+ }
+#endif // 0
+
+ // update the bounding box
+ CalcBoundingBox(x + minX, y + minY);
+ CalcBoundingBox(x + maxX, y + maxY);