diff options
author | Neil Hodgson <nyamatongwe@gmail.com> | 2018-05-21 15:20:08 +1000 |
---|---|---|
committer | Neil Hodgson <nyamatongwe@gmail.com> | 2018-05-21 15:20:08 +1000 |
commit | 9f00df4e57e917035d2f939ce70ccf2ee83a9725 (patch) | |
tree | d2c867d424dcb2ca9d545f23218d5bc95fb214cd | |
parent | 8bda8cce4b5daf0bc785401a887331182e4f2b74 (diff) | |
download | scintilla-mirror-9f00df4e57e917035d2f939ce70ccf2ee83a9725.tar.gz |
Backport: Remove CGContextRef field in QuartzTextLayout as it is only used in draw method
where it can easily be provided. Retaining a CGContextRef in QuartzTextLayout
could lead to it being used after being invalidated.
Backport of changeset 6963:a8774d6100a6.
-rw-r--r-- | cocoa/PlatCocoa.mm | 7 | ||||
-rw-r--r-- | cocoa/QuartzTextLayout.h | 21 |
2 files changed, 8 insertions, 20 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index fe1873ffa..b517a7e6a 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -134,7 +134,7 @@ SurfaceImpl::SurfaceImpl() y = 0; gc = NULL; - textLayout.reset(new QuartzTextLayout(nullptr)); + textLayout.reset(new QuartzTextLayout()); codePage = 0; verticalDeviceResolution = 0; @@ -156,7 +156,6 @@ SurfaceImpl::~SurfaceImpl() void SurfaceImpl::Clear() { - textLayout->setContext(nullptr); if (bitmapData) { bitmapData.reset(); @@ -206,7 +205,6 @@ void SurfaceImpl::Init(SurfaceID sid, WindowID) Release(); gc = static_cast<CGContextRef>(sid); CGContextSetLineWidth(gc, 1.0); - textLayout->setContext(gc); } //-------------------------------------------------------------------------------------------------- @@ -244,7 +242,6 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface* surface_, WindowID // and we have no use for the bitmap without the context bitmapData.reset(); } - textLayout->setContext (gc); // the context retains the color space, so we can release it CGColorSpaceRelease(colorSpace); @@ -920,7 +917,7 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION yba CGColorRelease(color); textLayout->setText(s, len, encoding, *style); - textLayout->draw(rc.left, ybase); + textLayout->draw(gc, rc.left, ybase); } //-------------------------------------------------------------------------------------------------- diff --git a/cocoa/QuartzTextLayout.h b/cocoa/QuartzTextLayout.h index 0f813f301..f2387dd9b 100644 --- a/cocoa/QuartzTextLayout.h +++ b/cocoa/QuartzTextLayout.h @@ -19,13 +19,9 @@ class QuartzTextLayout { public: - /** Create a text layout for drawing on the specified context. */ - explicit QuartzTextLayout( CGContextRef context ) + /** Create a text layout for drawing. */ + QuartzTextLayout() : mString(NULL), mLine(NULL), stringLength(0) { - mString = NULL; - mLine = NULL; - stringLength = 0; - setContext(context); } ~QuartzTextLayout() @@ -63,12 +59,13 @@ public: CFRelease( str ); } - /** Draw the text layout into the current CGContext at the specified position. + /** Draw the text layout into a CGContext at the specified position. + * @param gc The CGContext in which to draw the text. * @param x The x axis position to draw the baseline in the current CGContext. * @param y The y axis position to draw the baseline in the current CGContext. */ - void draw( float x, float y ) + void draw( CGContextRef gc, float x, float y ) { - if (mLine == NULL) + if (!mLine) return; ::CGContextSetTextMatrix(gc, CGAffineTransformMakeScale(1.0, -1.0)); @@ -96,13 +93,7 @@ public: return stringLength; } - inline void setContext (CGContextRef context) - { - gc = context; - } - private: - CGContextRef gc; CFAttributedStringRef mString; CTLineRef mLine; CFIndex stringLength; |