Permalink
Browse files

Add support for outlinewidth in legend icons (#5064)

  • Loading branch information...
dmorissette authored and tbonfort committed Feb 12, 2015
1 parent 936518b commit 537b40f910c8d7ebdd4e83c8ccf5b3c973f5f3b9
Showing with 77 additions and 49 deletions.
  1. +4 −46 mapdraw.c
  2. +18 −0 maplegend.c
  3. +52 −1 maprendering.c
  4. +2 −1 mapserver.h
  5. +1 −1 msautotest
View
@@ -1007,7 +1007,6 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
if (cache) {
styleObj *pStyle = layer->class[shape.classindex]->styles[0];
- colorObj tmp;
if (pStyle->outlinewidth > 0) {
/*
* RFC 49 implementation
@@ -1017,17 +1016,7 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
* - draw the shape (the outline) in the first pass of the
* caching mechanism
*/
-
- /* adapt width (must take scalefactor into account) */
- pStyle->width += (pStyle->outlinewidth / (layer->scalefactor/image->resolutionfactor)) * 2;
- pStyle->minwidth += pStyle->outlinewidth * 2;
- pStyle->maxwidth += pStyle->outlinewidth * 2;
- pStyle->size += (pStyle->outlinewidth/layer->scalefactor*(map->resolution/map->defresolution));
-
- /*swap color and outlinecolor*/
- tmp = pStyle->color;
- pStyle->color = pStyle->outlinecolor;
- pStyle->outlinecolor = tmp;
+ msOutlineRenderingPrepareStyle(pStyle, map, layer, image);
}
status = msDrawShape(map, layer, &shape, image, 0, drawmode|MS_DRAWMODE_SINGLESTYLE); /* draw a single style */
if (pStyle->outlinewidth > 0) {
@@ -1036,17 +1025,7 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
* original state, so the line fill will be drawn in the
* second pass of the caching mechanism
*/
-
- /* reset widths to original state */
- pStyle->width -= (pStyle->outlinewidth / (layer->scalefactor/image->resolutionfactor)) * 2;
- pStyle->minwidth -= pStyle->outlinewidth * 2;
- pStyle->maxwidth -= pStyle->outlinewidth * 2;
- pStyle->size -= (pStyle->outlinewidth/layer->scalefactor*(map->resolution/map->defresolution));
-
- /*reswap colors to original state*/
- tmp = pStyle->color;
- pStyle->color = pStyle->outlinecolor;
- pStyle->outlinecolor = tmp;
+ msOutlineRenderingRestoreStyle(pStyle, map, layer, image);
}
}
@@ -1107,7 +1086,6 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
}
} else if(s>0) {
if (pStyle->outlinewidth > 0 && MS_VALID_COLOR(pStyle->outlinecolor)) {
- colorObj tmp;
/*
* RFC 49 implementation
* if an outlinewidth is used:
@@ -1116,17 +1094,7 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
* - draw the shape (the outline) in the first pass of the
* caching mechanism
*/
-
- /* adapt width (must take scalefactor into account) */
- pStyle->width += (pStyle->outlinewidth / (layer->scalefactor/image->resolutionfactor)) * 2;
- pStyle->minwidth += pStyle->outlinewidth * 2;
- pStyle->maxwidth += pStyle->outlinewidth * 2;
- pStyle->size += (pStyle->outlinewidth/layer->scalefactor*(map->resolution/map->defresolution));
-
- /*swap color and outlinecolor*/
- tmp = pStyle->color;
- pStyle->color = pStyle->outlinecolor;
- pStyle->outlinecolor = tmp;
+ msOutlineRenderingPrepareStyle(pStyle, map, layer, image);
if(UNLIKELY(MS_FAILURE == msDrawLineSymbol(map, image, &current->shape, pStyle, layer->scalefactor))) {
return MS_FAILURE;
}
@@ -1135,17 +1103,7 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
* original state, so the line fill will be drawn in the
* second pass of the caching mechanism
*/
-
- /* reset widths to original state */
- pStyle->width -= (pStyle->outlinewidth / (layer->scalefactor/image->resolutionfactor)) * 2;
- pStyle->minwidth -= pStyle->outlinewidth * 2;
- pStyle->maxwidth -= pStyle->outlinewidth * 2;
- pStyle->size -= (pStyle->outlinewidth/layer->scalefactor*(map->resolution/map->defresolution));
-
- /*reswap colors to original state*/
- tmp = pStyle->color;
- pStyle->color = pStyle->outlinecolor;
- pStyle->outlinecolor = tmp;
+ msOutlineRenderingRestoreStyle(pStyle, map, layer, image);
}
/* draw a valid line, i.e. one with a color defined or of type pixmap*/
if(MS_VALID_COLOR(pStyle->color) ||
View
@@ -218,10 +218,28 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass,
if (theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_NONE ||
theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT ||
theclass->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
+ if (theclass->styles[i]->outlinewidth > 0) {
+ /* Swap the style contents to render the outline first,
+ * and then restore the style to render the interior of the line
+ */
+ msOutlineRenderingPrepareStyle(theclass->styles[i], map, lp, image);
+ ret = msDrawLineSymbol(map, image_draw, &zigzag, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor);
+ msOutlineRenderingRestoreStyle(theclass->styles[i], map, lp, image);
+ if(UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup;
+ }
ret = msDrawLineSymbol(map, image_draw, &zigzag, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor);
if(UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup;
}
else {
+ if (theclass->styles[i]->outlinewidth > 0) {
+ /* Swap the style contents to render the outline first,
+ * and then restore the style to render the interior of the line
+ */
+ msOutlineRenderingPrepareStyle(theclass->styles[i], map, lp, image);
+ ret = msDrawTransformedShape(map, image_draw, &zigzag, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor);
+ msOutlineRenderingRestoreStyle(theclass->styles[i], map, lp, image);
+ if(UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup;
+ }
ret = msDrawTransformedShape(map, image_draw, &zigzag, theclass->styles[i], lp->scalefactor * image_draw->resolutionfactor);
if(UNLIKELY(ret == MS_FAILURE)) goto legend_icon_cleanup;
}
View
@@ -561,7 +561,7 @@ int msDrawLineSymbol(mapObj *map, imageObj *image, shapeObj *p,
rendererVTableObj *renderer = image->format->vtable;
symbolObj *symbol;
shapeObj *offsetLine = p;
- int i,ret=MS_SUCCESS;
+ int i;
double width;
double finalscalefactor;
@@ -1077,3 +1077,54 @@ int msDrawPieSlice(mapObj *map, imageObj *image, pointObj *p, styleObj *style, d
msFree(circle);
return status;
}
+
+/*
+ * RFC 49 implementation
+ * if an outlinewidth is used:
+ * - augment the style's width to account for the outline width
+ * - swap the style color and outlinecolor
+ * - draw the shape (the outline) in the first pass of the
+ * caching mechanism
+ */
+
+void msOutlineRenderingPrepareStyle(styleObj *pStyle, mapObj *map, layerObj *layer, imageObj *image)
+{
+ colorObj tmp;
+
+ if (pStyle->outlinewidth > 0) {
+ /* adapt width (must take scalefactor into account) */
+ pStyle->width += (pStyle->outlinewidth / (layer->scalefactor/image->resolutionfactor)) * 2;
+ pStyle->minwidth += pStyle->outlinewidth * 2;
+ pStyle->maxwidth += pStyle->outlinewidth * 2;
+ pStyle->size += (pStyle->outlinewidth/layer->scalefactor*(map->resolution/map->defresolution));
+
+ /*swap color and outlinecolor*/
+ tmp = pStyle->color;
+ pStyle->color = pStyle->outlinecolor;
+ pStyle->outlinecolor = tmp;
+ }
+}
+
+/*
+ * RFC 49 implementation: switch back the styleobj to its
+ * original state, so the line fill will be drawn in the
+ * second pass of the caching mechanism
+ */
+
+void msOutlineRenderingRestoreStyle(styleObj *pStyle, mapObj *map, layerObj *layer, imageObj *image)
+{
+ colorObj tmp;
+
+ if (pStyle->outlinewidth > 0) {
+ /* reset widths to original state */
+ pStyle->width -= (pStyle->outlinewidth / (layer->scalefactor/image->resolutionfactor)) * 2;
+ pStyle->minwidth -= pStyle->outlinewidth * 2;
+ pStyle->maxwidth -= pStyle->outlinewidth * 2;
+ pStyle->size -= (pStyle->outlinewidth/layer->scalefactor*(map->resolution/map->defresolution));
+
+ /*reswap colors to original state*/
+ tmp = pStyle->color;
+ pStyle->color = pStyle->outlinecolor;
+ pStyle->outlinecolor = tmp;
+ }
+}
View
@@ -2535,7 +2535,8 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
MS_DLL_EXPORT int WARN_UNUSED msDrawPieSlice(mapObj *map, imageObj *image, pointObj *p, styleObj *style, double radius, double start, double end);
MS_DLL_EXPORT int WARN_UNUSED msDrawLabelBounds(mapObj *map, imageObj *image, label_bounds *bnds, styleObj *style, double scalefactor);
-
+ MS_DLL_EXPORT void msOutlineRenderingPrepareStyle(styleObj *pStyle, mapObj *map, layerObj *layer, imageObj *image);
+ MS_DLL_EXPORT void msOutlineRenderingRestoreStyle(styleObj *pStyle, mapObj *map, layerObj *layer, imageObj *image);
MS_DLL_EXPORT int WARN_UNUSED msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, labelObj *label, double scalefactor);
MS_DLL_EXPORT int WARN_UNUSED msDrawTextSymbol(mapObj *map, imageObj *image, pointObj labelPnt, textSymbolObj *ts);
Submodule msautotest updated from f03837 to e2ad7a

0 comments on commit 537b40f

Please sign in to comment.