[cairo] Copying from one surface to another

Richenderfer, Tom Tom.Richenderfer at xerox.com
Thu Feb 2 13:21:26 PST 2012


All,

 

                I have discovered the basic problem that I am running
into with this application.  The PNG files were created for 600 dpi and
I want the PS output created for 600 dpi, but it appears the PS output
is getting created for something like 72 dpi.  Is it possible to tell
the psSurface that it should be rendering the image data for a
particular resolution?  I have tried
cairo_surface_set_fallback_resolution on the psSurface, but it had no
effect.

 

Thanks,

 

Tom R.

 

From: cairo-bounces+tom.richenderfer=xerox.com at cairographics.org
[mailto:cairo-bounces+tom.richenderfer=xerox.com at cairographics.org] On
Behalf Of Richenderfer, Tom
Sent: Thursday, February 02, 2012 11:15 AM
To: cairo at cairographics.org
Subject: [cairo] Copying from one surface to another

 

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/19be0a81/attachment.html>


More information about the cairo mailing list