From e7e97a594def45262e1a46a4b4089d3d9305c311 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 20 Jul 2007 19:05:56 +0000 Subject: [PATCH] wxCocoa: Basic support for font underlining: * Make wxWindow::SetFont call wxWindowBase::SetFont. * Make wxDC::SetFont store the font in existing m_font. * Make wxFont::GetUnderlined return the m_underlined flag. * Implement underlining in wxDC::DoDrawText Copyright 2007, Software 2000 Ltd. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47598 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/dc.h | 2 +- src/cocoa/dc.mm | 19 +++++++++++++++++++ src/cocoa/font.cpp | 5 ++++- src/cocoa/window.mm | 4 ++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/wx/cocoa/dc.h b/include/wx/cocoa/dc.h index aaa3a6291e..7fcc9be39c 100644 --- a/include/wx/cocoa/dc.h +++ b/include/wx/cocoa/dc.h @@ -83,7 +83,7 @@ public: virtual void StartPage(void) {}; virtual void EndPage(void) {}; - virtual void SetFont(const wxFont& font) {} + virtual void SetFont(const wxFont& font); virtual void SetPen(const wxPen& pen); virtual void SetBrush(const wxBrush& brush); virtual void SetBackground(const wxBrush& brush); diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm index 832b6ba726..a56a4fa6ca 100644 --- a/src/cocoa/dc.mm +++ b/src/cocoa/dc.mm @@ -315,11 +315,25 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) NSPoint layoutLocation = [sm_cocoaNSLayoutManager locationForGlyphAtIndex:0]; layoutLocation.x = 0.0; layoutLocation.y *= -1.0; + + // Save the location as is for underlining + NSPoint underlineLocation = layoutLocation; + + // Offset the location by the baseline for drawing the glyphs. layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0]; + if(m_backgroundMode==wxSOLID) [sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint]; [sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation]; + int underlineStyle = GetFont().GetUnderlined() ? NSUnderlineStyleSingle : NSUnderlineStyleNone; + NSRange lineGlyphRange; + NSRect lineRect = [sm_cocoaNSLayoutManager lineFragmentRectForGlyphAtIndex:0 effectiveRange:&lineGlyphRange]; + + [sm_cocoaNSLayoutManager underlineGlyphRange:glyphRange underlineType:underlineStyle + lineFragmentRect:lineRect lineFragmentGlyphRange:lineGlyphRange + containerOrigin:underlineLocation]; + [context restoreGraphicsState]; } @@ -386,6 +400,11 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, { } +void wxDC::SetFont(const wxFont& font) +{ + m_font = font; +} + void wxDC::SetPen(const wxPen& pen) { m_pen = pen; diff --git a/src/cocoa/font.cpp b/src/cocoa/font.cpp index ed1fac7b70..bfbed70f38 100644 --- a/src/cocoa/font.cpp +++ b/src/cocoa/font.cpp @@ -60,7 +60,10 @@ int wxFont::GetPointSize() const bool wxFont::GetUnderlined() const { - return false; + if(M_FONTDATA) + return M_FONTDATA->m_underlined; + else + return false; } int wxFont::GetStyle() const diff --git a/src/cocoa/window.mm b/src/cocoa/window.mm index 23fee50c2a..3192fb8d58 100644 --- a/src/cocoa/window.mm +++ b/src/cocoa/window.mm @@ -1031,8 +1031,8 @@ void wxWindow::DoSetVirtualSize( int x, int y ) bool wxWindow::SetFont(const wxFont& font) { - // TODO - return true; + // FIXME: We may need to handle wx font inheritance. + return wxWindowBase::SetFont(font); } #if 0 // these are used when debugging the algorithm. -- 2.45.2