+ // scale/translate bitmap size
+ wxCoord bm_width = selected.GetWidth();
+ wxCoord bm_height = selected.GetHeight();
+
+ // Get clip coords for the bitmap. If we don't
+ // use wxBitmap::Rescale(), which can clip the
+ // bitmap, these are the same as the original
+ // coordinates
+ wxCoord cx = xx;
+ wxCoord cy = yy;
+ wxCoord cw = ww;
+ wxCoord ch = hh;
+
+ // interpret userscale of src too
+ double xsc,ysc;
+ memDC->GetUserScale(&xsc,&ysc);
+ bm_width = (int) (bm_width / xsc);
+ bm_height = (int) (bm_height / ysc);
+
+ wxCoord bm_ww = XLOG2DEVREL( bm_width );
+ wxCoord bm_hh = YLOG2DEVREL( bm_height );
+
+ // Scale bitmap if required
+ wxBitmap use_bitmap = selected;
+ if ((selected.GetWidth()!= bm_ww) || ( selected.GetHeight()!= bm_hh))
+ {
+ // This indicates that the blitting code below will get
+ // a clipped bitmap and therefore needs to move the origin
+ // accordingly
+ wxRegion tmp( xx,yy,ww,hh );
+ if (!m_currentClippingRegion.IsNull())
+ tmp.Intersect( m_currentClippingRegion );
+ tmp.GetBox(cx,cy,cw,ch);
+
+ // Scale and clipped bitmap
+ use_bitmap = selected.Rescale(cx-xx,cy-yy,cw,ch,bm_ww,bm_hh);
+ }
+
+ // apply mask if any
+ GdkBitmap *mask = (GdkBitmap *) NULL;
+ if (useMask && use_bitmap.GetMask())
+ mask = use_bitmap.GetMask()->GetBitmap();
+
+ GdkGC* use_gc = is_mono ? m_textGC : m_penGC;
+
+ bool mask_owned = false;
+
+ if (mask != NULL)
+ {
+ if (!m_currentClippingRegion.IsNull())
+ {
+ mask = GetClippedMask(mask, bm_ww, bm_hh, cx, cy,
+ xsrcMask, ysrcMask);
+ mask_owned = true;
+ }
+
+ gdk_gc_set_clip_mask(use_gc, mask);
+ if (mask_owned)
+ gdk_gc_set_clip_origin(use_gc, cx, cy);
+ else
+ gdk_gc_set_clip_origin(use_gc, cx - xsrcMask, cy - ysrcMask);
+ }
+
+ // Draw XPixmap or XBitmap, depending on what the wxBitmap contains.
+ if (is_mono)
+ {
+ DoDrawMonoBitmap(use_bitmap, bm_ww, bm_hh,
+ xsrc, ysrc, cx, cy, cw, ch);
+ }
+ else
+ {
+ // was: gdk_draw_drawable( m_gdkwindow, m_penGC, use_bitmap.GetPixmap(), xsrc, ysrc, xx, yy, ww, hh );
+ gdk_draw_drawable(m_gdkwindow, use_gc, use_bitmap.GetPixmap(), xsrc, ysrc, cx, cy, cw, ch);
+ }
+
+ // remove mask again if any
+ if (mask != NULL)
+ {
+ RemoveClipMask(use_gc);
+ if (mask_owned)
+ g_object_unref (mask);
+ }
+ }
+ else // use_bitmap_method
+ {
+ if (selected.IsOk() && ((width != ww) || (height != hh)))
+ {
+ wxBitmap bitmap = selected.Rescale( xsrc, ysrc, width, height, ww, hh );
+ // draw scaled bitmap
+ gdk_draw_drawable( m_gdkwindow, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 );
+ }
+ else
+ {
+ // No scaling and not a memory dc with a mask either
+ GdkWindow* window = NULL;
+ wxDCImpl *impl = source->GetImpl();
+ wxWindowDCImpl *gtk_impl = wxDynamicCast(impl, wxWindowDCImpl);
+ if (gtk_impl)
+ window = gtk_impl->GetGDKWindow();
+ if ( !window )
+ {
+ SetLogicalFunction( old_logical_func );
+ return false;
+ }
+
+ // copy including child window contents
+ gdk_gc_set_subwindow( m_penGC, GDK_INCLUDE_INFERIORS );
+ gdk_draw_drawable( m_gdkwindow, m_penGC,
+ window,
+ xsrc, ysrc, xx, yy,
+ width, height );
+ gdk_gc_set_subwindow( m_penGC, GDK_CLIP_BY_CHILDREN );
+ }
+ }
+
+ SetLogicalFunction( old_logical_func );
+
+ return true;
+}
+
+void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
+{
+ wxCHECK_RET( IsOk(), wxT("invalid window dc") );
+
+ if (!m_gdkwindow) return;
+
+ if (text.empty()) return;
+
+ x = XLOG2DEV(x);
+ y = YLOG2DEV(y);
+
+ 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") );
+
+ gdk_pango_context_set_colormap( m_context, m_cmap ); // not needed in gtk+ >= 2.6
+
+ bool underlined = m_font.IsOk() && m_font.GetUnderlined();
+
+ wxCharBuffer data = wxGTK_CONV(text);
+ if ( !data )
+ return;
+ size_t datalen = strlen(data);
+
+ // in Pango >= 1.16 the "underline of leading/trailing spaces" bug
+ // has been fixed and thus the hack implemented below should never be used
+ static bool pangoOk = !wx_pango_version_check(1, 16, 0);
+
+ bool needshack = underlined && !pangoOk;
+
+ if (needshack)
+ {
+ // a PangoLayout which has leading/trailing spaces with underlined font
+ // is not correctly drawn by this pango version: Pango won't underline the spaces.
+ // This can be a problem; e.g. wxHTML rendering of underlined text relies on
+ // this behaviour. To workaround this problem, we use a special hack here
+ // suggested by pango maintainer Behdad Esfahbod: we prepend and append two
+ // empty space characters and give them a dummy colour attribute.
+ // This will force Pango to underline the leading/trailing spaces, too.
+
+ wxCharBuffer data_tmp(datalen + 6);
+ // copy the leading U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
+ memcpy(data_tmp.data(), "\342\200\214", 3);
+ // copy the user string
+ memcpy(data_tmp.data() + 3, data, datalen);
+ // copy the trailing U+200C ZERO WIDTH NON-JOINER encoded in UTF8 format
+ memcpy(data_tmp.data() + 3 + datalen, "\342\200\214", 3);
+
+ data = data_tmp;
+ datalen += 6;
+ }
+
+ pango_layout_set_text(m_layout, 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);
+
+ if (needshack)
+ {
+ // dummy colour for the leading space
+ a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
+ a->start_index = 0;
+ a->end_index = 1;
+ pango_attr_list_insert(attrs, a);
+
+ // dummy colour for the trailing space
+ a = pango_attr_foreground_new (0x0057, 0x52A9, 0xD614);
+ a->start_index = datalen - 1;
+ a->end_index = datalen;
+ pango_attr_list_insert(attrs, a);
+ }
+
+ pango_layout_set_attributes(m_layout, attrs);
+ pango_attr_list_unref(attrs);
+ }
+
+ int oldSize = 0;
+ const bool isScaled = fabs(m_scaleY - 1.0) > 0.00001;
+ if (isScaled)
+ {
+ // If there is a user or actually any scale applied to
+ // the device context, scale the font.
+
+ // scale font description
+ oldSize = pango_font_description_get_size(m_fontdesc);
+ pango_font_description_set_size(m_fontdesc, int(oldSize * m_scaleY));
+
+ // actually apply scaled font
+ pango_layout_set_font_description( m_layout, m_fontdesc );
+ }
+
+ int w, h;
+ pango_layout_get_pixel_size(m_layout, &w, &h);
+
+ // Draw layout.
+ int x_rtl = x;
+ if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft)
+ x_rtl -= w;
+
+ const GdkColor* bg_col = NULL;
+ if (m_backgroundMode == wxBRUSHSTYLE_SOLID)
+ bg_col = m_textBackgroundColour.GetColor();
+
+ gdk_draw_layout_with_colors(m_gdkwindow, m_textGC, x_rtl, y, m_layout, NULL, bg_col);
+
+ if (isScaled)
+ {
+ // reset unscaled size
+ pango_font_description_set_size( m_fontdesc, oldSize );
+
+ // actually apply unscaled font
+ pango_layout_set_font_description( m_layout, m_fontdesc );
+ }
+ if (underlined)
+ {
+ // undo underline attributes setting:
+ pango_layout_set_attributes(m_layout, NULL);
+ }
+
+ CalcBoundingBox(x + int(w / m_scaleX), y + int(h / m_scaleY));
+ CalcBoundingBox(x, y);
+}
+
+// TODO: When GTK2.6 is required, merge DoDrawText and DoDrawRotatedText to
+// avoid code duplication
+void wxWindowDCImpl::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
+{
+ if (!m_gdkwindow || text.empty())
+ return;
+
+ wxCHECK_RET( IsOk(), wxT("invalid window dc") );
+
+#if __WXGTK26__
+ if (!gtk_check_version(2,6,0))
+ {
+ x = XLOG2DEV(x);
+ y = YLOG2DEV(y);
+
+ pango_layout_set_text(m_layout, wxGTK_CONV(text), -1);
+
+ if (m_font.GetUnderlined())