X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3e21fc053d9017f79ad71675db8d2e1497049159..b74077ace2413000c5556cbe0c41ab210ac12c54:/src/cocoa/dc.mm diff --git a/src/cocoa/dc.mm b/src/cocoa/dc.mm index 7ef93f80ee..a56a4fa6ca 100644 --- a/src/cocoa/dc.mm +++ b/src/cocoa/dc.mm @@ -6,13 +6,16 @@ // Created: 2003/04/01 // RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott -// Licence: wxWidgets licence +// Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" + +#include "wx/dc.h" + #ifndef WX_PRECOMP #include "wx/log.h" - #include "wx/dc.h" + #include "wx/math.h" //math constants #endif //WX_PRECOMP #include "wx/cocoa/autorelease.h" @@ -40,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()) @@ -146,6 +149,7 @@ wxDC::wxDC(void) wxDC::~wxDC(void) { + [m_cocoaWxToBoundsTransform release]; } bool wxDC::CocoaLockFocus() @@ -194,6 +198,7 @@ void wxDC::CocoaUnapplyTransformations() invertTransform = [m_cocoaWxToBoundsTransform copy]; [invertTransform invert]; [invertTransform concat]; + [invertTransform release]; } bool wxDC::CocoaGetBounds(void *rectData) @@ -225,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 @@ -310,70 +315,32 @@ 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 wxDCBase::LogicalToDeviceY(int y) const -{ - return y; -} + int underlineStyle = GetFont().GetUnderlined() ? NSUnderlineStyleSingle : NSUnderlineStyleNone; + NSRange lineGlyphRange; + NSRect lineRect = [sm_cocoaNSLayoutManager lineFragmentRectForGlyphAtIndex:0 effectiveRange:&lineGlyphRange]; -int wxDCBase::LogicalToDeviceXRel(int x) const -{ - return x; -} + [sm_cocoaNSLayoutManager underlineGlyphRange:glyphRange underlineType:underlineStyle + lineFragmentRect:lineRect lineFragmentGlyphRange:lineGlyphRange + containerOrigin:underlineLocation]; -int wxDCBase::LogicalToDeviceYRel(int y) const -{ - return y; + [context restoreGraphicsState]; } /////////////////////////////////////////////////////////////////////////// // cut here, the rest is stubs /////////////////////////////////////////////////////////////////////////// -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -#define mm2inches 0.0393700787402 -#define inches2mm 25.4 -#define mm2twips 56.6929133859 -#define twips2mm 0.0176388888889 -#define mm2pt 2.83464566929 -#define pt2mm 0.352777777778 - //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- @@ -382,8 +349,8 @@ void wxDC::DoDrawIcon( const wxIcon &WXUNUSED(icon), int WXUNUSED(x), int WXUNUS { }; -void wxDC::DoDrawPoint( int x, int y ) -{ +void wxDC::DoDrawPoint( int x, int y ) +{ }; void wxDC::DoDrawPolygon( int, wxPoint *, int, int, int) @@ -432,7 +399,12 @@ bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc) { } - + +void wxDC::SetFont(const wxFont& font) +{ + m_font = font; +} + void wxDC::SetPen(const wxPen& pen) { m_pen = pen; @@ -513,7 +485,7 @@ void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) fromRect: NSMakeRect(0.0,0.0,bmp.GetWidth(),bmp.GetHeight()) operation: NSCompositeSourceOver fraction: 1.0]; - + [nsimage release]; [context restoreGraphicsState]; } @@ -604,7 +576,7 @@ void wxDC::SetLogicalFunction(int) void wxDC::SetMapMode( int mode ) { - switch (mode) + switch (mode) { case wxMM_TWIPS: break; @@ -668,7 +640,7 @@ void wxDC::ComputeScaleAndOrigin(void) m_scaleX = m_logicalScaleX * m_userScaleX; m_scaleY = m_logicalScaleY * m_userScaleY; - // CMB: if scale has changed call SetPen to recalulate the line width + // CMB: if scale has changed call SetPen to recalulate the line width if (m_scaleX != origScaleX || m_scaleY != origScaleY) { // this is a bit artificial, but we need to force wxDC to think @@ -679,4 +651,3 @@ void wxDC::ComputeScaleAndOrigin(void) SetPen(* pen); } }; -