Text drawing question
Text drawing question
- Subject: Text drawing question
- From: Andrew Merenbach <email@hidden>
- Date: Sun, 12 Dec 2004 01:11:14 -0800
I've been looking for a way to get an NSAttributedString into a
perfectly-sized, alpha-channel NSImage--that is, one without any blank
rows or columns. I'm able to get the string drawn into an image, and
some sample code from Apple
(http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/
Tasks/StringHeight.html), with a slight modification for
NSAttributedStrings, seems to do the trick for giving me a size for my
text.
I for some reason, though, am unable to easily combine the two. I
initialise my image with the proper size, but when I use drawInRect:,
with the rectangle returned by my method, it does not position the text
properly. I have found, to my chagrin, that since -[NSLayoutManager
usedRectForTextContainer:] will return a zero origin (since I'm
measuring a rectangle to encompass all of my text, and the text is
measured in a new text container), I have a hard time knowing where to
draw my text.
Maybe this is a chicken-and-egg thing: if I knew where to position my
text when drawing within the NSImage, I might not need to do a
calculation for the drawn real text height in the first place.
I've tried various combinations of NSLayoutManager methods, such as
lineFragmentRectForGlyphAtIndex: and
lineFragmentUsedRectForGlyphAtIndex:, not to mention
boundingRectForGlyphRange:inTextContainer:, and even
attachmentSizeForGlyphAtIndex:, and have managed to get only some of
them working. Although a Cocoa programmer for several years, I am, as
must be quite obvious, new to such typesetting and text layout system
methods.
How might I achieve what I am trying to do? Is there a more
elegant/novel/efficient way to draw text to an NSImage without any
blank surrounding space (unused ascender, descender, and other metric
spaces being considered 'blank')?
Cheers,
Andrew
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden