@@ -1165,7 +1165,6 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
11651165static PyObject*
11661166GraphicsContext_draw_path_collection (GraphicsContext* self, PyObject* args)
11671167{
1168- PyObject* master_transform;
11691168 PyObject* cliprect;
11701169 PyObject* clippath;
11711170 PyObject* clippath_transform;
@@ -1187,19 +1186,18 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
11871186 return NULL ;
11881187 }
11891188
1190- if (!PyArg_ParseTuple (args, " OOOOOOOOOOOOO" , &master_transform,
1191- &cliprect,
1192- &clippath,
1193- &clippath_transform,
1194- &paths,
1195- &transforms,
1196- &offsets,
1197- &offset_transform,
1198- &facecolors,
1199- &edgecolors,
1200- &linewidths,
1201- &linestyles,
1202- &antialiaseds))
1189+ if (!PyArg_ParseTuple (args, " OOOOOOOOOOOO" , &cliprect,
1190+ &clippath,
1191+ &clippath_transform,
1192+ &paths,
1193+ &transforms,
1194+ &offsets,
1195+ &offset_transform,
1196+ &facecolors,
1197+ &edgecolors,
1198+ &linewidths,
1199+ &linestyles,
1200+ &antialiaseds))
12031201 return NULL ;
12041202
12051203 int ok = 1 ;
@@ -1235,43 +1233,22 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
12351233 PyErr_SetString (PyExc_ValueError, " transforms must be a sequence object" );
12361234 return NULL ;
12371235 }
1238- Py_ssize_t Ntransforms = PySequence_Size (transforms);
1239-
1240- CGContextSaveGState (cr);
1241- /* ------------------- Set master transform --------------------------- */
1242-
1243- if (Ntransforms)
1236+ const Py_ssize_t Ntransforms = PySequence_Size (transforms);
1237+ if (Ntransforms==0 )
12441238 {
1245- CGAffineTransform master;
1246- double a, b, c, d, tx, ty;
1247- PyObject* values = PyObject_CallMethod (master_transform, " to_values" , " " );
1248- if (!values)
1249- {
1250- ok = 0 ;
1251- goto exit;
1252- }
1253- if (!PyTuple_Check (values))
1254- {
1255- Py_DECREF (values);
1256- ok = 0 ;
1257- goto exit;
1258- }
1259- /* CGAffineTransform contains CGFloat; cannot use master directly */
1260- ok = PyArg_ParseTuple (values, " dddddd" , &a, &b, &c, &d, &tx, &ty);
1261- Py_DECREF (values);
1262- master.a = a;
1263- master.b = b;
1264- master.c = c;
1265- master.d = d;
1266- master.tx = tx;
1267- master.ty = ty;
1268- if (!ok) goto exit;
1269- CGContextConcatCTM (cr, master);
1239+ PyErr_SetString (PyExc_ValueError, " transforms should contain at least one item" );
1240+ return NULL ;
12701241 }
12711242
1272- /* ------------------- Check offsets array ---------------------------- */
1243+ /* ------------------- Read drawing arrays ---------------------------- */
12731244
1245+ CGContextSaveGState (cr);
12741246 offsets = PyArray_FromObject (offsets, NPY_DOUBLE, 0 , 2 );
1247+ facecolors = PyArray_FromObject (facecolors, NPY_DOUBLE, 1 , 2 );
1248+ edgecolors = PyArray_FromObject (edgecolors, NPY_DOUBLE, 1 , 2 );
1249+
1250+ /* ------------------- Check offsets array ---------------------------- */
1251+
12751252 if (!offsets ||
12761253 (PyArray_NDIM (offsets)==2 && PyArray_DIM (offsets, 1 )!=2 ) ||
12771254 (PyArray_NDIM (offsets)==1 && PyArray_DIM (offsets, 0 )!=0 ))
@@ -1282,11 +1259,36 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
12821259 }
12831260 const Py_ssize_t Noffsets = PyArray_DIM (offsets, 0 );
12841261
1262+ /* ------------------- Check facecolors array ------------------------- */
1263+
1264+ if (!facecolors ||
1265+ (PyArray_NDIM (facecolors)==1 && PyArray_DIM (facecolors, 0 )!=0 ) ||
1266+ (PyArray_NDIM (facecolors)==2 && PyArray_DIM (facecolors, 1 )!=4 ))
1267+ {
1268+ PyErr_SetString (PyExc_ValueError, " Facecolors must by a Nx4 numpy array or empty" );
1269+ ok = 0 ;
1270+ goto exit;
1271+ }
1272+
1273+ /* ------------------- Check edgecolors array ------------------------- */
1274+
1275+ if (!edgecolors ||
1276+ (PyArray_NDIM (edgecolors)==1 && PyArray_DIM (edgecolors, 0 )!=0 ) ||
1277+ (PyArray_NDIM (edgecolors)==2 && PyArray_DIM (edgecolors, 1 )!=4 ))
1278+ {
1279+ PyErr_SetString (PyExc_ValueError, " Edgecolors must by a Nx4 numpy array or empty" );
1280+ ok = 0 ;
1281+ goto exit;
1282+ }
1283+
1284+ /* -------------------------------------------------------------------- */
1285+
1286+ if (Npaths==0 ) goto exit; /* Nothing to do */
1287+
12851288 /* -------------------------------------------------------------------- */
12861289
12871290 Np = Npaths > Ntransforms ? Npaths : Ntransforms;
12881291 N = Np > Noffsets ? Np : Noffsets;
1289- if (N < Ntransforms) Ntransforms = N;
12901292
12911293 p = malloc (Np*sizeof (CGMutablePathRef));
12921294 if (!p)
@@ -1305,35 +1307,22 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
13051307 ok = 0 ;
13061308 goto exit;
13071309 }
1308- if (Ntransforms)
1310+ transform = PySequence_ITEM (transforms, i % Ntransforms);
1311+ if (!transform)
13091312 {
1310- transform = PySequence_ITEM (transforms, i % Ntransforms);
1311- if (!transform)
1312- {
1313- PyErr_SetString (PyExc_RuntimeError,
1314- " failed to obtain transform" );
1315- ok = 0 ;
1316- goto exit;
1317- }
1318- iterator = get_path_iterator (path,
1319- transform,
1320- 1 ,
1321- 0 ,
1322- rect,
1323- mode,
1324- 0 );
1325- Py_DECREF (transform);
1326- }
1327- else
1328- {
1329- iterator = get_path_iterator (path,
1330- master_transform,
1331- 1 ,
1332- 0 ,
1333- rect,
1334- mode,
1335- 0 );
1313+ PyErr_SetString (PyExc_RuntimeError, " failed to obtain transform" );
1314+ Py_DECREF (path);
1315+ ok = 0 ;
1316+ goto exit;
13361317 }
1318+ iterator = get_path_iterator (path,
1319+ transform,
1320+ 1 ,
1321+ 0 ,
1322+ rect,
1323+ mode,
1324+ 0 );
1325+ Py_DECREF (transform);
13371326 Py_DECREF (path);
13381327 if (!iterator)
13391328 {
@@ -1381,30 +1370,6 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
13811370 if (n > 0 ) CGContextClip (cr);
13821371 }
13831372
1384- /* ------------------- Check facecolors array ------------------------- */
1385-
1386- facecolors = PyArray_FromObject (facecolors, NPY_DOUBLE, 1 , 2 );
1387- if (!facecolors ||
1388- (PyArray_NDIM (facecolors)==1 && PyArray_DIM (facecolors, 0 )!=0 ) ||
1389- (PyArray_NDIM (facecolors)==2 && PyArray_DIM (facecolors, 1 )!=4 ))
1390- {
1391- PyErr_SetString (PyExc_ValueError, " Facecolors must by a Nx4 numpy array or empty" );
1392- ok = 0 ;
1393- goto exit;
1394- }
1395-
1396- /* ------------------- Check edgecolors array ------------------------- */
1397-
1398- edgecolors = PyArray_FromObject (edgecolors, NPY_DOUBLE, 1 , 2 );
1399- if (!edgecolors ||
1400- (PyArray_NDIM (edgecolors)==1 && PyArray_DIM (edgecolors, 0 )!=0 ) ||
1401- (PyArray_NDIM (edgecolors)==2 && PyArray_DIM (edgecolors, 1 )!=4 ))
1402- {
1403- PyErr_SetString (PyExc_ValueError, " Edgecolors must by a Nx4 numpy array or empty" );
1404- ok = 0 ;
1405- goto exit;
1406- }
1407-
14081373 /* ------------------- Check the other arguments ---------------------- */
14091374
14101375 if (!PySequence_Check (linewidths))
@@ -1610,7 +1575,6 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
16101575 free (p);
16111576 }
16121577 if (!ok) return NULL ;
1613-
16141578 Py_INCREF (Py_None);
16151579 return Py_None;
16161580}
@@ -2390,7 +2354,6 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
23902354 PyErr_SetString (PyExc_RuntimeError, " ATSUDrawText failed" );
23912355 return NULL ;
23922356 }
2393-
23942357 Py_INCREF (Py_None);
23952358 return Py_None;
23962359}
0 commit comments