1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
%module cairo
#pragma SWIG nowarn=312
%{
#include <cairo/cairo.h>
#include <cairo/cairo-pdf.h>
#include <cairo/cairo-svg.h>
/*
static cairo_status_t py_read_func(void *closure, unsigned char *data, unsigned int length)
{
PyObject *arg = Py_BuildValue("i", length);
PyObject *res = PyObject_Call((PyObject*)closure, arg, NULL);
Py_DECREF(arg);
if (!res)
{
PyErr_Print();
PyErr_Clear();
return CAIRO_STATUS_READ_ERROR;
}
if (PyString_Check(res))
{
long l = PyString_Size(res);
char *s = PyString_AsString(res);
if (l > (long)length)
l = length;
memcpy(s, data, l);
Py_DECREF(res);
return CAIRO_STATUS_SUCCESS;
}
Py_DECREF(res);
return CAIRO_STATUS_READ_ERROR;
}*/
%}
%ignore _cairo;
%ignore _cairo_surface;
%ignore _cairo_device;
%ignore _cairo_matrix;
%ignore _cairo_pattern;
%ignore _cairo_user_data_key;
%ignore _cairo_rectangle;
%ignore _cairo_rectangle_list;
%ignore _cairo_scaled_font;
%ignore _cairo_font_face;
%ignore _cairo_font_options;
%ignore _cairo_region;
%ignore _cairo_rectangle_int;
%ignore cairo_path_data_t;
%ignore cairo_path_t;
%ignore cairo_path;
%ignore cairo_rectangle_list_t;
%ignore cairo_rectangle_list_destroy;
%ignore cairo_destroy_func_t;
%ignore cairo_user_data_key_t;
// may need wrapping
%ignore cairo_copy_clip_rectangle_list;
%ignore cairo_user_scaled_font_init_func_t;
%ignore cairo_user_scaled_font_render_glyph_func_t;
%ignore cairo_user_scaled_font_text_to_glyphs_func_t;
%ignore cairo_user_scaled_font_unicode_to_glyph_func_t;
%ignore cairo_user_font_face_set_init_func;
%ignore cairo_user_font_face_set_render_glyph_func;
%ignore cairo_user_font_face_set_text_to_glyphs_func;
%ignore cairo_user_font_face_set_unicode_to_glyph_func;
%ignore cairo_user_font_face_get_init_func;
%ignore cairo_user_font_face_get_render_glyph_func;
%ignore cairo_user_font_face_get_text_to_glyphs_func;
%ignore cairo_user_font_face_get_unicode_to_glyph_func;
%ignore cairo_user_font_face_create;
%ignore cairo_device_t;
%ignore cairo_device_reference;
%ignore cairo_device_type_t;
%ignore cairo_device_get_type;
%ignore cairo_device_status;
%ignore cairo_device_acquire;
%ignore cairo_device_release;
%ignore cairo_device_flush;
%ignore cairo_device_finish;
%ignore cairo_device_destroy;
%ignore cairo_device_get_reference_count;
%ignore cairo_device_get_user_data;
%ignore cairo_device_set_user_data;
%ignore cairo_image_surface_get_data;
%ignore cairo_image_surface_create_for_data;
// create separate wrapper for these if needed
%ignore cairo_set_user_data;
%ignore cairo_get_user_data;
%ignore cairo_font_face_set_user_data;
%ignore cairo_font_face_get_user_data;
%ignore cairo_scaled_font_get_user_data;
%ignore cairo_scaled_font_set_user_data;
%ignore cairo_surface_get_user_data;
%ignore cairo_surface_set_user_data;
%ignore cairo_pattern_get_user_data;
%ignore cairo_pattern_set_user_data;
%ignore cairo_surface_get_mime_data;
%ignore cairo_read_func_t;
%ignore cairo_write_func_t;
//%ignore cairo_set_dash;
// needs separate wrapper
%ignore cairo_image_surface_create_from_png_stream;
%ignore cairo_surface_write_to_png_stream;
// Not supported in cairo 1.8.8 (from OEL6)
%ignore cairo_surface_set_mime_data;
%ignore cairo_region_contains_point;
%ignore cairo_region_contains_rectangle;
%ignore cairo_region_copy;
%ignore cairo_region_create;
%ignore cairo_region_create_rectangle;
%ignore cairo_region_destroy;
%ignore cairo_region_get_extents;
%ignore cairo_region_get_rectangle;
%ignore cairo_region_intersect;
%ignore cairo_region_intersect_rectangle;
%ignore cairo_region_is_empty;
%ignore cairo_region_num_rectangles;
%ignore cairo_region_status;
%ignore cairo_region_subtract;
%ignore cairo_region_subtract_rectangle;
%ignore cairo_region_translate;
%ignore cairo_region_union;
%ignore cairo_region_union_rectangle;
%ignore CAIRO_STATUS_INVALID_SIZE;
%ignore CAIRO_STATUS_LAST_STATUS;
%ignore CAIRO_SURFACE_TYPE_SCRIPT;
%ignore CAIRO_REGION_OVERLAP_IN;
%ignore CAIRO_REGION_OVERLAP_OUT;
%ignore CAIRO_REGION_OVERLAP_PART;
%typemap(in, numinputs=0) cairo_text_extents_t *extents (cairo_text_extents_t extout) {
$1 = &extout;
}
%typemap(argout) cairo_text_extents_t *extents {
PyObject *o= SWIG_NewPointerObj(new cairo_text_extents_t(*$1), SWIGTYPE_p_cairo_text_extents_t, 0 | 0 );
$result= SWIG_Python_AppendOutput($result, o);
}
%typemap(in) const char* (std::string s) {
if (PyUnicode_Check($input))
{
PyObject *tmp = PyUnicode_AsUTF8String($input);
s = PyString_AsString(tmp);
$1 = (char*)s.c_str();
Py_DECREF(tmp);
}
else if (PyString_Check($input))
{
s = PyString_AsString($input);
$1 = (char*)s.c_str();
}
else
{
PyErr_SetString(PyExc_TypeError, "not a string");
SWIG_fail;
}
}
%typemap(freearg) const char* {
}
%typemap(in) (const double *dashes, int num_dashes) {
if (PyList_Check($input)) {
$1 = new double[PyList_Size($input)];
$2 = PyList_Size($input);
for (int c= PyList_Size($input), i= 0; i < c; i++)
{
PyObject *item = PyList_GetItem($input, i);
if (PyFloat_Check(item))
$1[i] = PyFloat_AsDouble(item);
else
{
delete[] $1;
$1 = 0;
SWIG_exception_fail(SWIG_TypeError, "expected list of floats");
}
}
}
else
SWIG_exception_fail(SWIG_TypeError, "expected list of floats");
}
%typemap(freearg) (const double *dashes, int num_dashes) {
delete[] $1;
}
%include <cairo/cairo.h>
cairo_surface_t *cairo_image_surface_create_from_png_stream(PyObject *reader)
{
return cairo_image_surface_create_from_png_stream(py_read_func, reader);
}
|