Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Classes | Functions | Variables
objimageexport.cpp File Reference
#include "objimageexport.h"
#include "cmdutil.h"
#include "page.h"
#include <structmember.h>
#include <qfileinfo.h>
#include <vector>
#include "scribuscore.h"

Go to the source code of this file.

Classes

struct  ImageExport

Functions

static void ImageExport_dealloc (ImageExport *self)
static PyObject * ImageExport_new (PyTypeObject *type, PyObject *, PyObject *)
static int ImageExport_init (ImageExport *, PyObject *, PyObject *)
static PyObject * ImageExport_getName (ImageExport *self, void *)
static int ImageExport_setName (ImageExport *self, PyObject *value, void *)
static PyObject * ImageExport_getType (ImageExport *self, void *)
static int ImageExport_setType (ImageExport *self, PyObject *value, void *)
static PyObject * ImageExport_getAllTypes (ImageExport *, void *)
static int ImageExport_setAllTypes (ImageExport *, PyObject *, void *)
static PyObject * ImageExport_save (ImageExport *self)
static PyObject * ImageExport_saveAs (ImageExport *self, PyObject *args)

Variables

static PyMemberDef ImageExport_members []
static PyGetSetDef ImageExport_getseters []
static PyMethodDef ImageExport_methods []
PyTypeObject ImageExport_Type

Class Documentation

struct ImageExport

Definition at line 16 of file objimageexport.cpp.

Class Members
PyObject * allTypes
int dpi
PyObject_HEAD PyObject * name
int quality
int scale
PyObject * type

Function Documentation

static void ImageExport_dealloc ( ImageExport self) [static]

Definition at line 27 of file objimageexport.cpp.

{
       Py_XDECREF(self->name);
       Py_XDECREF(self->type);
       Py_XDECREF(self->allTypes);
       self->ob_type->tp_free((PyObject *)self);
}
static PyObject* ImageExport_getAllTypes ( ImageExport ,
void *   
) [static]

Definition at line 110 of file objimageexport.cpp.

{
       PyObject *l;
       int pos = 0;
       QStringList list = QImage::outputFormatList();
       l = PyList_New(list.count());
       for (QStringList::Iterator it = list.begin(); it != list.end(); ++it)
       {
              PyList_SetItem(l, pos, PyString_FromString((*it).latin1()));
              ++pos;
       }
       return l;
}
static PyObject* ImageExport_getName ( ImageExport self,
void *   
) [static]

Definition at line 65 of file objimageexport.cpp.

{
       Py_INCREF(self->name);
       return self->name;
}
static PyObject* ImageExport_getType ( ImageExport self,
void *   
) [static]

Definition at line 88 of file objimageexport.cpp.

{
       Py_INCREF(self->type);
       return self->type;
}
static int ImageExport_init ( ImageExport ,
PyObject *  ,
PyObject *   
) [static]

Definition at line 53 of file objimageexport.cpp.

{
       return 0;
}
static PyObject* ImageExport_new ( PyTypeObject *  type,
PyObject *  ,
PyObject *   
) [static]

Definition at line 35 of file objimageexport.cpp.

{
       if(!checkHaveDocument())
              return NULL;

       ImageExport *self;
       self = (ImageExport *)type->tp_alloc(type, 0);
       if (self != NULL) {
              self->name = PyString_FromString("ImageExport.png");
              self->type = PyString_FromString("PNG");
              self->allTypes = PyList_New(0);
              self->dpi = 72;
              self->scale = 100;
              self->quality = 100;
       }
       return (PyObject *) self;
}

Here is the call graph for this function:

static PyObject* ImageExport_save ( ImageExport self) [static]

Definition at line 137 of file objimageexport.cpp.

{
       if(!checkHaveDocument())
              return NULL;

       /* a little magic here - I need to compute the "maxGr" value...
       * We need to know the right size of the page for landscape,
       * portrait and user defined sizes.
       */
       double pixmapSize;
       (ScCore->primaryMainWindow()->doc->pageHeight > ScCore->primaryMainWindow()->doc->pageWidth)
                     ? pixmapSize = ScCore->primaryMainWindow()->doc->pageHeight
                     : pixmapSize = ScCore->primaryMainWindow()->doc->pageWidth;
       QImage im = ScCore->primaryMainWindow()->view->PageToPixmap(ScCore->primaryMainWindow()->doc->currentPage()->pageNr(), qRound(pixmapSize * self->scale * (self->dpi / 72.0) / 100.0), false);
       int dpi = qRound(100.0 / 2.54 * self->dpi);
       im.setDotsPerMeterY(dpi);
       im.setDotsPerMeterX(dpi);
       if (!im.save(PyString_AsString(self->name), PyString_AsString(self->type)))
       {
              PyErr_SetString(ScribusException, QObject::tr("Failed to export image", "python error"));
              return NULL;
       }
//     Py_INCREF(Py_True); // return True not None for backward compat
 //    return Py_True;
       Py_RETURN_TRUE;
}

Here is the call graph for this function:

