Anviking / Chromatism

iOS Syntax Highlighting in Swift
MIT License
100 stars 15 forks source link

Performance of live word wrapping #6

Closed Anviking closed 11 years ago

Anviking commented 11 years ago

There is no need creating a new typesetter, but we cannot use the old one.

Solution: use something else than a CTTypesetter, or split the attributed string into segments of hard line-breaks.

- (void)wordWrapLineWithIndex:(int)index
{
    NSRange lineRange = [self rangeOfLineWithIndex:index];
    NSLog(@"Word wrapping on line:\"%@\"",[self.attributedString.string substringWithRange:lineRange]);

    CGRect insetBounds = CGRectInset([self bounds], MARGIN, MARGIN);
    CGFloat boundsWidth = CGRectGetWidth(insetBounds);

    // Calculate the lines
    CFIndex start = lineRange.location;
    CFIndex currentIndex = index;
    NSUInteger length = CFAttributedStringGetLength((__bridge CFAttributedStringRef)(self.attributedString));

    NSLog(@"Deleting the first line with an index of %li", currentIndex);
    [self deleteLineWithNumber:index];

    // This is very time-consuming, but reusing the old framesetter seem to cause trouble.
    CTTypesetterRef typesetter = CTTypesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(self.attributedString));
Anviking commented 11 years ago

Fixed (in this shape) with the abandonment core text.