@@ -2240,6 +2240,14 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2240
2240
return 0;
2241
2241
}
2242
2242
2243
+
2244
+ static CGFloat _get_device_scale(CGContextRef cr)
2245
+ {
2246
+ CGSize pixelSize = CGContextConvertSizeToDeviceSpace(cr, CGSizeMake(1,1));
2247
+ return pixelSize.width;
2248
+ }
2249
+
2250
+
2243
2251
static PyObject*
2244
2252
GraphicsContext_draw_gouraud_triangle (GraphicsContext* self, PyObject* args)
2245
2253
@@ -2998,17 +3006,8 @@ static void _data_provider_release(void* info, const void* data, size_t size)
2998
3006
Py_DECREF(image);
2999
3007
}
3000
3008
3001
- /* Consider the drawing origin to be in user coordinates
3002
- * but the image size to be in device coordinates */
3003
- static void draw_image_user_coords_device_size(CGContextRef cr, CGImageRef im,
3004
- float x, float y, npy_intp ncols, npy_intp nrows)
3005
- {
3006
- CGRect dst;
3007
- dst.origin = CGPointMake(x,y);
3008
- dst.size = CGContextConvertSizeToUserSpace(cr, CGSizeMake(ncols,nrows));
3009
- dst.size.height = fabs(dst.size.height); /* believe it or not... */
3010
- CGContextDrawImage(cr, dst, im);
3011
- }
3009
+
3010
+
3012
3011
3013
3012
static PyObject*
3014
3013
GraphicsContext_draw_mathtext(GraphicsContext* self, PyObject* args)
@@ -3090,16 +3089,18 @@ static void draw_image_user_coords_device_size(CGContextRef cr, CGImageRef im,
3090
3089
return NULL;
3091
3090
}
3092
3091
3092
+ CGFloat deviceScale = _get_device_scale(cr);
3093
+
3093
3094
if (angle==0.0)
3094
3095
{
3095
- draw_image_user_coords_device_size (cr, bitmap, x, y, ncols, nrows);
3096
+ CGContextDrawImage (cr, CGRectMake( x, y, ncols/deviceScale , nrows/deviceScale), bitmap );
3096
3097
}
3097
3098
else
3098
3099
{
3099
3100
CGContextSaveGState(cr);
3100
3101
CGContextTranslateCTM(cr, x, y);
3101
3102
CGContextRotateCTM(cr, angle*M_PI/180);
3102
- draw_image_user_coords_device_size (cr, bitmap, 0, 0, ncols, nrows);
3103
+ CGContextDrawImage (cr, CGRectMake( 0, 0, ncols/deviceScale , nrows/deviceScale), bitmap );
3103
3104
CGContextRestoreGState(cr);
3104
3105
}
3105
3106
CGImageRelease(bitmap);
@@ -3189,7 +3190,9 @@ static void draw_image_user_coords_device_size(CGContextRef cr, CGImageRef im,
3189
3190
return NULL;
3190
3191
}
3191
3192
3192
- draw_image_user_coords_device_size(cr, bitmap, x, y, ncols, nrows);
3193
+ CGFloat deviceScale = _get_device_scale(cr);
3194
+
3195
+ CGContextDrawImage(cr, CGRectMake(x, y, ncols/deviceScale, nrows/deviceScale), bitmap);
3193
3196
CGImageRelease(bitmap);
3194
3197
3195
3198
Py_INCREF(Py_None);
@@ -3206,8 +3209,7 @@ static void draw_image_user_coords_device_size(CGContextRef cr, CGImageRef im,
3206
3209
return NULL;
3207
3210
}
3208
3211
3209
- CGSize pixelSize = CGContextConvertSizeToDeviceSpace(cr, CGSizeMake(1,1));
3210
- return PyFloat_FromDouble(pixelSize.width);
3212
+ return PyFloat_FromDouble(_get_device_scale(cr));
3211
3213
}
3212
3214
3213
3215
0 commit comments