/* assumes an angle of 0 regardless of what's in the label object */
int msGetLabelSize(mapObj *map, labelObj *label, char *string, double size, rectObj *rect, double **advances)
{
  rendererVTableObj *renderer = NULL;

  if (map)
    renderer =MS_MAP_RENDERER(map);

  if(!renderer) {
    msSetError(MS_MISCERR, "cannot compute label size without valid map and renderer", "msGetLabelSize()");
    return MS_FAILURE;
  }

  if(label->type == MS_TRUETYPE) {
    if(!label->font) {
      msSetError(MS_MISCERR, "label has no true type font", "msGetLabelSize()");
      return MS_FAILURE;
    }
    return msGetTruetypeTextBBox(renderer,label->font,&(map->fontset),size,string,rect,advances,1);
  } else if(label->type == MS_BITMAP) {
    if(renderer->supports_bitmap_fonts)
      return msGetRasterTextBBox(renderer,MS_NINT(label->size),string,rect);
    else {
      msSetError(MS_MISCERR, "renderer does not support bitmap fonts", "msGetLabelSize()");
      return MS_FAILURE;
    }
  } else {
    msSetError(MS_MISCERR, "unknown label type", "msGetLabelSize()");
    return MS_FAILURE;
  }
}
Beispiel #2
0
/*
** 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.
*/
int msGetMarkerSize(symbolSetObj *symbolset, styleObj *style, double *width, double *height, double scalefactor)
{
  rectObj rect;
  int size;
  symbolObj *symbol;
  *width = *height = 0; /* set a starting value */

  if(style->symbol > symbolset->numsymbols || style->symbol < 0) return(MS_FAILURE); /* no such symbol, 0 is OK */

  if(style->symbol == 0) { /* single point */
    *width = 1;
    *height = 1;
    return(MS_SUCCESS);
  }

  symbol = symbolset->symbol[style->symbol];
  if (symbol->type == MS_SYMBOL_PIXMAP && !symbol->pixmap_buffer) {
    if (MS_SUCCESS != msPreloadImageSymbol(MS_MAP_RENDERER(symbolset->map), symbol))
      return MS_FAILURE;
  }
  if(symbol->type == MS_SYMBOL_SVG && !symbol->renderer_cache) {
#ifdef USE_SVG_CAIRO
    if(MS_SUCCESS != msPreloadSVGSymbol(symbol))
      return MS_FAILURE;
#else
    msSetError(MS_SYMERR, "SVG symbol support is not enabled.", "msGetMarkerSize()");
    return MS_FAILURE;
#endif
  }
  if(style->size == -1) {
    size = ( msSymbolGetDefaultSize(symbol) * scalefactor );
  } else
    size = (style->size*scalefactor);
  size = MS_MAX(size, style->minsize);
  size = MS_MIN(size, style->maxsize);

  switch(symbol->type) {

    case(MS_SYMBOL_TRUETYPE):
      if(msGetTruetypeTextBBox(MS_MAP_RENDERER(symbolset->map),symbol->font,symbolset->fontset,size,symbol->character,&rect,NULL,0) != MS_SUCCESS)
        return(MS_FAILURE);

      *width = MS_MAX(*width, rect.maxx - rect.minx);
      *height = MS_MAX(*height, rect.maxy - rect.miny);

      break;

    case(MS_SYMBOL_PIXMAP):
      if(size == 1) {
        *width = MS_MAX(*width, symbol->pixmap_buffer->width);
        *height = MS_MAX(*height, symbol->pixmap_buffer->height);
      } else {
        *width = MS_MAX(*width, (((double)size/(double)symbol->pixmap_buffer->height) * symbol->pixmap_buffer->width));
        *height = MS_MAX(*height, size);
      }
      break;
    default: /* vector and ellipses, scalable */
      if(style->size > 0) {
        *width = MS_MAX(*width, ((size/symbol->sizey) * symbol->sizex));
        *height = MS_MAX(*height, size);
      } else { /* use symbol defaults */
        *width = MS_MAX(*width, symbol->sizex);
        *height = MS_MAX(*height, symbol->sizey);
      }
      break;
  }

  return(MS_SUCCESS);
}