예제 #1
0
int msCopySymbolSet(symbolSetObj *dst, symbolSetObj *src, mapObj *map)
{
  int i, return_value;

  MS_COPYSTRING(dst->filename, src->filename);

  dst->map = map;
  dst->fontset = &(map->fontset);

  /* Copy child symbols */
  for (i = 0; i < src->numsymbols; i++) {
    if (msGrowSymbolSet(dst) == NULL)
      return MS_FAILURE;
    return_value = msCopySymbol(dst->symbol[i], src->symbol[i], map);
    if (return_value != MS_SUCCESS) {
      msSetError(MS_MEMERR,"Failed to copy symbol.","msCopySymbolSet()");
      return(MS_FAILURE);
    }
    dst->numsymbols++;
  }

  /* MS_COPYSTELEM(imagecachesize); */

  /* I have a feeling that the code below is not quite right - Sean */
  /*copyProperty(&(dst->imagecache), &(src->imagecache),
               sizeof(struct imageCacheObj));
   */

  dst->imagecachesize = 0; /* since we are not copying the cache set the cache  to NUNLL and the size to 0 (bug 1521) */
  dst->imagecache = NULL;

  return(MS_SUCCESS);
}
예제 #2
0
void msInitSymbolSet(symbolSetObj *symbolset)
{
  symbolset->filename = NULL;

  symbolset->imagecache = NULL;
  symbolset->imagecachesize = 0; /* 0 symbols in the cache */

  symbolset->fontset = NULL;
  symbolset->map = NULL;

  symbolset->numsymbols = 0;
  symbolset->maxsymbols = 0;
  symbolset->symbol = NULL;

  /* Alloc symbol[] array and ensure there is at least 1 symbol:
   * symbol 0 which is the default symbol with all default params.
   */
  if (msGrowSymbolSet(symbolset) == NULL)
    return; /* alloc failed */
  symbolset->symbol[0]->type = MS_SYMBOL_ELLIPSE;
  symbolset->symbol[0]->filled = MS_TRUE;
  symbolset->symbol[0]->numpoints = 1;
  symbolset->symbol[0]->points[0].x = 1;
  symbolset->symbol[0]->points[0].y = 1;

  /* Just increment numsymbols to reserve symbol 0.
   * initSymbol() has already been called
   */
  symbolset->numsymbols = 1;

}
예제 #3
0
/*
** Little helper function to allow us to build symbol files on-the-fly
** from just a file name.
**
** Returns the symbol index or -1 if it could not be added.
*/
int msAddImageSymbol(symbolSetObj *symbolset, char *filename)
{
  char szPath[MS_MAXPATHLEN];
  symbolObj *symbol=NULL;

  if(!symbolset) {
    msSetError(MS_SYMERR, "Symbol structure unallocated.", "msAddImageSymbol()");
    return(-1);
  }

  if(!filename || strlen(filename) == 0) return(-1);

  /* Allocate/init memory for new symbol if needed */
  if (msGrowSymbolSet(symbolset) == NULL)
    return -1;
  symbol = symbolset->symbol[symbolset->numsymbols];

#ifdef USE_CURL
  if (strncasecmp(filename, "http", 4) == 0) {
    char *tmpfullfilename = NULL;
    char *tmpfilename = NULL;
    char *tmppath = NULL;
    int status = 0;
    char szPath[MS_MAXPATHLEN];
    int bCheckLocalCache = MS_TRUE;

    tmppath = msTmpPath(NULL, NULL, NULL);
    if (tmppath) {
      tmpfilename = msEncodeUrl(filename);
      tmpfullfilename = msBuildPath(szPath, tmppath, tmpfilename);
      if (tmpfullfilename) {
        /*use the url for now as a caching mechanism*/
        if (msHTTPGetFile(filename, tmpfullfilename, &status, -1, bCheckLocalCache, 0) == MS_SUCCESS) {
          symbol->imagepath = msStrdup(tmpfullfilename);
          symbol->full_pixmap_path = msStrdup(tmpfullfilename);
        }
      }
      msFree(tmpfilename);
      msFree(tmppath);
    }
  }
#endif
  /*if the http did not work, allow it to be treated as a file*/
  if (!symbol->full_pixmap_path) {
    if(symbolset->map) {
      symbol->full_pixmap_path = msStrdup(msBuildPath(szPath, symbolset->map->mappath, filename));
    } else {
      symbol->full_pixmap_path = msStrdup(msBuildPath(szPath, NULL, filename));
    }
    symbol->imagepath = msStrdup(filename);
  }
  symbol->name = msStrdup(filename);
  symbol->type = MS_SYMBOL_PIXMAP;
  return(symbolset->numsymbols++);
}
예제 #4
0
int msAppendSymbol(symbolSetObj *symbolset, symbolObj *symbol)
{
  /* Allocate memory for new symbol if needed */
  if (msGrowSymbolSet(symbolset) == NULL)
    return -1;

  /* we need to free the symbolObj that was already allocated as we are
   going to replace it with the provided symbolObj*. Not the most efficient
   technique, but this function should be rarely called, and in any case only
   by mapscript. Another option could be to use msCopySymbol(), in which case
   the call to MS_REFCNT_INCR(symbol) should be removed.*/
  if(symbolset->symbol[symbolset->numsymbols]) {
    msFreeSymbol(symbolset->symbol[symbolset->numsymbols]);
    msFree(symbolset->symbol[symbolset->numsymbols]);
  }
  symbolset->symbol[symbolset->numsymbols]=symbol;
  MS_REFCNT_INCR(symbol);
  return symbolset->numsymbols++;
}
예제 #5
0
/*
 * Add a default new symbol. If the symbol name exists
 * return the id of the symbol.
 */
