Fix string drawing based on Apple functionality

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@40214 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2016-11-10 23:11:43 +00:00
parent 056c24bf98
commit 37b37b1558

View file

@ -450,8 +450,28 @@ glyphs to be drawn upside-down, so we need to tell NSFont to flip the fonts.
- (void) drawInRect: (NSRect)rect
{
[self drawWithRect: rect
options: NSStringDrawingUsesLineFragmentOrigin];
NSAttributedString *attrstring = self;
// Redo string to fit in rectangle...
// Apple drawing does this by default...
NSSize titleSize = [self size];
if (titleSize.width > rect.size.width && [self length] > 4)
{
{
attrstring = [[self mutableCopy] autorelease];
//unichar ell = 0x2026;
NSString *ellipsis = @"...";
do
{
NSRange replaceRange = NSMakeRange(([attrstring length] / 2)-2, 4);
[(NSMutableAttributedString *)attrstring replaceCharactersInRange:replaceRange withString:ellipsis];
} while ([attrstring length] > 4 && [attrstring size].width > rect.size.width);
}
}
[attrstring drawWithRect: rect options: NSStringDrawingUsesLineFragmentOrigin];
}
- (void) drawWithRect: (NSRect)rect