[cairo-commit] python-cairo/cairo pycairo-font.c,NONE,1.1 Makefile.am,1.1,1.2 cairomodule.c,1.2,1.3 pycairo-context.c,1.2,1.3 pycairo-private.h,1.1,1.2 pycairo.h,1.2,1.3

James Henstridge commit at pdx.freedesktop.org
Tue Oct 28 07:53:15 PST 2003


Committed by: james

Update of /cvs/cairo/python-cairo/cairo
In directory pdx:/tmp/cvs-serv26022/cairo

Modified Files:
	Makefile.am cairomodule.c pycairo-context.c pycairo-private.h 
	pycairo.h 
Added Files:
	pycairo-font.c 
Log Message:
2003-10-28  James Henstridge  <james at daa.com.au>

    * cairo/pycairo-context.c (pycairo_set_font): wrap function.
    (pycairo_current_font): add accessor.

    * cairo/pycairo-font.c: wrapper for Cairo font type.

    * cairo/pycairo-context.c (pycairo_select_font): update to new
    signature.
    (pycairo_transform_font): update to new signature.
    (pycairo_context_new): release context if wrapper could not be
    created.



--- NEW FILE: pycairo-font.c ---
/* -*- mode: C; c-basic-offset: 4 -*- */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif
#include "pycairo-private.h"

PyObject *
pycairo_font_new(cairo_font_t *font)
{
    PyCairoFont *self;

    self = PyObject_New(PyCairoFont, &PyCairoFont_Type);
    if (!self) {
	cairo_font_destroy(font);
	return NULL;
    }

    self->font = font;

    return (PyObject *)self;
}

static void
pycairo_font_dealloc(PyCairoFont *self)
{
    if (self->font)
	cairo_font_destroy(self->font);
    self->font = NULL;

    if (self->ob_type->tp_free)
	self->ob_type->tp_free((PyObject *)self);
    else
	PyObject_Del(self);
}


static PyObject *
pycairo_font_set_transform(PyCairoFont *self, PyObject *args)
{
    PyCairoMatrix *matrix;

    if (!PyArg_ParseTuple(args, "O!:Font.set_transform",
			  &PyCairoMatrix_Type, &matrix))
	return NULL;

    cairo_font_set_transform(self->font, matrix->matrix);
    Py_INCREF(Py_None);
    return Py_None;
}

static PyMethodDef pycairo_font_methods[] = {
    { "set_transform", (PyCFunction)pycairo_font_set_transform, METH_VARARGS },
    { NULL, NULL, 0 }
};

static PyObject *
pycairo_font_current_transform(PyCairoFont *self)
{
    cairo_matrix_t *matrix;

    matrix = cairo_matrix_create();
    if (!matrix)
	return PyErr_NoMemory();
    cairo_font_current_transform(self->font, matrix);
    return pycairo_matrix_new(matrix);
}

static PyGetSetDef pycairo_font_getsets[] = {
    { "transform", (getter)pycairo_font_current_transform, (setter)0 },
    { NULL, (getter)0, (setter)0 }
};


PyTypeObject PyCairoFont_Type = {
    PyObject_HEAD_INIT(NULL)
    0,                                  /* ob_size */
    "cairo.Font",                       /* tp_name */
    sizeof(PyCairoFont),                /* tp_basicsize */
    0,                                  /* tp_itemsize */
    /* methods */
    (destructor)pycairo_font_dealloc,   /* tp_dealloc */
    (printfunc)0,                       /* tp_print */
    (getattrfunc)0,                     /* tp_getattr */
    (setattrfunc)0,                     /* tp_setattr */
    (cmpfunc)0,                         /* tp_compare */
    (reprfunc)0,                        /* tp_repr */
    0,                                  /* tp_as_number */
    0,                                  /* tp_as_sequence */
    0,                                  /* tp_as_mapping */
    (hashfunc)0,                        /* tp_hash */
    (ternaryfunc)0,                     /* tp_call */
    (reprfunc)0,                        /* tp_str */
    (getattrofunc)0,                    /* tp_getattro */
    (setattrofunc)0,                    /* tp_setattro */
    0,                                  /* tp_as_buffer */
    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
    NULL, /* Documentation string */
    (traverseproc)0,                    /* tp_traverse */
    (inquiry)0,                         /* tp_clear */
    (richcmpfunc)0,                     /* tp_richcompare */
    0,                                  /* tp_weaklistoffset */
    (getiterfunc)0,                     /* tp_iter */
    (iternextfunc)0,                    /* tp_iternext */
    pycairo_font_methods,               /* tp_methods */
    0,                                  /* tp_members */
    pycairo_font_getsets,               /* tp_getset */
    (PyTypeObject *)0,                  /* tp_base */
    (PyObject *)0,                      /* tp_dict */
    0,                                  /* tp_descr_get */
    0,                                  /* tp_descr_set */
    0,                                  /* tp_dictoffset */
    (initproc)0,                        /* tp_init */
    (allocfunc)0,                       /* tp_alloc */
    (newfunc)0,                         /* tp_new */
    0,                                  /* tp_free */
    (inquiry)0,                         /* tp_is_gc */
    (PyObject *)0,                      /* tp_bases */
};

Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/python-cairo/cairo/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile.am	17 Sep 2003 14:34:02 -0000	1.1
--- Makefile.am	28 Oct 2003 15:53:13 -0000	1.2
***************
*** 16,19 ****
--- 16,20 ----
    pycairo-matrix.c \
    pycairo-surface.c \
