RE: NSTextView and layout manager or cells - how to be most efficient?
RE: NSTextView and layout manager or cells - how to be most efficient?
- Subject: RE: NSTextView and layout manager or cells - how to be most efficient?
- From: Keith Blount <email@hidden>
- Date: Wed, 27 Apr 2005 02:29:46 -0700 (PDT)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Many thanks to both of you for your replies (sorry it
has taken a few days to thank you - I've only just got
back to this part of my app.)
I have followed your suggestions, and now instead of
having a simple NSString as an instance variable, my
note objects have an NSTextStorage. On initialisation,
I create a text container and layout manager and have
the text storage own these, rather than having to use
the shared layout manager. I'm not 100% sure this is
any faster than using the shared layout manager (the
shared layout manager was created using the code from
the Sketch example), but at least things are faster
than in my old implementation that used lots of text
views. A document with 200 notes (and it's highly
unlikely a real user will ever have as many notes) now
loads in about 4-5 seconds, whereas it used to take
about 8-10. I'd still like to speed things up further,
but maybe that's not going to happen on my G4 1Ghz
machine...
Thanks again,
Keith
---FROM : John Brownlow---
DATE : Fri Apr 22 19:28:11 2005
> For some reason this didn't make it to the list
> yesterday BUT..
>
> The slow line in your routine is the one that forces
> the layout manager
> to recalculate the layout. You should only do this
> for notes whose text
> has changed. That means you will either have to have
> a layout manager
> and text storage for each note, or find a way of
> caching the glyph info
> for each note so the shared layout manager can use
> it.
>
> If you do this it will be waaaaay faster.
--- Martin <email@hidden> wrote:
>
> On April 21 2005, Keith Blount
> <email@hidden> wrote:
>
> >I am convinced that getting the note objects to be
> able to
> >draw themselves is the best route rather than using
> >cells, but that means trying to get my
> >sizeWithWidth:attributes: method, below, to work
> >faster, as this has to be called on every note
> object
> >when the view is loaded.
>
>
> Have you considered having each of your note objects
> maintain their own layout manager and text storage?
> This would not do much to reduce the time required
> for the initial load, but subsequent layout cycles
> (and drawing) will be faster.
>
> ~Martin
>
>
>
FROM : Keith Blount
DATE : Thu Apr 21 17:27:14 2005
Sorry to reply to my own post, but I'm still
struggling with this. Having played with it more, I am
convinced that getting the note objects to be able to
draw themselves is the best route rather than using
cells, but that means trying to get my
sizeWithWidth:attributes: method, below, to work
faster, as this has to be called on every note object
when the view is loaded.
Can anyone see a way to make the following method
faster? The idea is that these note objects look just
like a text view, as I will be using a shared text
view to edit them...
Many thanks to anybody who has the time to look at
this,
Keith
// Returns the size with the specified width required
to draw the note's string with the given attributes.
- (NSSize)sizeWithWidth:(float)width
attributes:(NSDictionary *)attributes
{
if ([string length] > 0)
{
NSTextStorage *contents = [[NSTextStorage
alloc]
initWithString:string attributes:attributes];
NSLayoutManager *lm =
sharedDrawingLayoutManager();
NSTextContainer *tc = [[lm textContainers]
objectAtIndex:0];
NSRange glyphRange;
NSSize requiredSize;
[tc
setContainerSize:NSMakeSize(width,FLT_MAX)];
[contents addLayoutManager:lm];
// Force layout of the text and find out how
much of it fits in the container
glyphRange = [lm
glyphRangeForTextContainer:tc];
if (glyphRange.length>0)
{
requiredSize = [lm
usedRectForTextContainer:tc].size;
requiredSize.width = width; // Set width
regardless
of used rect
}
else
requiredSize = NSZeroSize;
[contents removeLayoutManager:lm];
[contents release];
return requiredSize;
}
else
return NSZeroSize;
}
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden