X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da80ae712a30132bf19127db544959db7e1a7b52..19cf1ef3a7077dd99a90f141847b8a9b67b318c9:/src/cocoa/dc.mm diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm index 4c1ad172aa..a56a4fa6ca 100644 --- a/src/cocoa/dc.mm +++ b/src/cocoa/dc.mm @@ -15,6 +15,7 @@ #ifndef WX_PRECOMP #include "wx/log.h" + #include "wx/math.h" //math constants #endif //WX_PRECOMP #include "wx/cocoa/autorelease.h" @@ -30,7 +31,6 @@ #import #import -#include "wx/math.h" //math constants #include "wx/listimpl.cpp" WX_DEFINE_LIST(wxCocoaDCStack); @@ -43,7 +43,7 @@ wxCocoaDCStack wxDC::sm_cocoaDCStack; inline void CocoaSetPenForNSBezierPath(wxPen &pen, NSBezierPath *bezpath) { [pen.GetNSColor() set]; - const float *pattern; + const CGFloat *pattern; [bezpath setLineDash:pattern count:pen.GetCocoaLineDash(&pattern) phase:0.0]; [bezpath setLineWidth:pen.GetWidth()]; switch(pen.GetJoin()) @@ -230,7 +230,7 @@ void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) [bezpath stroke]; } -void wxDC::DoGetTextExtent(const wxString& text, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, wxFont *theFont) const +void wxDC::DoGetTextExtent(const wxString& text, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, const wxFont *theFont) const { wxAutoNSAutoreleasePool pool; // FIXME: Cache this so it can be used for DoDrawText @@ -315,53 +315,26 @@ 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]; - [context restoreGraphicsState]; -} - -// wxDCBase functions -int wxDCBase::DeviceToLogicalX(int x) const -{ - return x; -} - -int wxDCBase::DeviceToLogicalY(int y) const -{ - return y; -} - -int wxDCBase::DeviceToLogicalXRel(int x) const -{ - return x; -} - -int wxDCBase::DeviceToLogicalYRel(int y) const -{ - return y; -} - -int wxDCBase::LogicalToDeviceX(int x) const -{ - return x; -} + int underlineStyle = GetFont().GetUnderlined() ? NSUnderlineStyleSingle : NSUnderlineStyleNone; + NSRange lineGlyphRange; + NSRect lineRect = [sm_cocoaNSLayoutManager lineFragmentRectForGlyphAtIndex:0 effectiveRange:&lineGlyphRange]; -int wxDCBase::LogicalToDeviceY(int y) const -{ - return y; -} + [sm_cocoaNSLayoutManager underlineGlyphRange:glyphRange underlineType:underlineStyle + lineFragmentRect:lineRect lineFragmentGlyphRange:lineGlyphRange + containerOrigin:underlineLocation]; -int wxDCBase::LogicalToDeviceXRel(int x) const -{ - return x; -} - -int wxDCBase::LogicalToDeviceYRel(int y) const -{ - return y; + [context restoreGraphicsState]; } /////////////////////////////////////////////////////////////////////////// @@ -427,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;