+   pycairo-font.c \
    pycairo-context.c \
    cairomodule.c

Index: cairomodule.c
===================================================================
RCS file: /cvs/cairo/python-cairo/cairo/cairomodule.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** cairomodule.c	24 Sep 2003 01:05:43 -0000	1.2
--- cairomodule.c	28 Oct 2003 15:53:13 -0000	1.3
***************
*** 99,102 ****
--- 99,104 ----
      &PyCairoSurface_Type,
      pycairo_surface_new,
+     &PyCairoFont_Type,
+     pycairo_font_new,
      &PyCairoContext_Type,
      pycairo_context_new,
***************
*** 117,120 ****
--- 119,123 ----
      INIT_TYPE(PyCairoMatrix_Type);
      INIT_TYPE(PyCairoSurface_Type);
+     INIT_TYPE(PyCairoFont_Type);
      INIT_TYPE(PyCairoContext_Type);
  
***************
*** 125,128 ****
--- 128,132 ----
      PyModule_AddObject(mod, "Matrix",  (PyObject *)&PyCairoMatrix_Type);
      PyModule_AddObject(mod, "Surface", (PyObject *)&PyCairoSurface_Type);
+     PyModule_AddObject(mod, "Font", (PyObject *)&PyCairoFont_Type);
      PyModule_AddObject(mod, "Context", (PyObject *)&PyCairoContext_Type);
  
***************
*** 192,195 ****
--- 196,206 ----
      CONSTANT(FILTER_NEAREST);
      CONSTANT(FILTER_BILINEAR);
+ 
+     CONSTANT(FONT_WEIGHT_NORMAL);
+     CONSTANT(FONT_WEIGHT_BOLD);
+ 
+     CONSTANT(FONT_SLANT_NORMAL);
+     CONSTANT(FONT_SLANT_ITALIC);
+     CONSTANT(FONT_SLANT_OBLIQUE);
  #undef CONSTANT
  

Index: pycairo-context.c
===================================================================
RCS file: /cvs/cairo/python-cairo/cairo/pycairo-context.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pycairo-context.c	9 Oct 2003 14:33:23 -0000	1.2
--- pycairo-context.c	28 Oct 2003 15:53:13 -0000	1.3
***************
*** 12,17 ****
  
      self = PyObject_New(PyCairoContext, &PyCairoContext_Type);
!     if (!self)
  	return NULL;
  
      self->ctx = ctx;
--- 12,19 ----
  
      self = PyObject_New(PyCairoContext, &PyCairoContext_Type);
!     if (!self) {
! 	cairo_destroy(ctx);
  	return NULL;
+     }
  
      self->ctx = ctx;
