MCPcopy Index your code
hub / github.com/MapServer/MapServer / msDrawLabel

Function msDrawLabel

mapdraw.c:2295–2393  ·  view source on GitHub ↗

** Draws a single label independently of the label cache. No collision avoidance is performed. */

Source from the content-addressed store, hash-verified

2293** Draws a single label independently of the label cache. No collision avoidance is performed.
2294*/
2295int msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, labelObj *label, double scalefactor)
2296{
2297 shapeObj labelPoly;
2298 lineObj labelPolyLine;
2299 pointObj labelPolyPoints[5];
2300 int needLabelPoly=MS_TRUE;
2301
2302 int label_offset_x, label_offset_y;
2303 double size;
2304 rectObj r;
2305
2306 if(!string) return MS_SUCCESS; /* not an error, just don't need to do anything more */
2307 if(strlen(string) == 0) return MS_SUCCESS; /* not an error, just don't need to do anything more */
2308
2309
2310
2311 if(label->type == MS_TRUETYPE) {
2312 size = label->size * scalefactor;
2313 size = MS_MAX(size, label->minsize*image->resolutionfactor);
2314 size = MS_MIN(size, label->maxsize*image->resolutionfactor);
2315 } else {
2316 size = label->size;
2317 }
2318 if(msGetLabelSize(map, label, string, size, &r, NULL)!= MS_SUCCESS)
2319 return MS_FAILURE;
2320
2321 label_offset_x = label->offsetx*scalefactor;
2322 label_offset_y = label->offsety*scalefactor;
2323
2324 if(label->position != MS_XY) {
2325 pointObj p;
2326 int needLabelPoint=MS_TRUE;
2327
2328 if(label->numstyles > 0) {
2329 int i;
2330
2331 for(i=0; i<label->numstyles; i++) {
2332 if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOINT) {
2333 if(needLabelPoint) {
2334 p = get_metrics_line(&labelPnt, label->position, r, label_offset_x, label_offset_y, label->angle, 0, NULL);
2335 needLabelPoint = MS_FALSE; /* don't re-compute */
2336 }
2337 msDrawMarkerSymbol(&map->symbolset, image, &p, label->styles[i], scalefactor);
2338 } else if(label->styles[i]->_geomtransform.type == MS_GEOMTRANSFORM_LABELPOLY) {
2339 if(needLabelPoly) {
2340 labelPoly.line = &labelPolyLine; /* setup the label polygon structure */
2341 labelPoly.numlines = 1;
2342 labelPoly.line->point = labelPolyPoints;
2343 labelPoly.line->numpoints = 5;
2344 p = get_metrics_line(&labelPnt, label->position, r, label_offset_x, label_offset_y, label->angle, 1, labelPoly.line);
2345 needLabelPoint = MS_FALSE; /* don't re-compute */
2346 needLabelPoly = MS_FALSE;
2347 }
2348 msDrawShadeSymbol(&map->symbolset, image, &labelPoly, label->styles[i], scalefactor);
2349 } else {
2350 /* TODO: need error msg about unsupported geomtransform */
2351 return MS_FAILURE;
2352 }

Callers 5

msDrawScalebarFunction · 0.85
msDrawShapeFunction · 0.85
msDrawPointFunction · 0.85
msDrawLegendIconFunction · 0.85
msDrawLegendFunction · 0.85

Calls 5

msGetLabelSizeFunction · 0.85
get_metrics_lineFunction · 0.85
msDrawMarkerSymbolFunction · 0.85
msDrawShadeSymbolFunction · 0.85
msDrawTextFunction · 0.85

Tested by

no test coverage detected