Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Current context when not in drawRect:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Current context when not in drawRect:



Hi

I'm sure this must have come up, but I'm having trouble phrasing the question for Google, so I'd really appreciate some pointers.

I'm writing various functions at the moment that render pdf or images on the command-line. It's RubyCocoa, but the gist is code like

pdf_context = CGPDFContextCreateWithURL(pdf_url, rect, nil)		

CGPDFContextBeginPage(pdf_context, nil)
CGContextDrawImage(pdf_context, rect, image)

Now I'd like to be able to use, for example, NSAttributedString to paint text

aString = NSAttributedString.alloc.initWithString("Hello World")
aString.drawInRect(CGRectMake(100, 100, 100, 100))

If I do this, then all hell breaks loose, viz:

Wed Apr 22 09:48:09 Longjohn-2.local ruby[74313] <Error>: CGContextSetFillColorWithColor: invalid context
Wed Apr 22 09:48:09 Longjohn-2.local ruby[74313] <Error>: CGContextSetStrokeColorWithColor: invalid context
...
Wed Apr 22 09:48:09 Longjohn-2.local ruby[74313] <Error>: CGContextShowGlyphsWithAdvances: invalid context


I'm guessing that somewhere upstream of drawRect: in NSView et al, something sets a thread-local CGContext for NSAttributedString, NSImage etc to catch hold of when they want to draw. So how can I set my pdf_context for them to see?

Or have I got this completely wrong?

Thanks in anticipation

Duncan McGregor
www.VelOCRaptor.com - Simple Mac OCR

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.