From 46142dc9520cfb4846e53d8cca168381fe0cbf0a Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Mon, 17 Dec 2007 07:05:35 +0000 Subject: [PATCH] remove some duplication in font scaling code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/dcclient.cpp | 66 +++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 1d2280dd4f..feb5484b63 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -1559,72 +1559,52 @@ void wxWindowDCImpl::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) pango_attr_list_unref(attrs); } - int w,h; - - if (fabs(m_scaleY - 1.0) > 0.00001) + 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 - 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 ); + 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 ); + } - 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_gdkwindow, m_textGC, TRUE, x, y, w, h); - gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); - } + int w, h; + 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_gdkwindow, m_textGC, true, x, y, w, h); + gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); + } - // Draw layout. - if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) - gdk_draw_layout( m_gdkwindow, m_textGC, x-w, y, m_layout ); - else - gdk_draw_layout( m_gdkwindow, m_textGC, x, y, m_layout ); + // Draw layout. + int x_rtl = x; + if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) + x_rtl -= w; + gdk_draw_layout(m_gdkwindow, m_textGC, x_rtl, y, m_layout); + 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 ); } - 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_gdkwindow, m_textGC, TRUE, x, y, w, h); - gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor()); - } - - // Draw layout. - if (m_window && m_window->GetLayoutDirection() == wxLayout_RightToLeft) - gdk_draw_layout( m_gdkwindow, m_textGC, x-w, y, m_layout ); - else - gdk_draw_layout( m_gdkwindow, 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; - - width = wxCoord(width / m_scaleX); - height = wxCoord(height / m_scaleY); - CalcBoundingBox (x + width, y + height); - CalcBoundingBox (x, y); + CalcBoundingBox(x + int(w / m_scaleX), y + int(h / m_scaleY)); + CalcBoundingBox(x, y); } -- 2.47.2