I've been trying to make a program using a function to draw to a context
that it is passed to render a custom view. I'd also like to be able to use
the same function that draws into the window to draw into a PDF.
At the moment the drawing is done by importing Quartz, and drawing into the
view's context using commands like
This works fine when I call it in my subclass of NSView, but when I try to
draw into a PDF it doesnt work properly.
Looking at this page:
I would have assumed that all you have to do is create a context for your
PDF, and then I could draw into it as usual using my generic drawing
function that renders the custom view.
However looking at the example file in
/Developer/Examples/Quartz/Python/circle.py, they use CoreGraphics, and seem
to be using a different calling style to call the drawing functions.
from CoreGraphics import *
import math # for pi
pageRect = CGRectMake (0, 0, 612, 792) # landscape
c = CGPDFContextCreateWithFilename ("circle.pdf", pageRect)
I have tried using this, and inserting my code using 'c' as the context, but
it does not work properly and gives the error:
2007-12-14 00:30:21.515 Python[992:613] <type 'exceptions.TypeError'>:
depythonifying struct, got no sequence
I don't understand what the difference between using CoreGraphics and Quartz
is, and why the calling conventions are different.
Do I need to use Quartz to create the PDF instead of CoreGraphics? Or do i
need to rewrite my custom view using importing coregraphics instead of
quartz? Why is the calling convention different? (the Quartz code I used for
the custom view I took from the dotView example is similar to the function
calls in the objective-C pdf creation example, whereas on the apple Quartz
2D python bindings page it is like the example above)
Any help would be much appreciated!
Get latest updates about Open Source Projects, Conferences and News.