|
From: | Andreas Höschler |
Subject: | Re: GNUstep app fails on Ubuntu 16 - found workaround |
Date: | Fri, 8 May 2020 22:53:59 +0200 |
Hi Fred,
NSLog(@"titleToDisplay %@", titleToDisplay); if (titleToDisplay && ipos != NSImageOnly) { titleSize = [titleToDisplay size]; NSLog(@"first %@", NSStringFromSize(titleSize)); } else { // When there is no text to display, ignore it in the calculations titleToDisplay = nil; ipos = NSImageOnly; } NSLog(@"final %@", NSStringFromSize(titleSize));
This produces: 2020-05-08 22:26:32.671 SOObjectBrowser[16581:16581] titleToDisplay 2020-05-08 22:26:32.671 SOObjectBrowser[16581:16581] first {width = 1; height = 1e+07} 2020-05-08 22:26:32.671 SOObjectBrowser[16581:16581] final {width = 1; height = 1e+07} It seems [NSAttributedString size] has a problem!? pico ./Source/NSStringDrawing.m - (NSSize) size { NSRect usedRect = [self boundingRectWithSize: NSZeroSize options: NSStringDrawingUsesLineFragmentOrigin]; return usedRect.size; } - (NSRect) boundingRectWithSize: (NSSize)size options: (NSStringDrawingOptions)options { // FIXME: This ignores options cache_t *c; NSRect result = NSZeroRect; BOOL hasSize = !NSEqualSizes(NSZeroSize, size); cache_lock(); NS_DURING { prepare_attributed_string(self); c = cache_lookup(hasSize, size, YES); result = c->usedRect; } NS_HANDLER { cache_unlock(); [localException raise]; } NS_ENDHANDLER; cache_unlock(); return result; } I did the following: - (NSSize) size { if ([self length] == 0) return NSZeroSize; // <-- inserted this NSRect usedRect = [self boundingRectWithSize: NSZeroSize options: NSStringDrawingUsesLineFragmentOrigin]; return usedRect.size; } - (NSSize) sizeWithAttributes: (NSDictionary *)attrs { if ([self length] == 0) return NSZeroSize; // <-- inserted this NSRect usedRect = [self boundingRectWithSize: NSZeroSize options: NSStringDrawingUsesLineFragmentOrigin attributes: attrs]; return usedRect.size; } Problem gone!! :-) Regards, Andreas |
[Prev in Thread] | Current Thread | [Next in Thread] |