NSATSTypesetter garbled text when switching to next container
NSATSTypesetter garbled text when switching to next container
- Subject: NSATSTypesetter garbled text when switching to next container
- From: Ross Carter <email@hidden>
- Date: Mon, 28 Aug 2006 18:46:46 -0400
To implement a custom text attribute specifying that a paragraph
should start on a new page, I implemented this override in
NSATSTypesetter:
- (void)getLineFragmentRect:(NSRectPointer)lineFragmentRect
usedRect:(NSRectPointer)lineFragmentUsedRect
remainingRect:(NSRectPointer)remainingRect
forStartingGlyphAtIndex:(unsigned)startingGlyphIndex
proposedRect:(NSRect)proposedRect
lineSpacing:(float)lineSpacing
paragraphSpacingBefore:(float)paragraphSpacingBefore
paragraphSpacingAfter:(float)paragraphSpacingAfter {
// Call super first:
[super getLineFragmentRect:(NSRectPointer)lineFragmentRect
usedRect:(NSRectPointer)lineFragmentUsedRect
remainingRect:(NSRectPointer)remainingRect
forStartingGlyphAtIndex:(unsigned)startingGlyphIndex
proposedRect:(NSRect)proposedRect
lineSpacing:(float)lineSpacing
paragraphSpacingBefore:(float)paragraphSpacingBefore
paragraphSpacingAfter:(float)paragraphSpacingAfter];
// the ivar startOnNewPage was set in beginParagraph:
if (startParaOnNewPage && [self paragraphGlyphRange].location ==
startingGlyphIndex) {
// It might already be on a new page:
if (lineFragmentRect->origin.y > 0.001) {
// Reset origin so text will draw at top of page:
lineFragmentRect->origin.y = 0.0;
if (currentTextContainer == [[self textContainers] lastObject]) {
currentTextContainerIndex = NSNotFound;
currentTextContainer = nil;
currentTextContainerSize = NSZeroSize;
} else {
currentTextContainerIndex++;
unsigned indexOfOldTC = [[self textContainers]
indexOfObjectIdenticalTo:currentTextContainer];
currentTextContainer = [[self textContainers]
objectAtIndex:indexOfOldTC + 1];
currentTextContainerSize = [currentTextContainer containerSize];
}
}
}
}
This works fine for the paragraph that starts on the new page, but
the text of page preceding the jump becomes garbled if I scroll
quickly. Some glyphs don't appear, and others appear but are
overwritten by the glyphs that are drawn on the subsequent page.
Moving the insertion point on that preceding page will fix about two
lines of text at a time.
Aki, I hope you're reading this! At WWDC you said that I should talk
to you if I run into a bug using this approach. Is this the bug?
Any suggestions appreciated.
Ross
_______________________________________________
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