]> git.saurik.com Git - wxWidgets.git/commitdiff
wxCocoa: Basic support for font underlining:
authorDavid Elliott <dfe@tgwbd.org>
Fri, 20 Jul 2007 19:05:56 +0000 (19:05 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Fri, 20 Jul 2007 19:05:56 +0000 (19:05 +0000)
* 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
src/cocoa/dc.mm
src/cocoa/font.cpp
src/cocoa/window.mm

index aaa3a6291ec34a7be1b675fae545f8438d59500f..7fcc9be39c4faeab2df2031b5124a41ee159c75d 100644 (file)
@@ -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);
index 832b6ba72672e8960587ef17bd491b01d15a9cf7..a56a4fa6ca6c7e6908db485574ea0b0273c48d4b 100644 (file)
@@ -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;
index ed1fac7b70aeb04b2a96244adc158044819d8a5d..bfbed70f383bba9336cc9e8016613ba4ac883d69 100644 (file)
@@ -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
index 23fee50c2aceb67e27a6786d0badf57845bbe2ed..3192fb8d5802c919eaf671a2a1a4bbb1c50c8a76 100644 (file)
@@ -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.