discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNUstep app fails on Ubuntu 16 - found workaround


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,

Am 08.05.2020 um 20:00 schrieb Andreas Höschler <ahoesch@smartsoft.de>:

NSButtonCell.m
==================
- (NSSize) cellSize
{
...
 if (imageToDisplay)
   {
     imageSize = [imageToDisplay size];
     NSLog(@"cellSize imageSize %@", NSStringFromSize(imageSize));
   }
...
     case NSImageLeft:
     case NSImageRight:
       s.width = imageSize.width + titleSize.width + GSCellTextImageXDist;
       NSLog(@"imageSize.height %f titleSize.height %f", imageSize.height, titleSize.height);
       s.height = MAX(imageSize.height, titleSize.height);
       break;
...

 // Add border size
 s.width += border.left + border.right;
 NSLog(@"border.top %f border.bottom %f", border.top, border.bottom);
 s.height += border.top + border.bottom;
 NSLog(@"returning s %@", NSStringFromSize(s));
...
}


2020-05-08 19:58:14.729 SOObjectBrowser[14224:14224] cellSize imageSize {width = 15; height = 15}
2020-05-08 19:58:14.730 SOObjectBrowser[14224:14224] imageSize.height 15.000000 titleSize.height 10000000.000000
2020-05-08 19:58:14.730 SOObjectBrowser[14224:14224] border.top 0.000000 border.bottom 0.000000
2020-05-08 19:58:14.730 SOObjectBrowser[14224:14224] returning s {width = 18; height = 1e+07}
2020-05-08 19:58:14.730 SOObjectBrowser[14224:14224] Reporting button::imagePosition 2
2020-05-08 19:58:14.730 SOObjectBrowser[14224:14224] Reporting _cell::imagePosition 2
2020-05-08 19:58:14.730 SOObjectBrowser[14224:14224] Got height 10000004.000000. We correct this ...

The mess is caused by the titleSize!? :-( I haven't set a title since this is an image only button!

Now we are getting closer. But this is weird, The variable titleSize gets initialised with NSZeroSize and later only changed here


 if (titleToDisplay != nil)
   {
     titleSize = [titleToDisplay size];
   }

Could you add another NSLog line there and report the value of titleToDisplay? This looks like either a bug in our NSString drawing code or the compiler itself. We really need to get to the bottom of this. Fixing NSWindow is just a work around that won’t help you much.


  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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]