2 /* =========================== Module _CG =========================== */
8 #include "pymactoolbox.h"
10 /* Macro to test whether a weak-loaded CFM function exists */
11 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
12 PyErr_SetString(PyExc_NotImplementedError, \
13 "Not available in this shared library/OS version"); \
18 #include <ApplicationServices/ApplicationServices.h>
20 extern int GrafObj_Convert(PyObject *, GrafPtr *);
26 PyObject *CGPoint_New(CGPoint *itself)
29 return Py_BuildValue("(ff)",
35 CGPoint_Convert(PyObject *v, CGPoint *p_itself)
37 if( !PyArg_Parse(v, "(ff)",
44 PyObject *CGRect_New(CGRect *itself)
47 return Py_BuildValue("(ffff)",
55 CGRect_Convert(PyObject *v, CGRect *p_itself)
57 if( !PyArg_Parse(v, "(ffff)",
60 &p_itself->size.width,
61 &p_itself->size.height) )
66 PyObject *CGAffineTransform_New(CGAffineTransform *itself)
69 return Py_BuildValue("(ffffff)",
79 CGAffineTransform_Convert(PyObject *v, CGAffineTransform *p_itself)
81 if( !PyArg_Parse(v, "(ffffff)",
92 static PyObject *CG_Error;
94 /* -------------------- Object type CGContextRef -------------------- */
96 PyTypeObject CGContextRef_Type;
98 #define CGContextRefObj_Check(x) ((x)->ob_type == &CGContextRef_Type || PyObject_TypeCheck((x), &CGContextRef_Type))
100 typedef struct CGContextRefObject {
102 CGContextRef ob_itself;
103 } CGContextRefObject;
105 PyObject *CGContextRefObj_New(CGContextRef itself)
107 CGContextRefObject *it;
108 it = PyObject_NEW(CGContextRefObject, &CGContextRef_Type);
109 if (it == NULL) return NULL;
110 it->ob_itself = itself;
111 return (PyObject *)it;
114 int CGContextRefObj_Convert(PyObject *v, CGContextRef *p_itself)
116 if (!CGContextRefObj_Check(v))
118 PyErr_SetString(PyExc_TypeError, "CGContextRef required");
121 *p_itself = ((CGContextRefObject *)v)->ob_itself;
125 static void CGContextRefObj_dealloc(CGContextRefObject *self)
127 CGContextRelease(self->ob_itself);
128 self->ob_type->tp_free((PyObject *)self);
131 static PyObject *CGContextRefObj_CGContextSaveGState(CGContextRefObject *_self, PyObject *_args)
133 PyObject *_res = NULL;
134 if (!PyArg_ParseTuple(_args, ""))
136 CGContextSaveGState(_self->ob_itself);
142 static PyObject *CGContextRefObj_CGContextRestoreGState(CGContextRefObject *_self, PyObject *_args)
144 PyObject *_res = NULL;
145 if (!PyArg_ParseTuple(_args, ""))
147 CGContextRestoreGState(_self->ob_itself);
153 static PyObject *CGContextRefObj_CGContextScaleCTM(CGContextRefObject *_self, PyObject *_args)
155 PyObject *_res = NULL;
158 if (!PyArg_ParseTuple(_args, "ff",
162 CGContextScaleCTM(_self->ob_itself,
170 static PyObject *CGContextRefObj_CGContextTranslateCTM(CGContextRefObject *_self, PyObject *_args)
172 PyObject *_res = NULL;
175 if (!PyArg_ParseTuple(_args, "ff",
179 CGContextTranslateCTM(_self->ob_itself,
187 static PyObject *CGContextRefObj_CGContextRotateCTM(CGContextRefObject *_self, PyObject *_args)
189 PyObject *_res = NULL;
191 if (!PyArg_ParseTuple(_args, "f",
194 CGContextRotateCTM(_self->ob_itself,
201 static PyObject *CGContextRefObj_CGContextConcatCTM(CGContextRefObject *_self, PyObject *_args)
203 PyObject *_res = NULL;
204 CGAffineTransform transform;
205 if (!PyArg_ParseTuple(_args, "O&",
206 CGAffineTransform_Convert, &transform))
208 CGContextConcatCTM(_self->ob_itself,
215 static PyObject *CGContextRefObj_CGContextGetCTM(CGContextRefObject *_self, PyObject *_args)
217 PyObject *_res = NULL;
218 CGAffineTransform _rv;
219 if (!PyArg_ParseTuple(_args, ""))
221 _rv = CGContextGetCTM(_self->ob_itself);
222 _res = Py_BuildValue("O&",
223 CGAffineTransform_New, &_rv);
227 static PyObject *CGContextRefObj_CGContextSetLineWidth(CGContextRefObject *_self, PyObject *_args)
229 PyObject *_res = NULL;
231 if (!PyArg_ParseTuple(_args, "f",
234 CGContextSetLineWidth(_self->ob_itself,
241 static PyObject *CGContextRefObj_CGContextSetLineCap(CGContextRefObject *_self, PyObject *_args)
243 PyObject *_res = NULL;
245 if (!PyArg_ParseTuple(_args, "i",
248 CGContextSetLineCap(_self->ob_itself,
255 static PyObject *CGContextRefObj_CGContextSetLineJoin(CGContextRefObject *_self, PyObject *_args)
257 PyObject *_res = NULL;
259 if (!PyArg_ParseTuple(_args, "i",
262 CGContextSetLineJoin(_self->ob_itself,
269 static PyObject *CGContextRefObj_CGContextSetMiterLimit(CGContextRefObject *_self, PyObject *_args)
271 PyObject *_res = NULL;
273 if (!PyArg_ParseTuple(_args, "f",
276 CGContextSetMiterLimit(_self->ob_itself,
283 static PyObject *CGContextRefObj_CGContextSetFlatness(CGContextRefObject *_self, PyObject *_args)
285 PyObject *_res = NULL;
287 if (!PyArg_ParseTuple(_args, "f",
290 CGContextSetFlatness(_self->ob_itself,
297 static PyObject *CGContextRefObj_CGContextSetAlpha(CGContextRefObject *_self, PyObject *_args)
299 PyObject *_res = NULL;
301 if (!PyArg_ParseTuple(_args, "f",
304 CGContextSetAlpha(_self->ob_itself,
311 static PyObject *CGContextRefObj_CGContextBeginPath(CGContextRefObject *_self, PyObject *_args)
313 PyObject *_res = NULL;
314 if (!PyArg_ParseTuple(_args, ""))
316 CGContextBeginPath(_self->ob_itself);
322 static PyObject *CGContextRefObj_CGContextMoveToPoint(CGContextRefObject *_self, PyObject *_args)
324 PyObject *_res = NULL;
327 if (!PyArg_ParseTuple(_args, "ff",
331 CGContextMoveToPoint(_self->ob_itself,
339 static PyObject *CGContextRefObj_CGContextAddLineToPoint(CGContextRefObject *_self, PyObject *_args)
341 PyObject *_res = NULL;
344 if (!PyArg_ParseTuple(_args, "ff",
348 CGContextAddLineToPoint(_self->ob_itself,
356 static PyObject *CGContextRefObj_CGContextAddCurveToPoint(CGContextRefObject *_self, PyObject *_args)
358 PyObject *_res = NULL;
365 if (!PyArg_ParseTuple(_args, "ffffff",
373 CGContextAddCurveToPoint(_self->ob_itself,
385 static PyObject *CGContextRefObj_CGContextAddQuadCurveToPoint(CGContextRefObject *_self, PyObject *_args)
387 PyObject *_res = NULL;
392 if (!PyArg_ParseTuple(_args, "ffff",
398 CGContextAddQuadCurveToPoint(_self->ob_itself,
408 static PyObject *CGContextRefObj_CGContextClosePath(CGContextRefObject *_self, PyObject *_args)
410 PyObject *_res = NULL;
411 if (!PyArg_ParseTuple(_args, ""))
413 CGContextClosePath(_self->ob_itself);
419 static PyObject *CGContextRefObj_CGContextAddRect(CGContextRefObject *_self, PyObject *_args)
421 PyObject *_res = NULL;
423 if (!PyArg_ParseTuple(_args, "O&",
424 CGRect_Convert, &rect))
426 CGContextAddRect(_self->ob_itself,
433 static PyObject *CGContextRefObj_CGContextAddArc(CGContextRefObject *_self, PyObject *_args)
435 PyObject *_res = NULL;
442 if (!PyArg_ParseTuple(_args, "fffffi",
450 CGContextAddArc(_self->ob_itself,
462 static PyObject *CGContextRefObj_CGContextAddArcToPoint(CGContextRefObject *_self, PyObject *_args)
464 PyObject *_res = NULL;
470 if (!PyArg_ParseTuple(_args, "fffff",
477 CGContextAddArcToPoint(_self->ob_itself,
488 static PyObject *CGContextRefObj_CGContextIsPathEmpty(CGContextRefObject *_self, PyObject *_args)
490 PyObject *_res = NULL;
492 if (!PyArg_ParseTuple(_args, ""))
494 _rv = CGContextIsPathEmpty(_self->ob_itself);
495 _res = Py_BuildValue("i",
500 static PyObject *CGContextRefObj_CGContextGetPathCurrentPoint(CGContextRefObject *_self, PyObject *_args)
502 PyObject *_res = NULL;
504 if (!PyArg_ParseTuple(_args, ""))
506 _rv = CGContextGetPathCurrentPoint(_self->ob_itself);
507 _res = Py_BuildValue("O&",
512 static PyObject *CGContextRefObj_CGContextGetPathBoundingBox(CGContextRefObject *_self, PyObject *_args)
514 PyObject *_res = NULL;
516 if (!PyArg_ParseTuple(_args, ""))
518 _rv = CGContextGetPathBoundingBox(_self->ob_itself);
519 _res = Py_BuildValue("O&",
524 static PyObject *CGContextRefObj_CGContextDrawPath(CGContextRefObject *_self, PyObject *_args)
526 PyObject *_res = NULL;
528 if (!PyArg_ParseTuple(_args, "i",
531 CGContextDrawPath(_self->ob_itself,
538 static PyObject *CGContextRefObj_CGContextFillPath(CGContextRefObject *_self, PyObject *_args)
540 PyObject *_res = NULL;
541 if (!PyArg_ParseTuple(_args, ""))
543 CGContextFillPath(_self->ob_itself);
549 static PyObject *CGContextRefObj_CGContextEOFillPath(CGContextRefObject *_self, PyObject *_args)
551 PyObject *_res = NULL;
552 if (!PyArg_ParseTuple(_args, ""))
554 CGContextEOFillPath(_self->ob_itself);
560 static PyObject *CGContextRefObj_CGContextStrokePath(CGContextRefObject *_self, PyObject *_args)
562 PyObject *_res = NULL;
563 if (!PyArg_ParseTuple(_args, ""))
565 CGContextStrokePath(_self->ob_itself);
571 static PyObject *CGContextRefObj_CGContextFillRect(CGContextRefObject *_self, PyObject *_args)
573 PyObject *_res = NULL;
575 if (!PyArg_ParseTuple(_args, "O&",
576 CGRect_Convert, &rect))
578 CGContextFillRect(_self->ob_itself,
585 static PyObject *CGContextRefObj_CGContextStrokeRect(CGContextRefObject *_self, PyObject *_args)
587 PyObject *_res = NULL;
589 if (!PyArg_ParseTuple(_args, "O&",
590 CGRect_Convert, &rect))
592 CGContextStrokeRect(_self->ob_itself,
599 static PyObject *CGContextRefObj_CGContextStrokeRectWithWidth(CGContextRefObject *_self, PyObject *_args)
601 PyObject *_res = NULL;
604 if (!PyArg_ParseTuple(_args, "O&f",
605 CGRect_Convert, &rect,
608 CGContextStrokeRectWithWidth(_self->ob_itself,
616 static PyObject *CGContextRefObj_CGContextClearRect(CGContextRefObject *_self, PyObject *_args)
618 PyObject *_res = NULL;
620 if (!PyArg_ParseTuple(_args, "O&",
621 CGRect_Convert, &rect))
623 CGContextClearRect(_self->ob_itself,
630 static PyObject *CGContextRefObj_CGContextClip(CGContextRefObject *_self, PyObject *_args)
632 PyObject *_res = NULL;
633 if (!PyArg_ParseTuple(_args, ""))
635 CGContextClip(_self->ob_itself);
641 static PyObject *CGContextRefObj_CGContextEOClip(CGContextRefObject *_self, PyObject *_args)
643 PyObject *_res = NULL;
644 if (!PyArg_ParseTuple(_args, ""))
646 CGContextEOClip(_self->ob_itself);
652 static PyObject *CGContextRefObj_CGContextClipToRect(CGContextRefObject *_self, PyObject *_args)
654 PyObject *_res = NULL;
656 if (!PyArg_ParseTuple(_args, "O&",
657 CGRect_Convert, &rect))
659 CGContextClipToRect(_self->ob_itself,
666 static PyObject *CGContextRefObj_CGContextSetGrayFillColor(CGContextRefObject *_self, PyObject *_args)
668 PyObject *_res = NULL;
671 if (!PyArg_ParseTuple(_args, "ff",
675 CGContextSetGrayFillColor(_self->ob_itself,
683 static PyObject *CGContextRefObj_CGContextSetGrayStrokeColor(CGContextRefObject *_self, PyObject *_args)
685 PyObject *_res = NULL;
688 if (!PyArg_ParseTuple(_args, "ff",
692 CGContextSetGrayStrokeColor(_self->ob_itself,
700 static PyObject *CGContextRefObj_CGContextSetRGBFillColor(CGContextRefObject *_self, PyObject *_args)
702 PyObject *_res = NULL;
707 if (!PyArg_ParseTuple(_args, "ffff",
713 CGContextSetRGBFillColor(_self->ob_itself,
723 static PyObject *CGContextRefObj_CGContextSetRGBStrokeColor(CGContextRefObject *_self, PyObject *_args)
725 PyObject *_res = NULL;
730 if (!PyArg_ParseTuple(_args, "ffff",
736 CGContextSetRGBStrokeColor(_self->ob_itself,
746 static PyObject *CGContextRefObj_CGContextSetCMYKFillColor(CGContextRefObject *_self, PyObject *_args)
748 PyObject *_res = NULL;
754 if (!PyArg_ParseTuple(_args, "fffff",
761 CGContextSetCMYKFillColor(_self->ob_itself,
772 static PyObject *CGContextRefObj_CGContextSetCMYKStrokeColor(CGContextRefObject *_self, PyObject *_args)
774 PyObject *_res = NULL;
780 if (!PyArg_ParseTuple(_args, "fffff",
787 CGContextSetCMYKStrokeColor(_self->ob_itself,
798 static PyObject *CGContextRefObj_CGContextGetInterpolationQuality(CGContextRefObject *_self, PyObject *_args)
800 PyObject *_res = NULL;
802 if (!PyArg_ParseTuple(_args, ""))
804 _rv = CGContextGetInterpolationQuality(_self->ob_itself);
805 _res = Py_BuildValue("i",
810 static PyObject *CGContextRefObj_CGContextSetInterpolationQuality(CGContextRefObject *_self, PyObject *_args)
812 PyObject *_res = NULL;
814 if (!PyArg_ParseTuple(_args, "i",
817 CGContextSetInterpolationQuality(_self->ob_itself,
824 static PyObject *CGContextRefObj_CGContextSetCharacterSpacing(CGContextRefObject *_self, PyObject *_args)
826 PyObject *_res = NULL;
828 if (!PyArg_ParseTuple(_args, "f",
831 CGContextSetCharacterSpacing(_self->ob_itself,
838 static PyObject *CGContextRefObj_CGContextSetTextPosition(CGContextRefObject *_self, PyObject *_args)
840 PyObject *_res = NULL;
843 if (!PyArg_ParseTuple(_args, "ff",
847 CGContextSetTextPosition(_self->ob_itself,
855 static PyObject *CGContextRefObj_CGContextGetTextPosition(CGContextRefObject *_self, PyObject *_args)
857 PyObject *_res = NULL;
859 if (!PyArg_ParseTuple(_args, ""))
861 _rv = CGContextGetTextPosition(_self->ob_itself);
862 _res = Py_BuildValue("O&",
867 static PyObject *CGContextRefObj_CGContextSetTextMatrix(CGContextRefObject *_self, PyObject *_args)
869 PyObject *_res = NULL;
870 CGAffineTransform transform;
871 if (!PyArg_ParseTuple(_args, "O&",
872 CGAffineTransform_Convert, &transform))
874 CGContextSetTextMatrix(_self->ob_itself,
881 static PyObject *CGContextRefObj_CGContextGetTextMatrix(CGContextRefObject *_self, PyObject *_args)
883 PyObject *_res = NULL;
884 CGAffineTransform _rv;
885 if (!PyArg_ParseTuple(_args, ""))
887 _rv = CGContextGetTextMatrix(_self->ob_itself);
888 _res = Py_BuildValue("O&",
889 CGAffineTransform_New, &_rv);
893 static PyObject *CGContextRefObj_CGContextSetTextDrawingMode(CGContextRefObject *_self, PyObject *_args)
895 PyObject *_res = NULL;
897 if (!PyArg_ParseTuple(_args, "i",
900 CGContextSetTextDrawingMode(_self->ob_itself,
907 static PyObject *CGContextRefObj_CGContextSetFontSize(CGContextRefObject *_self, PyObject *_args)
909 PyObject *_res = NULL;
911 if (!PyArg_ParseTuple(_args, "f",
914 CGContextSetFontSize(_self->ob_itself,
921 static PyObject *CGContextRefObj_CGContextSelectFont(CGContextRefObject *_self, PyObject *_args)
923 PyObject *_res = NULL;
927 if (!PyArg_ParseTuple(_args, "sfi",
932 CGContextSelectFont(_self->ob_itself,
941 static PyObject *CGContextRefObj_CGContextShowText(CGContextRefObject *_self, PyObject *_args)
943 PyObject *_res = NULL;
946 int cstring__in_len__;
947 if (!PyArg_ParseTuple(_args, "s#",
948 &cstring__in__, &cstring__in_len__))
950 cstring__len__ = cstring__in_len__;
951 CGContextShowText(_self->ob_itself,
952 cstring__in__, cstring__len__);
958 static PyObject *CGContextRefObj_CGContextShowTextAtPoint(CGContextRefObject *_self, PyObject *_args)
960 PyObject *_res = NULL;
965 int cstring__in_len__;
966 if (!PyArg_ParseTuple(_args, "ffs#",
969 &cstring__in__, &cstring__in_len__))
971 cstring__len__ = cstring__in_len__;
972 CGContextShowTextAtPoint(_self->ob_itself,
975 cstring__in__, cstring__len__);
981 static PyObject *CGContextRefObj_CGContextEndPage(CGContextRefObject *_self, PyObject *_args)
983 PyObject *_res = NULL;
984 if (!PyArg_ParseTuple(_args, ""))
986 CGContextEndPage(_self->ob_itself);
992 static PyObject *CGContextRefObj_CGContextFlush(CGContextRefObject *_self, PyObject *_args)
994 PyObject *_res = NULL;
995 if (!PyArg_ParseTuple(_args, ""))
997 CGContextFlush(_self->ob_itself);
1003 static PyObject *CGContextRefObj_CGContextSynchronize(CGContextRefObject *_self, PyObject *_args)
1005 PyObject *_res = NULL;
1006 if (!PyArg_ParseTuple(_args, ""))
1008 CGContextSynchronize(_self->ob_itself);
1014 static PyObject *CGContextRefObj_CGContextSetShouldAntialias(CGContextRefObject *_self, PyObject *_args)
1016 PyObject *_res = NULL;
1017 int shouldAntialias;
1018 if (!PyArg_ParseTuple(_args, "i",
1021 CGContextSetShouldAntialias(_self->ob_itself,
1029 static PyObject *CGContextRefObj_SyncCGContextOriginWithPort(CGContextRefObject *_self, PyObject *_args)
1031 PyObject *_res = NULL;
1033 if (!PyArg_ParseTuple(_args, "O&",
1034 GrafObj_Convert, &port))
1036 SyncCGContextOriginWithPort(_self->ob_itself,
1043 static PyObject *CGContextRefObj_ClipCGContextToRegion(CGContextRefObject *_self, PyObject *_args)
1045 PyObject *_res = NULL;
1048 if (!PyArg_ParseTuple(_args, "O&O&",
1049 PyMac_GetRect, &portRect,
1050 ResObj_Convert, ®ion))
1052 ClipCGContextToRegion(_self->ob_itself,
1061 static PyMethodDef CGContextRefObj_methods[] = {
1062 {"CGContextSaveGState", (PyCFunction)CGContextRefObj_CGContextSaveGState, 1,
1063 PyDoc_STR("() -> None")},
1064 {"CGContextRestoreGState", (PyCFunction)CGContextRefObj_CGContextRestoreGState, 1,
1065 PyDoc_STR("() -> None")},
1066 {"CGContextScaleCTM", (PyCFunction)CGContextRefObj_CGContextScaleCTM, 1,
1067 PyDoc_STR("(float sx, float sy) -> None")},
1068 {"CGContextTranslateCTM", (PyCFunction)CGContextRefObj_CGContextTranslateCTM, 1,
1069 PyDoc_STR("(float tx, float ty) -> None")},
1070 {"CGContextRotateCTM", (PyCFunction)CGContextRefObj_CGContextRotateCTM, 1,
1071 PyDoc_STR("(float angle) -> None")},
1072 {"CGContextConcatCTM", (PyCFunction)CGContextRefObj_CGContextConcatCTM, 1,
1073 PyDoc_STR("(CGAffineTransform transform) -> None")},
1074 {"CGContextGetCTM", (PyCFunction)CGContextRefObj_CGContextGetCTM, 1,
1075 PyDoc_STR("() -> (CGAffineTransform _rv)")},
1076 {"CGContextSetLineWidth", (PyCFunction)CGContextRefObj_CGContextSetLineWidth, 1,
1077 PyDoc_STR("(float width) -> None")},
1078 {"CGContextSetLineCap", (PyCFunction)CGContextRefObj_CGContextSetLineCap, 1,
1079 PyDoc_STR("(int cap) -> None")},
1080 {"CGContextSetLineJoin", (PyCFunction)CGContextRefObj_CGContextSetLineJoin, 1,
1081 PyDoc_STR("(int join) -> None")},
1082 {"CGContextSetMiterLimit", (PyCFunction)CGContextRefObj_CGContextSetMiterLimit, 1,
1083 PyDoc_STR("(float limit) -> None")},
1084 {"CGContextSetFlatness", (PyCFunction)CGContextRefObj_CGContextSetFlatness, 1,
1085 PyDoc_STR("(float flatness) -> None")},
1086 {"CGContextSetAlpha", (PyCFunction)CGContextRefObj_CGContextSetAlpha, 1,
1087 PyDoc_STR("(float alpha) -> None")},
1088 {"CGContextBeginPath", (PyCFunction)CGContextRefObj_CGContextBeginPath, 1,
1089 PyDoc_STR("() -> None")},
1090 {"CGContextMoveToPoint", (PyCFunction)CGContextRefObj_CGContextMoveToPoint, 1,
1091 PyDoc_STR("(float x, float y) -> None")},
1092 {"CGContextAddLineToPoint", (PyCFunction)CGContextRefObj_CGContextAddLineToPoint, 1,
1093 PyDoc_STR("(float x, float y) -> None")},
1094 {"CGContextAddCurveToPoint", (PyCFunction)CGContextRefObj_CGContextAddCurveToPoint, 1,
1095 PyDoc_STR("(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) -> None")},
1096 {"CGContextAddQuadCurveToPoint", (PyCFunction)CGContextRefObj_CGContextAddQuadCurveToPoint, 1,
1097 PyDoc_STR("(float cpx, float cpy, float x, float y) -> None")},
1098 {"CGContextClosePath", (PyCFunction)CGContextRefObj_CGContextClosePath, 1,
1099 PyDoc_STR("() -> None")},
1100 {"CGContextAddRect", (PyCFunction)CGContextRefObj_CGContextAddRect, 1,
1101 PyDoc_STR("(CGRect rect) -> None")},
1102 {"CGContextAddArc", (PyCFunction)CGContextRefObj_CGContextAddArc, 1,
1103 PyDoc_STR("(float x, float y, float radius, float startAngle, float endAngle, int clockwise) -> None")},
1104 {"CGContextAddArcToPoint", (PyCFunction)CGContextRefObj_CGContextAddArcToPoint, 1,
1105 PyDoc_STR("(float x1, float y1, float x2, float y2, float radius) -> None")},
1106 {"CGContextIsPathEmpty", (PyCFunction)CGContextRefObj_CGContextIsPathEmpty, 1,
1107 PyDoc_STR("() -> (int _rv)")},
1108 {"CGContextGetPathCurrentPoint", (PyCFunction)CGContextRefObj_CGContextGetPathCurrentPoint, 1,
1109 PyDoc_STR("() -> (CGPoint _rv)")},
1110 {"CGContextGetPathBoundingBox", (PyCFunction)CGContextRefObj_CGContextGetPathBoundingBox, 1,
1111 PyDoc_STR("() -> (CGRect _rv)")},
1112 {"CGContextDrawPath", (PyCFunction)CGContextRefObj_CGContextDrawPath, 1,
1113 PyDoc_STR("(int mode) -> None")},
1114 {"CGContextFillPath", (PyCFunction)CGContextRefObj_CGContextFillPath, 1,
1115 PyDoc_STR("() -> None")},
1116 {"CGContextEOFillPath", (PyCFunction)CGContextRefObj_CGContextEOFillPath, 1,
1117 PyDoc_STR("() -> None")},
1118 {"CGContextStrokePath", (PyCFunction)CGContextRefObj_CGContextStrokePath, 1,
1119 PyDoc_STR("() -> None")},
1120 {"CGContextFillRect", (PyCFunction)CGContextRefObj_CGContextFillRect, 1,
1121 PyDoc_STR("(CGRect rect) -> None")},
1122 {"CGContextStrokeRect", (PyCFunction)CGContextRefObj_CGContextStrokeRect, 1,
1123 PyDoc_STR("(CGRect rect) -> None")},
1124 {"CGContextStrokeRectWithWidth", (PyCFunction)CGContextRefObj_CGContextStrokeRectWithWidth, 1,
1125 PyDoc_STR("(CGRect rect, float width) -> None")},
1126 {"CGContextClearRect", (PyCFunction)CGContextRefObj_CGContextClearRect, 1,
1127 PyDoc_STR("(CGRect rect) -> None")},
1128 {"CGContextClip", (PyCFunction)CGContextRefObj_CGContextClip, 1,
1129 PyDoc_STR("() -> None")},
1130 {"CGContextEOClip", (PyCFunction)CGContextRefObj_CGContextEOClip, 1,
1131 PyDoc_STR("() -> None")},
1132 {"CGContextClipToRect", (PyCFunction)CGContextRefObj_CGContextClipToRect, 1,
1133 PyDoc_STR("(CGRect rect) -> None")},
1134 {"CGContextSetGrayFillColor", (PyCFunction)CGContextRefObj_CGContextSetGrayFillColor, 1,
1135 PyDoc_STR("(float gray, float alpha) -> None")},
1136 {"CGContextSetGrayStrokeColor", (PyCFunction)CGContextRefObj_CGContextSetGrayStrokeColor, 1,
1137 PyDoc_STR("(float gray, float alpha) -> None")},
1138 {"CGContextSetRGBFillColor", (PyCFunction)CGContextRefObj_CGContextSetRGBFillColor, 1,
1139 PyDoc_STR("(float red, float green, float blue, float alpha) -> None")},
1140 {"CGContextSetRGBStrokeColor", (PyCFunction)CGContextRefObj_CGContextSetRGBStrokeColor, 1,
1141 PyDoc_STR("(float red, float green, float blue, float alpha) -> None")},
1142 {"CGContextSetCMYKFillColor", (PyCFunction)CGContextRefObj_CGContextSetCMYKFillColor, 1,
1143 PyDoc_STR("(float cyan, float magenta, float yellow, float black, float alpha) -> None")},
1144 {"CGContextSetCMYKStrokeColor", (PyCFunction)CGContextRefObj_CGContextSetCMYKStrokeColor, 1,
1145 PyDoc_STR("(float cyan, float magenta, float yellow, float black, float alpha) -> None")},
1146 {"CGContextGetInterpolationQuality", (PyCFunction)CGContextRefObj_CGContextGetInterpolationQuality, 1,
1147 PyDoc_STR("() -> (int _rv)")},
1148 {"CGContextSetInterpolationQuality", (PyCFunction)CGContextRefObj_CGContextSetInterpolationQuality, 1,
1149 PyDoc_STR("(int quality) -> None")},
1150 {"CGContextSetCharacterSpacing", (PyCFunction)CGContextRefObj_CGContextSetCharacterSpacing, 1,
1151 PyDoc_STR("(float spacing) -> None")},
1152 {"CGContextSetTextPosition", (PyCFunction)CGContextRefObj_CGContextSetTextPosition, 1,
1153 PyDoc_STR("(float x, float y) -> None")},
1154 {"CGContextGetTextPosition", (PyCFunction)CGContextRefObj_CGContextGetTextPosition, 1,
1155 PyDoc_STR("() -> (CGPoint _rv)")},
1156 {"CGContextSetTextMatrix", (PyCFunction)CGContextRefObj_CGContextSetTextMatrix, 1,
1157 PyDoc_STR("(CGAffineTransform transform) -> None")},
1158 {"CGContextGetTextMatrix", (PyCFunction)CGContextRefObj_CGContextGetTextMatrix, 1,
1159 PyDoc_STR("() -> (CGAffineTransform _rv)")},
1160 {"CGContextSetTextDrawingMode", (PyCFunction)CGContextRefObj_CGContextSetTextDrawingMode, 1,
1161 PyDoc_STR("(int mode) -> None")},
1162 {"CGContextSetFontSize", (PyCFunction)CGContextRefObj_CGContextSetFontSize, 1,
1163 PyDoc_STR("(float size) -> None")},
1164 {"CGContextSelectFont", (PyCFunction)CGContextRefObj_CGContextSelectFont, 1,
1165 PyDoc_STR("(char * name, float size, int textEncoding) -> None")},
1166 {"CGContextShowText", (PyCFunction)CGContextRefObj_CGContextShowText, 1,
1167 PyDoc_STR("(Buffer cstring) -> None")},
1168 {"CGContextShowTextAtPoint", (PyCFunction)CGContextRefObj_CGContextShowTextAtPoint, 1,
1169 PyDoc_STR("(float x, float y, Buffer cstring) -> None")},
1170 {"CGContextEndPage", (PyCFunction)CGContextRefObj_CGContextEndPage, 1,
1171 PyDoc_STR("() -> None")},
1172 {"CGContextFlush", (PyCFunction)CGContextRefObj_CGContextFlush, 1,
1173 PyDoc_STR("() -> None")},
1174 {"CGContextSynchronize", (PyCFunction)CGContextRefObj_CGContextSynchronize, 1,
1175 PyDoc_STR("() -> None")},
1176 {"CGContextSetShouldAntialias", (PyCFunction)CGContextRefObj_CGContextSetShouldAntialias, 1,
1177 PyDoc_STR("(int shouldAntialias) -> None")},
1179 {"SyncCGContextOriginWithPort", (PyCFunction)CGContextRefObj_SyncCGContextOriginWithPort, 1,
1180 PyDoc_STR("(CGrafPtr port) -> None")},
1181 {"ClipCGContextToRegion", (PyCFunction)CGContextRefObj_ClipCGContextToRegion, 1,
1182 PyDoc_STR("(Rect portRect, RgnHandle region) -> None")},
1187 #define CGContextRefObj_getsetlist NULL
1190 #define CGContextRefObj_compare NULL
1192 #define CGContextRefObj_repr NULL
1194 #define CGContextRefObj_hash NULL
1195 #define CGContextRefObj_tp_init 0
1197 #define CGContextRefObj_tp_alloc PyType_GenericAlloc
1199 static PyObject *CGContextRefObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
1202 CGContextRef itself;
1203 char *kw[] = {"itself", 0};
1205 if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CGContextRefObj_Convert, &itself)) return NULL;
1206 if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;
1207 ((CGContextRefObject *)_self)->ob_itself = itself;
1211 #define CGContextRefObj_tp_free PyObject_Del
1214 PyTypeObject CGContextRef_Type = {
1215 PyObject_HEAD_INIT(NULL)
1217 "_CG.CGContextRef", /*tp_name*/
1218 sizeof(CGContextRefObject), /*tp_basicsize*/
1221 (destructor) CGContextRefObj_dealloc, /*tp_dealloc*/
1223 (getattrfunc)0, /*tp_getattr*/
1224 (setattrfunc)0, /*tp_setattr*/
1225 (cmpfunc) CGContextRefObj_compare, /*tp_compare*/
1226 (reprfunc) CGContextRefObj_repr, /*tp_repr*/
1227 (PyNumberMethods *)0, /* tp_as_number */
1228 (PySequenceMethods *)0, /* tp_as_sequence */
1229 (PyMappingMethods *)0, /* tp_as_mapping */
1230 (hashfunc) CGContextRefObj_hash, /*tp_hash*/
1233 PyObject_GenericGetAttr, /*tp_getattro*/
1234 PyObject_GenericSetAttr, /*tp_setattro */
1236 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1240 0, /*tp_richcompare*/
1241 0, /*tp_weaklistoffset*/
1244 CGContextRefObj_methods, /* tp_methods */
1246 CGContextRefObj_getsetlist, /*tp_getset*/
1251 0, /*tp_dictoffset*/
1252 CGContextRefObj_tp_init, /* tp_init */
1253 CGContextRefObj_tp_alloc, /* tp_alloc */
1254 CGContextRefObj_tp_new, /* tp_new */
1255 CGContextRefObj_tp_free, /* tp_free */
1258 /* ------------------ End object type CGContextRef ------------------ */
1262 static PyObject *CG_CreateCGContextForPort(PyObject *_self, PyObject *_args)
1264 PyObject *_res = NULL;
1269 if (!PyArg_ParseTuple(_args, "O&", GrafObj_Convert, &port))
1272 _err = CreateCGContextForPort(port, &ctx);
1274 if (_err != noErr) return PyMac_Error(_err);
1275 _res = Py_BuildValue("O&", CGContextRefObj_New, ctx);
1281 static PyMethodDef CG_methods[] = {
1283 {"CreateCGContextForPort", (PyCFunction)CG_CreateCGContextForPort, 1,
1284 PyDoc_STR("(CGrafPtr) -> CGContextRef")},
1300 m = Py_InitModule("_CG", CG_methods);
1301 d = PyModule_GetDict(m);
1302 CG_Error = PyMac_GetOSErrException();
1303 if (CG_Error == NULL ||
1304 PyDict_SetItemString(d, "Error", CG_Error) != 0)
1306 CGContextRef_Type.ob_type = &PyType_Type;
1307 if (PyType_Ready(&CGContextRef_Type) < 0) return;
1308 Py_INCREF(&CGContextRef_Type);
1309 PyModule_AddObject(m, "CGContextRef", (PyObject *)&CGContextRef_Type);
1310 /* Backward-compatible name */
1311 Py_INCREF(&CGContextRef_Type);
1312 PyModule_AddObject(m, "CGContextRefType", (PyObject *)&CGContextRef_Type);
1315 /* ========================= End module _CG ========================= */