***************
*** 644,653 ****
  pycairo_select_font(PyCairoContext *self, PyObject *args)
  {
!     const char *key;
  
!     if (!PyArg_ParseTuple(args, "s:Context.select_font", &key))
  	return NULL;
  
!     cairo_select_font(self->ctx, key);
      if (pycairo_check_status(cairo_status(self->ctx)))
  	return NULL;
--- 646,658 ----
  pycairo_select_font(PyCairoContext *self, PyObject *args)
  {
!     const char *family;
!     cairo_font_slant_t slant = CAIRO_FONT_SLANT_NORMAL;
!     cairo_font_weight_t weight = CAIRO_FONT_WEIGHT_NORMAL;
  
!     if (!PyArg_ParseTuple(args, "s|ii:Context.select_font",
! 			  &family, &slant, &weight))
  	return NULL;
  
!     cairo_select_font(self->ctx, family, slant, weight);
      if (pycairo_check_status(cairo_status(self->ctx)))
  	return NULL;
***************
*** 674,683 ****
  pycairo_transform_font(PyCairoContext *self, PyObject *args)
  {
!     double a, b, c, d;
  
!     if (!PyArg_ParseTuple(args, "dddd:Context.transform_font", &a, &b, &c, &d))
  	return NULL;
  
!     cairo_transform_font(self->ctx, a, b, c, d);
      if (pycairo_check_status(cairo_status(self->ctx)))
  	return NULL;
--- 679,689 ----
  pycairo_transform_font(PyCairoContext *self, PyObject *args)
  {
!     PyCairoMatrix *matrix;
  
!     if (!PyArg_ParseTuple(args, "O!:Context.transform_font",
! 			  &PyCairoMatrix_Type, &matrix))
  	return NULL;
  
!     cairo_transform_font(self->ctx, matrix->matrix);
      if (pycairo_check_status(cairo_status(self->ctx)))
  	return NULL;
***************
*** 687,715 ****
  
  static PyObject *
! pycairo_text_extents(PyCairoContext *self, PyObject *args)
  {
      const unsigned char *utf8;
-     double x, y, width, height, dx, dy;
  
!     if (!PyArg_ParseTuple(args, "s:Context.text_extents", &utf8))
  	return NULL;
  
!     cairo_text_extents(self->ctx, utf8, &x, &y, &width, &height, &dx, &dy);
      if (pycairo_check_status(cairo_status(self->ctx)))
  	return NULL;
!     return Py_BuildValue("(dddddd)", x, y, width, height, dx, dy);
  }
  
  static PyObject *
! pycairo_show_text(PyCairoContext *self, PyObject *args)
  {
!     const unsigned char *utf8;
  
!     if (!PyArg_ParseTuple(args, "s:Context.show_text", &utf8))
  	return NULL;
  
!     cairo_show_text(self->ctx, utf8);
!     if (pycairo_check_status(cairo_status(self->ctx)))
! 	return NULL;
      if (pycairo_check_status(cairo_status(self->ctx)))
  	return NULL;
--- 693,725 ----
  
  static PyObject *
! pycairo_show_text(PyCairoContext *self, PyObject *args)
  {
      const unsigned char *utf8;
  
!     if (!PyArg_ParseTuple(args, "s:Context.show_text", &utf8))
  	return NULL;
  
!     cairo_show_text(self->ctx, utf8);
      if (pycairo_check_status(cairo_status(self->ctx)))
  	return NULL;
!     if (pycairo_check_status(cairo_status(self->ctx)))
! 	return NULL;
!     Py_INCREF(Py_None);
!     return Py_None;
  }
  
+ /* XXXX - show_glyphs */
+ /* XXXX - current_font_extents */
+ 
  static PyObject *
! pycairo_set_font(PyCairoContext *self, PyObject *args)
  {
!     PyCairoFont *font;
  
!     if (!PyArg_ParseTuple(args, "O!:Context.set_font",
! 			  &PyCairoFont_Type, &font))
  	return NULL;
  
!     cairo_set_font(self->ctx, font->font);
      if (pycairo_check_status(cairo_status(self->ctx)))
  	return NULL;
***************
*** 718,721 ****
--- 728,748 ----
  }
  
+ #if 0
+ static PyObject *
+ pycairo_text_extents(PyCairoContext *self, PyObject *args)
+ {
+     const unsigned char *utf8;
+     double x, y, width, height, dx, dy;
+ 
+     if (!PyArg_ParseTuple(args, "s:Context.text_extents", &utf8))
+ 	return NULL;
+ 
+     cairo_text_extents(self->ctx, utf8, &x, &y, &width, &height, &dx, &dy);
+     if (pycairo_check_status(cairo_status(self->ctx)))
+ 	return NULL;
+     return Py_BuildValue("(dddddd)", x, y, width, height, dx, dy);
+ }
+ #endif
+ 
  static PyObject *
  pycairo_show_surface(PyCairoContext *self, PyObject *args)
***************
*** 771,775 ****
      { "curve_to", (PyCFunction)pycairo_curve_to, METH_VARARGS },
      { "arc", (PyCFunction)pycairo_arc, METH_VARARGS },
!     { "arc_negative", (PyCFunction)pycairo_arc, METH_VARARGS },
      { "rel_move_to", (PyCFunction)pycairo_rel_move_to, METH_VARARGS },
      { "rel_line_to", (PyCFunction)pycairo_rel_line_to, METH_VARARGS },
--- 798,802 ----
      { "curve_to", (PyCFunction)pycairo_curve_to, METH_VARARGS },
      { "arc", (PyCFunction)pycairo_arc, METH_VARARGS },
!     { "arc_negative", (PyCFunction)pycairo_arc_negative, METH_VARARGS },
      { "rel_move_to", (PyCFunction)pycairo_rel_move_to, METH_VARARGS },
      { "rel_line_to", (PyCFunction)pycairo_rel_line_to, METH_VARARGS },
***************
*** 783,788 ****
      { "scale_font", (PyCFunction)pycairo_scale_font, METH_VARARGS },
      { "transform_font", (PyCFunction)pycairo_transform_font, METH_VARARGS },
-     { "text_extents", (PyCFunction)pycairo_text_extents, METH_VARARGS },
      { "show_text", (PyCFunction)pycairo_show_text, METH_VARARGS },
      { "show_surface", (PyCFunction)pycairo_show_surface, METH_VARARGS },
      { NULL, NULL, 0 }
--- 810,818 ----
      { "scale_font", (PyCFunction)pycairo_scale_font, METH_VARARGS },
      { "transform_font", (PyCFunction)pycairo_transform_font, METH_VARARGS },
      { "show_text", (PyCFunction)pycairo_show_text, METH_VARARGS },
+     { "set_font", (PyCFunction)pycairo_set_font, METH_VARARGS },
+ #if 0
+     { "text_extents", (PyCFunction)pycairo_text_extents, METH_VARARGS },
+ #endif
      { "show_surface", (PyCFunction)pycairo_show_surface, METH_VARARGS },
      { NULL, NULL, 0 }
***************
*** 790,793 ****
--- 820,837 ----
  
  static PyObject *
+ pycairo_current_font(PyCairoContext *self)
+ {
+     cairo_font_t *font;
+ 
+     font = cairo_current_font(self->ctx);
+     if (!font) {
+ 	Py_INCREF(Py_None);
+ 	return Py_None;
+     }
+     cairo_font_reference(font);
+     return pycairo_font_new(font);
+ }
+ 
+ static PyObject *
  pycairo_current_operator(PyCairoContext *self)
  {
***************
*** 882,885 ****
--- 926,930 ----
  
  static PyGetSetDef pycairo_getsets[] = {
+     { "font", (getter)pycairo_current_font, (setter)0 },
      { "operator", (getter)pycairo_current_operator, (setter)0 },
      { "rgb_color", (getter)pycairo_current_rgb_color, (setter)0 },

Index: pycairo-private.h
===================================================================
RCS file: /cvs/cairo/python-cairo/cairo/pycairo-private.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pycairo-private.h	17 Sep 2003 14:34:02 -0000	1.1
--- pycairo-private.h	28 Oct 2003 15:53:13 -0000	1.2
***************
*** 13,16 ****
--- 13,17 ----
  extern PyTypeObject PyCairoContext_Type;
  extern PyTypeObject PyCairoSurface_Type;
+ extern PyTypeObject PyCairoFont_Type;
  
  int       pycairo_check_status(cairo_status_t status);
***************
*** 18,26 ****
  /* takes ownership of reference */
  PyObject *pycairo_matrix_new(cairo_matrix_t *matrix);
- 
  PyObject *pycairo_context_new(cairo_t *ctx);
- 
- /* takes ownership of reference */
  PyObject *pycairo_surface_new(cairo_surface_t *surface);
  
  #endif
--- 19,25 ----
  /* takes ownership of reference */
  PyObject *pycairo_matrix_new(cairo_matrix_t *matrix);
  PyObject *pycairo_context_new(cairo_t *ctx);
  PyObject *pycairo_surface_new(cairo_surface_t *surface);
+ PyObject *pycairo_font_new(cairo_font_t *font);
  
  #endif

Index: pycairo.h
===================================================================
RCS file: /cvs/cairo/python-cairo/cairo/pycairo.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** pycairo.h	24 Sep 2003 01:05:43 -0000	1.2
--- pycairo.h	28 Oct 2003 15:53:13 -0000	1.3
***************
*** 22,25 ****
--- 22,30 ----
  } PyCairoSurface;
  
+ typedef struct {
+     PyObject_HEAD
+     cairo_font_t *font;
+ } PyCairoFont;
+ 
  struct _PyCairo_FunctionStruct {
      int (* check_status)(cairo_status_t status);
***************
*** 28,31 ****
--- 33,38 ----
      PyTypeObject *surface_type;
      PyObject *(* surface_new)(cairo_surface_t *surface);
+     PyTypeObject *font_type;
+     PyObject *(* font_new)(cairo_font_t *font);
      PyTypeObject *context_type;
      PyObject *(* context_new)(cairo_t *ctx);
***************
*** 45,48 ****
--- 52,57 ----
  #define PyCairoSurface_Type *(_PyCairo_API->surface_type)
  #define pycairo_surface_new  (_PyCairo_API->surface_new)
+ #define PyCairoFont_Type *(_PyCairo_API->font_type)
+ #define pycairo_font_new  (_PyCairo_API->font_new)
  #define PyCairoContext_Type *(_PyCairo_API->context_type)
  #define pycairo_context_new  (_PyCairo_API->context_new)





More information about the cairo-commit mailing list