static PyObject* ImageExport_saveAs ( ImageExport self,
PyObject *  args 
) [static]

Definition at line 164 of file objimageexport.cpp.

{
       char* value;
       if(!checkHaveDocument())
              return NULL;
       if (!PyArg_ParseTuple(args, const_cast<char*>("es"), "utf-8", &value))
              return NULL;

       /* a little magic here - I need to compute the "maxGr" value...
       * We need to know the right size of the page for landscape,
       * portrait and user defined sizes.
       */
       double pixmapSize;
       (ScCore->primaryMainWindow()->doc->pageHeight > ScCore->primaryMainWindow()->doc->pageWidth)
                     ? pixmapSize = ScCore->primaryMainWindow()->doc->pageHeight
                     : pixmapSize = ScCore->primaryMainWindow()->doc->pageWidth;
       QImage im = ScCore->primaryMainWindow()->view->PageToPixmap(ScCore->primaryMainWindow()->doc->currentPage()->pageNr(), qRound(pixmapSize * self->scale * (self->dpi / 72.0) / 100.0), false);
       int dpi = qRound(100.0 / 2.54 * self->dpi);
       im.setDotsPerMeterY(dpi);
       im.setDotsPerMeterX(dpi);
       if (!im.save(value, PyString_AsString(self->type)))
       {
              PyErr_SetString(ScribusException, QObject::tr("Failed to export image", "python error"));
              return NULL;
       }
//     Py_INCREF(Py_True); // return True not None for backward compat
 //    return Py_True;
       Py_RETURN_TRUE;
}

Here is the call graph for this function:

static int ImageExport_setAllTypes ( ImageExport ,
PyObject *  ,
void *   
) [static]

Definition at line 124 of file objimageexport.cpp.

{
       PyErr_SetString(PyExc_ValueError, QObject::tr("'allTypes' attribute is READ-ONLY", "python error"));
       return -1;
}

Here is the call graph for this function:

static int ImageExport_setName ( ImageExport self,
PyObject *  value,
void *   
) [static]

Definition at line 71 of file objimageexport.cpp.

{
       if (!PyString_Check(value)) {
              PyErr_SetString(PyExc_TypeError, QObject::tr("The filename must be a string.", "python error"));
              return -1;
       }
       if (PyString_Size(value) < 1)
       {
              PyErr_SetString(PyExc_TypeError, QObject::tr("The filename should not be empty string.", "python error"));
              return -1;
       }
       Py_DECREF(self->name);
       Py_INCREF(value);
       self->name = value;
       return 0;
}

Here is the call graph for this function:

static int ImageExport_setType ( ImageExport self,
PyObject *  value,
void *   
) [static]

Definition at line 94 of file objimageexport.cpp.

{
       if (value == NULL) {
              PyErr_SetString(PyExc_TypeError, QObject::tr("Cannot delete image type settings.", "python error"));
              return -1;
       }
       if (!PyString_Check(value)) {
              PyErr_SetString(PyExc_TypeError, QObject::tr("The image type must be a string.", "python error"));
              return -1;
       }
       Py_DECREF(self->type);
       Py_INCREF(value);
       self->type = value;
       return 0;
}

Here is the call graph for this function:


Variable Documentation

PyGetSetDef ImageExport_getseters[] [static]
Initial value:
 {
       {const_cast<char*>("name"), (getter)ImageExport_getName, (setter)ImageExport_setName, imgexp_filename__doc__, NULL},
       {const_cast<char*>("type"), (getter)ImageExport_getType, (setter)ImageExport_setType, imgexp_type__doc__, NULL},
       {const_cast<char*>("allTypes"), (getter)ImageExport_getAllTypes, (setter)ImageExport_setAllTypes, imgexp_alltypes__doc__, NULL},
       {NULL, NULL, NULL, NULL, NULL}  
}

Definition at line 130 of file objimageexport.cpp.

PyMemberDef ImageExport_members[] [static]
Initial value:
 {
       {const_cast<char*>("dpi"), T_INT, offsetof(ImageExport, dpi), 0, imgexp_dpi__doc__},
       {const_cast<char*>("scale"), T_INT, offsetof(ImageExport, scale), 0, imgexp_scale__doc__},
       {const_cast<char*>("quality"), T_INT, offsetof(ImageExport, quality), 0, imgexp_quality__doc__},
       {NULL, 0, 0, 0, NULL} 
}

Definition at line 58 of file objimageexport.cpp.

PyMethodDef ImageExport_methods[] [static]
Initial value:
 {
       {const_cast<char*>("save"), (PyCFunction)ImageExport_save, METH_NOARGS, imgexp_save__doc__},
       {const_cast<char*>("saveAs"), (PyCFunction)ImageExport_saveAs, METH_VARARGS, imgexp_saveas__doc__},
       {NULL, (PyCFunction)(0), 0, NULL} 
}

Definition at line 194 of file objimageexport.cpp.

PyTypeObject ImageExport_Type

Definition at line 200 of file objimageexport.cpp.