| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import string |
| 9 |
|
| 10 |
|
| 11 |
MODNAME = '_CG' |
| 12 |
|
| 13 |
|
| 14 |
MODPREFIX = 'CG' |
| 15 |
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' |
| 16 |
OUTPUTFILE = MODNAME + "module.c" |
| 17 |
|
| 18 |
from macsupport import * |
| 19 |
|
| 20 |
CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj") |
| 21 |
RgnHandle = OpaqueByValueType("RgnHandle", "ResObj") |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
includestuff = includestuff + """ |
| 26 |
#include <ApplicationServices/ApplicationServices.h> |
| 27 |
|
| 28 |
extern int GrafObj_Convert(PyObject *, GrafPtr *); |
| 29 |
|
| 30 |
/* |
| 31 |
** Manual converters |
| 32 |
*/ |
| 33 |
|
| 34 |
PyObject *CGPoint_New(CGPoint *itself) |
| 35 |
{ |
| 36 |
|
| 37 |
return Py_BuildValue("(ff)", |
| 38 |
itself->x, |
| 39 |
itself->y); |
| 40 |
} |
| 41 |
|
| 42 |
int |
| 43 |
CGPoint_Convert(PyObject *v, CGPoint *p_itself) |
| 44 |
{ |
| 45 |
if( !PyArg_Parse(v, "(ff)", |
| 46 |
&p_itself->x, |
| 47 |
&p_itself->y) ) |
| 48 |
return 0; |
| 49 |
return 1; |
| 50 |
} |
| 51 |
|
| 52 |
PyObject *CGRect_New(CGRect *itself) |
| 53 |
{ |
| 54 |
|
| 55 |
return Py_BuildValue("(ffff)", |
| 56 |
itself->origin.x, |
| 57 |
itself->origin.y, |
| 58 |
itself->size.width, |
| 59 |
itself->size.height); |
| 60 |
} |
| 61 |
|
| 62 |
int |
| 63 |
CGRect_Convert(PyObject *v, CGRect *p_itself) |
| 64 |
{ |
| 65 |
if( !PyArg_Parse(v, "(ffff)", |
| 66 |
&p_itself->origin.x, |
| 67 |
&p_itself->origin.y, |
| 68 |
&p_itself->size.width, |
| 69 |
&p_itself->size.height) ) |
| 70 |
return 0; |
| 71 |
return 1; |
| 72 |
} |
| 73 |
|
| 74 |
PyObject *CGAffineTransform_New(CGAffineTransform *itself) |
| 75 |
{ |
| 76 |
|
| 77 |
return Py_BuildValue("(ffffff)", |
| 78 |
itself->a, |
| 79 |
itself->b, |
| 80 |
itself->c, |
| 81 |
itself->d, |
| 82 |
itself->tx, |
| 83 |
itself->ty); |
| 84 |
} |
| 85 |
|
| 86 |
int |
| 87 |
CGAffineTransform_Convert(PyObject *v, CGAffineTransform *p_itself) |
| 88 |
{ |
| 89 |
if( !PyArg_Parse(v, "(ffffff)", |
| 90 |
&p_itself->a, |
| 91 |
&p_itself->b, |
| 92 |
&p_itself->c, |
| 93 |
&p_itself->d, |
| 94 |
&p_itself->tx, |
| 95 |
&p_itself->ty) ) |
| 96 |
return 0; |
| 97 |
return 1; |
| 98 |
} |
| 99 |
""" |
| 100 |
|
| 101 |
class MyOpaqueByValueType(OpaqueByValueType): |
| 102 |
"""Sort of a mix between OpaqueByValueType and OpaqueType.""" |
| 103 |
def mkvalueArgs(self, name): |
| 104 |
return "%s, &%s" % (self.new, name) |
| 105 |
|
| 106 |
CGPoint = MyOpaqueByValueType('CGPoint', 'CGPoint') |
| 107 |
CGRect = MyOpaqueByValueType('CGRect', 'CGRect') |
| 108 |
CGAffineTransform = MyOpaqueByValueType('CGAffineTransform', 'CGAffineTransform') |
| 109 |
|
| 110 |
char_ptr = Type("char *", "s") |
| 111 |
|
| 112 |
CGTextEncoding = int |
| 113 |
CGLineCap = int |
| 114 |
CGLineJoin = int |
| 115 |
CGTextDrawingMode = int |
| 116 |
CGPathDrawingMode = int |
| 117 |
CGInterpolationQuality = int |
| 118 |
|
| 119 |
|
| 120 |
CGContextRef = OpaqueByValueType("CGContextRef", "CGContextRefObj") |
| 121 |
|
| 122 |
|
| 123 |
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
| 124 |
def outputStructMembers(self): |
| 125 |
ObjectDefinition.outputStructMembers(self) |
| 126 |
def outputCleanupStructMembers(self): |
| 127 |
Output("CGContextRelease(self->ob_itself);") |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) |
| 132 |
|
| 133 |
CGContextRef_object = MyObjectDefinition('CGContextRef', 'CGContextRefObj', 'CGContextRef') |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
module.addobject(CGContextRef_object) |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
Function = FunctionGenerator |
| 143 |
Method = MethodGenerator |
| 144 |
|
| 145 |
CGContextRef_methods = [] |
| 146 |
|
| 147 |
|
| 148 |
execfile(INPUTFILE) |
| 149 |
|
| 150 |
|
| 151 |
f = Method(void, 'SyncCGContextOriginWithPort', |
| 152 |
(CGContextRef, 'ctx', InMode), |
| 153 |
(CGrafPtr, 'port', InMode), |
| 154 |
) |
| 155 |
CGContextRef_methods.append(f) |
| 156 |
|
| 157 |
|
| 158 |
f = Method(void, 'ClipCGContextToRegion', |
| 159 |
(CGContextRef, 'ctx', InMode), |
| 160 |
(Rect, 'portRect', InMode), |
| 161 |
(RgnHandle, 'region', InMode), |
| 162 |
) |
| 163 |
CGContextRef_methods.append(f) |
| 164 |
|
| 165 |
|
| 166 |
CreateCGContextForPort_body = """\ |
| 167 |
GrafPtr port; |
| 168 |
CGContextRef ctx; |
| 169 |
OSStatus _err; |
| 170 |
|
| 171 |
if (!PyArg_ParseTuple(_args, "O&", GrafObj_Convert, &port)) |
| 172 |
return NULL; |
| 173 |
|
| 174 |
_err = CreateCGContextForPort(port, &ctx); |
| 175 |
if (_err != noErr) |
| 176 |
if (_err != noErr) return PyMac_Error(_err); |
| 177 |
_res = Py_BuildValue("O&", CGContextRefObj_New, ctx); |
| 178 |
return _res; |
| 179 |
""" |
| 180 |
|
| 181 |
f = ManualGenerator("CreateCGContextForPort", CreateCGContextForPort_body); |
| 182 |
f.docstring = lambda: "(CGrafPtr) -> CGContextRef" |
| 183 |
module.add(f) |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
for f in CGContextRef_methods: |
| 188 |
CGContextRef_object.add(f) |
| 189 |
|
| 190 |
|
| 191 |
SetOutputFileName(OUTPUTFILE) |
| 192 |
module.generate() |