Re: Cocoa Text Handling Crashes
Re: Cocoa Text Handling Crashes
- Subject: Re: Cocoa Text Handling Crashes
- From: Andrew Thompson <email@hidden>
- Date: Tue, 7 Jan 2003 20:51:45 -0500
On Monday, Jan 6, 2003, at 21:38 America/New_York, Andrew Thompson
wrote:
To compensate, I've developed this class category for NSFont:
Just incase anyone browsing the archives decides to use this code (go
right ahead if you want to!)
I've changed the implementation a tiny bit.
- (BOOL) unicharIsRenderable: (unichar) a_char {
NSAttributedString *charString = [[NSAttributedString alloc]
autorelease];
[charString initWithString: [NSString stringWithCharacters: &a_char
length: 1]
attributes: [self makeFontDictionary]];
BOOL result = NO;
if ( charString != nil && ![@"" isEqual: charString] ) {
NSTextStorage *chars = [[NSTextStorage alloc]
initWithAttributedString: charString];
NSLayoutManager *man = [[NSLayoutManager alloc] init];
[chars addLayoutManager: man];
[man release]; //see [1]
if ( [man numberOfGlyphs] > 0 ) {
NSGlyph g = [man glyphAtIndex: 0];
//detect garbage glyphs, which have a bad habit of breaking
the layout system
result = [self glyphIsEncoded: g] && (g != NSNullGlyph) &&
[self advancementForGlyph: g].width != 0;
// !NSEqualRects([self boundingRectForGlyph: g],
NSZeroRect); <- cuts too much
}
[chars release];
}
return result;
}
As you can see I'm using advancementForGlyph: rather than
boundingRectForGlyph: because it seems to filter all of the bad
characters out pretty well. boundingRectForGlyph: was too eager. The
space character (ASCII 32) would be filtered, etc, and you probably
want to allow those.
AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside
(see you later space cowboy ...)
_______________________________________________
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.