From 18a2fa3715239bc43484e0bc6c31001de04e0b34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Karsten=20Ball=C3=BCder?= Date: Fri, 17 Jul 1998 10:06:26 +0000 Subject: [PATCH] fixed underline for drawing text, as suggested by Chris Breeze git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@285 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/dcclient.cpp | 25 ++++++++++++++++++++----- src/gtk1/dcclient.cpp | 25 ++++++++++++++++++++----- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 6f44374a4b..c4b2b3ee14 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -463,12 +463,16 @@ bool wxPaintDC::Blit( long xdest, long ydest, long width, long height, return TRUE; }; -void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(use16) ) +void wxPaintDC::DrawText( const wxString &text, long x, long y, bool +WXUNUSED(use16) ) { if (!Ok()) return; - + GdkFont *font = m_font.GetInternalFont( m_scaleY ); + x = XLOG2DEV(x); + y = YLOG2DEV(y); + // CMB 21/5/98: draw text background if mode is wxSOLID if (m_backgroundMode == wxSOLID) { @@ -478,11 +482,22 @@ void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(us 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, - XLOG2DEV(x), - YLOG2DEV(y) + font->ascent, text ); + gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text ); + + // 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()) + { + long width = gdk_string_width( font, text ); + long 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); + } }; + + bool wxPaintDC::CanGetTextExtent(void) const { return TRUE; diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 6f44374a4b..c4b2b3ee14 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -463,12 +463,16 @@ bool wxPaintDC::Blit( long xdest, long ydest, long width, long height, return TRUE; }; -void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(use16) ) +void wxPaintDC::DrawText( const wxString &text, long x, long y, bool +WXUNUSED(use16) ) { if (!Ok()) return; - + GdkFont *font = m_font.GetInternalFont( m_scaleY ); + x = XLOG2DEV(x); + y = YLOG2DEV(y); + // CMB 21/5/98: draw text background if mode is wxSOLID if (m_backgroundMode == wxSOLID) { @@ -478,11 +482,22 @@ void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(us 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, - XLOG2DEV(x), - YLOG2DEV(y) + font->ascent, text ); + gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text ); + + // 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()) + { + long width = gdk_string_width( font, text ); + long 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); + } }; + + bool wxPaintDC::CanGetTextExtent(void) const { return TRUE; -- 2.47.2