Re: Invisible Characters & Specifying Their "Width"
Re: Invisible Characters & Specifying Their "Width"
- Subject: Re: Invisible Characters & Specifying Their "Width"
- From: Seth Willits <email@hidden>
- Date: Thu, 2 Nov 2006 22:23:42 -0800
On Nov 2, 2006, at 7:48 PM, Martin Wierschin wrote:
But with many invisible characters (like, all others - the null
character for example), they have no width at all, so drawing a
character at the location where they normally would be just draws
on top of the next character.
You'll want to create an NSTypesetter subclass that overrides:
- actionForControlCharacterAtIndex:
- boundingBoxForControlGlyphAtIndex:etc:
If its idea of a control glyph is different than your own, then
you'll have to look to modifying the NSGlyphGenerator.
Hmmm....
Well, like Dominik (http://www.cocoabuilder.com/archive/message/cocoa/
2006/4/10/160743), I don't see any layout change, but the methods are
being called appropriately.
NSTypesetter subclass:
- (NSTypesetterControlCharacterAction)
actionForControlCharacterAtIndex:(unsigned)charIndex;
{
CFStringInlineBuffer *buffer = [(CCTextStorage *)[[self
layoutManager] textStorage] buffer];
unichar c = ' ';
c = CFStringGetCharacterFromInlineBuffer(buffer, charIndex);
if (c == ' ' || c == '\n' || c == '\r' || c == '\t') {
} else if (c < 0x20 || (0x007f <= c && c <= 0x009f) ||
[[NSCharacterSet illegalCharacterSet] characterIsMember:c]) {
return NSTypesetterWhitespaceAction;
}
return [super actionForControlCharacterAtIndex:charIndex];
}
- (NSRect)boundingBoxForControlGlyphAtIndex:(unsigned)glyphIndex
forTextContainer:(NSTextContainer *)tc proposedLineFragment:(NSRect)
proposedRect glyphPosition:(NSPoint)glyphPosition characterIndex:
(unsigned)charIndex
{
NSRect rect;
rect.origin = glyphPosition;
rect.size.height = proposedRect.size.height;
NSDictionary * attributes = [[self attributedString]
attributesAtIndex:charIndex effectiveRange:NULL];
rect.size.width = [@"W" sizeWithAttributes:attributes].width;
//NSLog(@"%@", NSStringFromRect(rect));
return rect;
}
I guess I'll have to try the glyph generator...?
--
Seth Willits
_______________________________________________
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