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

Function msGetMarkerSize

mapsymbol.c:588–658  ·  view source on GitHub ↗

** Returns the size, in pixels, of a marker symbol defined by a specific style and scalefactor. Used for annotation ** layer collision avoidance. A marker is made up of a number of styles so the calling code must either do the looping ** itself or call this function for the bottom style which should be the largest. */

Source from the content-addressed store, hash-verified

586** itself or call this function for the bottom style which should be the largest.
587*/
588int msGetMarkerSize(symbolSetObj *symbolset, styleObj *style, int *width, int *height, double scalefactor)
589{
590 rectObj rect;
591 int size;
592 symbolObj *symbol;
593 *width = *height = 0; /* set a starting value */
594
595 if(style->symbol > symbolset->numsymbols || style->symbol < 0) return(MS_FAILURE); /* no such symbol, 0 is OK */
596
597 if(style->symbol == 0) { /* single point */
598 *width = 1;
599 *height = 1;
600 return(MS_SUCCESS);
601 }
602
603 symbol = symbolset->symbol[style->symbol];
604 if(style->size == -1) {
605 size = MS_NINT( msSymbolGetDefaultSize(symbol) * scalefactor );
606 }
607 else
608 size = MS_NINT(style->size*scalefactor);
609 size = MS_MAX(size, style->minsize);
610 size = MS_MIN(size, style->maxsize);
611
612 switch(symbol->type) {
613
614#ifdef USE_GD_FT
615 case(MS_SYMBOL_TRUETYPE):
616 if(!symbol->full_font_path) {
617 char *font = msLookupHashTable(&(symbolset->fontset->fonts),symbol->font);
618 if(!font) {
619 msSetError(MS_MISCERR,"font (%s) not found in fontset","msGetMarkerSize()",symbol->font);
620 return(MS_FAILURE);
621 }
622 symbol->full_font_path = msStrdup(font);
623 }
624 if(msGetTruetypeTextBBox(MS_MAP_RENDERER(symbolset->map),symbol->full_font_path,size,symbol->character,&rect,NULL) != MS_SUCCESS)
625 return(MS_FAILURE);
626
627 *width = (int) MS_MAX(*width, rect.maxx - rect.minx);
628 *height = (int) MS_MAX(*height, rect.maxy - rect.miny);
629
630 break;
631#endif
632
633 case(MS_SYMBOL_PIXMAP):
634 if(!symbol->pixmap_buffer) {
635 msSetError(MS_MISCERR,"msGetMarkerSize() called on unloaded pixmap symbol, this is a bug in mapserver itself","msGetMArkerSize()");
636 return MS_FAILURE;
637 }
638 if(size == 1) {
639 *width = MS_MAX(*width, symbol->pixmap_buffer->width);
640 *height = MS_MAX(*height, symbol->pixmap_buffer->height);
641 } else {
642 *width = MS_MAX(*width, MS_NINT((size/symbol->pixmap_buffer->height) * symbol->pixmap_buffer->width));
643 *height = MS_MAX(*height, size);
644 }
645 break;

Callers 3

msDrawLabelCacheFunction · 0.85
msAddLabelFunction · 0.85
msDrawLabelCacheIMFunction · 0.85

Calls 6

MS_NINTFunction · 0.85
msSymbolGetDefaultSizeFunction · 0.85
msLookupHashTableFunction · 0.85
msSetErrorFunction · 0.85
msStrdupFunction · 0.85
msGetTruetypeTextBBoxFunction · 0.85

Tested by

no test coverage detected