11
11
#define PY3K 0
12
12
#endif
13
13
14
+ #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >=3)
15
+ #define PY33 1
16
+ #else
17
+ #define PY33 0
18
+ #endif
19
+
14
20
/* Must define Py_TYPE for Python 2.5 or older */
15
21
#ifndef Py_TYPE
16
22
# define Py_TYPE (o ) ((o)->ob_type)
@@ -2584,7 +2590,6 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2584
2590
{
2585
2591
float x;
2586
2592
float y;
2587
- const UniChar* text;
2588
2593
int n;
2589
2594
PyObject* family;
2590
2595
float size;
@@ -2594,6 +2599,11 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2594
2599
CTFontRef font;
2595
2600
CGColorRef color;
2596
2601
CGFloat descent;
2602
+ #if PY33
2603
+ const char * text;
2604
+ #else
2605
+ const UniChar* text;
2606
+ #endif
2597
2607
2598
2608
CFStringRef keys[2 ];
2599
2609
CFTypeRef values[2 ];
@@ -2604,7 +2614,19 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2604
2614
PyErr_SetString (PyExc_RuntimeError, " CGContextRef is NULL" );
2605
2615
return NULL ;
2606
2616
}
2607
-
2617
+ #if PY33
2618
+ if (!PyArg_ParseTuple (args, " ffs#Ofssf" ,
2619
+ &x,
2620
+ &y,
2621
+ &text,
2622
+ &n,
2623
+ &family,
2624
+ &size,
2625
+ &weight,
2626
+ &italic,
2627
+ &angle)) return NULL ;
2628
+ CFStringRef s = CFStringCreateWithCString (kCFAllocatorDefault , text, kCFStringEncodingUTF8 );
2629
+ #else
2608
2630
if (!PyArg_ParseTuple (args, " ffu#Ofssf" ,
2609
2631
&x,
2610
2632
&y,
@@ -2615,6 +2637,8 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2615
2637
&weight,
2616
2638
&italic,
2617
2639
&angle)) return NULL ;
2640
+ CFStringRef s = CFStringCreateWithCharacters (kCFAllocatorDefault , text, n);
2641
+ #endif
2618
2642
2619
2643
font = setfont (cr, family, size, weight, italic);
2620
2644
@@ -2636,8 +2660,6 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2636
2660
CGColorRelease (color);
2637
2661
CFRelease (font);
2638
2662
2639
- CFStringRef s = CFStringCreateWithCharacters (kCFAllocatorDefault , text, n);
2640
-
2641
2663
CFAttributedStringRef string = CFAttributedStringCreate (kCFAllocatorDefault ,
2642
2664
s,
2643
2665
attributes);
@@ -2679,13 +2701,18 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2679
2701
static PyObject*
2680
2702
GraphicsContext_get_text_width_height_descent (GraphicsContext* self, PyObject* args)
2681
2703
{
2682
- const UniChar* text;
2683
2704
int n;
2684
2705
PyObject* family;
2685
2706
float size;
2686
2707
const char * weight;
2687
2708
const char * italic;
2688
2709
2710
+ #if PY33
2711
+ const char * text;
2712
+ #else
2713
+ const UniChar* text;
2714
+ #endif
2715
+
2689
2716
CGFloat ascent;
2690
2717
CGFloat descent;
2691
2718
double width;
@@ -2700,9 +2727,25 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2700
2727
return NULL ;
2701
2728
}
2702
2729
2730
+ #if PY33
2731
+ if (!PyArg_ParseTuple (args, " s#Ofss" ,
2732
+ &text,
2733
+ &n,
2734
+ &family,
2735
+ &size,
2736
+ &weight,
2737
+ &italic)) return NULL ;
2738
+ CFStringRef s = CFStringCreateWithCString (kCFAllocatorDefault , text, kCFStringEncodingUTF8 );
2739
+ #else
2703
2740
if (!PyArg_ParseTuple (args, " u#Ofss" ,
2704
- &text, &n, &family, &size, &weight, &italic))
2705
- return NULL ;
2741
+ &text,
2742
+ &n,
2743
+ &family,
2744
+ &size,
2745
+ &weight,
2746
+ &italic)) return NULL ;
2747
+ CFStringRef s = CFStringCreateWithCharacters (kCFAllocatorDefault , text, n);
2748
+ #endif
2706
2749
2707
2750
font = setfont (cr, family, size, weight, italic);
2708
2751
@@ -2719,8 +2762,6 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2719
2762
&kCFTypeDictionaryValueCallBacks );
2720
2763
CFRelease (font);
2721
2764
2722
- CFStringRef s = CFStringCreateWithCharacters (kCFAllocatorDefault , text, n);
2723
-
2724
2765
CFAttributedStringRef string = CFAttributedStringCreate (kCFAllocatorDefault ,
2725
2766
s,
2726
2767
attributes);
@@ -2745,7 +2786,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
2745
2786
return Py_BuildValue (" fff" , width, rect.size .height , descent);
2746
2787
}
2747
2788
2748
- #else
2789
+ #else // Text drawing for OSX versions <10.5
2749
2790
2750
2791
static PyObject*
2751
1E0A
td>2792
GraphicsContext_draw_text (GraphicsContext* self, PyObject* args)
@@ -4948,7 +4989,11 @@ -(void)save_figure:(id)sender
4948
4989
unsigned int n = [filename length ];
4949
4990
unichar * buffer = malloc (n*sizeof (unichar ));
4950
4991
[filename getCharacters
6255
: buffer];
4992
+ #if PY33
4993
+ PyObject* string = PyUnicode_FromKindAndData (PyUnicode_2BYTE_KIND, buffer, n);
4994
+ #else
4951
4995
PyObject* string = PyUnicode_FromUnicode (buffer, n);
4996
+ #endif
4952
4997
free (buffer);
4953
4998
return string;
4954
4999
}
0 commit comments