static PyObject *
matrix_invert (PycairoMatrix *o)
{
    if (Pycairo_Check_Status (cairo_matrix_invert (&o->matrix)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_set_dash (PycairoContext *o, PyObject *args)
{
    double *dashes, offset = 0;
    int ndash, i;
    PyObject *py_dashes;

    if (!PyArg_ParseTuple (args, "O|d:Context.set_dash", &py_dashes, &offset))
	return NULL;

    py_dashes = PySequence_Fast (py_dashes,
				 "first argument must be a sequence");
    if (!py_dashes)
	return NULL;

    ndash = PySequence_Fast_GET_SIZE(py_dashes);
    dashes = malloc (ndash * sizeof(double));
    for (i = 0; i < ndash; i++) {
	PyObject *item = PySequence_Fast_GET_ITEM(py_dashes, i);

	dashes[i] = PyFloat_AsDouble(item);
	if (PyErr_Occurred()) {
	    free (dashes);
	    Py_DECREF(py_dashes);
	    return NULL;
	}
    }
    Py_DECREF(py_dashes);

    cairo_set_dash (o->ctx, dashes, ndash, offset);
    free (dashes);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 3
0
static PyObject *
pycairo_copy_clip_rectangle_list (PycairoContext *o) {
  int i;
  PyObject *rv = NULL;
  cairo_rectangle_t *r;
  cairo_rectangle_list_t *rlist = cairo_copy_clip_rectangle_list (o->ctx);
  if (rlist->status != CAIRO_STATUS_SUCCESS) {
    Pycairo_Check_Status (rlist->status);
    goto exit;
  }

  rv = PyTuple_New(rlist->num_rectangles);
  if (rv == NULL)
    goto exit;

  for (i = 0, r = rlist->rectangles; i < rlist->num_rectangles; i++, r++) {
    PyObject *py_rect = Py_BuildValue("(dddd)", r->x, r->y,
				      r->width, r->height);
    if (py_rect == NULL) {
      Py_CLEAR(rv);
      goto exit;
    }
    PyTuple_SET_ITEM (rv, i, py_rect);
  }
 exit:
  cairo_rectangle_list_destroy(rlist);
  return rv;
}
Exemplo n.º 4
0
/* METH_O */
static PyObject *
surface_write_to_png (PycairoSurface *o, PyObject *file)
{
    FILE *fp;
    cairo_status_t status;

    if (PyObject_TypeCheck (file, &PyBaseString_Type)) {
	fp = fopen (PyString_AsString(file), "wb");
	if (fp == NULL) {
	    PyErr_SetString(PyExc_IOError, "unable to open file for writing");
	    return NULL;
	}
    } else if (PyObject_TypeCheck (file, &PyFile_Type)) {
	fp = PyFile_AsFile(file);

    } else {
	PyErr_SetString(PyExc_TypeError,
			"Surface.write_to_png takes one argument "
			"which must be a filename (str) or file object");
	return NULL;
    }
    status = cairo_surface_write_to_png_stream (o->surface, _write_func, fp);
    if (PyObject_TypeCheck (file, &PyBaseString_Type))
    	fclose (fp);

    if (Pycairo_Check_Status (status))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 5
0
static PyObject *
scaled_font_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    PycairoFontFace *ff;
    PycairoFontOptions *fo;
    PycairoMatrix *mx1, *mx2;

    if (!PyArg_ParseTuple(args, "O!O!O!O!:ScaledFont.__new__",
			  &PycairoFontFace_Type, &ff,
			  &PycairoMatrix_Type, &mx1,
			  &PycairoMatrix_Type, &mx2,
			  &PycairoFontOptions_Type, &fo))
	return NULL;

    PyObject *o = type->tp_alloc(type, 0);
    if (o != NULL) {
	cairo_scaled_font_t *scaled_font = cairo_scaled_font_create
	    (ff->font_face, &mx1->matrix, &mx2->matrix, fo->font_options);

	if (Pycairo_Check_Status (cairo_scaled_font_status (scaled_font))) {
	    cairo_scaled_font_destroy (scaled_font);
	    Py_DECREF(o);
	    return NULL;
	}
	((PycairoScaledFont *)o)->scaled_font = scaled_font;
    }
    return o;
}
Exemplo n.º 6
0
/* PycairoFontFace_FromFontFace
 * Create a new PycairoFontFace from a cairo_font_face_t
 * font_face - a cairo_font_face_t to 'wrap' into a Python object.
 *             it is unreferenced if the PycairoFontFace creation fails
 * Return value: New reference or NULL on failure
 */
PyObject *
PycairoFontFace_FromFontFace (cairo_font_face_t *font_face)
{
    PyTypeObject *type = NULL;
    PyObject *o;

    assert (font_face != NULL);

    if (Pycairo_Check_Status (cairo_font_face_status (font_face))) {
	cairo_font_face_destroy (font_face);
	return NULL;
    }

    switch (cairo_font_face_get_type (font_face)) {
    case CAIRO_FONT_TYPE_TOY:
        type = &PycairoToyFontFace_Type;
        break;
    default:
        type = &PycairoFontFace_Type;
        break;
    }
    o = type->tp_alloc (type, 0);
    if (o == NULL)
	cairo_font_face_destroy (font_face);
    else
	((PycairoFontFace *)o)->font_face = font_face;
    return o;
}
Exemplo n.º 7
0
static PyObject *
ps_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    const char *filename;
    double width_in_points, height_in_points;
    cairo_surface_t *surface;
    PyObject *o;

    if (!PyArg_ParseTuple(args, "sdd:PSSurface.__new__",
			  &filename, &width_in_points, &height_in_points))
	return NULL;

    o = type->tp_alloc(type, 0);
    if (o) {
	surface = cairo_ps_surface_create (filename, width_in_points,
					   height_in_points);
	if (Pycairo_Check_Status (cairo_surface_status (surface))) {
	    cairo_surface_destroy (surface);
	    Py_DECREF(o);
	    return NULL;
	}
	((PycairoPSSurface *)o)->surface = surface;
    }
    return o;
}
Exemplo n.º 8
0
/* PycairoSurface_FromSurface
 * Create a new PycairoSurface from a cairo_surface_t
 * surface - a cairo_surface_t to 'wrap' into a Python object.
 *           it is unreferenced if the PycairoSurface creation fails, or if
             the cairo_surface_t has an error status
 * type - the type of the object to instantiate; it can be NULL,
 *        meaning a base enso_win32.cairo.Surface type, or it can be a subclass of
 *        enso_win32.cairo.Surface.
 * base - the base object used to create the context, or NULL.
 *        it is referenced to keep it alive while the cairo_surface_t is
 *        being used
 * Return value: New reference or NULL on failure
 */
PyObject *
PycairoSurface_FromSurface (cairo_surface_t *surface, PyTypeObject *type,
			    PyObject *base)
{
    PyObject *o;

    assert (surface != NULL);

    if (Pycairo_Check_Status (cairo_surface_status (surface))) {
	cairo_surface_destroy (surface);
	return NULL;
    }

    if (type == NULL)
        type = &PycairoSurface_Type;
    o = PycairoSurface_Type.tp_alloc (type, 0);
    if (o) {
	((PycairoSurface *)o)->surface = surface;
	Py_XINCREF(base);
	((PycairoSurface *)o)->base = base;
    } else {
	cairo_surface_destroy (surface);
    }
    return o;
}
static PyObject *
pycairo_stroke_preserve (PycairoContext *o)
{
    cairo_stroke_preserve (o->ctx);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_reset_clip (PycairoContext *o)
{
    cairo_reset_clip (o->ctx);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_new_path (PycairoContext *o)
{
    cairo_new_path (o->ctx);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_identity_matrix (PycairoContext *o)
{
    cairo_identity_matrix (o->ctx);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 13
0
/* PycairoSurface_FromSurface
 * Create a new
 *   PycairoImageSurface,
 *   PycairoPDFSurface,
 *   PycairoPSSurface,
 *   PycairoSVGSurface,
 *   PycairoWin32Surface, or
 *   PycairoXlibSurface from a cairo_surface_t.
 * surface - a cairo_surface_t to 'wrap' into a Python object.
 *   It is unreferenced if the PycairoSurface creation fails, or if the
 *   cairo_surface_t has an error status.
 * base - the base object used to create the surface, or NULL.
 *   It is referenced to keep it alive while the cairo_surface_t is being used.
 * Return value: New reference or NULL on failure
 */
PyObject *
PycairoSurface_FromSurface (cairo_surface_t *surface, PyObject *base)
{
    PyTypeObject *type = NULL;
    PyObject *o;

    assert (surface != NULL);

    if (Pycairo_Check_Status (cairo_surface_status (surface))) {
	cairo_surface_destroy (surface);
	return NULL;
    }

    switch (cairo_surface_get_type (surface)) {
#if CAIRO_HAS_IMAGE_SURFACE
    case CAIRO_SURFACE_TYPE_IMAGE:
	type = &PycairoImageSurface_Type;
	break;
#endif
#if CAIRO_HAS_PDF_SURFACE
    case CAIRO_SURFACE_TYPE_PDF:
	type = &PycairoPDFSurface_Type;
	break;
#endif
#if CAIRO_HAS_PS_SURFACE
    case CAIRO_SURFACE_TYPE_PS:
	type = &PycairoPSSurface_Type;
	break;
#endif
#if CAIRO_HAS_SVG_SURFACE
    case CAIRO_SURFACE_TYPE_SVG:
	type = &PycairoSVGSurface_Type;
	break;
#endif
#if CAIRO_HAS_WIN32_SURFACE
    case CAIRO_SURFACE_TYPE_WIN32:
	type = &PycairoWin32Surface_Type;
	break;
#endif
#if CAIRO_HAS_XLIB_SURFACE
    case CAIRO_SURFACE_TYPE_XLIB:
	type = &PycairoXlibSurface_Type;
	break;
#endif
    default:
	type = &PycairoSurface_Type;
	break;
    }
    o = type->tp_alloc (type, 0);
    if (o == NULL) {
	cairo_surface_destroy (surface);
    } else {
	((PycairoSurface *)o)->surface = surface;
	Py_XINCREF(base);
	((PycairoSurface *)o)->base = base;
    }
    return o;
}
static PyObject *
pycairo_stroke_extents (PycairoContext *o)
{
    double x1, y1, x2, y2;
    cairo_stroke_extents (o->ctx, &x1, &y1, &x2, &y2);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    return Py_BuildValue("(dddd)", x1, y1, x2, y2);
}
Exemplo n.º 15
0
static PyObject *
surface_flush (PycairoSurface *o)
{
    cairo_surface_flush (o->surface);

    if (Pycairo_Check_Status (cairo_surface_status(o->surface)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_font_extents (PycairoContext *o)
{
    cairo_font_extents_t e;

    cairo_font_extents (o->ctx, &e);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    return Py_BuildValue("(ddddd)", e.ascent, e.descent, e.height,
			 e.max_x_advance, e.max_y_advance);
}
Exemplo n.º 17
0
static PyObject *
scaled_font_extents (PycairoScaledFont *o)
{
    cairo_font_extents_t e;

    cairo_scaled_font_extents (o->scaled_font, &e);
    if (Pycairo_Check_Status (cairo_scaled_font_status(o->scaled_font)))
	return NULL;
    return Py_BuildValue ("(ddddd)", e.ascent, e.descent, e.height,
			  e.max_x_advance, e.max_y_advance);
}
static PyObject *
pycairo_set_antialias (PycairoContext *o, PyObject *args)
{
    cairo_antialias_t antialias = CAIRO_ANTIALIAS_DEFAULT;

    if (!PyArg_ParseTuple(args, "|i:Context.set_antialias", &antialias))
	return NULL;

    cairo_set_antialias (o->ctx, antialias);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 19
0
static PyObject *
font_options_set_hint_style (PycairoFontOptions *o, PyObject *args)
{
    cairo_hint_style_t hs = CAIRO_HINT_STYLE_DEFAULT;

    if (!PyArg_ParseTuple(args, "|i:FontOptions.set_hint_style", &hs))
	return NULL;

    cairo_font_options_set_hint_style (o->font_options, hs);
    if (Pycairo_Check_Status (cairo_font_options_status (o->font_options)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_set_line_join (PycairoContext *o, PyObject *args)
{
    cairo_line_join_t line_join;

    if (!PyArg_ParseTuple (args, "i:Context.set_line_join", &line_join))
	return NULL;

    cairo_set_line_join (o->ctx, line_join);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 21
0
static PyObject *
font_options_set_antialias (PycairoFontOptions *o, PyObject *args)
{
    cairo_antialias_t aa = CAIRO_ANTIALIAS_DEFAULT;

    if (!PyArg_ParseTuple(args, "|i:FontOptions.set_antialias", &aa))
	return NULL;

    cairo_font_options_set_antialias (o->font_options, aa);
    if (Pycairo_Check_Status (cairo_font_options_status (o->font_options)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_show_text (PycairoContext *o, PyObject *args)
{
    const char *utf8;

    if (!PyArg_ParseTuple(args, "s:Context.show_text", &utf8))
	return NULL;

    cairo_show_text (o->ctx, utf8);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_set_tolerance (PycairoContext *o, PyObject *args)
{
    double tolerance;

    if (!PyArg_ParseTuple (args, "d:Context.set_tolerance", &tolerance))
	return NULL;

    cairo_set_tolerance (o->ctx, tolerance);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_set_operator(PycairoContext *o, PyObject *args)
{
    cairo_operator_t op;

    if (!PyArg_ParseTuple(args, "i:Context.set_operator", &op))
	return NULL;

    cairo_set_operator(o->ctx, op);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_set_miter_limit (PycairoContext *o, PyObject *args)
{
    double limit;

    if (!PyArg_ParseTuple (args, "d:Context.set_miter_limit", &limit))
	return NULL;

    cairo_set_miter_limit (o->ctx, limit);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_set_line_width (PycairoContext *o, PyObject *args)
{
    double width;

    if (!PyArg_ParseTuple (args, "d:Context.set_line_width", &width))
	return NULL;

    cairo_set_line_width (o->ctx, width);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 27
0
static PyObject *
font_options_set_hint_metrics (PycairoFontOptions *o, PyObject *args)
{
    cairo_hint_metrics_t hm = CAIRO_HINT_METRICS_DEFAULT;

    if (!PyArg_ParseTuple(args, "|i:FontOptions.set_hint_metrics", &hm))
	return NULL;

    cairo_font_options_set_hint_metrics (o->font_options, hm);
    if (Pycairo_Check_Status (cairo_font_options_status (o->font_options)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_set_fill_rule (PycairoContext *o, PyObject *args)
{
    cairo_fill_rule_t fill_rule;

    if (!PyArg_ParseTuple (args, "i:Context.set_fill_rule", &fill_rule))
	return NULL;

    cairo_set_fill_rule (o->ctx, fill_rule);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}
Exemplo n.º 29
0
static PyObject *
font_options_set_subpixel_order (PycairoFontOptions *o, PyObject *args)
{
    cairo_subpixel_order_t so = CAIRO_SUBPIXEL_ORDER_DEFAULT;

    if (!PyArg_ParseTuple(args, "|i:FontOptions.set_subpixel_order", &so))
	return NULL;

    cairo_font_options_set_subpixel_order (o->font_options, so);
    if (Pycairo_Check_Status (cairo_font_options_status (o->font_options)))
	return NULL;
    Py_RETURN_NONE;
}
static PyObject *
pycairo_set_font_size (PycairoContext *o, PyObject *args)
{
    double size;

    if (!PyArg_ParseTuple (args, "d:Context.set_font_size", &size))
	return NULL;

    cairo_set_font_size (o->ctx, size);
    if (Pycairo_Check_Status (cairo_status (o->ctx)))
	return NULL;
    Py_RETURN_NONE;
}