Permalink
Browse files

refactor symbol loading, add svg marker lines

  • Loading branch information...
1 parent 0b4ad75 commit 741a56d824533ce6bce685fc22922da45eabf271 @tbonfort tbonfort committed Jul 26, 2013
Showing with 70 additions and 104 deletions.
  1. +69 −103 maprendering.c
  2. +1 −1 msautotest
View
@@ -136,6 +136,44 @@ tileCacheObj *searchTileCache(imageObj *img, symbolObj *symbol, symbolStyleObj *
return NULL;
}
+int preloadSymbol(symbolSetObj *symbolset, symbolObj *symbol, rendererVTableObj *renderer) {
+ switch(symbol->type) {
+ case MS_SYMBOL_VECTOR:
+ case MS_SYMBOL_ELLIPSE:
+ case MS_SYMBOL_SIMPLE:
+ break;
+ case (MS_SYMBOL_SVG):
+#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
+ return msPreloadSVGSymbol(symbol);
+#else
+ msSetError(MS_SYMERR, "SVG symbol support is not enabled.", "preloadSymbol()");
+ return MS_FAILURE;
+#endif
+ break;
+ case (MS_SYMBOL_TRUETYPE): {
+ if(!symbol->full_font_path)
+ symbol->full_font_path = msStrdup(msLookupHashTable(&(symbolset->fontset->fonts),
+ symbol->font));
+ if(!symbol->full_font_path) {
+ msSetError(MS_MEMERR,"allocation error", "preloadSymbol()");
+ return MS_FAILURE;
+ }
+ }
+ break;
+ case (MS_SYMBOL_PIXMAP): {
+ if(!symbol->pixmap_buffer) {
+ if(MS_SUCCESS != msPreloadImageSymbol(renderer,symbol))
+ return MS_FAILURE;
+ }
+ }
+ break;
+ default:
+ msSetError(MS_MISCERR,"unsupported symbol type %d", "preloadSymbol()", symbol->type);
+ return MS_FAILURE;
+ }
+ return MS_SUCCESS;
+}
+
/* add a cached tile to the current image's cache */
tileCacheObj *addTileCache(imageObj *img,
imageObj *tile, symbolObj *symbol, symbolStyleObj *style, int width, int height)
@@ -192,6 +230,7 @@ imageObj *getTile(imageObj *img, symbolObj *symbol, symbolStyleObj *s, int widt
width=height=MS_MAX(symbol->sizex,symbol->sizey);
}
tile = searchTileCache(img,symbol,s,width,height);
+
if(tile==NULL) {
imageObj *tileimg;
double p_x,p_y;
@@ -204,9 +243,6 @@ imageObj *getTile(imageObj *img, symbolObj *symbol, symbolStyleObj *s, int widt
renderer->renderTruetypeSymbol(tileimg, p_x, p_y, symbol, s);
break;
case (MS_SYMBOL_PIXMAP):
- if(msPreloadImageSymbol(renderer,symbol) != MS_SUCCESS) {
- return NULL; /* failed to load image, renderer should have set the error message */
- }
renderer->renderPixmapSymbol(tileimg, p_x, p_y, symbol, s);
break;
case (MS_SYMBOL_ELLIPSE):
@@ -218,9 +254,6 @@ imageObj *getTile(imageObj *img, symbolObj *symbol, symbolStyleObj *s, int widt
case (MS_SYMBOL_SVG):
#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
- if(msPreloadSVGSymbol(symbol) != MS_SUCCESS) {
- return NULL; //failed to load image, renderer should have set the error message
- }
if (renderer->supports_svg) {
if(renderer->renderSVGSymbol(tileimg, p_x, p_y, symbol, s) != MS_SUCCESS) {
return NULL;
@@ -256,9 +289,6 @@ imageObj *getTile(imageObj *img, symbolObj *symbol, symbolStyleObj *s, int widt
renderer->renderTruetypeSymbol(tile3img, p_x, p_y, symbol, s);
break;
case (MS_SYMBOL_PIXMAP):
- if(msPreloadImageSymbol(renderer,symbol) != MS_SUCCESS) {
- return NULL; /* failed to load image, renderer should have set the error message */
- }
renderer->renderPixmapSymbol(tile3img, p_x, p_y, symbol, s);
break;
case (MS_SYMBOL_ELLIPSE):
@@ -271,9 +301,6 @@ imageObj *getTile(imageObj *img, symbolObj *symbol, symbolStyleObj *s, int widt
only be for vector symbols. But if that changes ...*/
case (MS_SYMBOL_SVG):
#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
- if(msPreloadSVGSymbol(symbol) != MS_SUCCESS) {
- return NULL; //failed to load image, renderer should have set the error message
- }
if (renderer->supports_svg) {
renderer->renderSVGSymbol(tile3img, p_x, p_y, symbol, s);
} else {
@@ -391,6 +418,18 @@ int msImagePolylineMarkers(imageObj *image, shapeObj *p, symbolObj *symbol,
case MS_SYMBOL_TRUETYPE:
ret = renderer->renderTruetypeSymbol(image, point.x, point.y, symbol, style);
break;
+ case (MS_SYMBOL_SVG):
+#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
+ if (renderer->supports_svg) {
+ ret = renderer->renderSVGSymbol(image, point.x, point.y, symbol, style);
+ } else {
+ ret = msRenderRasterizedSVGSymbol(image,point.x,point.y,symbol, style);
+ }
+#else
+ msSetError(MS_SYMERR, "SVG symbol support is not enabled.", "msImagePolylineMarkers()()");
+ ret = MS_FAILURE;
+#endif
+ break;
}
if( ret != MS_SUCCESS)
return ret;
@@ -449,6 +488,18 @@ int msImagePolylineMarkers(imageObj *image, shapeObj *p, symbolObj *symbol,
case MS_SYMBOL_TRUETYPE:
ret = renderer->renderTruetypeSymbol(image, point.x, point.y, symbol, style);
break;
+ case (MS_SYMBOL_SVG):
+#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
+ if (renderer->supports_svg) {
+ ret = renderer->renderSVGSymbol(image, point.x, point.y, symbol, style);
+ } else {
+ ret = msRenderRasterizedSVGSymbol(image,point.x,point.y,symbol, style);
+ }
+#else
+ msSetError(MS_SYMERR, "SVG symbol support is not enabled.", "msImagePolylineMarkers()()");
+ ret = MS_FAILURE;
+#endif
+ break;
}
break; /* we have rendered the single marker for this line */
}
@@ -520,35 +571,13 @@ int msDrawLineSymbol(symbolSetObj *symbolset, imageObj *image, shapeObj *p,
renderer->renderLine(image,offsetLine,&s);
} else {
symbolStyleObj s;
- switch (symbol->type) {
- case (MS_SYMBOL_TRUETYPE): {
- if(!symbol->full_font_path)
- symbol->full_font_path = msStrdup(msLookupHashTable(&(symbolset->fontset->fonts),
- symbol->font));
- if(!symbol->full_font_path) {
- msSetError(MS_MEMERR,"allocation error", "msDrawMArkerSymbol()");
- return MS_FAILURE;
- }
- }
- break;
- case (MS_SYMBOL_PIXMAP): {
- if(!symbol->pixmap_buffer) {
- if(MS_SUCCESS != msPreloadImageSymbol(renderer,symbol))
- return MS_FAILURE;
- }
- }
- break;
+ if(preloadSymbol(symbolset, symbol, renderer) != MS_SUCCESS) {
+ return MS_FAILURE;
}
INIT_SYMBOL_STYLE(s);
computeSymbolStyle(&s,style,symbol,scalefactor,image->resolutionfactor);
s.style = style;
- if(symbol->type == MS_SYMBOL_TRUETYPE) {
- if(!symbol->full_font_path)
- symbol->full_font_path = msStrdup(msLookupHashTable(&(symbolset->fontset->fonts),
- symbol->font));
- assert(symbol->full_font_path);
- }
/* compute a markerStyle and use it on the line */
if(style->gap<0) {
@@ -686,42 +715,8 @@ int msDrawShadeSymbol(symbolSetObj *symbolset, imageObj *image, shapeObj *p, sty
imageObj *tile;
int seamless = 0;
-
- switch(symbol->type) {
- case MS_SYMBOL_PIXMAP:
- if(MS_SUCCESS != msPreloadImageSymbol(renderer,symbol)) {
- ret = MS_FAILURE;
- goto cleanup;
- }
- break;
- case MS_SYMBOL_TRUETYPE:
- if(!symbol->full_font_path)
- symbol->full_font_path = msStrdup(msLookupHashTable(&(symbolset->fontset->fonts),
- symbol->font));
- if(!symbol->full_font_path) {
- msSetError(MS_MEMERR,"allocation error", "msDrawMarkerSymbol()");
- ret = MS_FAILURE;
- goto cleanup;
- }
- break;
- case MS_SYMBOL_SVG:
-#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
- if(MS_SUCCESS != msPreloadSVGSymbol(symbol)) {
- ret = MS_FAILURE;
- goto cleanup;
- }
-#else
- msSetError(MS_SYMERR, "SVG symbol support is not enabled.", "msDrawMarkerSymbol()");
- return MS_FAILURE;
-#endif
- break;
- case MS_SYMBOL_VECTOR:
- case MS_SYMBOL_ELLIPSE:
- break;
- default:
- msSetError(MS_MISCERR,"unsupported symbol type %d", "msDrawShadeSymbol()", symbol->type);
- ret = MS_FAILURE;
- goto cleanup;
+ if(preloadSymbol(symbolset,symbol,renderer) != MS_SUCCESS) {
+ return MS_FAILURE;
}
INIT_SYMBOL_STYLE(s);
@@ -800,37 +795,8 @@ int msDrawMarkerSymbol(symbolSetObj *symbolset,imageObj *image, pointObj *p, sty
symbolObj *symbol = symbolset->symbol[style->symbol];
/* store a reference to the renderer to be used for freeing */
symbol->renderer = renderer;
- switch (symbol->type) {
- case (MS_SYMBOL_TRUETYPE): {
- if (!symbol->full_font_path)
- symbol->full_font_path = msStrdup(msLookupHashTable(&(symbolset->fontset->fonts),
- symbol->font));
- if (!symbol->full_font_path) {
- msSetError(MS_MEMERR, "allocation error", "msDrawMarkerSymbol()");
- return MS_FAILURE;
- }
- }
- break;
- case (MS_SYMBOL_PIXMAP): {
- if (!symbol->pixmap_buffer) {
- if (MS_SUCCESS != msPreloadImageSymbol(renderer, symbol))
- return MS_FAILURE;
- }
- }
- break;
-
- case (MS_SYMBOL_SVG): {
-#if defined(USE_SVG_CAIRO) || defined(USE_RSVG)
- if (!symbol->renderer_cache) {
- if (MS_SUCCESS != msPreloadSVGSymbol(symbol))
- return MS_FAILURE;
- }
-#else
- msSetError(MS_SYMERR, "SVG symbol support is not enabled.", "msDrawMarkerSymbol()");
- return MS_FAILURE;
-#endif
- }
- break;
+ if(preloadSymbol(symbolset,symbol,renderer) != MS_SUCCESS) {
+ return MS_FAILURE;
}
computeSymbolStyle(&s,style,symbol,scalefactor,image->resolutionfactor);

0 comments on commit 741a56d

Please sign in to comment.