From e0e105ea1559874a5a9097461d0d7933cb5cbbb4 Mon Sep 17 00:00:00 2001 From: Neil Hodgson Date: Mon, 21 May 2018 15:20:08 +1000 Subject: 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. --- cocoa/QuartzTextLayout.h | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'cocoa/QuartzTextLayout.h') diff --git a/cocoa/QuartzTextLayout.h b/cocoa/QuartzTextLayout.h index c33231176..a3ed910de 100644 --- a/cocoa/QuartzTextLayout.h +++ b/cocoa/QuartzTextLayout.h @@ -18,12 +18,8 @@ class QuartzTextLayout { public: - /** Create a text layout for drawing on the specified context. */ - explicit QuartzTextLayout(CGContextRef context) { - mString = NULL; - mLine = NULL; - stringLength = 0; - setContext(context); + /** Create a text layout for drawing. */ + QuartzTextLayout() : mString(NULL), mLine(NULL), stringLength(0) { } ~QuartzTextLayout() { @@ -58,11 +54,12 @@ 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) { - if (mLine == NULL) + void draw(CGContextRef gc, float x, float y) { + if (!mLine) return; ::CGContextSetTextMatrix(gc, CGAffineTransformMakeScale(1.0, -1.0)); @@ -89,12 +86,7 @@ public: return stringLength; } - inline void setContext(CGContextRef context) { - gc = context; - } - private: - CGContextRef gc; CFAttributedStringRef mString; CTLineRef mLine; CFIndex stringLength; -- cgit v1.2.3