Skip to content

Commit

Permalink
Add support for outlinewidth in legend icons (#5064)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorissette authored and tbonfort committed Feb 13, 2015
1 parent 936518b commit 537b40f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 49 deletions.
50 changes: 4 additions & 46 deletions mapdraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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:
Expand All @@ -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;
}
Expand All @@ -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) ||
Expand Down
18 changes: 18 additions & 0 deletions maplegend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
53 changes: 52 additions & 1 deletion maprendering.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion mapserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion msautotest
Submodule msautotest updated from f03837 to e2ad7a

0 comments on commit 537b40f

Please sign in to comment.