Re: how to get baseline info
Re: how to get baseline info
- Subject: Re: how to get baseline info
- From: Aki Inoue <email@hidden>
- Date: Mon, 12 Sep 2011 15:50:03 -0700
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 (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden