@@ -451,6 +451,20 @@ - (BOOL) updateTexture
451
451
452
452
}
453
453
454
+ - (void )applyShadowOnContext : (CGContextRef)context color : (CGColorRef)color blurRadius : (CGFloat)blurRadius offset : (CGPoint)offset {
455
+
456
+ CGContextSetShadowWithColor (context, CGSizeMake (offset.x , -offset.y ), blurRadius, color);
457
+
458
+ }
459
+
460
+ - (void )applyOutlineOnContext : (CGContextRef)context color : (CGColorRef)color width : (CGFloat)width {
461
+ CGContextSetTextDrawingMode (context, kCGTextStroke );
462
+ CGContextSetLineWidth (context, width * 2 );
463
+ CGContextSetLineJoin (context, kCGLineJoinRound );
464
+ CGContextSetStrokeColorWithColor (context, color);
465
+
466
+ }
467
+
454
468
- (CCTexture*) createTextureWithAttributedString : (NSAttributedString *)attributedString useFullColor : (BOOL ) fullColor
455
469
{
456
470
NSAssert (attributedString, @" Invalid attributedString" );
@@ -589,36 +603,37 @@ - (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributed
589
603
free (data);
590
604
return NULL ;
591
605
}
592
- // Handle shadow
593
- if (hasShadow)
594
- {
595
- CGContextSetShadowWithColor (context, CGSizeMake (shadowOffset.x , -shadowOffset.y ), shadowBlurRadius, _shadowColor.CGColor );
596
- }
597
606
598
- // Handle outline
599
- if (hasOutline)
600
- {
601
- CGContextSetTextDrawingMode (context, kCGTextFillStroke );
602
- CGContextSetLineWidth (context, outlineWidth * 2 );
603
- CGContextSetLineJoin (context, kCGLineJoinRound );
604
-
605
- NSMutableAttributedString * outlineString = [attributedString mutableCopy ];
606
- // [outlineString addAttribute:NSForegroundColorAttributeName value:(__bridge id)_outlineColor.CGColor range:NSMakeRange(0, outlineString.length)]; //donotcheckin
607
-
608
- [self drawAttributedString: outlineString inContext: context inRect: drawArea];
609
-
610
- // Don't draw shadow for main font
611
- CGContextSetShadowWithColor (context, CGSizeZero, 0 , NULL );
612
-
613
- if (hasShadow)
614
- {
615
- // Draw outline again because shadow overlap
616
- [self drawAttributedString: outlineString inContext: context inRect: drawArea];
617
- }
618
- CGContextSetTextDrawingMode (context, kCGTextFill );
619
- }
620
607
621
- [self drawAttributedString: attributedString inContext: context inRect: drawArea];
608
+ if (!hasShadow && !hasOutline) {
609
+ [self drawAttributedString: attributedString inContext: context inRect: drawArea];
610
+
611
+ } else if (hasShadow && !hasOutline) {
612
+ [self applyShadowOnContext: context color: _shadowColor.CGColor blurRadius: shadowBlurRadius offset: shadowOffset];
613
+ [self drawAttributedString: attributedString inContext: context inRect: drawArea];
614
+
615
+ } else if (!hasShadow && hasOutline) {
616
+ CGContextSaveGState (context);
617
+ [self applyOutlineOnContext: context color: _outlineColor.CGColor width: outlineWidth];
618
+ [self drawAttributedString: attributedString inContext: context inRect: drawArea];
619
+ CGContextRestoreGState (context);
620
+ [self drawAttributedString: attributedString inContext: context inRect: drawArea];
621
+
622
+
623
+ } else if (hasShadow && hasOutline) {
624
+ CGContextSaveGState (context);
625
+ [self applyOutlineOnContext: context color: _outlineColor.CGColor width: outlineWidth];
626
+ [self applyShadowOnContext: context color: _shadowColor.CGColor blurRadius: shadowBlurRadius offset: shadowOffset];
627
+ [self drawAttributedString: attributedString inContext: context inRect: drawArea];
628
+ CGContextRestoreGState (context);
629
+ CGContextSaveGState (context);
630
+ [self applyOutlineOnContext: context color: _outlineColor.CGColor width: outlineWidth];
631
+ [self drawAttributedString: attributedString inContext: context inRect: drawArea];
632
+ CGContextRestoreGState (context);
633
+ [self drawAttributedString: attributedString inContext: context inRect: drawArea];
634
+
635
+
636
+ }
622
637
623
638
CGContextRelease (context);
624
639
0 commit comments