Why use a CoreText text layout, can text be displayed in a 1px width path?

I wrote code using CoreText to place some texts, as shown below. Red rectangle - text area, black rectangle is empty for images or other objects. I am using kCTFrameClippingPathsAttributeName tell CoreText that the black rectangle will not show texts.

core text text layout

Detailed image as below:

enter image description here

Why is some text broken into this position? The red rectangle and the black rectangle have only a small area, 1px wide, why does the text come out?

The right red frame of the rectangle (533, 40, 440, 668) , the right rectangle of the rectangle (534, 98, 440, 399) .

code:

 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); 
+4
source share
1 answer

It looks like your attributedString missing paragraph style information.

I assume that you created NSAttributedString from NSString and did not specify the key value kCTParagraphStyleAttributeName in the attribute dictionary.

+2
source

All Articles