I wrote a code use CoreText layout some texts like picture below. Red rectangle is text area, black rectangle is empty for images or other objects. I use kCTFrameClippingPathsAttributeName tell CoreText that, black rectangle will not show texts.

Detail picture as below:

Why some text rend at this position? Red rectangle and black rectangle only have a very small area, size only 1px width, why text come out?
Right red rectangle frame is (533, 40, 440, 668), right small rectangle frame is (534, 98, 440, 399).
code like that:
CGPathRef textArea;
// An array of clipping paths
NSMutableArray * clippingPaths = [NSMutableArray array];
for (TNPageMedium *medium in self.media) {
NSDictionary *clippingPathDict = @{(NSString *)kCTFramePathClippingPathAttributeName:(__bridge id)path};
[clippingPaths addObject:clippingPathDict];
}
NSDictionary *optionsDict = @{(NSString*)kCTFrameClippingPathsAttributeName : clippingPaths};
// create frame using texAreaPath, an optionDictionary contains clipping paths
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(pos, 0), textAreaPath, (__bridge CFDictionaryRef)(optionsDict));
// Draw Frame
CTFrameDraw(frame, context);
Looks like your
attributedStringis missing paragraph style information.I guess you created
NSAttributedStringfromNSString, and didn’t providekCTParagraphStyleAttributeNamekey-value in attributes dictionary.