You can iterate through the line fragment positions using -[NSLayoutManager 
lineFragmentRectForGlyphIndex:effectiveRange:].

>From the line fragment origin, the baseline offset can be determine by using 
>-[NSTypesetter baselineOffsetInLayoutManager:glyphIndex:].

The typesetter can be obtained via -[NSLayoutManager typesetter].

Aki

On Sep 12, 2011, at 1:35 AM, Gerriet M. Denkmann wrote:

> 
> I have a subclass of NSTextView which does:
> 
> - (void)setUpData
> {
>       [ [ self textStorage ] setAttributedString: someAttributedString ];     
> //      uses self.usedFont 
>       NSLayoutManager *layoutManager = [ self layoutManager ]; 
>       baselineOffset = [ layoutManager defaultBaselineOffsetForFont: 
> self.usedFont ];
>       lineHeight = [ layoutManager defaultLineHeightForFont: self.usedFont ];
> }
> 
> 
> - (void)drawRect:(NSRect)dirtyRect
> {
>       [ super drawRect: dirtyRect ];
>       
>       for( NSUInteger line = 0; line < NBR_OF_LINES; line++ )
>       {
>               CGFloat bax = lineHeight * line + baselineOffset;
> 
>               [ [ NSColor blueColor ] set ];          //      base line
>               [ NSBezierPath  strokeLineFromPoint:    NSMakePoint( 
> NSMinX(dirtyRect), bax )  
>                                               toPoint:                        
>         NSMakePoint( NSMaxX(dirtyRect), bax ) 
>               ];
>       };
> }
> 
> This works, because currently all lines use the same font.
> 
> But how would I handle the more general case, where each line might contain 
> several and/or different fonts?
> 
> 
> Kind regards,
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/aki%40apple.com
> 
> This email sent to a...@apple.com

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to