Maintain backwards compatibility with python < 2.3 by dynamically
[python/dscho.git] / Mac / Modules / cg / _CGmodule.c
blob3bc114c82b164e6a0250a7ebf1b612c4d02fcf26
2 /* =========================== Module _CG =========================== */
4 #include "Python.h"
8 #ifdef _WIN32
9 #include "pywintoolbox.h"
10 #else
11 #include "macglue.h"
12 #include "pymactoolbox.h"
13 #endif
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
19 return NULL; \
20 }} while(0)
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <Quickdraw.h>
25 #include <CGContext.h>
26 #else
27 #include <ApplicationServices/ApplicationServices.h>
28 #endif
30 #if !TARGET_API_MAC_OSX
31 /* This code is adapted from the CallMachOFramework demo at:
32 http://developer.apple.com/samplecode/Sample_Code/Runtime_Architecture/CallMachOFramework.htm
33 It allows us to call Mach-O functions from CFM apps. */
35 #include <Folders.h>
36 #include "CFMLateImport.h"
38 static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr)
39 // This routine finds a the named framework and creates a CFBundle
40 // object for it. It looks for the framework in the frameworks folder,
41 // as defined by the Folder Manager. Currently this is
42 // "/System/Library/Frameworks", but we recommend that you avoid hard coded
43 // paths to ensure future compatibility.
45 // You might think that you could use CFBundleGetBundleWithIdentifier but
46 // that only finds bundles that are already loaded into your context.
47 // That would work in the case of the System framework but it wouldn't
48 // work if you're using some other, less-obvious, framework.
50 OSStatus err;
51 FSRef frameworksFolderRef;
52 CFURLRef baseURL;
53 CFURLRef bundleURL;
55 *bundlePtr = nil;
57 baseURL = nil;
58 bundleURL = nil;
60 // Find the frameworks folder and create a URL for it.
62 err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
63 if (err == noErr) {
64 baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
65 if (baseURL == nil) {
66 err = coreFoundationUnknownErr;
70 // Append the name of the framework to the URL.
72 if (err == noErr) {
73 bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false);
74 if (bundleURL == nil) {
75 err = coreFoundationUnknownErr;
79 // Create a bundle based on that URL and load the bundle into memory.
80 // We never unload the bundle, which is reasonable in this case because
81 // the sample assumes that you'll be calling functions from this
82 // framework throughout the life of your application.
84 if (err == noErr) {
85 *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
86 if (*bundlePtr == nil) {
87 err = coreFoundationUnknownErr;
90 if (err == noErr) {
91 if ( ! CFBundleLoadExecutable( *bundlePtr ) ) {
92 err = coreFoundationUnknownErr;
96 // Clean up.
98 if (err != noErr && *bundlePtr != nil) {
99 CFRelease(*bundlePtr);
100 *bundlePtr = nil;
102 if (bundleURL != nil) {
103 CFRelease(bundleURL);
105 if (baseURL != nil) {
106 CFRelease(baseURL);
109 return err;
114 // The CFMLateImport approach requires that you define a fragment
115 // initialisation routine that latches the fragment's connection
116 // ID and locator. If your code already has a fragment initialiser
117 // you will have to integrate the following into it.
119 static CFragConnectionID gFragToFixConnID;
120 static FSSpec gFragToFixFile;
121 static CFragSystem7DiskFlatLocator gFragToFixLocator;
123 extern OSErr FragmentInit(const CFragInitBlock *initBlock);
124 extern OSErr FragmentInit(const CFragInitBlock *initBlock)
126 __initialize(initBlock); /* call the "original" initializer */
127 gFragToFixConnID = (CFragConnectionID) initBlock->closureID;
128 gFragToFixFile = *(initBlock->fragLocator.u.onDisk.fileSpec);
129 gFragToFixLocator = initBlock->fragLocator.u.onDisk;
130 gFragToFixLocator.fileSpec = &gFragToFixFile;
132 return noErr;
135 #endif
137 extern int GrafObj_Convert(PyObject *, GrafPtr *);
140 ** Manual converters
143 PyObject *CGPoint_New(CGPoint *itself)
146 return Py_BuildValue("(ff)",
147 itself->x,
148 itself->y);
152 CGPoint_Convert(PyObject *v, CGPoint *p_itself)
154 if( !PyArg_Parse(v, "(ff)",
155 &p_itself->x,
156 &p_itself->y) )
157 return 0;
158 return 1;
161 PyObject *CGRect_New(CGRect *itself)
164 return Py_BuildValue("(ffff)",
165 itself->origin.x,
166 itself->origin.y,
167 itself->size.width,
168 itself->size.height);
172 CGRect_Convert(PyObject *v, CGRect *p_itself)
174 if( !PyArg_Parse(v, "(ffff)",
175 &p_itself->origin.x,
176 &p_itself->origin.y,
177 &p_itself->size.width,
178 &p_itself->size.height) )
179 return 0;
180 return 1;
183 PyObject *CGAffineTransform_New(CGAffineTransform *itself)
186 return Py_BuildValue("(ffffff)",
187 itself->a,
188 itself->b,
189 itself->c,
190 itself->d,
191 itself->tx,
192 itself->ty);
196 CGAffineTransform_Convert(PyObject *v, CGAffineTransform *p_itself)
198 if( !PyArg_Parse(v, "(ffffff)",
199 &p_itself->a,
200 &p_itself->b,
201 &p_itself->c,
202 &p_itself->d,
203 &p_itself->tx,
204 &p_itself->ty) )
205 return 0;
206 return 1;
209 static PyObject *CG_Error;
211 /* -------------------- Object type CGContextRef -------------------- */
213 PyTypeObject CGContextRef_Type;
215 #define CGContextRefObj_Check(x) ((x)->ob_type == &CGContextRef_Type || PyObject_TypeCheck((x), &CGContextRef_Type))
217 typedef struct CGContextRefObject {
218 PyObject_HEAD
219 CGContextRef ob_itself;
220 } CGContextRefObject;
222 PyObject *CGContextRefObj_New(CGContextRef itself)
224 CGContextRefObject *it;
225 it = PyObject_NEW(CGContextRefObject, &CGContextRef_Type);
226 if (it == NULL) return NULL;
227 it->ob_itself = itself;
228 return (PyObject *)it;
230 int CGContextRefObj_Convert(PyObject *v, CGContextRef *p_itself)
232 if (!CGContextRefObj_Check(v))
234 PyErr_SetString(PyExc_TypeError, "CGContextRef required");
235 return 0;
237 *p_itself = ((CGContextRefObject *)v)->ob_itself;
238 return 1;
241 static void CGContextRefObj_dealloc(CGContextRefObject *self)
243 CGContextRelease(self->ob_itself);
244 self->ob_type->tp_free((PyObject *)self);
247 static PyObject *CGContextRefObj_CGContextSaveGState(CGContextRefObject *_self, PyObject *_args)
249 PyObject *_res = NULL;
250 if (!PyArg_ParseTuple(_args, ""))
251 return NULL;
252 CGContextSaveGState(_self->ob_itself);
253 Py_INCREF(Py_None);
254 _res = Py_None;
255 return _res;
258 static PyObject *CGContextRefObj_CGContextRestoreGState(CGContextRefObject *_self, PyObject *_args)
260 PyObject *_res = NULL;
261 if (!PyArg_ParseTuple(_args, ""))
262 return NULL;
263 CGContextRestoreGState(_self->ob_itself);
264 Py_INCREF(Py_None);
265 _res = Py_None;
266 return _res;
269 static PyObject *CGContextRefObj_CGContextScaleCTM(CGContextRefObject *_self, PyObject *_args)
271 PyObject *_res = NULL;
272 float sx;
273 float sy;
274 if (!PyArg_ParseTuple(_args, "ff",
275 &sx,
276 &sy))
277 return NULL;
278 CGContextScaleCTM(_self->ob_itself,
280 sy);
281 Py_INCREF(Py_None);
282 _res = Py_None;
283 return _res;
286 static PyObject *CGContextRefObj_CGContextTranslateCTM(CGContextRefObject *_self, PyObject *_args)
288 PyObject *_res = NULL;
289 float tx;
290 float ty;
291 if (!PyArg_ParseTuple(_args, "ff",
292 &tx,
293 &ty))
294 return NULL;
295 CGContextTranslateCTM(_self->ob_itself,
297 ty);
298 Py_INCREF(Py_None);
299 _res = Py_None;
300 return _res;
303 static PyObject *CGContextRefObj_CGContextRotateCTM(CGContextRefObject *_self, PyObject *_args)
305 PyObject *_res = NULL;
306 float angle;
307 if (!PyArg_ParseTuple(_args, "f",
308 &angle))
309 return NULL;
310 CGContextRotateCTM(_self->ob_itself,
311 angle);
312 Py_INCREF(Py_None);
313 _res = Py_None;
314 return _res;
317 static PyObject *CGContextRefObj_CGContextConcatCTM(CGContextRefObject *_self, PyObject *_args)
319 PyObject *_res = NULL;
320 CGAffineTransform transform;
321 if (!PyArg_ParseTuple(_args, "O&",
322 CGAffineTransform_Convert, &transform))
323 return NULL;
324 CGContextConcatCTM(_self->ob_itself,
325 transform);
326 Py_INCREF(Py_None);
327 _res = Py_None;
328 return _res;
331 static PyObject *CGContextRefObj_CGContextGetCTM(CGContextRefObject *_self, PyObject *_args)
333 PyObject *_res = NULL;
334 CGAffineTransform _rv;
335 if (!PyArg_ParseTuple(_args, ""))
336 return NULL;
337 _rv = CGContextGetCTM(_self->ob_itself);
338 _res = Py_BuildValue("O&",
339 CGAffineTransform_New, &_rv);
340 return _res;
343 static PyObject *CGContextRefObj_CGContextSetLineWidth(CGContextRefObject *_self, PyObject *_args)
345 PyObject *_res = NULL;
346 float width;
347 if (!PyArg_ParseTuple(_args, "f",
348 &width))
349 return NULL;
350 CGContextSetLineWidth(_self->ob_itself,
351 width);
352 Py_INCREF(Py_None);
353 _res = Py_None;
354 return _res;
357 static PyObject *CGContextRefObj_CGContextSetLineCap(CGContextRefObject *_self, PyObject *_args)
359 PyObject *_res = NULL;
360 int cap;
361 if (!PyArg_ParseTuple(_args, "i",
362 &cap))
363 return NULL;
364 CGContextSetLineCap(_self->ob_itself,
365 cap);
366 Py_INCREF(Py_None);
367 _res = Py_None;
368 return _res;
371 static PyObject *CGContextRefObj_CGContextSetLineJoin(CGContextRefObject *_self, PyObject *_args)
373 PyObject *_res = NULL;
374 int join;
375 if (!PyArg_ParseTuple(_args, "i",
376 &join))
377 return NULL;
378 CGContextSetLineJoin(_self->ob_itself,
379 join);
380 Py_INCREF(Py_None);
381 _res = Py_None;
382 return _res;
385 static PyObject *CGContextRefObj_CGContextSetMiterLimit(CGContextRefObject *_self, PyObject *_args)
387 PyObject *_res = NULL;
388 float limit;
389 if (!PyArg_ParseTuple(_args, "f",
390 &limit))
391 return NULL;
392 CGContextSetMiterLimit(_self->ob_itself,
393 limit);
394 Py_INCREF(Py_None);
395 _res = Py_None;
396 return _res;
399 static PyObject *CGContextRefObj_CGContextSetFlatness(CGContextRefObject *_self, PyObject *_args)
401 PyObject *_res = NULL;
402 float flatness;
403 if (!PyArg_ParseTuple(_args, "f",
404 &flatness))
405 return NULL;
406 CGContextSetFlatness(_self->ob_itself,
407 flatness);
408 Py_INCREF(Py_None);
409 _res = Py_None;
410 return _res;
413 static PyObject *CGContextRefObj_CGContextSetAlpha(CGContextRefObject *_self, PyObject *_args)
415 PyObject *_res = NULL;
416 float alpha;
417 if (!PyArg_ParseTuple(_args, "f",
418 &alpha))
419 return NULL;
420 CGContextSetAlpha(_self->ob_itself,
421 alpha);
422 Py_INCREF(Py_None);
423 _res = Py_None;
424 return _res;
427 static PyObject *CGContextRefObj_CGContextBeginPath(CGContextRefObject *_self, PyObject *_args)
429 PyObject *_res = NULL;
430 if (!PyArg_ParseTuple(_args, ""))
431 return NULL;
432 CGContextBeginPath(_self->ob_itself);
433 Py_INCREF(Py_None);
434 _res = Py_None;
435 return _res;
438 static PyObject *CGContextRefObj_CGContextMoveToPoint(CGContextRefObject *_self, PyObject *_args)
440 PyObject *_res = NULL;
441 float x;
442 float y;
443 if (!PyArg_ParseTuple(_args, "ff",
445 &y))
446 return NULL;
447 CGContextMoveToPoint(_self->ob_itself,
450 Py_INCREF(Py_None);
451 _res = Py_None;
452 return _res;
455 static PyObject *CGContextRefObj_CGContextAddLineToPoint(CGContextRefObject *_self, PyObject *_args)
457 PyObject *_res = NULL;
458 float x;
459 float y;
460 if (!PyArg_ParseTuple(_args, "ff",
462 &y))
463 return NULL;
464 CGContextAddLineToPoint(_self->ob_itself,
467 Py_INCREF(Py_None);
468 _res = Py_None;
469 return _res;
472 static PyObject *CGContextRefObj_CGContextAddCurveToPoint(CGContextRefObject *_self, PyObject *_args)
474 PyObject *_res = NULL;
475 float cp1x;
476 float cp1y;
477 float cp2x;
478 float cp2y;
479 float x;
480 float y;
481 if (!PyArg_ParseTuple(_args, "ffffff",
482 &cp1x,
483 &cp1y,
484 &cp2x,
485 &cp2y,
487 &y))
488 return NULL;
489 CGContextAddCurveToPoint(_self->ob_itself,
490 cp1x,
491 cp1y,
492 cp2x,
493 cp2y,
496 Py_INCREF(Py_None);
497 _res = Py_None;
498 return _res;
501 static PyObject *CGContextRefObj_CGContextAddQuadCurveToPoint(CGContextRefObject *_self, PyObject *_args)
503 PyObject *_res = NULL;
504 float cpx;
505 float cpy;
506 float x;
507 float y;
508 if (!PyArg_ParseTuple(_args, "ffff",
509 &cpx,
510 &cpy,
512 &y))
513 return NULL;
514 CGContextAddQuadCurveToPoint(_self->ob_itself,
515 cpx,
516 cpy,
519 Py_INCREF(Py_None);
520 _res = Py_None;
521 return _res;
524 static PyObject *CGContextRefObj_CGContextClosePath(CGContextRefObject *_self, PyObject *_args)
526 PyObject *_res = NULL;
527 if (!PyArg_ParseTuple(_args, ""))
528 return NULL;
529 CGContextClosePath(_self->ob_itself);
530 Py_INCREF(Py_None);
531 _res = Py_None;
532 return _res;
535 static PyObject *CGContextRefObj_CGContextAddRect(CGContextRefObject *_self, PyObject *_args)
537 PyObject *_res = NULL;
538 CGRect rect;
539 if (!PyArg_ParseTuple(_args, "O&",
540 CGRect_Convert, &rect))
541 return NULL;
542 CGContextAddRect(_self->ob_itself,
543 rect);
544 Py_INCREF(Py_None);
545 _res = Py_None;
546 return _res;
549 static PyObject *CGContextRefObj_CGContextAddArc(CGContextRefObject *_self, PyObject *_args)
551 PyObject *_res = NULL;
552 float x;
553 float y;
554 float radius;
555 float startAngle;
556 float endAngle;
557 int clockwise;
558 if (!PyArg_ParseTuple(_args, "fffffi",
561 &radius,
562 &startAngle,
563 &endAngle,
564 &clockwise))
565 return NULL;
566 CGContextAddArc(_self->ob_itself,
569 radius,
570 startAngle,
571 endAngle,
572 clockwise);
573 Py_INCREF(Py_None);
574 _res = Py_None;
575 return _res;
578 static PyObject *CGContextRefObj_CGContextAddArcToPoint(CGContextRefObject *_self, PyObject *_args)
580 PyObject *_res = NULL;
581 float x1;
582 float y1;
583 float x2;
584 float y2;
585 float radius;
586 if (!PyArg_ParseTuple(_args, "fffff",
587 &x1,
588 &y1,
589 &x2,
590 &y2,
591 &radius))
592 return NULL;
593 CGContextAddArcToPoint(_self->ob_itself,
598 radius);
599 Py_INCREF(Py_None);
600 _res = Py_None;
601 return _res;
604 static PyObject *CGContextRefObj_CGContextIsPathEmpty(CGContextRefObject *_self, PyObject *_args)
606 PyObject *_res = NULL;
607 int _rv;
608 if (!PyArg_ParseTuple(_args, ""))
609 return NULL;
610 _rv = CGContextIsPathEmpty(_self->ob_itself);
611 _res = Py_BuildValue("i",
612 _rv);
613 return _res;
616 static PyObject *CGContextRefObj_CGContextGetPathCurrentPoint(CGContextRefObject *_self, PyObject *_args)
618 PyObject *_res = NULL;
619 CGPoint _rv;
620 if (!PyArg_ParseTuple(_args, ""))
621 return NULL;
622 _rv = CGContextGetPathCurrentPoint(_self->ob_itself);
623 _res = Py_BuildValue("O&",
624 CGPoint_New, &_rv);
625 return _res;
628 static PyObject *CGContextRefObj_CGContextGetPathBoundingBox(CGContextRefObject *_self, PyObject *_args)
630 PyObject *_res = NULL;
631 CGRect _rv;
632 if (!PyArg_ParseTuple(_args, ""))
633 return NULL;
634 _rv = CGContextGetPathBoundingBox(_self->ob_itself);
635 _res = Py_BuildValue("O&",
636 CGRect_New, &_rv);
637 return _res;
640 static PyObject *CGContextRefObj_CGContextDrawPath(CGContextRefObject *_self, PyObject *_args)
642 PyObject *_res = NULL;
643 int mode;
644 if (!PyArg_ParseTuple(_args, "i",
645 &mode))
646 return NULL;
647 CGContextDrawPath(_self->ob_itself,
648 mode);
649 Py_INCREF(Py_None);
650 _res = Py_None;
651 return _res;
654 static PyObject *CGContextRefObj_CGContextFillPath(CGContextRefObject *_self, PyObject *_args)
656 PyObject *_res = NULL;
657 if (!PyArg_ParseTuple(_args, ""))
658 return NULL;
659 CGContextFillPath(_self->ob_itself);
660 Py_INCREF(Py_None);
661 _res = Py_None;
662 return _res;
665 static PyObject *CGContextRefObj_CGContextEOFillPath(CGContextRefObject *_self, PyObject *_args)
667 PyObject *_res = NULL;
668 if (!PyArg_ParseTuple(_args, ""))
669 return NULL;
670 CGContextEOFillPath(_self->ob_itself);
671 Py_INCREF(Py_None);
672 _res = Py_None;
673 return _res;
676 static PyObject *CGContextRefObj_CGContextStrokePath(CGContextRefObject *_self, PyObject *_args)
678 PyObject *_res = NULL;
679 if (!PyArg_ParseTuple(_args, ""))
680 return NULL;
681 CGContextStrokePath(_self->ob_itself);
682 Py_INCREF(Py_None);
683 _res = Py_None;
684 return _res;
687 static PyObject *CGContextRefObj_CGContextFillRect(CGContextRefObject *_self, PyObject *_args)
689 PyObject *_res = NULL;
690 CGRect rect;
691 if (!PyArg_ParseTuple(_args, "O&",
692 CGRect_Convert, &rect))
693 return NULL;
694 CGContextFillRect(_self->ob_itself,
695 rect);
696 Py_INCREF(Py_None);
697 _res = Py_None;
698 return _res;
701 static PyObject *CGContextRefObj_CGContextStrokeRect(CGContextRefObject *_self, PyObject *_args)
703 PyObject *_res = NULL;
704 CGRect rect;
705 if (!PyArg_ParseTuple(_args, "O&",
706 CGRect_Convert, &rect))
707 return NULL;
708 CGContextStrokeRect(_self->ob_itself,
709 rect);
710 Py_INCREF(Py_None);
711 _res = Py_None;
712 return _res;
715 static PyObject *CGContextRefObj_CGContextStrokeRectWithWidth(CGContextRefObject *_self, PyObject *_args)
717 PyObject *_res = NULL;
718 CGRect rect;
719 float width;
720 if (!PyArg_ParseTuple(_args, "O&f",
721 CGRect_Convert, &rect,
722 &width))
723 return NULL;
724 CGContextStrokeRectWithWidth(_self->ob_itself,
725 rect,
726 width);
727 Py_INCREF(Py_None);
728 _res = Py_None;
729 return _res;
732 static PyObject *CGContextRefObj_CGContextClearRect(CGContextRefObject *_self, PyObject *_args)
734 PyObject *_res = NULL;
735 CGRect rect;
736 if (!PyArg_ParseTuple(_args, "O&",
737 CGRect_Convert, &rect))
738 return NULL;
739 CGContextClearRect(_self->ob_itself,
740 rect);
741 Py_INCREF(Py_None);
742 _res = Py_None;
743 return _res;
746 static PyObject *CGContextRefObj_CGContextClip(CGContextRefObject *_self, PyObject *_args)
748 PyObject *_res = NULL;
749 if (!PyArg_ParseTuple(_args, ""))
750 return NULL;
751 CGContextClip(_self->ob_itself);
752 Py_INCREF(Py_None);
753 _res = Py_None;
754 return _res;
757 static PyObject *CGContextRefObj_CGContextEOClip(CGContextRefObject *_self, PyObject *_args)
759 PyObject *_res = NULL;
760 if (!PyArg_ParseTuple(_args, ""))
761 return NULL;
762 CGContextEOClip(_self->ob_itself);
763 Py_INCREF(Py_None);
764 _res = Py_None;
765 return _res;
768 static PyObject *CGContextRefObj_CGContextClipToRect(CGContextRefObject *_self, PyObject *_args)
770 PyObject *_res = NULL;
771 CGRect rect;
772 if (!PyArg_ParseTuple(_args, "O&",
773 CGRect_Convert, &rect))
774 return NULL;
775 CGContextClipToRect(_self->ob_itself,
776 rect);
777 Py_INCREF(Py_None);
778 _res = Py_None;
779 return _res;
782 static PyObject *CGContextRefObj_CGContextSetGrayFillColor(CGContextRefObject *_self, PyObject *_args)
784 PyObject *_res = NULL;
785 float gray;
786 float alpha;
787 if (!PyArg_ParseTuple(_args, "ff",
788 &gray,
789 &alpha))
790 return NULL;
791 CGContextSetGrayFillColor(_self->ob_itself,
792 gray,
793 alpha);
794 Py_INCREF(Py_None);
795 _res = Py_None;
796 return _res;
799 static PyObject *CGContextRefObj_CGContextSetGrayStrokeColor(CGContextRefObject *_self, PyObject *_args)
801 PyObject *_res = NULL;
802 float gray;
803 float alpha;
804 if (!PyArg_ParseTuple(_args, "ff",
805 &gray,
806 &alpha))
807 return NULL;
808 CGContextSetGrayStrokeColor(_self->ob_itself,
809 gray,
810 alpha);
811 Py_INCREF(Py_None);
812 _res = Py_None;
813 return _res;
816 static PyObject *CGContextRefObj_CGContextSetRGBFillColor(CGContextRefObject *_self, PyObject *_args)
818 PyObject *_res = NULL;
819 float r;
820 float g;
821 float b;
822 float alpha;
823 if (!PyArg_ParseTuple(_args, "ffff",
827 &alpha))
828 return NULL;
829 CGContextSetRGBFillColor(_self->ob_itself,
833 alpha);
834 Py_INCREF(Py_None);
835 _res = Py_None;
836 return _res;
839 static PyObject *CGContextRefObj_CGContextSetRGBStrokeColor(CGContextRefObject *_self, PyObject *_args)
841 PyObject *_res = NULL;
842 float r;
843 float g;
844 float b;
845 float alpha;
846 if (!PyArg_ParseTuple(_args, "ffff",
850 &alpha))
851 return NULL;
852 CGContextSetRGBStrokeColor(_self->ob_itself,
856 alpha);
857 Py_INCREF(Py_None);
858 _res = Py_None;
859 return _res;
862 static PyObject *CGContextRefObj_CGContextSetCMYKFillColor(CGContextRefObject *_self, PyObject *_args)
864 PyObject *_res = NULL;
865 float c;
866 float m;
867 float y;
868 float k;
869 float alpha;
870 if (!PyArg_ParseTuple(_args, "fffff",
875 &alpha))
876 return NULL;
877 CGContextSetCMYKFillColor(_self->ob_itself,
882 alpha);
883 Py_INCREF(Py_None);
884 _res = Py_None;
885 return _res;
888 static PyObject *CGContextRefObj_CGContextSetCMYKStrokeColor(CGContextRefObject *_self, PyObject *_args)
890 PyObject *_res = NULL;
891 float c;
892 float m;
893 float y;
894 float k;
895 float alpha;
896 if (!PyArg_ParseTuple(_args, "fffff",
901 &alpha))
902 return NULL;
903 CGContextSetCMYKStrokeColor(_self->ob_itself,
908 alpha);
909 Py_INCREF(Py_None);
910 _res = Py_None;
911 return _res;
914 static PyObject *CGContextRefObj_CGContextSetCharacterSpacing(CGContextRefObject *_self, PyObject *_args)
916 PyObject *_res = NULL;
917 float spacing;
918 if (!PyArg_ParseTuple(_args, "f",
919 &spacing))
920 return NULL;
921 CGContextSetCharacterSpacing(_self->ob_itself,
922 spacing);
923 Py_INCREF(Py_None);
924 _res = Py_None;
925 return _res;
928 static PyObject *CGContextRefObj_CGContextSetTextPosition(CGContextRefObject *_self, PyObject *_args)
930 PyObject *_res = NULL;
931 float x;
932 float y;
933 if (!PyArg_ParseTuple(_args, "ff",
935 &y))
936 return NULL;
937 CGContextSetTextPosition(_self->ob_itself,
940 Py_INCREF(Py_None);
941 _res = Py_None;
942 return _res;
945 static PyObject *CGContextRefObj_CGContextGetTextPosition(CGContextRefObject *_self, PyObject *_args)
947 PyObject *_res = NULL;
948 CGPoint _rv;
949 if (!PyArg_ParseTuple(_args, ""))
950 return NULL;
951 _rv = CGContextGetTextPosition(_self->ob_itself);
952 _res = Py_BuildValue("O&",
953 CGPoint_New, &_rv);
954 return _res;
957 static PyObject *CGContextRefObj_CGContextSetTextMatrix(CGContextRefObject *_self, PyObject *_args)
959 PyObject *_res = NULL;
960 CGAffineTransform transform;
961 if (!PyArg_ParseTuple(_args, "O&",
962 CGAffineTransform_Convert, &transform))
963 return NULL;
964 CGContextSetTextMatrix(_self->ob_itself,
965 transform);
966 Py_INCREF(Py_None);
967 _res = Py_None;
968 return _res;
971 static PyObject *CGContextRefObj_CGContextGetTextMatrix(CGContextRefObject *_self, PyObject *_args)
973 PyObject *_res = NULL;
974 CGAffineTransform _rv;
975 if (!PyArg_ParseTuple(_args, ""))
976 return NULL;
977 _rv = CGContextGetTextMatrix(_self->ob_itself);
978 _res = Py_BuildValue("O&",
979 CGAffineTransform_New, &_rv);
980 return _res;
983 static PyObject *CGContextRefObj_CGContextSetTextDrawingMode(CGContextRefObject *_self, PyObject *_args)
985 PyObject *_res = NULL;
986 int mode;
987 if (!PyArg_ParseTuple(_args, "i",
988 &mode))
989 return NULL;
990 CGContextSetTextDrawingMode(_self->ob_itself,
991 mode);
992 Py_INCREF(Py_None);
993 _res = Py_None;
994 return _res;
997 static PyObject *CGContextRefObj_CGContextSetFontSize(CGContextRefObject *_self, PyObject *_args)
999 PyObject *_res = NULL;
1000 float size;
1001 if (!PyArg_ParseTuple(_args, "f",
1002 &size))
1003 return NULL;
1004 CGContextSetFontSize(_self->ob_itself,
1005 size);
1006 Py_INCREF(Py_None);
1007 _res = Py_None;
1008 return _res;
1011 static PyObject *CGContextRefObj_CGContextSelectFont(CGContextRefObject *_self, PyObject *_args)
1013 PyObject *_res = NULL;
1014 char * name;
1015 float size;
1016 int textEncoding;
1017 if (!PyArg_ParseTuple(_args, "sfi",
1018 &name,
1019 &size,
1020 &textEncoding))
1021 return NULL;
1022 CGContextSelectFont(_self->ob_itself,
1023 name,
1024 size,
1025 textEncoding);
1026 Py_INCREF(Py_None);
1027 _res = Py_None;
1028 return _res;
1031 static PyObject *CGContextRefObj_CGContextShowText(CGContextRefObject *_self, PyObject *_args)
1033 PyObject *_res = NULL;
1034 char *cstring__in__;
1035 long cstring__len__;
1036 int cstring__in_len__;
1037 if (!PyArg_ParseTuple(_args, "s#",
1038 &cstring__in__, &cstring__in_len__))
1039 return NULL;
1040 cstring__len__ = cstring__in_len__;
1041 CGContextShowText(_self->ob_itself,
1042 cstring__in__, cstring__len__);
1043 Py_INCREF(Py_None);
1044 _res = Py_None;
1045 return _res;
1048 static PyObject *CGContextRefObj_CGContextShowTextAtPoint(CGContextRefObject *_self, PyObject *_args)
1050 PyObject *_res = NULL;
1051 float x;
1052 float y;
1053 char *cstring__in__;
1054 long cstring__len__;
1055 int cstring__in_len__;
1056 if (!PyArg_ParseTuple(_args, "ffs#",
1059 &cstring__in__, &cstring__in_len__))
1060 return NULL;
1061 cstring__len__ = cstring__in_len__;
1062 CGContextShowTextAtPoint(_self->ob_itself,
1065 cstring__in__, cstring__len__);
1066 Py_INCREF(Py_None);
1067 _res = Py_None;
1068 return _res;
1071 static PyObject *CGContextRefObj_CGContextEndPage(CGContextRefObject *_self, PyObject *_args)
1073 PyObject *_res = NULL;
1074 if (!PyArg_ParseTuple(_args, ""))
1075 return NULL;
1076 CGContextEndPage(_self->ob_itself);
1077 Py_INCREF(Py_None);
1078 _res = Py_None;
1079 return _res;
1082 static PyObject *CGContextRefObj_CGContextFlush(CGContextRefObject *_self, PyObject *_args)
1084 PyObject *_res = NULL;
1085 if (!PyArg_ParseTuple(_args, ""))
1086 return NULL;
1087 CGContextFlush(_self->ob_itself);
1088 Py_INCREF(Py_None);
1089 _res = Py_None;
1090 return _res;
1093 static PyObject *CGContextRefObj_CGContextSynchronize(CGContextRefObject *_self, PyObject *_args)
1095 PyObject *_res = NULL;
1096 if (!PyArg_ParseTuple(_args, ""))
1097 return NULL;
1098 CGContextSynchronize(_self->ob_itself);
1099 Py_INCREF(Py_None);
1100 _res = Py_None;
1101 return _res;
1104 static PyObject *CGContextRefObj_CGContextSetShouldAntialias(CGContextRefObject *_self, PyObject *_args)
1106 PyObject *_res = NULL;
1107 int shouldAntialias;
1108 if (!PyArg_ParseTuple(_args, "i",
1109 &shouldAntialias))
1110 return NULL;
1111 CGContextSetShouldAntialias(_self->ob_itself,
1112 shouldAntialias);
1113 Py_INCREF(Py_None);
1114 _res = Py_None;
1115 return _res;
1118 static PyObject *CGContextRefObj_SyncCGContextOriginWithPort(CGContextRefObject *_self, PyObject *_args)
1120 PyObject *_res = NULL;
1121 CGrafPtr port;
1122 if (!PyArg_ParseTuple(_args, "O&",
1123 GrafObj_Convert, &port))
1124 return NULL;
1125 SyncCGContextOriginWithPort(_self->ob_itself,
1126 port);
1127 Py_INCREF(Py_None);
1128 _res = Py_None;
1129 return _res;
1132 static PyObject *CGContextRefObj_ClipCGContextToRegion(CGContextRefObject *_self, PyObject *_args)
1134 PyObject *_res = NULL;
1135 Rect portRect;
1136 RgnHandle region;
1137 if (!PyArg_ParseTuple(_args, "O&O&",
1138 PyMac_GetRect, &portRect,
1139 ResObj_Convert, &region))
1140 return NULL;
1141 ClipCGContextToRegion(_self->ob_itself,
1142 &portRect,
1143 region);
1144 Py_INCREF(Py_None);
1145 _res = Py_None;
1146 return _res;
1149 static PyMethodDef CGContextRefObj_methods[] = {
1150 {"CGContextSaveGState", (PyCFunction)CGContextRefObj_CGContextSaveGState, 1,
1151 PyDoc_STR("() -> None")},
1152 {"CGContextRestoreGState", (PyCFunction)CGContextRefObj_CGContextRestoreGState, 1,
1153 PyDoc_STR("() -> None")},
1154 {"CGContextScaleCTM", (PyCFunction)CGContextRefObj_CGContextScaleCTM, 1,
1155 PyDoc_STR("(float sx, float sy) -> None")},
1156 {"CGContextTranslateCTM", (PyCFunction)CGContextRefObj_CGContextTranslateCTM, 1,
1157 PyDoc_STR("(float tx, float ty) -> None")},
1158 {"CGContextRotateCTM", (PyCFunction)CGContextRefObj_CGContextRotateCTM, 1,
1159 PyDoc_STR("(float angle) -> None")},
1160 {"CGContextConcatCTM", (PyCFunction)CGContextRefObj_CGContextConcatCTM, 1,
1161 PyDoc_STR("(CGAffineTransform transform) -> None")},
1162 {"CGContextGetCTM", (PyCFunction)CGContextRefObj_CGContextGetCTM, 1,
1163 PyDoc_STR("() -> (CGAffineTransform _rv)")},
1164 {"CGContextSetLineWidth", (PyCFunction)CGContextRefObj_CGContextSetLineWidth, 1,
1165 PyDoc_STR("(float width) -> None")},
1166 {"CGContextSetLineCap", (PyCFunction)CGContextRefObj_CGContextSetLineCap, 1,
1167 PyDoc_STR("(int cap) -> None")},
1168 {"CGContextSetLineJoin", (PyCFunction)CGContextRefObj_CGContextSetLineJoin, 1,
1169 PyDoc_STR("(int join) -> None")},
1170 {"CGContextSetMiterLimit", (PyCFunction)CGContextRefObj_CGContextSetMiterLimit, 1,
1171 PyDoc_STR("(float limit) -> None")},
1172 {"CGContextSetFlatness", (PyCFunction)CGContextRefObj_CGContextSetFlatness, 1,
1173 PyDoc_STR("(float flatness) -> None")},
1174 {"CGContextSetAlpha", (PyCFunction)CGContextRefObj_CGContextSetAlpha, 1,
1175 PyDoc_STR("(float alpha) -> None")},
1176 {"CGContextBeginPath", (PyCFunction)CGContextRefObj_CGContextBeginPath, 1,
1177 PyDoc_STR("() -> None")},
1178 {"CGContextMoveToPoint", (PyCFunction)CGContextRefObj_CGContextMoveToPoint, 1,
1179 PyDoc_STR("(float x, float y) -> None")},
1180 {"CGContextAddLineToPoint", (PyCFunction)CGContextRefObj_CGContextAddLineToPoint, 1,
1181 PyDoc_STR("(float x, float y) -> None")},
1182 {"CGContextAddCurveToPoint", (PyCFunction)CGContextRefObj_CGContextAddCurveToPoint, 1,
1183 PyDoc_STR("(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) -> None")},
1184 {"CGContextAddQuadCurveToPoint", (PyCFunction)CGContextRefObj_CGContextAddQuadCurveToPoint, 1,
1185 PyDoc_STR("(float cpx, float cpy, float x, float y) -> None")},
1186 {"CGContextClosePath", (PyCFunction)CGContextRefObj_CGContextClosePath, 1,
1187 PyDoc_STR("() -> None")},
1188 {"CGContextAddRect", (PyCFunction)CGContextRefObj_CGContextAddRect, 1,
1189 PyDoc_STR("(CGRect rect) -> None")},
1190 {"CGContextAddArc", (PyCFunction)CGContextRefObj_CGContextAddArc, 1,
1191 PyDoc_STR("(float x, float y, float radius, float startAngle, float endAngle, int clockwise) -> None")},
1192 {"CGContextAddArcToPoint", (PyCFunction)CGContextRefObj_CGContextAddArcToPoint, 1,
1193 PyDoc_STR("(float x1, float y1, float x2, float y2, float radius) -> None")},
1194 {"CGContextIsPathEmpty", (PyCFunction)CGContextRefObj_CGContextIsPathEmpty, 1,
1195 PyDoc_STR("() -> (int _rv)")},
1196 {"CGContextGetPathCurrentPoint", (PyCFunction)CGContextRefObj_CGContextGetPathCurrentPoint, 1,
1197 PyDoc_STR("() -> (CGPoint _rv)")},
1198 {"CGContextGetPathBoundingBox", (PyCFunction)CGContextRefObj_CGContextGetPathBoundingBox, 1,
1199 PyDoc_STR("() -> (CGRect _rv)")},
1200 {"CGContextDrawPath", (PyCFunction)CGContextRefObj_CGContextDrawPath, 1,
1201 PyDoc_STR("(int mode) -> None")},
1202 {"CGContextFillPath", (PyCFunction)CGContextRefObj_CGContextFillPath, 1,
1203 PyDoc_STR("() -> None")},
1204 {"CGContextEOFillPath", (PyCFunction)CGContextRefObj_CGContextEOFillPath, 1,
1205 PyDoc_STR("() -> None")},
1206 {"CGContextStrokePath", (PyCFunction)CGContextRefObj_CGContextStrokePath, 1,
1207 PyDoc_STR("() -> None")},
1208 {"CGContextFillRect", (PyCFunction)CGContextRefObj_CGContextFillRect, 1,
1209 PyDoc_STR("(CGRect rect) -> None")},
1210 {"CGContextStrokeRect", (PyCFunction)CGContextRefObj_CGContextStrokeRect, 1,
1211 PyDoc_STR("(CGRect rect) -> None")},
1212 {"CGContextStrokeRectWithWidth", (PyCFunction)CGContextRefObj_CGContextStrokeRectWithWidth, 1,
1213 PyDoc_STR("(CGRect rect, float width) -> None")},
1214 {"CGContextClearRect", (PyCFunction)CGContextRefObj_CGContextClearRect, 1,
1215 PyDoc_STR("(CGRect rect) -> None")},
1216 {"CGContextClip", (PyCFunction)CGContextRefObj_CGContextClip, 1,
1217 PyDoc_STR("() -> None")},
1218 {"CGContextEOClip", (PyCFunction)CGContextRefObj_CGContextEOClip, 1,
1219 PyDoc_STR("() -> None")},
1220 {"CGContextClipToRect", (PyCFunction)CGContextRefObj_CGContextClipToRect, 1,
1221 PyDoc_STR("(CGRect rect) -> None")},
1222 {"CGContextSetGrayFillColor", (PyCFunction)CGContextRefObj_CGContextSetGrayFillColor, 1,
1223 PyDoc_STR("(float gray, float alpha) -> None")},
1224 {"CGContextSetGrayStrokeColor", (PyCFunction)CGContextRefObj_CGContextSetGrayStrokeColor, 1,
1225 PyDoc_STR("(float gray, float alpha) -> None")},
1226 {"CGContextSetRGBFillColor", (PyCFunction)CGContextRefObj_CGContextSetRGBFillColor, 1,
1227 PyDoc_STR("(float r, float g, float b, float alpha) -> None")},
1228 {"CGContextSetRGBStrokeColor", (PyCFunction)CGContextRefObj_CGContextSetRGBStrokeColor, 1,
1229 PyDoc_STR("(float r, float g, float b, float alpha) -> None")},
1230 {"CGContextSetCMYKFillColor", (PyCFunction)CGContextRefObj_CGContextSetCMYKFillColor, 1,
1231 PyDoc_STR("(float c, float m, float y, float k, float alpha) -> None")},
1232 {"CGContextSetCMYKStrokeColor", (PyCFunction)CGContextRefObj_CGContextSetCMYKStrokeColor, 1,
1233 PyDoc_STR("(float c, float m, float y, float k, float alpha) -> None")},
1234 {"CGContextSetCharacterSpacing", (PyCFunction)CGContextRefObj_CGContextSetCharacterSpacing, 1,
1235 PyDoc_STR("(float spacing) -> None")},
1236 {"CGContextSetTextPosition", (PyCFunction)CGContextRefObj_CGContextSetTextPosition, 1,
1237 PyDoc_STR("(float x, float y) -> None")},
1238 {"CGContextGetTextPosition", (PyCFunction)CGContextRefObj_CGContextGetTextPosition, 1,
1239 PyDoc_STR("() -> (CGPoint _rv)")},
1240 {"CGContextSetTextMatrix", (PyCFunction)CGContextRefObj_CGContextSetTextMatrix, 1,
1241 PyDoc_STR("(CGAffineTransform transform) -> None")},
1242 {"CGContextGetTextMatrix", (PyCFunction)CGContextRefObj_CGContextGetTextMatrix, 1,
1243 PyDoc_STR("() -> (CGAffineTransform _rv)")},
1244 {"CGContextSetTextDrawingMode", (PyCFunction)CGContextRefObj_CGContextSetTextDrawingMode, 1,
1245 PyDoc_STR("(int mode) -> None")},
1246 {"CGContextSetFontSize", (PyCFunction)CGContextRefObj_CGContextSetFontSize, 1,
1247 PyDoc_STR("(float size) -> None")},
1248 {"CGContextSelectFont", (PyCFunction)CGContextRefObj_CGContextSelectFont, 1,
1249 PyDoc_STR("(char * name, float size, int textEncoding) -> None")},
1250 {"CGContextShowText", (PyCFunction)CGContextRefObj_CGContextShowText, 1,
1251 PyDoc_STR("(Buffer cstring) -> None")},
1252 {"CGContextShowTextAtPoint", (PyCFunction)CGContextRefObj_CGContextShowTextAtPoint, 1,
1253 PyDoc_STR("(float x, float y, Buffer cstring) -> None")},
1254 {"CGContextEndPage", (PyCFunction)CGContextRefObj_CGContextEndPage, 1,
1255 PyDoc_STR("() -> None")},
1256 {"CGContextFlush", (PyCFunction)CGContextRefObj_CGContextFlush, 1,
1257 PyDoc_STR("() -> None")},
1258 {"CGContextSynchronize", (PyCFunction)CGContextRefObj_CGContextSynchronize, 1,
1259 PyDoc_STR("() -> None")},
1260 {"CGContextSetShouldAntialias", (PyCFunction)CGContextRefObj_CGContextSetShouldAntialias, 1,
1261 PyDoc_STR("(int shouldAntialias) -> None")},
1262 {"SyncCGContextOriginWithPort", (PyCFunction)CGContextRefObj_SyncCGContextOriginWithPort, 1,
1263 PyDoc_STR("(CGrafPtr port) -> None")},
1264 {"ClipCGContextToRegion", (PyCFunction)CGContextRefObj_ClipCGContextToRegion, 1,
1265 PyDoc_STR("(Rect portRect, RgnHandle region) -> None")},
1266 {NULL, NULL, 0}
1269 #define CGContextRefObj_getsetlist NULL
1272 #define CGContextRefObj_compare NULL
1274 #define CGContextRefObj_repr NULL
1276 #define CGContextRefObj_hash NULL
1277 #define CGContextRefObj_tp_init 0
1279 #define CGContextRefObj_tp_alloc PyType_GenericAlloc
1281 static PyObject *CGContextRefObj_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1283 PyObject *self;
1284 CGContextRef itself;
1285 char *kw[] = {"itself", 0};
1287 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, CGContextRefObj_Convert, &itself)) return NULL;
1288 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1289 ((CGContextRefObject *)self)->ob_itself = itself;
1290 return self;
1293 #define CGContextRefObj_tp_free PyObject_Del
1296 PyTypeObject CGContextRef_Type = {
1297 PyObject_HEAD_INIT(NULL)
1298 0, /*ob_size*/
1299 "_CG.CGContextRef", /*tp_name*/
1300 sizeof(CGContextRefObject), /*tp_basicsize*/
1301 0, /*tp_itemsize*/
1302 /* methods */
1303 (destructor) CGContextRefObj_dealloc, /*tp_dealloc*/
1304 0, /*tp_print*/
1305 (getattrfunc)0, /*tp_getattr*/
1306 (setattrfunc)0, /*tp_setattr*/
1307 (cmpfunc) CGContextRefObj_compare, /*tp_compare*/
1308 (reprfunc) CGContextRefObj_repr, /*tp_repr*/
1309 (PyNumberMethods *)0, /* tp_as_number */
1310 (PySequenceMethods *)0, /* tp_as_sequence */
1311 (PyMappingMethods *)0, /* tp_as_mapping */
1312 (hashfunc) CGContextRefObj_hash, /*tp_hash*/
1313 0, /*tp_call*/
1314 0, /*tp_str*/
1315 PyObject_GenericGetAttr, /*tp_getattro*/
1316 PyObject_GenericSetAttr, /*tp_setattro */
1317 0, /*tp_as_buffer*/
1318 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1319 0, /*tp_doc*/
1320 0, /*tp_traverse*/
1321 0, /*tp_clear*/
1322 0, /*tp_richcompare*/
1323 0, /*tp_weaklistoffset*/
1324 0, /*tp_iter*/
1325 0, /*tp_iternext*/
1326 CGContextRefObj_methods, /* tp_methods */
1327 0, /*tp_members*/
1328 CGContextRefObj_getsetlist, /*tp_getset*/
1329 0, /*tp_base*/
1330 0, /*tp_dict*/
1331 0, /*tp_descr_get*/
1332 0, /*tp_descr_set*/
1333 0, /*tp_dictoffset*/
1334 CGContextRefObj_tp_init, /* tp_init */
1335 CGContextRefObj_tp_alloc, /* tp_alloc */
1336 CGContextRefObj_tp_new, /* tp_new */
1337 CGContextRefObj_tp_free, /* tp_free */
1340 /* ------------------ End object type CGContextRef ------------------ */
1343 static PyObject *CG_CreateCGContextForPort(PyObject *_self, PyObject *_args)
1345 PyObject *_res = NULL;
1346 GrafPtr port;
1347 CGContextRef ctx;
1348 OSStatus _err;
1350 if (!PyArg_ParseTuple(_args, "O&", GrafObj_Convert, &port))
1351 return NULL;
1353 _err = CreateCGContextForPort(port, &ctx);
1354 if (_err != noErr)
1355 if (_err != noErr) return PyMac_Error(_err);
1356 _res = Py_BuildValue("O&", CGContextRefObj_New, ctx);
1357 return _res;
1361 static PyMethodDef CG_methods[] = {
1362 {"CreateCGContextForPort", (PyCFunction)CG_CreateCGContextForPort, 1,
1363 PyDoc_STR("(CGrafPtr) -> CGContextRef")},
1364 {NULL, NULL, 0}
1370 void init_CG(void)
1372 PyObject *m;
1373 PyObject *d;
1377 #if !TARGET_API_MAC_OSX
1378 CFBundleRef sysBundle;
1379 OSStatus err;
1381 if (&LoadFrameworkBundle == NULL) {
1382 PyErr_SetString(PyExc_ImportError, "CoreCraphics not supported");
1383 return;
1385 err = LoadFrameworkBundle(CFSTR("ApplicationServices.framework"), &sysBundle);
1386 if (err == noErr)
1387 err = CFMLateImportBundle(&gFragToFixLocator, gFragToFixConnID, FragmentInit, "\pCGStubLib", sysBundle);
1388 if (err != noErr) {
1389 PyErr_SetString(PyExc_ImportError, "CoreCraphics not supported");
1390 return;
1392 #endif /* !TARGET_API_MAC_OSX */
1395 m = Py_InitModule("_CG", CG_methods);
1396 d = PyModule_GetDict(m);
1397 CG_Error = PyMac_GetOSErrException();
1398 if (CG_Error == NULL ||
1399 PyDict_SetItemString(d, "Error", CG_Error) != 0)
1400 return;
1401 CGContextRef_Type.ob_type = &PyType_Type;
1402 if (PyType_Ready(&CGContextRef_Type) < 0) return;
1403 Py_INCREF(&CGContextRef_Type);
1404 PyModule_AddObject(m, "CGContextRef", (PyObject *)&CGContextRef_Type);
1405 /* Backward-compatible name */
1406 Py_INCREF(&CGContextRef_Type);
1407 PyModule_AddObject(m, "CGContextRefType", (PyObject *)&CGContextRef_Type);
1410 /* ========================= End module _CG ========================= */