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!
Each view is either flipped or not. I assume you are using a custom view subclass; in that case, you can implement -(BOOL)isFlipped to return YES or NO depending on whether you want your view to be flipped. It affects the global behavior of your view's coordinate system, so consider it carefully. For views that display text in top-to-bottom lines, the flipped orientation is much more natural, and in fact direct drawing with NSLayoutManager expects it. You can, however, use an NSAffineTransform if necessary, to temporarily flip the coordinate system so that you can use NSLayoutManager to draw in an unflipped view.
Alternatively, you can use the simpler string drawing methods to display your text. The difference is that if you retain an NSLayoutManager, it preserves the layout information about your text, which can have performance advantages if the same text is being drawn repeatedly. See the Worm example for more information. For most casual drawing of text, however, the string drawing methods are more convenient, and I would recommend using them until and unless you determine that they are a performance bottleneck in your particular application.
Douglas Davidson
|