In windowWillUseStandardFrame:defaultFrame: in a subclass of NSDocument (which 
is also the delegate of it's window) I want to set the window to just contain a 
certain line.

- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender 
defaultFrame:(NSRect)defaultFrame
{
        //      myTextView is an NSTextView inside a scroll view, which is the 
sole window content

        NSString *mySpecialLine = @"... something...";
        NSDictionary *typingAttributes = [ myTextView typingAttributes ];
        NSFont *typingFont = [ typingAttributes objectForKey: 
NSFontAttributeName ];

        NSSize oneSize = [ mySpecialLine sizeWithAttributes: typingAttributes 
];        
        //      this does not work - it always uses printer fonts even if 
myTextView does not.

        //      so I tried:
        NSLayoutManager *layoutManager = [ myTextView layoutManager ] ;
        BOOL usesScreenFonts = [ layoutManager usesScreenFonts ];
        NSStringDrawingOptions options = NSStringDrawingOneShot; 
        if ( !usesScreenFonts ) options |= 
NSStringDrawingDisableScreenFontSubstitution; 
        NSRect oneRect = [ mySpecialLine boundingRectWithSize: 
NSMakeSize(9999,99) options: options attributes: typingAttributes ]; 
        //      but I still get the metrics of the printer font.

        CGFloat lineWidth = ...
        //      but even when I get the length of mySpecialLine I have to add a 
magic value of 10 to get the appropriate frame size of myTextView
        CGFloat textExtra = 10; //      ???

        //      then there is some difference between window.frame.size.width 
and myTextView (this is not a problem)
        NSRect  textFrame = [ theText frame ];
        CGFloat windowExtra = winFrame.size.width - textFrame.size.width;

        newWindowRect.size.width = lineWidth + textExtra + windowExtra; 
        return newWindowRect;
}

How to get the size of mySpecialLine with screen fonts?
How do I avoid hardcoding a special value of 10? 

10.8, but should work on 10.7.4 as well.

Gerriet.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to