Copying from one surface to another

"Richenderfer, Tom" <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <9B7EC7F6FAF49F4A9AACB4293B2DC7BD0F55E3C5@USA7061MS02.na.xerox.net>
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.

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.