int msAddNewSymbol(mapObj *map, char *name)
{
  int i = 0;

  if (!map || !name)
    return -1;

  i = msGetSymbolIndex(&map->symbolset, name, MS_TRUE);
  if (i >= 0)
    return i;

  /* Allocate memory for new symbol if needed */
  if (msGrowSymbolSet(&(map->symbolset)) == NULL)
    return -1;

  i = map->symbolset.numsymbols;
  map->symbolset.symbol[i]->name = msStrdup(name);

  map->symbolset.numsymbols++;

  return i;
}
예제 #6
0
파일: mapscale.c 프로젝트: havatv/mapserver
int msEmbedScalebar(mapObj *map, imageObj *img)
{
    int l,index,s;
    pointObj point;
    imageObj *image = NULL;
    rendererVTableObj *renderer = MS_MAP_RENDERER(map);
    symbolObj *embededSymbol;

    if( ! renderer ) {
        msSetError(MS_MISCERR,"unsupported outputformat","msEmbedScalebar()");
        return MS_FAILURE;
    }
    index = msGetSymbolIndex(&(map->symbolset), "scalebar", MS_FALSE);
    if(index != -1)
        msRemoveSymbol(&(map->symbolset), index); /* remove cached symbol in case the function is called multiple
                      times with different zoom levels */

    if((embededSymbol=msGrowSymbolSet(&map->symbolset)) == NULL)
        return MS_FAILURE;
    s = map->symbolset.numsymbols;
    map->symbolset.numsymbols++;

    image = msDrawScalebar(map);
    if(!image) {
        return MS_FAILURE;
    }
    embededSymbol->pixmap_buffer = calloc(1,sizeof(rasterBufferObj));
    MS_CHECK_ALLOC(embededSymbol->pixmap_buffer, sizeof(rasterBufferObj), MS_FAILURE);

    if(MS_SUCCESS != renderer->getRasterBufferCopy(image,embededSymbol->pixmap_buffer)) {
        return MS_FAILURE;
    }

    embededSymbol->type = MS_SYMBOL_PIXMAP; /* intialize a few things */
    embededSymbol->name = msStrdup("scalebar");
    embededSymbol->sizex = embededSymbol->pixmap_buffer->width;
    embededSymbol->sizey = embededSymbol->pixmap_buffer->height;
    if(map->scalebar.transparent) {
        embededSymbol->transparent = MS_TRUE;
        embededSymbol->transparentcolor = 0;
    }

    switch(map->scalebar.position) {
    case(MS_LL):
        point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
        point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
        break;
    case(MS_LR):
        point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
        point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
        break;
    case(MS_LC):
        point.x = MS_NINT(map->width/2.0);
        point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
        break;
    case(MS_UR):
        point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
        point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
        break;
    case(MS_UL):
        point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
        point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
        break;
    case(MS_UC):
        point.x = MS_NINT(map->width/2.0);
        point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
        break;
    }

    l = msGetLayerIndex(map, "__embed__scalebar");
    if(l == -1) {
        if (msGrowMapLayers(map) == NULL)
            return(-1);
        l = map->numlayers;
        map->numlayers++;
        if(initLayer((GET_LAYER(map, l)), map) == -1) return(-1);
        GET_LAYER(map, l)->name = msStrdup("__embed__scalebar");
        GET_LAYER(map, l)->type = MS_LAYER_POINT;

        if (msGrowLayerClasses( GET_LAYER(map, l) ) == NULL)
            return(-1);

        if(initClass(GET_LAYER(map, l)->class[0]) == -1) return(-1);
        GET_LAYER(map, l)->numclasses = 1; /* so we make sure to free it */

        /* update the layer order list with the layer's index. */
        map->layerorder[l] = l;
    }

    GET_LAYER(map, l)->status = MS_ON;
    if(map->scalebar.postlabelcache) { /* add it directly to the image */
        if(msMaybeAllocateClassStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE) return MS_FAILURE;
        GET_LAYER(map, l)->class[0]->styles[0]->symbol = s;
        msDrawMarkerSymbol(&map->symbolset, img, &point, GET_LAYER(map, l)->class[0]->styles[0], 1.0);
    } else {
        if(!GET_LAYER(map, l)->class[0]->labels) {
예제 #7
0
int loadSymbolSet(symbolSetObj *symbolset, mapObj *map)
{
  int status=1;
  char szPath[MS_MAXPATHLEN], *pszSymbolPath=NULL;

  int foundSymbolSetToken=MS_FALSE;
  int token;

  if(!symbolset) {
    msSetError(MS_SYMERR, "Symbol structure unallocated.", "loadSymbolSet()");
    return(-1);
  }

  symbolset->map = (mapObj *)map;

  if(!symbolset->filename) return(0);

  /*
  ** Open the file
  */
  if((msyyin = fopen(msBuildPath(szPath, symbolset->map->mappath, symbolset->filename), "r")) == NULL) {
    msSetError(MS_IOERR, "(%s)", "loadSymbolSet()", symbolset->filename);
    return(-1);
  }

  pszSymbolPath = msGetPath(szPath);

  msyystate = MS_TOKENIZE_FILE; /* restore lexer state to INITIAL, and do return comments */
  msyylex(); /* sets things up, but doesn't process any tokens */

  msyylineno = 0; /* reset line counter */
  msyyrestart(msyyin); /* flush the scanner - there's a better way but this works for now */

  /*
  ** Read the symbol file
  */
  for(;;) {
    token = msyylex();

    if(!foundSymbolSetToken && token != SYMBOLSET) {
      msSetError(MS_IDENTERR, "First token must be SYMBOLSET, this doesn't look like a symbol file.", "msLoadSymbolSet()");
      return(-1);
    }

    switch(token) {
      case(END):
      case(EOF):
        status = 0;
        break;
      case(SYMBOL):
        /* Allocate/init memory for new symbol if needed */
        if (msGrowSymbolSet(symbolset) == NULL) {
          status = -1;
        } else if((loadSymbol((symbolset->symbol[symbolset->numsymbols]), pszSymbolPath) == -1))
          status = -1;
        else
          symbolset->numsymbols++;
        break;
      case(SYMBOLSET):
        foundSymbolSetToken = MS_TRUE;
        break;
      default:
        msSetError(MS_IDENTERR, "Parsing error near (%s):(line %d)", "loadSymbolSet()", msyystring_buffer, msyylineno);
        status = -1;
    } /* end switch */

    if(status != 1) break;
  } /* end for */

  fclose(msyyin);
  msyyin = NULL;
  free(pszSymbolPath);
  return(status);
}