Question

How do I make an NSLayoutManager that assigns each paragraph in its text to a different NSTextContainer?

This would be similar to the multiple page/column usage that is common in TextKit, but each page corresponds to a different paragraph of variable length.

Était-ce utile?

La solution

I think the easiest way to do this is to subclass NSTextContainer and override

- (CGRect)lineFragmentRectForProposedRect:(CGRect)proposedRect atIndex:(NSUInteger)characterIndex writingDirection:(NSWritingDirection)baseWritingDirection remainingRect:(CGRect *)remainingRect

In your custom method, you'd inspect the attributes at characterIndex and see if they matched the paragraph that text container is assigned to. If they are, just return super's implementation of the method, otherwise return CGRectZero to signify that the proposed rect is invalid for this text container. This does mean you'll have to track paragraph attributes and the text containers they correlate to (and vice versa).

Autres conseils

Another way is inserting page break control character (ASCII code: 12) at the end of each paragraph.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top