@@ -141,6 +141,8 @@ @interface ASTextNodeDrawParameter : NSObject {
141
141
BOOL _opaque;
142
142
CGRect _bounds;
143
143
ASPrimitiveTraitCollection _traitCollection;
144
+ ASDisplayNodeContextModifier _willDisplayNodeContentWithRenderingContext;
145
+ ASDisplayNodeContextModifier _didDisplayNodeContentWithRenderingContext;
144
146
}
145
147
@end
146
148
@@ -152,7 +154,9 @@ - (instancetype)initWithRendererAttributes:(ASTextKitAttributes)rendererAttribut
152
154
contentScale : (CGFloat)contentScale
153
155
opaque : (BOOL )opaque
154
156
bounds : (CGRect)bounds
155
- traitCollection : (ASPrimitiveTraitCollection)traitCollection
157
+ traitCollection : (ASPrimitiveTraitCollection)traitCollection
158
+ willDisplayNodeContentWithRenderingContext : (ASDisplayNodeContextModifier)willDisplayNodeContentWithRenderingContext
159
+ didDisplayNodeContentWithRenderingContext : (ASDisplayNodeContextModifier)didDisplayNodeContentWithRenderingContext
156
160
{
157
161
self = [super init ];
158
162
if (self != nil ) {
@@ -163,6 +167,8 @@ - (instancetype)initWithRendererAttributes:(ASTextKitAttributes)rendererAttribut
163
167
_opaque = opaque;
164
168
_bounds = bounds;
165
169
_traitCollection = traitCollection;
170
+ _willDisplayNodeContentWithRenderingContext = willDisplayNodeContentWithRenderingContext;
171
+ _didDisplayNodeContentWithRenderingContext = didDisplayNodeContentWithRenderingContext;
166
172
}
167
173
return self;
168
174
}
@@ -560,7 +566,9 @@ - (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer
560
566
contentScale: _contentsScaleForDisplay
561
567
opaque: self .isOpaque
562
568
bounds: [self threadSafeBounds ]
563
- traitCollection: self .primitiveTraitCollection];
569
+ traitCollection: self .primitiveTraitCollection
570
+ willDisplayNodeContentWithRenderingContext: self .willDisplayNodeContentWithRenderingContext
571
+ didDisplayNodeContentWithRenderingContext: self .didDisplayNodeContentWithRenderingContext];
564
572
}
565
573
566
574
+ (UIImage *)displayWithParameters : (id <NSObject >)parameters isCancelled : (NS_NOESCAPE asdisplaynode_iscancelled_block_t )isCancelled
@@ -574,12 +582,19 @@ + (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(NS_NOES
574
582
UIColor *backgroundColor = drawParameter->_backgroundColor ;
575
583
UIEdgeInsets textContainerInsets = drawParameter ? drawParameter->_textContainerInsets : UIEdgeInsetsZero;
576
584
ASTextKitRenderer *renderer = [drawParameter rendererForBounds: drawParameter->_bounds];
585
+ ASDisplayNodeContextModifier willDisplayNodeContentWithRenderingContext = drawParameter->_willDisplayNodeContentWithRenderingContext ;
586
+ ASDisplayNodeContextModifier didDisplayNodeContentWithRenderingContext = drawParameter->_didDisplayNodeContentWithRenderingContext ;
577
587
578
588
UIImage *result = ASGraphicsCreateImage (drawParameter->_traitCollection , CGSizeMake (drawParameter->_bounds .size .width , drawParameter->_bounds .size .height ), drawParameter->_opaque , drawParameter->_contentScale , nil , nil , ^{
579
589
CGContextRef context = UIGraphicsGetCurrentContext ();
580
590
ASDisplayNodeAssert (context, @" This is no good without a context." );
581
591
582
592
CGContextSaveGState (context);
593
+
594
+ if (context && willDisplayNodeContentWithRenderingContext) {
595
+ willDisplayNodeContentWithRenderingContext (context, drawParameter);
596
+ }
597
+
583
598
CGContextTranslateCTM (context, textContainerInsets.left , textContainerInsets.top );
584
599
585
600
// Fill background
@@ -591,6 +606,11 @@ + (UIImage *)displayWithParameters:(id<NSObject>)parameters isCancelled:(NS_NOES
591
606
592
607
// Draw text
593
608
[renderer drawInContext: context bounds: drawParameter->_bounds];
609
+
610
+ if (context && didDisplayNodeContentWithRenderingContext) {
611
+ didDisplayNodeContentWithRenderingContext (context, drawParameter);
612
+ }
613
+
594
614
CGContextRestoreGState (context);
595
615
});
596
616
0 commit comments