Merge pull request #195 from facebook/text-context-passing

Safe calls in ASTextNodeRenderer
This commit is contained in:
Nadine Salter
2015-01-05 17:29:04 -08:00
3 changed files with 6 additions and 7 deletions

View File

@@ -338,7 +338,7 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
// Draw text
bounds.origin = parameters.textOrigin;
[parameters.renderer drawInRect:bounds isRasterizing:isRasterizing];
[parameters.renderer drawInRect:bounds inContext:context];
CGContextRestoreGState(context);
}

View File

@@ -60,8 +60,7 @@ typedef NS_ENUM(NSUInteger, ASTextNodeRendererMeasureOption) {
* Draw the renderer's text content into the bounds provided.
*
* @param bounds The rect in which to draw the contents of the renderer.
* @param isRasterizing If YES, the renderer will not draw its background color
* within the bounds.
* @param context The CGContext in which to draw the contents of the renderer.
*
* @discussion Note that if a shadow is to be drawn, then the text will actually
* draw inside a region that is inset from the bounds provided. Use
@@ -72,7 +71,7 @@ typedef NS_ENUM(NSUInteger, ASTextNodeRendererMeasureOption) {
* You may want to consider triggering this cost before hitting the draw method
* if you are sensitive to this cost in drawInRect...
*/
- (void)drawInRect:(CGRect)bounds isRasterizing:(BOOL)isRasterizing;
- (void)drawInRect:(CGRect)bounds inContext:(CGContextRef)context;
#pragma mark - Layout

View File

@@ -578,11 +578,10 @@ static const CGFloat ASTextNodeRendererTextCapHeightPadding = 1.3;
#pragma mark - Drawing
- (void)drawInRect:(CGRect)bounds isRasterizing:(BOOL)isRasterizing
- (void)drawInRect:(CGRect)bounds inContext:(CGContextRef)context
{
CGContextRef context = UIGraphicsGetCurrentContext();
ASDisplayNodeAssert(context, @"This is no good without a context.");
UIGraphicsPushContext(context);
CGContextSaveGState(context);
[self _initializeTextKitComponentsIfNeeded];
@@ -594,6 +593,7 @@ static const CGFloat ASTextNodeRendererTextCapHeightPadding = 1.3;
}
CGContextRestoreGState(context);
UIGraphicsPopContext();
}
#pragma mark - String Ranges