Imported Upstream version 1.15.4 upstream/1.15.4
authorDongHun Kwak <dh0128.kwak@samsung.com>
Wed, 31 Oct 2018 02:17:11 +0000 (11:17 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Wed, 31 Oct 2018 02:17:11 +0000 (11:17 +0900)
14 files changed:
NEWS
PKG-INFO
README.rst
cairo/context.c
cairo/device.c
cairo/error.c
cairo/font.c
cairo/pattern.c
cairo/private.h
cairo/surface.c
docs/images/example.svg [new file with mode: 0644]
setup.cfg
setup.py
tests/test_context.py

diff --git a/NEWS b/NEWS
index 3d1130a..9276c99 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,19 @@
 Since version 1.11.0 Pycairo uses `Semantic Versioning
 <http://semver.org/>`__ i.e. the newest version is the latest stable one.
 
+.. _v1.15.4:
+
+1.15.4 - 2017-11-08
+-------------------
+
+Fixes:
+  * Fix some enum conversation errors with (unused) large and negative values.
+    :pr:`81`
+
+Tests:
+  * Fix a rare test error :pr:`80` (:user:`Sergei Trofimovich <trofi>`)
+
+
 .. _v1.15.3:
 
 1.15.3 - 2017-09-17
index 96154ee..678bc46 100644 (file)
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: pycairo
-Version: 1.15.3
+Version: 1.15.4
 Summary: Python interface for cairo
 Home-page: https://pycairo.readthedocs.io
 Author: Christoph Reiter
@@ -13,7 +13,9 @@ Description: .. image:: https://cdn.rawgit.com/pygobject/pycairo/master/docs/ima
         |
         
         Pycairo is a Python module providing bindings for the `cairo graphics library
-        <https://cairographics.org/>`__.
+        <https://cairographics.org/>`__. It depends on **cairo >= 1.13.1** and
+        works with **Python 2.7+** as well as **Python 3.3+**. Pycairo, including this
+        documentation, is licensed under the **LGPLv2.1** as well as the **MPLv1.1**.
         
         The Pycairo bindings are designed to match the cairo C API as closely as
         possible, and to deviate only in cases which are clearly better implemented in
@@ -25,10 +27,35 @@ Description: .. image:: https://cdn.rawgit.com/pygobject/pycairo/master/docs/ima
         * Queries the error status of objects and translates them to exceptions.
         * Provides a C API that can be used by other Python extensions.
         
-        Pycairo depends on **cairo >= 1.14** (the 1.13 git snapshot present in Ubuntu
-        14.04 works as well) and works with **Python 2.7+** as well as **Python
-        3.3+**. Pycairo, including this documentation, is licensed under the
-        **LGPLv2.1** as well as the **MPLv1.1**.
+        ----
+        
+        .. image:: https://cdn.rawgit.com/pygobject/pycairo/master/docs/images/example.svg
+           :align: right
+           :width: 200px
+        
+        .. code:: python
+        
+            import cairo
+        
+            surface = cairo.SVGSurface("example.svg", 200, 200)
+            context = cairo.Context(surface)
+            x, y, x1, y1 = 0.1, 0.5, 0.4, 0.9
+            x2, y2, x3, y3 = 0.6, 0.1, 0.9, 0.5
+            context.scale(200, 200)
+            context.set_line_width(0.04)
+            context.move_to(x, y)
+            context.curve_to(x1, y1, x2, y2, x3, y3)
+            context.stroke()
+            context.set_source_rgba(1, 0.2, 0.2, 0.6)
+            context.set_line_width(0.02)
+            context.move_to(x, y)
+            context.line_to(x1, y1)
+            context.move_to(x2, y2)
+            context.line_to(x3, y3)
+            context.stroke()
+            surface.finish()
+        
+        ----
         
         If Pycairo is not what you need, have a look at `cairocffi
         <https://cairocffi.readthedocs.io>`__, which is an API compatible package
index 62d513e..53c40cd 100644 (file)
@@ -5,7 +5,9 @@
 |
 
 Pycairo is a Python module providing bindings for the `cairo graphics library
-<https://cairographics.org/>`__.
+<https://cairographics.org/>`__. It depends on **cairo >= 1.13.1** and
+works with **Python 2.7+** as well as **Python 3.3+**. Pycairo, including this
+documentation, is licensed under the **LGPLv2.1** as well as the **MPLv1.1**.
 
 The Pycairo bindings are designed to match the cairo C API as closely as
 possible, and to deviate only in cases which are clearly better implemented in
@@ -17,10 +19,35 @@ Features of the Pycairo bindings:
 * Queries the error status of objects and translates them to exceptions.
 * Provides a C API that can be used by other Python extensions.
 
-Pycairo depends on **cairo >= 1.14** (the 1.13 git snapshot present in Ubuntu
-14.04 works as well) and works with **Python 2.7+** as well as **Python
-3.3+**. Pycairo, including this documentation, is licensed under the
-**LGPLv2.1** as well as the **MPLv1.1**.
+----
+
+.. image:: https://cdn.rawgit.com/pygobject/pycairo/master/docs/images/example.svg
+   :align: right
+   :width: 200px
+
+.. code:: python
+
+    import cairo
+
+    surface = cairo.SVGSurface("example.svg", 200, 200)
+    context = cairo.Context(surface)
+    x, y, x1, y1 = 0.1, 0.5, 0.4, 0.9
+    x2, y2, x3, y3 = 0.6, 0.1, 0.9, 0.5
+    context.scale(200, 200)
+    context.set_line_width(0.04)
+    context.move_to(x, y)
+    context.curve_to(x1, y1, x2, y2, x3, y3)
+    context.stroke()
+    context.set_source_rgba(1, 0.2, 0.2, 0.6)
+    context.set_line_width(0.02)
+    context.move_to(x, y)
+    context.line_to(x1, y1)
+    context.move_to(x2, y2)
+    context.line_to(x3, y3)
+    context.stroke()
+    surface.finish()
+
+----
 
 If Pycairo is not what you need, have a look at `cairocffi
 <https://cairocffi.readthedocs.io>`__, which is an API compatible package
index ff06130..860e22e 100644 (file)
@@ -650,10 +650,14 @@ pycairo_push_group (PycairoContext *o) {
 static PyObject *
 pycairo_push_group_with_content (PycairoContext *o, PyObject *args) {
   cairo_content_t content;
+  int content_arg;
 
-  if (!PyArg_ParseTuple(args, "i:Context.push_group_with_content",
-                       &content))
+  if (!PyArg_ParseTuple (args, "i:Context.push_group_with_content",
+                         &content_arg))
     return NULL;
+
+  content = (cairo_content_t)content_arg;
+
   cairo_push_group_with_content (o->ctx, content);
   RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
   Py_RETURN_NONE;
@@ -757,13 +761,18 @@ pycairo_scale (PycairoContext *o, PyObject *args) {
 static PyObject *
 pycairo_select_font_face (PycairoContext *o, PyObject *args) {
   const char *utf8;
-  cairo_font_slant_t slant   = CAIRO_FONT_SLANT_NORMAL;
-  cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
+  cairo_font_slant_t slant;
+  cairo_font_weight_t weight;
+  int slant_arg = CAIRO_FONT_SLANT_NORMAL;
+  int weight_arg = CAIRO_FONT_WEIGHT_NORMAL;
 
   if (!PyArg_ParseTuple (args, PYCAIRO_ENC_TEXT_FORMAT "|ii:Context.select_font_face",
-                        "utf-8", &utf8, &slant, &weight))
+                         "utf-8", &utf8, &slant_arg, &weight_arg))
     return NULL;
 
+  slant = (cairo_font_slant_t)slant_arg;
+  weight = (cairo_font_weight_t)weight_arg;
+
   cairo_select_font_face (o->ctx, utf8, slant, weight);
   PyMem_Free((void *)utf8);
   RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
@@ -772,11 +781,14 @@ pycairo_select_font_face (PycairoContext *o, PyObject *args) {
 
 static PyObject *
 pycairo_set_antialias (PycairoContext *o, PyObject *args) {
-  cairo_antialias_t antialias = CAIRO_ANTIALIAS_DEFAULT;
+  cairo_antialias_t antialias;
+  int antialias_arg = CAIRO_ANTIALIAS_DEFAULT;
 
-  if (!PyArg_ParseTuple(args, "|i:Context.set_antialias", &antialias))
+  if (!PyArg_ParseTuple (args, "|i:Context.set_antialias", &antialias_arg))
     return NULL;
 
+  antialias = (cairo_antialias_t)antialias_arg;
+
   cairo_set_antialias (o->ctx, antialias);
   RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
   Py_RETURN_NONE;
@@ -826,10 +838,13 @@ pycairo_set_dash (PycairoContext *o, PyObject *args) {
 static PyObject *
 pycairo_set_fill_rule (PycairoContext *o, PyObject *args) {
   cairo_fill_rule_t fill_rule;
+  int fill_rule_arg;
 
-  if (!PyArg_ParseTuple (args, "i:Context.set_fill_rule", &fill_rule))
+  if (!PyArg_ParseTuple (args, "i:Context.set_fill_rule", &fill_rule_arg))
     return NULL;
 
+  fill_rule = (cairo_fill_rule_t)fill_rule_arg;
+
   cairo_set_fill_rule (o->ctx, fill_rule);
   RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
   Py_RETURN_NONE;
@@ -892,10 +907,13 @@ pycairo_set_font_size (PycairoContext *o, PyObject *args) {
 static PyObject *
 pycairo_set_line_cap (PycairoContext *o, PyObject *args) {
   cairo_line_cap_t line_cap;
+  int line_cap_arg;
 
-  if (!PyArg_ParseTuple (args, "i:Context.set_line_cap", &line_cap))
+  if (!PyArg_ParseTuple (args, "i:Context.set_line_cap", &line_cap_arg))
     return NULL;
 
+  line_cap = (cairo_line_cap_t)line_cap_arg;
+
   cairo_set_line_cap (o->ctx, line_cap);
   RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
   Py_RETURN_NONE;
@@ -904,10 +922,13 @@ pycairo_set_line_cap (PycairoContext *o, PyObject *args) {
 static PyObject *
 pycairo_set_line_join (PycairoContext *o, PyObject *args) {
   cairo_line_join_t line_join;
+  int line_join_arg;
 
-  if (!PyArg_ParseTuple (args, "i:Context.set_line_join", &line_join))
+  if (!PyArg_ParseTuple (args, "i:Context.set_line_join", &line_join_arg))
     return NULL;
 
+  line_join = (cairo_line_join_t)line_join_arg;
+
   cairo_set_line_join (o->ctx, line_join);
   RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
   Py_RETURN_NONE;
@@ -952,12 +973,15 @@ pycairo_set_miter_limit (PycairoContext *o, PyObject *args) {
 
 static PyObject *
 pycairo_set_operator(PycairoContext *o, PyObject *args) {
-  cairo_operator_t op;
+  cairo_operator_t operator;
+  int operator_arg;
 
-  if (!PyArg_ParseTuple(args, "i:Context.set_operator", &op))
+  if (!PyArg_ParseTuple (args, "i:Context.set_operator", &operator_arg))
     return NULL;
 
-  cairo_set_operator(o->ctx, op);
+  operator = (cairo_operator_t)operator_arg;
+
+  cairo_set_operator(o->ctx, operator);
   RETURN_NULL_IF_CAIRO_CONTEXT_ERROR(o->ctx);
   Py_RETURN_NONE;
 }
@@ -1199,6 +1223,7 @@ pycairo_show_text_glyphs (PycairoContext *o, PyObject *args) {
   PyObject *glyphs_arg, *glyphs_seq = NULL;
   PyObject *clusters_arg, *clusters_seq = NULL;
   cairo_text_cluster_flags_t cluster_flags;
+  int cluster_flags_arg;
   PyObject *py_item;
   cairo_glyph_t *glyphs = NULL;
   cairo_text_cluster_t *clusters = NULL;
@@ -1206,9 +1231,11 @@ pycairo_show_text_glyphs (PycairoContext *o, PyObject *args) {
 
   if (!PyArg_ParseTuple (args,
       PYCAIRO_ENC_TEXT_FORMAT "OOi:Context.show_text_glyphs",
-      "utf-8", &utf8, &glyphs_arg, &clusters_arg, &cluster_flags))
+      "utf-8", &utf8, &glyphs_arg, &clusters_arg, &cluster_flags_arg))
     return NULL;
 
+  cluster_flags = (cairo_text_cluster_flags_t)cluster_flags_arg;
+
   glyphs_seq = PySequence_Fast (glyphs_arg, "glyphs must be a sequence");
   if (glyphs_seq == NULL)
     goto error;
index f1dc845..3040774 100644 (file)
@@ -249,10 +249,13 @@ script_device_get_mode (PycairoDevice *obj) {
 static PyObject *
 script_device_set_mode (PycairoDevice *obj, PyObject *args) {
     cairo_script_mode_t mode;
+    int mode_arg;
 
-    if (!PyArg_ParseTuple(args, "i:ScriptDevice.set_mode", &mode))
+    if (!PyArg_ParseTuple (args, "i:ScriptDevice.set_mode", &mode_arg))
         return NULL;
 
+    mode = (cairo_script_mode_t)mode_arg;
+
     Py_BEGIN_ALLOW_THREADS;
     cairo_script_set_mode (obj->device, mode);
     Py_END_ALLOW_THREADS;
index 6ed38c1..bb20f5d 100644 (file)
@@ -159,10 +159,13 @@ error_str(PycairoErrorObject *self)
 static PyObject *
 error_check_status (PyTypeObject *type, PyObject *args) {
     cairo_status_t status;
+    int status_arg;
 
-    if (!PyArg_ParseTuple(args, "i:Error._check_status", &status))
+    if (!PyArg_ParseTuple (args, "i:Error._check_status", &status_arg))
         return NULL;
 
+    status = (cairo_status_t)status_arg;
+
     if (Pycairo_Check_Status (status))
         return NULL;
 
index fd96c24..ebd43a3 100644 (file)
@@ -165,13 +165,18 @@ static PyObject *
 toy_font_face_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
   const char *utf8;
   PyObject *o;
-  cairo_font_slant_t slant   = CAIRO_FONT_SLANT_NORMAL;
-  cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
+  cairo_font_slant_t slant;
+  cairo_font_weight_t weight;
+  int slant_arg = CAIRO_FONT_SLANT_NORMAL;
+  int weight_arg = CAIRO_FONT_WEIGHT_NORMAL;
 
   if (!PyArg_ParseTuple (args, PYCAIRO_ENC_TEXT_FORMAT "|ii:ToyFontFace.__new__",
-                        "utf-8", &utf8, &slant, &weight))
+                         "utf-8", &utf8, &slant_arg, &weight_arg))
     return NULL;
 
+  slant = (cairo_font_slant_t)slant_arg;
+  weight = (cairo_font_weight_t)weight_arg;
+
   o = PycairoFontFace_FromFontFace (
                     cairo_toy_font_face_create (utf8, slant, weight));
   PyMem_Free((void *)utf8);
@@ -650,48 +655,63 @@ font_options_get_subpixel_order (PycairoFontOptions *o) {
 
 static PyObject *
 font_options_set_antialias (PycairoFontOptions *o, PyObject *args) {
-  cairo_antialias_t aa = CAIRO_ANTIALIAS_DEFAULT;
+  cairo_antialias_t antialias;
+  int antialias_arg = CAIRO_ANTIALIAS_DEFAULT;
 
-  if (!PyArg_ParseTuple(args, "|i:FontOptions.set_antialias", &aa))
+  if (!PyArg_ParseTuple (args, "|i:FontOptions.set_antialias", &antialias_arg))
     return NULL;
 
-  cairo_font_options_set_antialias (o->font_options, aa);
+  antialias = (cairo_antialias_t)antialias_arg;
+
+  cairo_font_options_set_antialias (o->font_options, antialias);
   RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
   Py_RETURN_NONE;
 }
 
 static PyObject *
 font_options_set_hint_metrics (PycairoFontOptions *o, PyObject *args) {
-  cairo_hint_metrics_t hm = CAIRO_HINT_METRICS_DEFAULT;
+  cairo_hint_metrics_t hint_metrics;
+  int hint_metrics_arg = CAIRO_HINT_METRICS_DEFAULT;
 
-  if (!PyArg_ParseTuple(args, "|i:FontOptions.set_hint_metrics", &hm))
+  if (!PyArg_ParseTuple (args, "|i:FontOptions.set_hint_metrics",
+                         &hint_metrics_arg))
     return NULL;
 
-  cairo_font_options_set_hint_metrics (o->font_options, hm);
+  hint_metrics = (cairo_hint_metrics_t)hint_metrics_arg;
+
+  cairo_font_options_set_hint_metrics (o->font_options, hint_metrics);
   RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
   Py_RETURN_NONE;
 }
 
 static PyObject *
 font_options_set_hint_style (PycairoFontOptions *o, PyObject *args) {
-  cairo_hint_style_t hs = CAIRO_HINT_STYLE_DEFAULT;
+  cairo_hint_style_t hint_style;
+  int hint_style_arg = CAIRO_HINT_STYLE_DEFAULT;
 
-  if (!PyArg_ParseTuple(args, "|i:FontOptions.set_hint_style", &hs))
+  if (!PyArg_ParseTuple (args, "|i:FontOptions.set_hint_style",
+                         &hint_style_arg))
     return NULL;
 
-  cairo_font_options_set_hint_style (o->font_options, hs);
+  hint_style = (cairo_hint_style_t)hint_style_arg;
+
+  cairo_font_options_set_hint_style (o->font_options, hint_style);
   RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
   Py_RETURN_NONE;
 }
 
 static PyObject *
 font_options_set_subpixel_order (PycairoFontOptions *o, PyObject *args) {
-  cairo_subpixel_order_t so = CAIRO_SUBPIXEL_ORDER_DEFAULT;
+  cairo_subpixel_order_t subpixel_order;
+  int subpixel_order_arg = CAIRO_SUBPIXEL_ORDER_DEFAULT;
 
-  if (!PyArg_ParseTuple(args, "|i:FontOptions.set_subpixel_order", &so))
+  if (!PyArg_ParseTuple (args, "|i:FontOptions.set_subpixel_order",
+                         &subpixel_order_arg))
     return NULL;
 
-  cairo_font_options_set_subpixel_order (o->font_options, so);
+  subpixel_order = (cairo_subpixel_order_t)subpixel_order_arg;
+
+  cairo_font_options_set_subpixel_order (o->font_options, subpixel_order);
   RETURN_NULL_IF_CAIRO_FONT_OPTIONS_ERROR(o->font_options);
   Py_RETURN_NONE;
 }
index 8b88624..78c53f8 100644 (file)
@@ -117,10 +117,13 @@ pattern_get_matrix (PycairoPattern *o) {
 static PyObject *
 pattern_set_extend (PycairoPattern *o, PyObject *args) {
   cairo_extend_t extend;
+  int extend_arg;
 
-  if (!PyArg_ParseTuple(args, "i:Pattern.set_extend", &extend))
+  if (!PyArg_ParseTuple (args, "i:Pattern.set_extend", &extend_arg))
     return NULL;
 
+  extend = (cairo_extend_t)extend_arg;
+
   cairo_pattern_set_extend (o->pattern, extend);
   Py_RETURN_NONE;
 }
@@ -151,10 +154,13 @@ pattern_get_filter (PycairoPattern *o) {
 static PyObject *
 pattern_set_filter (PycairoPattern *o, PyObject *args) {
   cairo_filter_t filter;
+  int filter_arg;
 
-  if (!PyArg_ParseTuple (args, "i:Pattern.set_filter", &filter))
+  if (!PyArg_ParseTuple (args, "i:Pattern.set_filter", &filter_arg))
     return NULL;
 
+  filter = (cairo_filter_t)filter_arg;
+
   Py_BEGIN_ALLOW_THREADS;
   cairo_pattern_set_filter (o->pattern, filter);
   Py_END_ALLOW_THREADS;
@@ -919,12 +925,14 @@ PyTypeObject PycairoMeshPattern_Type = {
 static PyObject *
 raster_source_pattern_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
   cairo_content_t content;
-  int width, height;
+  int width, height, content_arg;
 
   if (!PyArg_ParseTuple (args, "iii:RasterSourcePattern.__new__",
-      &content, &width, &height))
+                         &content_arg, &width, &height))
     return NULL;
 
+  content = (cairo_content_t)content_arg;
+
   return PycairoPattern_FromPattern (
     cairo_pattern_create_raster_source (NULL, content, width, height), NULL);
 }
index 5e3d1e3..62adba1 100644 (file)
@@ -266,8 +266,15 @@ PyObject *int_enum_create(PyTypeObject *type, long value);
 
 #define DECL_ENUM(name) extern PyTypeObject Pycairo_##name##_Type;
 
+/* A defined variant of (int)(unsigned int)(u). The cast from unsigned to
+ * signed gives the reverse result of a signed to unsigned cast. */
+#define _ENSURE_INT(u) ( \
+        ((unsigned int)(u) > INT_MAX) ? \
+            -(int)(UINT_MAX - (unsigned int)(u)) - 1 : (int)(unsigned int)(u) \
+    )
+
 #define CREATE_INT_ENUM(type_name, value) \
-    (int_enum_create(&Pycairo_##type_name##_Type, value))
+    (int_enum_create(&Pycairo_##type_name##_Type, _ENSURE_INT(value)))
 
 #define RETURN_INT_ENUM(type_name, value) \
     return CREATE_INT_ENUM(type_name, value);
index f0e0f4d..4a26ab0 100644 (file)
@@ -208,11 +208,14 @@ surface_copy_page (PycairoSurface *o) {
 static PyObject *
 surface_create_similar (PycairoSurface *o, PyObject *args) {
   cairo_content_t content;
-  int width, height;
+  int width, height, content_arg;
 
   if (!PyArg_ParseTuple (args, "iii:Surface.create_similar",
-                        &content, &width, &height))
+                         &content_arg, &width, &height))
     return NULL;
+
+  content = (cairo_content_t)content_arg;
+
   return PycairoSurface_FromSurface (
             cairo_surface_create_similar (o->surface, content, width, height),
             NULL);
@@ -369,13 +372,15 @@ surface_show_page (PycairoSurface *o) {
 static PyObject *
 surface_create_similar_image (PycairoSurface *o, PyObject *args) {
   cairo_format_t format;
-  int width, height;
+  int width, height, format_arg;
   cairo_surface_t *new;
 
   if (!PyArg_ParseTuple (args, "iii:Surface.create_similar_image",
-                         &format, &width, &height))
+                         &format_arg, &width, &height))
     return NULL;
 
+  format = (cairo_format_t)format_arg;
+
   Py_BEGIN_ALLOW_THREADS;
   new = cairo_surface_create_similar_image (o->surface, format, width, height);
   Py_END_ALLOW_THREADS;
@@ -769,11 +774,14 @@ PyTypeObject PycairoSurface_Type = {
 static PyObject *
 image_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
   cairo_format_t format;
-  int width, height;
+  int width, height, format_arg;
 
   if (!PyArg_ParseTuple (args, "iii:ImageSurface.__new__",
-                        &format, &width, &height))
+                         &format_arg, &width, &height))
     return NULL;
+
+  format = (cairo_format_t)format_arg;
+
   return PycairoSurface_FromSurface (
             cairo_image_surface_create (format, width, height),
             NULL);
@@ -785,14 +793,16 @@ image_surface_create_for_data (PyTypeObject *type, PyObject *args) {
   cairo_surface_t *surface;
   cairo_format_t format;
   unsigned char *buffer;
-  int width, height, stride = -1, res;
+  int width, height, stride = -1, res, format_arg;
   Py_ssize_t buffer_len;
   PyObject *obj;
 
-  if (!PyArg_ParseTuple(args, "Oiii|i:ImageSurface.create_for_data",
-                       &obj, &format, &width, &height, &stride))
+  if (!PyArg_ParseTuple (args, "Oiii|i:ImageSurface.create_for_data",
+                         &obj, &format_arg, &width, &height, &stride))
     return NULL;
 
+  format = (cairo_format_t)format_arg;
+
   res = PyObject_AsWriteBuffer (obj, (void **)&buffer, &buffer_len);
   if (res == -1)
     return NULL;
@@ -900,9 +910,14 @@ image_surface_create_from_png (PyTypeObject *type, PyObject *args) {
 static PyObject *
 image_surface_format_stride_for_width (PyObject *self, PyObject *args) {
   cairo_format_t format;
-  int width;
-  if (!PyArg_ParseTuple(args, "ii:format_stride_for_width", &format, &width))
+  int width, format_arg;
+
+  if (!PyArg_ParseTuple (args, "ii:format_stride_for_width",
+                         &format_arg, &width))
     return NULL;
+
+  format = (cairo_format_t)format_arg;
+
   return PYCAIRO_PyLong_FromLong (cairo_format_stride_for_width (format, width));
 }
 
@@ -1265,11 +1280,14 @@ pdf_get_versions (PyObject *self) {
 static PyObject *
 pdf_version_to_string (PyObject *self,  PyObject *args) {
   cairo_pdf_version_t version;
+  int version_arg;
   const char *version_string;
 
-  if (!PyArg_ParseTuple(args, "i:PDFSurface.version_to_string", &version))
+  if (!PyArg_ParseTuple (args, "i:PDFSurface.version_to_string", &version_arg))
     return NULL;
 
+  version = (cairo_pdf_version_t)version_arg;
+
   Py_BEGIN_ALLOW_THREADS;
   version_string = cairo_pdf_version_to_string (version);
   Py_END_ALLOW_THREADS;
@@ -1285,10 +1303,14 @@ pdf_version_to_string (PyObject *self,  PyObject *args) {
 static PyObject *
 pdf_surface_restrict_to_version (PycairoPDFSurface *o, PyObject *args) {
   cairo_pdf_version_t version;
+  int version_arg;
 
-  if (!PyArg_ParseTuple(args, "i:PDFSurface.restrict_to_version", &version))
+  if (!PyArg_ParseTuple (args, "i:PDFSurface.restrict_to_version",
+                         &version_arg))
     return NULL;
 
+  version = (cairo_pdf_version_t)version_arg;
+
   Py_BEGIN_ALLOW_THREADS;
   cairo_pdf_surface_restrict_to_version (o->surface, version);
   Py_END_ALLOW_THREADS;
@@ -1360,13 +1382,16 @@ typedef PycairoSurface PycairoScriptSurface;
 static PyObject *
 script_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
   cairo_content_t content;
+  int content_arg;
   double width, height;
   PyObject *pydevice;
 
   if (!PyArg_ParseTuple (args, "O!idd:ScriptSurface.__new__",
-      &PycairoScriptDevice_Type, &pydevice, &content, &width, &height))
+      &PycairoScriptDevice_Type, &pydevice, &content_arg, &width, &height))
     return NULL;
 
+  content = (cairo_content_t)content_arg;
+
   return PycairoSurface_FromSurface (
     cairo_script_surface_create (
       ((PycairoDevice*)pydevice)->device, content, width, height),
@@ -1523,9 +1548,14 @@ ps_surface_get_eps (PycairoPSSurface *o) {
 static PyObject *
 ps_level_to_string (PyObject *self, PyObject *args) {
   cairo_ps_level_t level;
+  int level_arg;
   const char *s;
-  if (!PyArg_ParseTuple(args, "i:PSSurface.level_to_string", &level))
+
+  if (!PyArg_ParseTuple (args, "i:PSSurface.level_to_string", &level_arg))
     return NULL;
+
+  level = (cairo_ps_level_t)level_arg;
+
   s = cairo_ps_level_to_string (level);
   if (s == NULL){
     PyErr_SetString(PyExc_ValueError, "level_to_string: "
@@ -1538,9 +1568,13 @@ ps_level_to_string (PyObject *self, PyObject *args) {
 static PyObject *
 ps_surface_restrict_to_level (PycairoPSSurface *o, PyObject *args) {
   cairo_ps_level_t level;
+  int level_arg;
 
-  if (!PyArg_ParseTuple(args, "i:PSSurface.restrict_to_level", &level))
+  if (!PyArg_ParseTuple (args, "i:PSSurface.restrict_to_level", &level_arg))
     return NULL;
+
+  level = (cairo_ps_level_t)level_arg;
+
   cairo_ps_surface_restrict_to_level (o->surface, level);
   RETURN_NULL_IF_CAIRO_SURFACE_ERROR(o->surface);
   Py_RETURN_NONE;
@@ -1666,12 +1700,15 @@ recording_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
   cairo_content_t content;
   cairo_rectangle_t extents, *extents_ptr;
   cairo_surface_t *sfc;
+  int content_arg;
   PyObject *extents_tuple;
 
-  if (!PyArg_ParseTuple(args, "iO:RecordingSurface.__new__",
-                       &content, &extents_tuple))
+  if (!PyArg_ParseTuple (args, "iO:RecordingSurface.__new__",
+                         &content_arg, &extents_tuple))
     return NULL;
 
+  content = (cairo_content_t)content_arg;
+
   if (extents_tuple == Py_None) {
     extents_ptr = NULL;
   } else {
@@ -1851,11 +1888,14 @@ svg_get_versions (PyObject *self) {
 static PyObject *
 svg_version_to_string (PyObject *self,  PyObject *args) {
   cairo_svg_version_t version;
+  int version_arg;
   const char *version_string;
 
-  if (!PyArg_ParseTuple(args, "i:SVGSurface.version_to_string", &version))
+  if (!PyArg_ParseTuple (args, "i:SVGSurface.version_to_string", &version_arg))
     return NULL;
 
+  version = (cairo_svg_version_t)version_arg;
+
   Py_BEGIN_ALLOW_THREADS;
   version_string = cairo_svg_version_to_string (version);
   Py_END_ALLOW_THREADS;
@@ -1871,10 +1911,14 @@ svg_version_to_string (PyObject *self,  PyObject *args) {
 static PyObject *
 svg_surface_restrict_to_version (PycairoPDFSurface *o, PyObject *args) {
   cairo_svg_version_t version;
+  int version_arg;
 
-  if (!PyArg_ParseTuple(args, "i:SVGSurface.restrict_to_version", &version))
+  if (!PyArg_ParseTuple (args, "i:SVGSurface.restrict_to_version",
+                         &version_arg))
     return NULL;
 
+  version = (cairo_svg_version_t)version_arg;
+
   Py_BEGIN_ALLOW_THREADS;
   cairo_svg_surface_restrict_to_version (o->surface, version);
   Py_END_ALLOW_THREADS;
diff --git a/docs/images/example.svg b/docs/images/example.svg
new file mode 100644 (file)
index 0000000..3b6f45a
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200pt" height="200pt" viewBox="0 0 200 200" version="1.1">
+<g id="surface1">
+<path style="fill:none;stroke-width:0.04;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 0.1 0.5 C 0.4 0.9 0.6 0.1 0.9 0.5 " transform="matrix(200,0,0,200,0,0)"/>
+<path style="fill:none;stroke-width:0.02;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,20%,20%);stroke-opacity:0.6;stroke-miterlimit:10;" d="M 0.1 0.5 L 0.4 0.9 M 0.6 0.1 L 0.9 0.5 " transform="matrix(200,0,0,200,0,0)"/>
+</g>
+</svg>
index d318d3d..0674fe9 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [flake8]
-ignore=E402
+ignore=E402,E741
 builtins=buffer,unichr
 
 [coverage:run]
index 22b59fd..3fe4328 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@ from distutils.core import Extension, setup, Command, Distribution
 from distutils.ccompiler import new_compiler
 
 
-PYCAIRO_VERSION = '1.15.3'
+PYCAIRO_VERSION = '1.15.4'
 CAIRO_VERSION_REQUIRED = '1.13.1'
 XPYB_VERSION_REQUIRED = '1.3'
 
index a8cad59..e9fb5a6 100644 (file)
@@ -1,5 +1,6 @@
 import cairo
 import pytest
+import ctypes
 
 
 @pytest.fixture
@@ -39,6 +40,15 @@ def test_get_operator(context):
     assert isinstance(context.get_operator(), cairo.Operator)
 
 
+def test_get_set_operator_limits(context):
+    max_int = 2 ** (ctypes.sizeof(ctypes.c_int()) * 8 - 1) - 1
+    min_int = -max_int - 1
+
+    for val in [-1, 0, max_int, min_int]:
+        context.set_operator(val)
+        assert context.get_operator() == val
+
+
 def test_show_text_glyphs():
     surface = cairo.PDFSurface(None, 300, 300)
     context = cairo.Context(surface)