Re: layoutManager drawGlyphs is moving lines up? (WAS: Watch for overflow when drawing...)
Re: layoutManager drawGlyphs is moving lines up? (WAS: Watch for overflow when drawing...)
- Subject: Re: layoutManager drawGlyphs is moving lines up? (WAS: Watch for overflow when drawing...)
- From: Justin Hawkwood <email@hidden>
- Date: Thu, 23 Jun 2005 14:36:55 -0700
I resolved this issue by calling drawInRect: on the attributedString
from the glyphRange of the textContainer, and not using
drawGlyphsForGlyphRange:atPoint: at all. Here is some code from the
workaround:
layoutManager = [[[textStorage layoutManagers] lastObject]
retain];
glyphRange = [layoutManager glyphRangeForTextContainer:
[[layoutManager
textContainers] objectAtIndex:0]];
strRange = [layoutManager
characterRangeForGlyphRange:glyphRange actualGlyphRange:nil];
usedH = multH * [layoutManager usedRectForTextContainer:
[[layoutManager textContainers]
objectAtIndex:0]].size.height;
pRect = NSMakeRect(mLeft, (mBottom + 58.0 + (restH * 0.6) -
tRectH - usedH), mWidth, usedH);
[[textStorage attributedSubstringFromRange:strRange]
drawInRect:pRect];
~ Justin
On Jun 22, 2005, at 6:02 PM, Justin Hawkwood wrote:
I have a textStorage that I am trying to display during the
drawRect function of an NSView (for printing). The documentation
gives an example of using the NSLayoutManager's function
"drawGlyphsForGlyphRange:atPoint:" but when I do this the lines
print from bottom to top. The documentation also said that it will
expect a flipped view, but I cannot figure out how to flip the
NSView, or correct this some other way. I also tried using an
NSTextView, but I could not get it to display at all!
Suggestions? Help?
~ Justin
On Jun 13, 2005, at 8:27 PM, Fritz Anderson wrote:
On 13 Jun 2005, at 9:56 PM, Justin Hawkwood wrote:
I have an NSString that I would like to draw (using drawInRect:
withAttributes:?) to an NSView for printing. As this string was
entered using a NSTextView, it could be very long, and I want to
know if it overflows the rect that I set it to draw in, and if so
where in the string it was clipped, so that I can continue the
rest of the string on an other page (rinse and repeat).
PLUS how to do this in pre-10.3?
Once you get into measuring text layouts and multiple text
containers, you are officially out of the realm of NSString
convenience methods, and into NSLayoutManager and NSTextContainer.
Stop for a couple of hours and learn the Cocoa text stack.
You want to read: <http://developer.apple.com/documentation/Cocoa/
Conceptual/TextLayout/index.html>.
Possible prerequisite: <http://developer.apple.com/documentation/
Cocoa/Conceptual/TextArchitecture/index.html>
Examples at /Developer/Examples/TextEdit and /Developer/Examples/
TextSizingExample
I'm sorry, but your head will hurt for a little while
(technically, it _is_ brain damage...), but it's the only way to
do everything you say you want to do.
-- F
_______________________________________________
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