| 528 | } |
| 529 | |
| 530 | imageObj* createImageCairo(int width, int height, outputFormatObj *format,colorObj* bg) { |
| 531 | imageObj *image = NULL; |
| 532 | cairo_renderer *r=NULL; |
| 533 | if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode!= MS_IMAGEMODE_RGBA) { |
| 534 | msSetError(MS_MISCERR, |
| 535 | "Cairo driver only supports RGB or RGBA pixel models.","msImageCreateCairo()"); |
| 536 | return image; |
| 537 | } |
| 538 | if (width > 0 && height > 0) { |
| 539 | image = (imageObj *) calloc(1, sizeof(imageObj)); |
| 540 | r = (cairo_renderer*)calloc(1,sizeof(cairo_renderer)); |
| 541 | if(!strcasecmp(format->driver,"cairo/pdf")) { |
| 542 | r->outputStream = (bufferObj*)malloc(sizeof(bufferObj)); |
| 543 | msBufferInit(r->outputStream); |
| 544 | r->surface = cairo_pdf_surface_create_for_stream( |
| 545 | _stream_write_fn, |
| 546 | r->outputStream, |
| 547 | width,height); |
| 548 | } else if(!strcasecmp(format->driver,"cairo/svg")) { |
| 549 | r->outputStream = (bufferObj*)malloc(sizeof(bufferObj)); |
| 550 | msBufferInit(r->outputStream); |
| 551 | r->surface = cairo_svg_surface_create_for_stream( |
| 552 | _stream_write_fn, |
| 553 | r->outputStream, |
| 554 | width,height); |
| 555 | } else if(!strcasecmp(format->driver,"cairo/winGDI") && format->device) { |
| 556 | #if CAIRO_HAS_WIN32_SURFACE |
| 557 | r->outputStream = NULL; |
| 558 | r->surface = cairo_win32_surface_create(format->device); |
| 559 | #else |
| 560 | msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.", |
| 561 | "msImageCreateCairo()"); |
| 562 | #endif |
| 563 | } else if(!strcasecmp(format->driver,"cairo/winGDIPrint") && format->device) { |
| 564 | #if CAIRO_HAS_WIN32_SURFACE |
| 565 | r->outputStream = NULL; |
| 566 | r->surface = cairo_win32_printing_surface_create(format->device); |
| 567 | #else |
| 568 | msSetError(MS_RENDERERERR, "Cannot create cairo image. Cairo was not compiled with support for the win32 backend.", |
| 569 | "msImageCreateCairo()"); |
| 570 | #endif |
| 571 | } else { |
| 572 | r->outputStream = NULL; |
| 573 | r->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); |
| 574 | } |
| 575 | r->cr = cairo_create(r->surface); |
| 576 | if(format->transparent || !bg || !MS_VALID_COLOR(*bg)) { |
| 577 | r->use_alpha = 1; |
| 578 | cairo_set_source_rgba (r->cr, 0,0,0,0); |
| 579 | } else { |
| 580 | r->use_alpha = 0; |
| 581 | msCairoSetSourceColor(r->cr,bg); |
| 582 | } |
| 583 | cairo_save (r->cr); |
| 584 | cairo_set_operator (r->cr, CAIRO_OPERATOR_SOURCE); |
| 585 | cairo_paint (r->cr); |
| 586 | cairo_restore (r->cr); |
| 587 |
nothing calls this directly
no test coverage detected