int msPreloadSVGSymbol(symbolObj *symbol) { #if defined(USE_SVG_CAIRO) || defined(USE_RSVG) struct svg_symbol_cache *cache; if(!symbol->renderer_cache) { cache = msSmallCalloc(1,sizeof(struct svg_symbol_cache)); symbol->renderer_free_func = &freeSVGCache; } else { cache = symbol->renderer_cache; } if(cache->svgc) return MS_SUCCESS; #ifdef USE_SVG_CAIRO { unsigned int svg_width, svg_height; int status; status = svg_cairo_create(&cache->svgc); if (status) { msSetError(MS_RENDERERERR, "problem creating cairo svg", "msPreloadSVGSymbol()"); return MS_FAILURE; } status = svg_cairo_parse(cache->svgc, symbol->full_pixmap_path); if (status) { msSetError(MS_RENDERERERR, "problem parsing svg symbol", "msPreloadSVGSymbol()"); return MS_FAILURE; } svg_cairo_get_size (cache->svgc, &svg_width, &svg_height); if (svg_width == 0 || svg_height == 0) { msSetError(MS_RENDERERERR, "problem parsing svg symbol", "msPreloadSVGSymbol()"); return MS_FAILURE; } symbol->sizex = svg_width; symbol->sizey = svg_height; } #else { RsvgDimensionData dim; cache->svgc = rsvg_handle_new_from_file(symbol->full_pixmap_path,NULL); if(!cache->svgc) { msSetError(MS_RENDERERERR,"failed to load svg file %s", "msPreloadSVGSymbol()", symbol->full_pixmap_path); } rsvg_handle_get_dimensions_sub (cache->svgc, &dim, NULL); symbol->sizex = dim.width; symbol->sizey = dim.height; } #endif symbol->renderer_cache = cache; return MS_SUCCESS; #else msSetError(MS_MISCERR, "SVG Symbols requested but is not built with libsvgcairo", "msPreloadSVGSymbol()"); return MS_FAILURE; #endif }
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; }