How can I draw some text to an offscreen view and then print it? Looking for
a simple way to do this.
Details:
I have a bunch of NSTextFields in a window, the contents of which must be
printed. There is some other stuff in the window however, which I do not
want print with the text. Also the text must be repositioned for printing.
So, I decided the easiest way would be to copy the text from all of the
NSTextFields into an offscreen view, and then print that. But, I am running
into problems. Here is what I did:
1.. Created a very basic subclass of NSView.
2.. Instantiate this subclass from code using alloc/initwithframe.
3.. Attempt to lockfocus on this NSView, so that I can draw text to it.
This is where I run into problems. Upon calling lockfocus I am given the
message in Run Log: "lockfocus sent to a view whose window is deferred and
does not yet have a corresponding platform window".
Do I have to put the view in a window if I want to draw offscreen? This
means I will have to instantiate the window as well as hide it, which is
more complicated than I had intended. It looks like my other option is the
unpublished defaultGlyphForChar method, using NSBezierPath to draw the text.
Again, this is not as simple as I was looking for. Is there an easy way to
draw text offscreen?
> How can I draw some text to an offscreen view and then print it? Looking for
> a simple way to do this.
>
> Details:
>
> I have a bunch of NSTextFields in a window, the contents of which must be
> printed. There is some other stuff in the window however, which I do not
> want print with the text. Also the text must be repositioned for printing.
>
> So, I decided the easiest way would be to copy the text from all of the
> NSTextFields into an offscreen view, and then print that. But, I am running
> into problems. Here is what I did:
>
> 1.. Created a very basic subclass of NSView.
>
> 2.. Instantiate this subclass from code using alloc/initwithframe.
>
> 3.. Attempt to lockfocus on this NSView, so that I can draw text to it.
>
> This is where I run into problems. Upon calling lockfocus I am given the
> message in Run Log: "lockfocus sent to a view whose window is deferred and
> does not yet have a corresponding platform window".
Sounds like there's something screwy with your architecture. Why are you
calling lockfocus at all? Just have the NSView's drawRect method
describe what you want printed. m.
--
matt neuburg, phd = ma...@tidbits.com, http://www.tidbits.com/matt/
AppleScript: The Definitive Guide
http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
Read TidBITS! It's free and smart. http://www.tidbits.com