bugGNUstep - Bugs: bug #21696, [NSText sizeToFit] resizes only to...

Group
 
 

bug #21696: [NSText sizeToFit] resizes only to include the first character

Submitter:  Christopher Wojno <wojno>
Submitted:  Sun 02 Dec 2007 03:08:09 AM UTC
   
 
Category:  Gui/AppKit Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  FredKiefer
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 04 Jan 2008 09:04:10 PM UTC, comment #2: 

I added some code to SVN that should fix this problem. Please test it an report back.

Fred Kiefer <FredKiefer>
Group Member
Thu 27 Dec 2007 04:30:45 PM UTC, comment #1: 

I spend some time tracking down this problem and as far as I can tell it is caused by GSHorizontalTypesetter. There in the method layoutLineNewParagraph: we get a rectangle for the next set of glyphs and this is already limited by the text container size. In our case the text container has a size of (1, 15) and we and up with an almost empty rectangle to layout into.
What happens is that the first character already overlaps and it tries to break the line. As this fails the rest of the characters as set to invisible and a wrong rectangle gets computed.

I don't have a glue how to solve this. One way would be to already report the text container size differently, when it is resizesable. Or use this information in some other way here. But the whole code looks rather fragile and I dare not touch it.

Fred Kiefer <FredKiefer>
Group Member
Sun 02 Dec 2007 03:08:09 AM UTC, original submission:  

Similar to bug #21695, however, while I claimed Horizontal worked, it changed the size only such that the first character in the string sent to the NSText by setString is sized. The remainder of the string is clipped.

NSText *text;
text = [[NSText alloc] initWithFrame:NSMakeRect(0,0,1,15)];
[text setHorizontallyResizable:YES];
[text setVerticallyResizable:NO]; // fails with this YES or NO
[text setFont:[NSFont fontWithName:@"Helvetica" size:10]];
[text setString: @"Menu"];
[text sizeToFit];
NSRect bad = [text frame];

Result:
12 = bad.size.width

One may think that a work-around would be to manually set the frame after multiplying it. This is not the case: Twelve pixes is APPROXIMATELY 1/4th the size as the string is 4 characters. But that is only an estimation and exact only with Monospaced fonts. Additionally, attempts to set the width AFTER a sizeToFit call have not effect.

Summary:

  • Resized incorrectly (wrong width)
  • Cannot manually set width later (by design?)
Christopher Wojno <wojno>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by FredKiefer (Posted a comment)
  • -email is unavailable- added by wojno (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2008-11-29 FredKiefer StatusReady For Test Fixed
        Open/ClosedIn Test Closed
    2008-01-04 FredKiefer StatusNone Ready For Test
        Assigned toNone FredKiefer
        Open/ClosedOpen In Test

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code