slow text drawing
slow text drawing
- Subject: slow text drawing
- From: Simon Olsberg <email@hidden>
- Date: Fri, 21 Feb 2003 16:11:34 -0500
I am trying to look for ways to speed up text drawing for a
spreadsheet-type view in my application but do not seem to be getting
very good results.
I have abstracted the problem into the simple example below which draws
a series of random strings in a grid. If you size the window quite
large to about a grid of 20 x 40 or around 800 strings there is a
significant wait for the view to redraw - a couple of seconds.
I can't believe that this is the fastest that Cocoa can manage and
would appreciate any tips on how to speed things up. I have also tried
to use NSLayoutManager & NSTextStorage directly but this seems to do no
better.
I also tried using CoreGraphics function calls (i.e.
CGContextShowTextAtPoint) but was unable to get this to work so I don't
know if that would be a better approach - so any pointers on how to do
that would be great also.
Thanks
Simon Olsberg
/
************************************************************************
**********/
#import "TextTest.h"
#define LINE_HEIGHT 20
#define COL_WIDTH 50
#define X_INSET 5
#define Y_INSET 5
#define STRING_LEN 10
@implementation TextTest
- (id)initWithFrame:(NSRect)frameRect
{
[super initWithFrame:frameRect];
cell = [[NSTextFieldCell alloc] initTextCell:@""];
[cell setDrawsBackground:NO];
return self;
}
- (void)dealloc {
[cell release];
[super dealloc];
}
- (void)drawRect:(NSRect)rect
{
NSSize sz = [self frame].size;
long x = 0, y = 0;
while (y < sz.height)
{
x = 0;
while (x < sz.width)
{
char buf[STRING_LEN + 1];
short i;
for (i = 0; i < STRING_LEN; i++)
buf[i] = 33 + (90.0 * rand() / RAND_MAX);
buf[i] = 0;
[cell setStringValue:[NSString stringWithCString:buf]];
[cell drawInteriorWithFrame:NSMakeRect(x, y, COL_WIDTH -
X_INSET, LINE_HEIGHT - Y_INSET) inView:self];
x += COL_WIDTH;
}
y += LINE_HEIGHT;
}
}
- (void)mouseDown:(NSEvent *)theEvent
{
[self setNeedsDisplay:YES];
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.