NSTextView, bottom region of text missing in the view
NSTextView, bottom region of text missing in the view
- Subject: NSTextView, bottom region of text missing in the view
- From: Michael Hanna <email@hidden>
- Date: Thu, 11 Nov 2004 11:52:38 -0500
I have two NSTextViews that share an NSTextStorage. When my font setting is >13 or so for most plaintext files, there is data missing in the view(but nothing missing from the NSTextStorage). If I peer into the sizes of the NSTextView, NSTextContainer and NSTextStorage when I open the file, there is usually a discrepancy between the NSTextView height and the NSTextStorage height. I widen the NSTextContainer so that wider plaintext lines aren't CR'd to the next line. When I change the font in MyPreferences.m, I send a Notification from the changeFont: method.
my reading code goes like this(most snarfed from TextEdit):
<x-tad-smaller> </x-tad-smaller><x-tad-smaller>while</x-tad-smaller><x-tad-smaller> (</x-tad-smaller><x-tad-smaller>TRUE</x-tad-smaller><x-tad-smaller>) { </x-tad-smaller><x-tad-smaller>// We actually run through this once or twice, no more</x-tad-smaller><x-tad-smaller>
</x-tad-smaller><x-tad-smaller>BOOL</x-tad-smaller><x-tad-smaller> success;
NSSize theNewSize;
[myTopLayoutManager retain]; </x-tad-smaller><x-tad-smaller>// Temporarily remove layout manager so it doesn't do any work while loading</x-tad-smaller><x-tad-smaller>
[myBottomLayoutManager retain]; </x-tad-smaller><x-tad-smaller>// Temporarily remove layout manager so it doesn't do any work while loading</x-tad-smaller><x-tad-smaller>
[myDocumentTextStorage removeLayoutManager:myTopLayoutManager];
[myDocumentTextStorage removeLayoutManager:myBottomLayoutManager];
[myDocumentTextStorage beginEditing]; </x-tad-smaller><x-tad-smaller>// Bracket with begin/end editing for efficiency</x-tad-smaller><x-tad-smaller>
success = [myDocumentTextStorage readFromURL:url options:options documentAttributes:&docAttrs]; </x-tad-smaller><x-tad-smaller>// Read!</x-tad-smaller><x-tad-smaller>
[myDocumentTextStorage endEditing];
[myTopTextContainer setContainerSize:[myDocumentTextStorage size]];
[myBottomTextContainer setContainerSize:[myDocumentTextStorage size]];
[myDocumentTextStorage addLayoutManager:myTopLayoutManager]; </x-tad-smaller><x-tad-smaller>// Hook layout manager back up</x-tad-smaller><x-tad-smaller>
[myDocumentTextStorage addLayoutManager:myBottomLayoutManager]; </x-tad-smaller><x-tad-smaller>// Hook layout manager back up</x-tad-smaller><x-tad-smaller>
</x-tad-smaller><x-tad-smaller>//resize the text container so files with longer lines aren't CR'd</x-tad-smaller><x-tad-smaller>
theNewSize = [myBottomTextContainer containerSize];
theNewSize.width = [myDocumentTextStorage size].height;
[myBottomTextContainer setContainerSize:theNewSize];
[myTopTextContainer setContainerSize:theNewSize];
[myTopLayoutManager release];
[myBottomLayoutManager release];
NSLog(</x-tad-smaller><x-tad-smaller>@"***_readvisualfile: %@"</x-tad-smaller><x-tad-smaller>, [prompter visualPromptPath]);
NSLog(</x-tad-smaller><x-tad-smaller>@"[myBottomTextView bounds].size: h,w: %f, %f"</x-tad-smaller><x-tad-smaller>, [myBottomTextView bounds].size.height, [myBottomTextView bounds].size.width);
NSLog(</x-tad-smaller><x-tad-smaller>@"[myDocumentTextStorage size] h,w: %f, %f"</x-tad-smaller><x-tad-smaller>, [myDocumentTextStorage size].height, [myDocumentTextStorage size].width);
NSLog(</x-tad-smaller><x-tad-smaller>@"[myBottomTextContainer containerSize]h, w: %f, %f"</x-tad-smaller><x-tad-smaller>, [myBottomTextContainer containerSize].height, [myBottomTextContainer containerSize].width);
[...]
</x-tad-smaller>
after reading in a really large plaintext file, at Monaco 18:
2004-11-11 11:36:12.463 tab[6272] ***_readvisualfile: /Users/tao/Documents/goldeneye_agent_a.txt
2004-11-11 11:36:12.471 tab[6272] [myBottomTextView bounds].size: h,w: 515.000000, 783.000000
2004-11-11 11:36:12.868 tab[6272] [myDocumentTextStorage size] h,w: 18900.000000, 461.000000
2004-11-11 11:36:12.873 tab[6272] [myBottomTextContainer containerSize]h, w: 18900.000000, 18900.000000
approximately half is missing from the NSTextView.
the moment I choose a font in the standard font panel(my Preferences window is its' first responder), I send a notification to MyDocument, handleFontChange:.
<x-tad-smaller>- (</x-tad-smaller><x-tad-smaller>void</x-tad-smaller><x-tad-smaller>)handleFontChange:(NSNotification *)note
{
NSSize theNewSize;
NSFont *font = [note object];
[myBottomTextView setFont:font];
</x-tad-smaller><x-tad-smaller>//resize the text container, really wide</x-tad-smaller><x-tad-smaller>
theNewSize = [myBottomTextContainer containerSize];
theNewSize.width = [myDocumentTextStorage size].height;
theNewSize.height = [myDocumentTextStorage size].height;
[myBottomTextContainer setContainerSize:theNewSize];
[myTopTextContainer setContainerSize:theNewSize];
NSLog(</x-tad-smaller><x-tad-smaller>@"***handleFontChange:"</x-tad-smaller><x-tad-smaller>);
NSLog(</x-tad-smaller><x-tad-smaller>@"[myBottomTextView bounds].size: h,w: %f, %f"</x-tad-smaller><x-tad-smaller>, [myBottomTextView bounds].size.height, [myBottomTextView bounds].size.width);
NSLog(</x-tad-smaller><x-tad-smaller>@"[myDocumentTextStorage size] h,w: %f, %f"</x-tad-smaller><x-tad-smaller>, [myDocumentTextStorage size].height, [myDocumentTextStorage size].width);
NSLog(</x-tad-smaller><x-tad-smaller>@"[myBottomTextContainer containerSize]h, w: %f, %f"</x-tad-smaller><x-tad-smaller>, [myBottomTextContainer containerSize].height, [myBottomTextContainer containerSize].width);
[...]</x-tad-smaller>
the numbers seem to reflect the problem I'm seeing where about half the document is missing from the bottom, since the NSTextView is height 18900 and the NSTextStorage is height 37800(see below). I changed the font to Monaco 24.
When calling -setBoundsSize: on the NSTextView, and -setNeedsRedisplay:YES, and sending it the size of the NSTextStorage, it just seems to stretch/warp the text rather than matching it up.
2004-11-11 11:39:41.761 tab[6290] ***handleFontChange:
2004-11-11 11:39:41.785 tab[6290] [myBottomTextView bounds].size: h,w: 18900.000000, 783.000000
2004-11-11 11:39:42.281 tab[6290] [myDocumentTextStorage size] h,w: 37800.000000, 1137.785034
2004-11-11 11:39:42.295 tab[6290] [myBottomTextContainer containerSize]h, w: 37800.000000, 37800.000000
2004-11-11 11:39:42.309 tab[6290] Sent Notification TAOFontChanged
Sometimes even, the numbers do appear OK, but the truncation still occurs. For instance if I set the font to Monaco 12, the NSTextView is smaller than the NSTextStorage, but 1/3 of the text is missing in the view:
2004-11-11 11:48:58.823 tab[6308] ***handleFontChange:
2004-11-11 11:48:58.844 tab[6308] [myBottomTextView bounds].size: h,w: 18899.000000, 783.000000
2004-11-11 11:48:59.467 tab[6308] [myDocumentTextStorage size] h,w: 18900.000000, 553.000000
2004-11-11 11:48:59.489 tab[6308] [myBottomTextContainer containerSize]h, w: 18900.000000, 18900.000000
2004-11-11 11:48:59.515 tab[6308] Sent Notification TAOFontChanged
Any ideas on what I'm missing here?
Note: I've set up my text system as in figure 4 in "Common Configurations" in the documentation.
regards,
Michael
_______________________________________________
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