Height and location of text within a line in NSLayoutManager ignoring spacing?
Height and location of text within a line in NSLayoutManager ignoring spacing?
- Subject: Height and location of text within a line in NSLayoutManager ignoring spacing?
- From: Keith Blount <email@hidden>
- Date: Mon, 18 Feb 2008 04:25:43 -0800 (PST)
Hi,
I'm currently implementing "Show/hide invisibles" by overriding NSLayoutManager's - (void)drawGlyphsForGlyphRange:(NSRange)glyphRange atPoint:(NSPoint)containerOrigin method. If invisibles are turned on, I just check for control characters and draw them before calling super.
It's mostly working well, except for the fact that because my editor uses rich text, I have to take into account line spacing, line height multiple, paragraph space before and so forth. I've looked at other implementations (e.g. IDEKit) but none of them takes these things into consideration and so the invisibles get drawn in the wrong place as soon as you start playing with line heights and spacing.
I've tried several approaches but none of them give me exactly what I want. What I want to do is get it so that the invisibles are centred vertically between or next to the characters. All the methods I've tried are unsatisfactory. Namely:
- boundingRectForGlyphRange:effectiveRange: gives the whole bounding rect and provides no information about where within that bounding rectangle the baseline of the text may lie, or how high the actual text may be (I would need to centre the invisible between the baseline of the actual text and the top of the text). Thus, this can only be used if there is no spacing before or after or no line height multiple.
- lineFragmentRectForGlyphAtIndex:effectiveRange: in combination with -locationOfGlyphAtIndex: this is better and does give me the point at which the original glyph would be drawn. However, there seems to be no way to then offset this for the new character. If I call NSString's -sizeWithAttributes: on the control character I'm going to draw, I get padding above and below the character in that method and cannot find a way to offset that so that it will then get drawn at the right location.
- rectArrayForCharacterRange:... This works to an extent, as it gives you the area that would be selected, so you get the actual baseline and the height of the text. However, if there is a minimum line height or lineSpacing set in the paragraph style, this too doesn't match the actual height of the text.
I have also tried messing around with NSFont's -ascender and -descender values to no good effect as yet.
So, essentially, what I want is a way within -drawGlyphsForGlyphRange: to draw a string representing a control character so that it is vertically centred between the bottom and top of the actual text itself, ignoring the space above and below the text. I'm probably missing something obvious, or I probably just haven't hit on the exact combination of the above to do what I want, but either way I would be very grateful if somebody could point me in the right direction.
Many thanks and all the best,
Keith
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_______________________________________________
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