Esempio n. 1
0
void freeSVGCache(symbolObj *s) {
#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
      struct svg_symbol_cache *cache = s->renderer_cache;
      assert(cache->svgc);
#ifdef USE_SVG_CAIRO
      svg_cairo_destroy(cache->svgc);
#else
      rsvg_handle_close(cache->svgc, NULL);
  #if LIBRSVG_CHECK_VERSION(2,35,0)
      g_object_unref(cache->svgc);
  #else
      rsvg_handle_free(cache->svgc);
  #endif
#endif
      if(cache->pixmap_buffer) {
        msFreeRasterBuffer(cache->pixmap_buffer);
        free(cache->pixmap_buffer);
      }
      msFree(s->renderer_cache);
#endif
}
Esempio n. 2
0
int freeSymbolCairo(symbolObj *s)
{
    if(!s->renderer_cache)
        return MS_SUCCESS;
    switch(s->type) {
    case MS_SYMBOL_VECTOR:
        cairo_path_destroy(s->renderer_cache);
        break;
    case MS_SYMBOL_PIXMAP:
        cairo_surface_destroy(s->renderer_cache);
        break;
    case MS_SYMBOL_SVG: {
#ifdef USE_SVG_CAIRO
        struct svg_symbol_cache *cache = s->renderer_cache;
        assert(cache->svgc);
        svg_cairo_destroy(cache->svgc);
        msFree(s->renderer_cache);
#endif
    }
    break;
    }
    s->renderer_cache=NULL;
    return MS_SUCCESS;
}
Esempio n. 3
0
static svg_cairo_status_t
render_to_png (FILE *svg_file, FILE *png_file, double scale, int width, int height)
{
    unsigned int svg_width, svg_height;

    svg_cairo_status_t status;
    cairo_t *cr;
    svg_cairo_t *svgc;
    cairo_surface_t *surface;
    double dx = 0, dy = 0;

    status = svg_cairo_create (&svgc);
    if (status) {
	fprintf (stderr, "Failed to create svg_cairo_t. Exiting.\n");
	exit(1);
    }

    status = svg_cairo_parse_file (svgc, svg_file);
    if (status)
	return status;

    svg_cairo_get_size (svgc, &svg_width, &svg_height);

    if (width < 0 && height < 0) {
	width = (svg_width * scale + 0.5);
	height = (svg_height * scale + 0.5);
    } else if (width < 0) {
	scale = (double) height / (double) svg_height;
	width = (svg_width * scale + 0.5);
    } else if (height < 0) {
	scale = (double) width / (double) svg_width;
	height = (svg_height * scale + 0.5);
    } else {
	scale = MIN ((double) width / (double) svg_width, (double) height / (double) svg_height);
	/* Center the resulting image */
	dx = (width - (int) (svg_width * scale + 0.5)) / 2;
	dy = (height - (int) (svg_height * scale + 0.5)) / 2;
    }

    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
    cr = cairo_create (surface);
    
    cairo_save (cr);
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
    cairo_paint (cr);
    cairo_restore (cr);

    cairo_translate (cr, dx, dy);
    cairo_scale (cr, scale, scale);

    /* XXX: This probably doesn't need to be here (eventually) */
    cairo_set_source_rgb (cr, 1, 1, 1);

    status = svg_cairo_render (svgc, cr);

    status = write_surface_to_png_file (surface, png_file);
    cairo_surface_destroy (surface);
    cairo_destroy (cr);
    
    if (status)
	return status;

    svg_cairo_destroy (svgc);

    return status;
}
Esempio n. 4
0
File: svg.c Progetto: udhos/voyksed
SDL_Surface *load_svg(frame_t *frame, const char *name, int alpha)
{
  svg_cairo_t     *svg;
  unsigned int     svg_width;
  unsigned int     svg_height;
  int              bpp    = 32; /* bits per pixel */
  int              btpp   = 4;  /* bytes per pixel */
  int              stride;
  int              space;
  char            *image;
  cairo_surface_t *cairo_surface;
  cairo_t         *cr;
  Uint32           rmask = 0x00ff0000;
  Uint32           gmask = 0x0000ff00;
  Uint32           bmask = 0x000000ff;
  Uint32           amask = 0xff000000;
  SDL_Surface     *sdl_surf_tmp;
  SDL_Surface     *sdl_surf;

  svg_cairo_create(&svg);
  svg_cairo_parse(svg, name);
  svg_cairo_get_size(svg, &svg_width, &svg_height);

  stride = svg_width * btpp;    /* scanline width */
  space  = svg_height * stride; 

  image = malloc(space);
  if (!image) {
    fprintf(stderr, "ugh: malloc(%d)\n", space);
    exit(1);
  }

  cairo_surface = cairo_image_surface_create_for_data(image,
						      CAIRO_FORMAT_ARGB32,
						      svg_width, svg_height,
						      stride);

  cr = cairo_create(cairo_surface);
  /* cairo_scale(cr, 1, 1); */

  svg_cairo_render(svg, cr);

  cairo_destroy(cr);
  cairo_surface_destroy(cairo_surface);
  svg_cairo_destroy(svg);
    
  sdl_surf_tmp = SDL_CreateRGBSurfaceFrom(image, svg_width, svg_height,
					  bpp, stride,
					  rmask, gmask, bmask, amask);

  sdl_surf = alpha ? 
    SDL_DisplayFormatAlpha(sdl_surf_tmp) :
    SDL_DisplayFormat(sdl_surf_tmp);

  if (!sdl_surf) {
    fprintf(stderr, "ugh: unable to convert image: %s: %s\n", 
	    name, SDL_GetError());
    exit(1);
  }
  SDL_FreeSurface(sdl_surf_tmp);

  frame->image_list[frame->image_list_size] = sdl_surf;

  show_image_info(frame, sdl_surf, name, alpha);

  ++frame->image_list_size;

  return sdl_surf;
}