Skip to content

Commit

Permalink
All changes wrapped by preprocessor directive PY33 to make backward c…
Browse files Browse the repository at this point in the history
…ompatible.
  • Loading branch information
bingjeff committed Apr 18, 2013
1 parent 6433af0 commit b167fe3
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions src/_macosx.m
Expand Up @@ -11,6 +11,12 @@
#define PY3K 0
#endif

#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >=3)
#define PY33 1
#else
#define PY33 0
#endif

/* Must define Py_TYPE for Python 2.5 or older */
#ifndef Py_TYPE
# define Py_TYPE(o) ((o)->ob_type)
Expand Down Expand Up @@ -2539,13 +2545,17 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
int n;
PyObject* family;
float size;
const char* text;
const char* weight;
const char* italic;
float angle;
CTFontRef font;
CGColorRef color;
CGFloat descent;
#if PY33
const char* text;
#else
const UniChar* text;
#endif

CFStringRef keys[2];
CFTypeRef values[2];
Expand All @@ -2556,7 +2566,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
PyErr_SetString(PyExc_RuntimeError, "CGContextRef is NULL");
return NULL;
}

#if PY33
if(!PyArg_ParseTuple(args, "ffs#Ofssf",
&x,
&y,
Expand All @@ -2568,6 +2578,19 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
&italic,
&angle)) return NULL;
CFStringRef s = CFStringCreateWithCString(kCFAllocatorDefault, text, kCFStringEncodingUTF8);
#else
if(!PyArg_ParseTuple(args, "ffu#Ofssf",
&x,
&y,
&text,
&n,
&family,
&size,
&weight,
&italic,
&angle)) return NULL;
CFStringRef s = CFStringCreateWithCharacters(kCFAllocatorDefault, text, n);
#endif

font = setfont(cr, family, size, weight, italic);

Expand Down Expand Up @@ -2633,9 +2656,13 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
int n;
PyObject* family;
float size;
const char* text;
const char* weight;
const char* italic;
#if PY33
const char* text;
#else
const UniChar* text;
#endif

CGFloat ascent;
CGFloat descent;
Expand All @@ -2651,6 +2678,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
return NULL;
}

#if PY33
if(!PyArg_ParseTuple(args, "s#Ofss",
&text,
&n,
Expand All @@ -2659,6 +2687,16 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
&weight,
&italic)) return NULL;
CFStringRef s = CFStringCreateWithCString(kCFAllocatorDefault, text, kCFStringEncodingUTF8);
#else
if(!PyArg_ParseTuple(args, "u#Ofss",
&text,
&n,
&family,
&size,
&weight,
&italic)) return NULL;
CFStringRef s = CFStringCreateWithCharacters(kCFAllocatorDefault, text, n);
#endif

font = setfont(cr, family, size, weight, italic);

Expand Down Expand Up @@ -4902,7 +4940,7 @@ -(void)save_figure:(id)sender
unsigned int n = [filename length];
unichar* buffer = malloc(n*sizeof(unichar));
[filename getCharacters: buffer];
#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 3)
#if PY33
PyObject* string = PyUnicode_FromKindAndData(PyUnicode_2BYTE_KIND, buffer, n);
#else
PyObject* string = PyUnicode_FromUnicode(buffer, n);
Expand Down

0 comments on commit b167fe3

Please sign in to comment.