#include #include #include // Draw some data to a PDF surface, then copy it to an image surface for // rasterization. The output should be non-AA'd (But it is...) // // Build with: // gcc -g `pkg-config --cflags --libs cairo` simple_copy.c int main(int argc, char *argv[]) { // Make a PDF surface const char fileName[] = "source.pdf"; const int width = 1000; const int height = 1000; cairo_surface_t *pdfSurface = cairo_pdf_surface_create( fileName, width, height); cairo_t *pdfContext = cairo_create(pdfSurface); // Uncomment this to achieve non-AA'd output. But why? // Why do you have to set this on the PDF surface, *before* // drawing anything? AA should only be being done during // the copy/rasterization (below). /* cairo_set_antialias(pdfContext, CAIRO_ANTIALIAS_NONE); */ // Draw some circles { cairo_set_source_rgba(pdfContext, 0.0, 1.0, 0.0, 1); const double ang1 = 0; const double ang2 = 360 * M_PI/180.0; const double cenX = width / 2.0; const double cenY = height / 2.0; int i; for (i=50; i<=700; i+=50) { cairo_arc(pdfContext, cenX, cenY, i, ang1, ang2); cairo_stroke(pdfContext); } } // Make the image surface cairo_surface_t *imgSurface = cairo_image_surface_create( CAIRO_FORMAT_RGB24, width, height); cairo_t *imgContext = cairo_create(imgSurface); // This is where I'd expect to turn off AA, to get non-AA'd output. // However, this seems to have no effect. cairo_set_antialias(imgContext, CAIRO_ANTIALIAS_NONE); // Copy the PDF to the image cairo_set_source_surface(imgContext, pdfSurface, 0, 0); cairo_paint(imgContext); cairo_surface_write_to_png(imgSurface, "output.png"); cairo_destroy(imgContext); cairo_destroy(pdfContext); cairo_surface_destroy(imgSurface); cairo_surface_destroy(pdfSurface); cairo_debug_reset_static_data(); // Valgrind return 0; }