Transparent NSTextView Performance

I have an NSWindow with NSImage and an NSTextView above it with long text http://www.gutenberg.org/cache/epub/100/pg100.txt , and if I draw a solid background, editing the text is quick.

But if I draw without a background, [self setDrawsBackground:NO]it is very slow.

Any updates? I also tried

  [self setDrawsBackground:YES];
    [self setBackgroundColor:[NSColor clearColor]];

Maybe with setBackgroundFilters from NSTextView?

Thank!

+1
source share
1 answer

I found a partial solution. If you disable the anti-aliased font, performance will improve significantly. You must first have a subclass of NSTextView. Then,

- (void)drawRect:(NSRect)dirtyRect
{
    [[NSGraphicsContext currentContext] setShouldAntialias:YES];
    CGContextSetShouldAntialias((CGContextRef)[[NSGraphicsContext currentContext] graphicsPort], YES);
    CGContextSetShouldSmoothFonts((CGContextRef)[[NSGraphicsContext currentContext] graphicsPort], NO);

    [super drawRect:dirtyRect];

    // Drawing code here.
}

Alternatively, you can use:

self.textview.layoutManager.allowsNonContiguousLayout = YES;

to improve performance a bit.

, , .

0

All Articles