[cairo] Copying from one surface to another
Richenderfer, Tom
Tom.Richenderfer at xerox.com
Thu Feb 2 08:15:18 PST 2012
Hello,
I am new to using Cairo and I am having a problem
getting my code to work correctly. I have a set of PNG files that I
want Cairo to read in and copy to a PS surface (doing a PNG -> PS
conversion). The code seems to work except that all of the PS pages in
the resulting PS file are blank. I am following the example given in
the Cairo FAQ about copying surfaces. Any ideas on what I am doing
wrong? The basic code is:
// create Cairo PS surface
psSurface =
cairo_ps_surface_create("/var/tmp/PNG2PSPlugin.ps", 864, 1584);
if(cairo_surface_status(psSurface) !=
CAIRO_STATUS_SUCCESS)
{
return(false);
}
// create context
psTarget = cairo_create(psSurface);
if(cairo_status(psTarget) != CAIRO_STATUS_SUCCESS)
{
// could not create context, abort
return(false);
}
// loop to read the page png files into a PNG surface
and paint into a PS surface
for(pageNum = 1; ; pageNum++)
{
// build the file name
sprintf(pageFileName,
"/var/tmp/PNGFile%d.png", pageNum);
// try to open the file
dataFileHandle.open(pageFileName, ios::in
| ios::binary);
if(!dataFileHandle.is_open())
{
// at end of file set
break;
}
else
{
dataFileHandle.close();
}
// create the png surface with the file
pngSurface =
cairo_image_surface_create_from_png((const char*)pageFileName);
if(cairo_surface_status(pngSurface) !=
CAIRO_STATUS_SUCCESS)
{
// could not create png
surface, abort
return(false);
}
// paint the png surface to the ps
surface
cairo_set_source_surface(psTarget,
pngSurface, 0.0, 0.0);
cairo_paint(psTarget);
cairo_surface_show_page(psSurface);
cairo_surface_destroy(pngSurface);
}
// check on the context
if(cairo_status(psTarget) != CAIRO_STATUS_SUCCESS)
{
// something went wrong, abort
return(false);
}
// delete the context
cairo_destroy(psTarget);
// close out drawing to the ps surface
cairo_surface_finish(psSurface);
// check the status of the ps surface
if(cairo_surface_status(psSurface) !=
CAIRO_STATUS_SUCCESS)
{
// something went wrong, abort
return(false);
}
// done with the ps surface
cairo_surface_destroy(psSurface);
Thanks,
Tom R.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20120202/eb506f45/attachment.html>
More information about the cairo
mailing list