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
|
/* Python.h should always be first */
#include <Python.h>
#include <cairo/cairo.h>
#include <string.h>
#include "grdel.h"
#include "cferbind.h"
#include "cairoCFerBind.h"
#include "FerMem.h"
/*
* Ends a "View" for this "Window".
*
* Returns one if successful. If an error occurs, grdelerrmsg
* is assigned an appropriate error message and zero is returned.
*/
grdelBool cairoCFerBind_endView(CFerBind *self)
{
CairoCFerBindData *instdata;
CCFBPicture *thispic;
cairo_status_t status;
/* Sanity check */
if ( (self->enginename != CairoCFerBindName) &&
(self->enginename != PyQtCairoCFerBindName) ) {
strcpy(grdelerrmsg, "cairoCFerBind_endView: unexpected error, "
"self is not a valid CFerBind struct");
return 0;
}
instdata = (CairoCFerBindData *) self->instancedata;
/* Nothing to do if neither an image nor recording surface */
if ( (instdata->imageformat != CCFBIF_PNG) &&
(instdata->imageformat != CCFBIF_REC) ) {
return 1;
}
/* If something was drawn, delete the context but save the surface */
if ( instdata->somethingdrawn ) {
if ( instdata->context == NULL ) {
strcpy(grdelerrmsg, "cairoCFerBind_endView: unexpected error, "
"something drawn without a context");
return 0;
}
if ( instdata->surface == NULL ) {
strcpy(grdelerrmsg, "cairoCFerBind_endView: unexpected error, "
"something drawn without a surface");
return 0;
}
/* Allocate a new picture for the linked list */
thispic = (CCFBPicture *) FerMem_Malloc(sizeof(CCFBPicture), __FILE__, __LINE__);
if ( thispic == NULL ) {
strcpy(grdelerrmsg, "cairoCFerBind_endView: "
"Out of memory for a CCFBPicture structure");
return 0;
}
/* Only need the surface, not the context */
/* cairo_show_page(instdata->context); - adds a newpage */
/* Make sure the context is not in an error state */
status = cairo_status(instdata->context);
if ( status != CAIRO_STATUS_SUCCESS ) {
sprintf(grdelerrmsg, "cairoCFerBind_endView: "
"cairo context error: %s",
cairo_status_to_string(status));
return 0;
}
cairo_destroy(instdata->context);
instdata->context = NULL;
cairo_surface_flush(instdata->surface);
/* Make sure the surface is not in an error state */
status = cairo_surface_status(instdata->surface);
if ( status != CAIRO_STATUS_SUCCESS ) {
sprintf(grdelerrmsg, "cairoCFerBind_endView: "
"cairo surface error: %s",
cairo_status_to_string(status));
return 0;
}
/* Assign the current surface and segment ID to this picture */
thispic->next = NULL;
thispic->surface = instdata->surface;
thispic->segid = instdata->segid;
instdata->surface = NULL;
instdata->somethingdrawn = 0;
/* Add the picture to the linked list */
if ( instdata->lastpic == NULL ) {
instdata->firstpic = thispic;
instdata->lastpic = thispic;
}
else {
instdata->lastpic->next = thispic;
instdata->lastpic = thispic;
}
}
return 1;
}
|