Re: Problem getting subclass of NSTextContainer working
Re: Problem getting subclass of NSTextContainer working
- Subject: Re: Problem getting subclass of NSTextContainer working
- From: Gordon Apple <email@hidden>
- Date: Sat, 10 May 2008 15:38:32 -0500
One thing it doesn't do for you is keep track of the earlier rect
heignts on the same line, as I showed at <www.ed4u.com/textflow>. You have
to keep track of that yourself to keep it from overwriting itself on the
next line.
Here is part of my solution. Note that it still doesn't line up the
baselines in the correct place. You have to have the ability to backtrack
to the beginning of the line to do that, and I don't know how to do it yet.
This code also solves the problem of the layout balking when it encounters a
space too narrow for any text. It keeps moving down until it either finds a
wide enough space or hits the end of the container. There is also some
logic that determines when you are starting a new line. "prMaxY" keeps
track of the max segment height on the line.
- (NSRect)myLineFragmentRectForProposedRect:(NSRect)proposedRect
sweepDirection:(NSLineSweepDirection)sweepDirection
movementDirection:(NSLineMovementDirection)movementDirection
remainingRect:(NSRectPointer)remainingRect
{
// This routine is necessary due to having to iteratively find a
viable text line to return
r = proposedRect;
pr = proposedRect;
prMaxY = r.origin.y + r.size.height;
prMinY = r.origin.y;
[xa clear]; // Dump any previous ranges.
int n = [spa count];
int i;
for(i = 0; i < n; i++) {
SubpathInfo* info = [spa objectAtIndex:i];
// [spa element:&info
// atIndex:i];
NSRect test = info -> bounds;
test.origin.x = pr.origin.x;
if(EDIntersectsRect(test, pr)) {
[self ClipSubpathToRectHeight:info -> subpath];
[self determineXRanges];
}
}
[self clipToXRange];
*remainingRect = rr;
return r;
}
- (NSRect)lineFragmentRectForProposedRect:(NSRect)proposedRect
sweepDirection:(NSLineSweepDirection)sweepDirection
movementDirection:(NSLineMovementDirection)movementDirection
remainingRect:(NSRectPointer)remainingRect
{
if(!hasContainer) // Nothing to do here
return [super lineFragmentRectForProposedRect:proposedRect
sweepDirection:sweepDirection
movementDirection:movementDirection
remainingRect:remainingRect];
float increment = proposedRect.size.height / 2;
NSRect myProposedRect = proposedRect;
NSRect myRect;
// *********************************************
// *** Workaround for areas of container that aren't wide enough
// *** to contain text and where the layout manager balks
while(1) {
// Keep moving down until a viable range is found or we hit bottom
// (Why the hell doesn't the LayoutManager do this?)
myRect = [self myLineFragmentRectForProposedRect:myProposedRect
sweepDirection:sweepDirection
movementDirection:movementDirection
remainingRect:remainingRect];
if(myRect.size.width < minWidth &&
(myProposedRect.origin.y + myProposedRect.size.height) < [self
containerSize].height)
myProposedRect = NSOffsetRect(myProposedRect, 0, increment);
else break; // Our exit cue
}
> Thanks Kyle, that seems to be the correct interpretation - my code is
> working great now.
>
> If anyone's interested in this, I can post the code here if requested.
>
>
> G.
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden