• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
[[NSTextView textStorage] size] produces different results when called more than once
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[[NSTextView textStorage] size] produces different results when called more than once


  • Subject: [[NSTextView textStorage] size] produces different results when called more than once
  • From: Chris Giordano <email@hidden>
  • Date: Wed, 13 Aug 2003 18:32:49 -0400

I've been getting some strange behavior while attempting to get the size of the text storage (attributed string) of an NSTextView. Getting this value twice in succession, with no changes (or even no other code) in between can give different results in some instances. All that I have to do is send a size message to the NSTextView's textStorage twice and the second time I get a very different result.

I've pared things down to the following code which replicates the problem. On a whim (after lots of changes to try to eliminate the problem), I removed the final newline character and got two identical size values.

In any case, is this a hole in my understanding of the mechanisms in place, or am I correct in thinking that something's not right here? I'd guess it's my understanding. If that's the case, can someone kindly point out where that hole is and some documentation that could help me to start filling that hole with the appropriate knowledge?

thanks,
chris

-----------

(My test was compiled as follows with the results listed:

gcc -o ts_test -framework Foundation -framework Cocoa main.m
./ts_test

Results:
2003-08-13 18:24:17.270 ts_test[4197] Getting size two times:
2003-08-13 18:24:17.296 ts_test[4197] Sizes A:{609, 220} B:{4.5003e+06, 191} Equal?: No

)

## ------------------------
## main.m
## ------------------------

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>

int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * contentStr = @"Hello World\n"
@"There are so many things I'd like to do\n\n"
@"How shall I count the ways\n";
NSFont * bigFont = [NSFont fontWithName:@"Helvetica" size:36.0];
NSTextView * _textView = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 640.0, 480.0)];
NSSize s1, s2;

[_textView setUsesRuler:YES];
[_textView setRulerVisible:YES];
[_textView setString:contentStr];
[_textView setAlignment:NSCenterTextAlignment];

[[_textView textStorage] ensureAttributesAreFixedInRange:NSMakeRange(0, [[_textView textStorage] length])];

NSLog(@"Getting size two times:");
s1 = [[_textView textStorage] size];
s2 = [[_textView textStorage] size];
NSLog(@"Sizes A:%@ B:%@ Equal?: %@", NSStringFromSize(s1), NSStringFromSize(s2), NSEqualSizes(s1, s2) ? @"Yes" : @"No");

[pool release];
return 0;
}



*/
_______________________________________________
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.

  • Prev by Date: Re: Emulating NSColorPanel window behaviors
  • Next by Date: Re: scribbling
  • Previous by thread: Re: Emulating NSColorPanel window behaviors
  • Next by thread: (Possible OT) Localized variants
  • Index(es):
    • Date
    • Thread