Text System: NSRunStorage exception. Workaround Needed!
Text System: NSRunStorage exception. Workaround Needed!
- Subject: Text System: NSRunStorage exception. Workaround Needed!
- From: Dirk Theisen <email@hidden>
- Date: Mon, 05 Aug 2002 18:51:18 +0200 (Europe/Berlin)
Hello, Everybody, hello David!
I'm desparately seeking a solution or workaround for a problem with the
cocoa text system in Mac OS 10.1.5:
I've reduced the problem to just a few lines of the (slightly modified)
TextViewConfig Apple example code which is available here:
<
http://www.objectpark.org/Releases/OPTextViewConfig.tgz>
Whenever I create a new TextContainer (and view) and connect it to the
existing one (sharing a TextStorage and a LayoutManager), I get the
following Exception:
2002-08-05 18:13:35.169 TextViewConfig[5229] *** NSRunStorage,
_NSBlockNumberForIndex(): index (39) beyond array bounds (0)
The guts of the code looks like this (which is very similar to the one
in TextEdit, which seems to work):
- (void) addSlide {
unsigned i = [[layoutManager textContainers] count]+1;
NSTextContainer *textContainer = [[NSTextContainer alloc]
initWithContainerSize:NSMakeSize(SLIDE_WIDTH, SLIDE_HEIGHT)];
NSTextView *textView = [[NSTextView alloc]
initWithFrame:NSMakeRect(SLIDE_BORDER, SLIDE_BORDER + (NUM_SLIDES -
i) * (SLIDE_HEIGHT + SLIDE_BORDER), SLIDE_WIDTH, SLIDE_HEIGHT)
textContainer:textContainer];
[textView setHorizontallyResizable:NO];
[textView setVerticallyResizable:NO];
[layoutManager addTextContainer:textContainer];
[textContainer release];
[customView addSubview:textView];
[textView release];
}
In order to provoke the exception, scroll to the only slide on the
right, then enter enough text to fill the slide. The app now creates a
second slide. The above exception occurs.
After that, the system exhibits "funny" behaviour. Obviously the text
system is left in a "confused" state.
Has anybody had the same problem and a solution or workaround?
Any help welcome!
Greetings,
Dirk
Here is an old message I found in the archive. However, I was unable to
properly relate it to my problem. :-/
Date: Mon, 3 Apr 2000 20:18:20 +0200
From: email@hidden (Carsten Gehle)
To: email@hidden
Subject: Re: [BUG] NSTextView offsets
Message-ID: <email@hidden>
<flushleft><fontfamily><param>Helvetica</param>> 1. horizontal =
offset by 5 points
</fontfamily><fontfamily><param>Symbol</param>> =
[...]</fontfamily><fontfamily><param>Helvetica</param>
Check [NSTextConatiner lineFragmentPadding] , but beware of setting
the = line fragment padding to 0, because NSLayoutManager will have
some = problems if the last lines do not contain visible glyphs.
2. vertical head-room/offset
[...]
It seems that the line-height is the =20
only factor considered for calculating the top-offset.
Yes. You may want to subclass NSTypesetter and implement
- - (void)typesetterLaidOneGlyph:(NSTypesetterGlyphInfo *)gl;
BTW: You may be interested in the following things:
A)
[NSLayoutManager =
glyphIndexForPoint:inTextContainer:fractionOfDistanceThroughGlyph:]
[NSLayoutManager locationForGlyphAtIndex:]
Doc says: Performs glyph generation and layout if needed.
In fact it doesn't and may raise an exception if the view did not
draw = already:
</fontfamily><fixed><fontfamily><param>Courier</param> ***
NSRunStorage, = _NSBlockNumberForIndex(): index =
(</fontfamily><italic></italic></fixed><fontfamily><param>Times</param>las=
tIndex</fontfamily></flushleft><fixed><fontfamily><param>Courier</para
m>)
=
beyond array bounds (0)
</fontfamily></fixed><fontfamily><param>Helvetica</param>
Workaround: Calling -textContainerForGlyphAtIndex:effectiveRange: =
performs layout if the text storage contains any characters.
Otherwise = _recalculateUsageForTextContainerAtIndex: seems to work.
B)
[NSTextConatiner =
lineFragmentRectForProposedRect:sweepDirection:movementDirection:
remainingRect:]
NSLayoutManager crashes if any of it's text containers does not
contain = a single glyph (or character ?).
Workaround: Remove text containers from the layout manager which are =
completely hidden by something else.
Carsten
www.gehlesoftware.de
_______________________________________________
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.