Merged trunk 47598:

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/branches/WX_2_8_BRANCH@47599 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2007-07-20 19:47:02 +00:00
parent ada47ad6fb
commit 729535acbe
4 changed files with 26 additions and 4 deletions

View File

@@ -83,7 +83,7 @@ public:
virtual void StartPage(void) {}; virtual void StartPage(void) {};
virtual void EndPage(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 SetPen(const wxPen& pen);
virtual void SetBrush(const wxBrush& brush); virtual void SetBrush(const wxBrush& brush);
virtual void SetBackground(const wxBrush& brush); virtual void SetBackground(const wxBrush& brush);

View File

@@ -315,11 +315,25 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
NSPoint layoutLocation = [sm_cocoaNSLayoutManager locationForGlyphAtIndex:0]; NSPoint layoutLocation = [sm_cocoaNSLayoutManager locationForGlyphAtIndex:0];
layoutLocation.x = 0.0; layoutLocation.x = 0.0;
layoutLocation.y *= -1.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]; layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0];
if(m_backgroundMode==wxSOLID) if(m_backgroundMode==wxSOLID)
[sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint]; [sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint];
[sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation]; [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]; [context restoreGraphicsState];
} }
@@ -427,6 +441,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) void wxDC::SetPen(const wxPen& pen)
{ {
m_pen = pen; m_pen = pen;

View File

@@ -60,7 +60,10 @@ int wxFont::GetPointSize() const
bool wxFont::GetUnderlined() const bool wxFont::GetUnderlined() const
{ {
return false; if(M_FONTDATA)
return M_FONTDATA->m_underlined;
else
return false;
} }
int wxFont::GetStyle() const int wxFont::GetStyle() const

View File

@@ -972,8 +972,8 @@ void wxWindow::DoSetVirtualSize( int x, int y )
bool wxWindow::SetFont(const wxFont& font) bool wxWindow::SetFont(const wxFont& font)
{ {
// TODO // FIXME: We may need to handle wx font inheritance.
return true; return wxWindowBase::SetFont(font);
} }
#if 0 // these are used when debugging the algorithm. #if 0 // these are used when debugging the algorithm.