int msGetRasterTextBBox(rendererVTableObj *renderer, int size, char *string, rectObj *rect)
{
  if(renderer && renderer->supports_bitmap_fonts) {
    int num_lines=1, cur_line_length=0, max_line_length=0;
    char *stringPtr = string;
    fontMetrics *fontPtr;
    if((fontPtr=renderer->bitmapFontMetrics[size]) == NULL) {
      msSetError(MS_MISCERR, "selected renderer does not support bitmap font size %d", "msGetRasterTextBBox()",size);
      return MS_FAILURE;
    }
    while(*stringPtr) {
      if(*stringPtr=='\n') {
        max_line_length = MS_MAX(cur_line_length,max_line_length);
        num_lines++;
        cur_line_length=0;
      } else {
        if(*stringPtr!='\r')
          cur_line_length++;
      }
      stringPtr++;
    }
    max_line_length = MS_MAX(cur_line_length,max_line_length);
    rect->minx = 0;
    rect->miny = -fontPtr->charHeight;
    rect->maxx = fontPtr->charWidth * max_line_length;
    rect->maxy = fontPtr->charHeight * (num_lines-1);
    return MS_SUCCESS;
  } else if(!renderer) {
    int ret = MS_FAILURE;
    outputFormatObj *format = msCreateDefaultOutputFormat(NULL,"AGG/PNG","tmp");
    if(!format) {
      msSetError(MS_MISCERR, "failed to create default format", "msGetRasterTextBBox()");
      return MS_FAILURE;
    }
    msInitializeRendererVTable(format);
    renderer = format->vtable;
    ret = msGetRasterTextBBox(renderer,size,string,rect);
    msFreeOutputFormat(format);
    return ret;
  } else {
    msSetError(MS_MISCERR, "selected renderer does not support raster fonts", "msGetRasterTextBBox()");
    return MS_FAILURE;
  }
}
Exemple #2
0
void msApplyDefaultOutputFormats( mapObj *map )
{
  char *saved_imagetype;
  struct defaultOutputFormatEntry *defEntry;

  if( map->imagetype == NULL )
    saved_imagetype = NULL;
  else
    saved_imagetype = msStrdup(map->imagetype);

  defEntry = defaultoutputformats;
  while(defEntry->name) {
    if( msSelectOutputFormat( map, defEntry->name ) == NULL )
      msCreateDefaultOutputFormat( map, defEntry->driver, defEntry->name );
    defEntry++;
  }
  if( map->imagetype != NULL )
    free( map->imagetype );
  map->imagetype = saved_imagetype;
}
Exemple #3
0
outputFormatObj *msSelectOutputFormat( mapObj *map, 
                                       const char *imagetype )

{
    int index;
    outputFormatObj *format = NULL;

    if( map == NULL || imagetype == NULL || strlen(imagetype) == 0 )
        return NULL;
    
/* -------------------------------------------------------------------- */
/*      Try to find the format in the maps list of formats, first by    */
/*      mime type, and then by output format name.                      */
/* -------------------------------------------------------------------- */
    index = msGetOutputFormatIndex(map, imagetype);
    if (index >= 0) {
        format = map->outputformatlist[index];
    } else {
       struct defaultOutputFormatEntry *formatEntry = defaultoutputformats;
       while(formatEntry->name) {
          if(!strcasecmp(imagetype,formatEntry->name) || !strcasecmp(imagetype,formatEntry->mimetype)) {
             format = msCreateDefaultOutputFormat( map, formatEntry->driver, formatEntry->name );
             break;
          }
          formatEntry++;
       }

    }

    if (format)
    {
        if (map->imagetype)
            free(map->imagetype);
        map->imagetype = msStrdup(format->name);
    }

    if( format != NULL )
        msOutputFormatValidate( format, MS_FALSE );

    return format;
}
Handle<Value> MSOutputFormat::New(const Arguments &args) {
  HandleScope scope;
  MSOutputFormat *obj;
  
  if (!args.IsConstructCall()) {
    return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));
  }

  if (args[0]->IsExternal()) {
    Local<External> ext = Local<External>::Cast(args[0]);
    void* ptr = ext->Value();
    obj = static_cast<MSOutputFormat*>(ptr);
    obj->Wrap(args.This());
    return args.This();
  }
  
  REQ_STR_ARG(0, driver);
  REQ_STR_ARG(1, name);
  
  outputFormatObj *format = msCreateDefaultOutputFormat(NULL, *driver, *name);

  /* in the case of unsupported formats, msCreateDefaultOutputFormat
     should return NULL */
  if (!format) {
    msSetError(MS_MISCERR, "Unsupported format driver: %s",
               "outputFormatObj()", *driver);
    return args.This();
  }

  msInitializeRendererVTable(format);

  /* Else, continue */
  format->refcount++;
  format->inmapfile = MS_TRUE;
  
  obj = new MSOutputFormat(format);
  obj->Wrap(args.This());
  return args.This();
}
int msGetTruetypeTextBBox(rendererVTableObj *renderer, char* fontstring, fontSetObj *fontset,
                          double size, char *string, rectObj *rect, double **advances, int bAdjustbaseline)
{
  outputFormatObj *format = NULL;
  int ret = MS_FAILURE;
  char *lookedUpFonts[MS_MAX_LABEL_FONTS];
  int numfonts;
  if(!renderer) {
    format = msCreateDefaultOutputFormat(NULL,"AGG/PNG","tmp");
    if(!format) {
      goto tt_cleanup;
    }
    msInitializeRendererVTable(format);
    renderer = format->vtable;
  }
  if(MS_FAILURE == msFontsetLookupFonts(fontstring, &numfonts, fontset, lookedUpFonts))
    goto tt_cleanup;
  ret = renderer->getTruetypeTextBBox(renderer,lookedUpFonts,numfonts,size,string,rect,advances,bAdjustbaseline);
tt_cleanup:
  if(format) {
    msFreeOutputFormat(format);
  }
  return ret;
}
Exemple #6
0
outputFormatObj *msCreateDefaultOutputFormat( mapObj *map,
    const char *driver,
    const char *name )

{

  outputFormatObj *format = NULL;
  if( strncasecmp(driver,"GD/",3) == 0 ) {
    return msCreateDefaultOutputFormat( map, "AGG/PNG8", name );
  }

  if( strcasecmp(driver,"UTFGRID") == 0 ) {
    if(!name) name="utfgrid";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("application/json");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("json");
    format->renderer = MS_RENDER_WITH_UTFGRID;
  }

  else if( strcasecmp(driver,"AGG/PNG") == 0 ) {
    if(!name) name="png24";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/png");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("png");
    format->renderer = MS_RENDER_WITH_AGG;
  }

  else if( strcasecmp(driver,"AGG/PNG8") == 0 ) {
    if(!name) name="png8";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/png; mode=8bit");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("png");
    format->renderer = MS_RENDER_WITH_AGG;
    msSetOutputFormatOption( format, "QUANTIZE_FORCE", "on");
    msSetOutputFormatOption( format, "QUANTIZE_COLORS", "256");
  }

  else if( strcasecmp(driver,"AGG/JPEG") == 0 ) {
    if(!name) name="jpeg";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/jpeg");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("jpg");
    format->renderer = MS_RENDER_WITH_AGG;
  }

  else if( strcasecmp(driver,"AGG/MIXED") == 0 &&
           name != NULL && strcasecmp(name,"jpegpng") == 0 ) {
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/vnd.jpeg-png");
    format->imagemode = MS_IMAGEMODE_RGBA;
    format->extension = msStrdup("XXX");
    format->renderer = MS_RENDER_WITH_AGG;
    msSetOutputFormatOption( format, "OPAQUE_FORMAT", "jpeg");
    msSetOutputFormatOption( format, "TRANSPARENT_FORMAT", "png24");
  }

  else if( strcasecmp(driver,"AGG/MIXED") == 0 &&
           name != NULL && strcasecmp(name,"jpegpng8") == 0 ) {
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/vnd.jpeg-png8");
    format->imagemode = MS_IMAGEMODE_RGBA;
    format->extension = msStrdup("XXX");
    format->renderer = MS_RENDER_WITH_AGG;
    msSetOutputFormatOption( format, "OPAQUE_FORMAT", "jpeg");
    msSetOutputFormatOption( format, "TRANSPARENT_FORMAT", "png8");
  }

  else if( strcasecmp(driver,"AGG/MIXED") == 0 ) {
    if(!name) name="mixed";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/mixed");
    format->imagemode = MS_IMAGEMODE_RGBA;
    format->extension = msStrdup("XXX");
    format->renderer = MS_RENDER_WITH_AGG;
  }

#if defined(USE_CAIRO)
  else if( strcasecmp(driver,"CAIRO/PNG") == 0 ) {
    if(!name) name="cairopng";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/png; mode=24bit");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("png");
    format->renderer = MS_RENDER_WITH_CAIRO_RASTER;
  }
  else if( strcasecmp(driver,"CAIRO/JPEG") == 0 ) {
    if(!name) name="cairojpeg";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/jpeg");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("jpg");
    format->renderer = MS_RENDER_WITH_CAIRO_RASTER;
  }
  else if( strcasecmp(driver,"CAIRO/PDF") == 0 ) {
    if(!name) name="pdf";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("application/x-pdf");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("pdf");
    format->renderer = MS_RENDER_WITH_CAIRO_PDF;
  }
  else if( strcasecmp(driver,"CAIRO/SVG") == 0 ) {
    if(!name) name="svg";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/svg+xml");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("svg");
    format->renderer = MS_RENDER_WITH_CAIRO_SVG;
  }
#ifdef _WIN32
  else if( strcasecmp(driver,"CAIRO/WINGDI") == 0 ) {
    if(!name) name="cairowinGDI";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("");
    format->renderer = MS_RENDER_WITH_CAIRO_RASTER;
  }
  else if( strcasecmp(driver,"CAIRO/WINGDIPRINT") == 0 ) {
    if(!name) name="cairowinGDIPrint";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("");
    format->renderer = MS_RENDER_WITH_CAIRO_RASTER;
  }
#endif
#endif

#if defined(USE_OGL)
  else if( strcasecmp(driver,"OGL/PNG") == 0 ) {
    if(!name) name="oglpng24";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("image/png; mode=24bit");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("png");
    format->renderer = MS_RENDER_WITH_OGL;
  }
#endif

#if defined(USE_KML)
  else if( strcasecmp(driver,"KML") == 0 ) {
    if(!name) name="kml";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("application/vnd.google-earth.kml+xml");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("kml");
    format->renderer = MS_RENDER_WITH_KML;
    msSetOutputFormatOption( format, "ATTACHMENT", "mapserver.kml");
  }
  else if( strcasecmp(driver,"KMZ") == 0 ) {
    if(!name) name="kmz";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("application/vnd.google-earth.kmz");
    format->imagemode = MS_IMAGEMODE_RGB;
    format->extension = msStrdup("kmz");
    format->renderer = MS_RENDER_WITH_KML;
    msSetOutputFormatOption( format, "ATTACHMENT", "mapserver.kmz");
  }
#endif



#ifdef USE_GDAL
  else if( strncasecmp(driver,"gdal/",5) == 0 ) {
    if(!name) name=driver+5;
    format = msAllocOutputFormat( map, name, driver );
    if( msInitDefaultGDALOutputFormat( format ) == MS_FAILURE ) {
      if( map != NULL ) {
        map->numoutputformats--;
        map->outputformatlist[map->numoutputformats] = NULL;
      }

      msFreeOutputFormat( format );
      format = NULL;
    }
  }
#endif
#ifdef USE_OGR
  else if( strncasecmp(driver,"ogr/",4) == 0 ) {
    if(!name) name=driver+4;
    format = msAllocOutputFormat( map, name, driver );
    if( msInitDefaultOGROutputFormat( format ) == MS_FAILURE ) {
      if( map != NULL ) {
        map->numoutputformats--;
        map->outputformatlist[map->numoutputformats] = NULL;
      }

      msFreeOutputFormat( format );
      format = NULL;
    }
  }
#endif
  else if( strcasecmp(driver,"imagemap") == 0 ) {
    if(!name) name="imagemap";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("text/html; driver=imagemap");
    format->extension = msStrdup("html");
    format->imagemode = MS_IMAGEMODE_NULL;
    format->renderer = MS_RENDER_WITH_IMAGEMAP;
  }

  else if( strcasecmp(driver,"template") == 0 ) {
    if(!name) name="template";
    format = msAllocOutputFormat( map, name, driver );
    format->mimetype = msStrdup("text/html");
    format->extension = msStrdup("html");
    format->imagemode = MS_IMAGEMODE_FEATURE;
    format->renderer = MS_RENDER_WITH_TEMPLATE;
  }

  if( format != NULL )
    format->inmapfile = MS_FALSE;


  return format;
}
Exemple #7
0
void msWriteErrorImage(mapObj *map, char *filename, int blank) {
    imageObj *img;
    rendererVTableObj *renderer;
    int font_index = 0;
    int width=400, height=300;
    int nMargin =5;
    int nTextLength = 0;
    int nUsableWidth = 0;
    int nMaxCharsPerLine = 0;
    int nLines = 0;
    int i = 0;
    int nStart = 0;
    int nEnd = 0;
    int nLength = 0;
    char **papszLines = NULL;
    int nXPos = 0;
    int nYPos = 0;
    int nWidthTxt = 0;
    outputFormatObj *format = NULL;
    char *errormsg = msGetErrorString("; ");
    fontMetrics *font = NULL;
    char *imagepath = NULL, *imageurl = NULL;
    labelStyleObj ls;
    colorObj labelcolor, labeloutlinecolor, imagecolor, *imagecolorptr=NULL;
    ls.color = &labelcolor;
    ls.outlinecolor = &labeloutlinecolor;

    if (map) {
        if( map->width > 0 && map->height > 0 )
        {
            width = map->width;
            height = map->height;
        }
        format = map->outputformat;
        imagepath = map->web.imagepath;
        imageurl = map->web.imageurl;
    }

    /* Default to GIF if no suitable GD output format set */
    if (format == NULL || !MS_RENDERER_PLUGIN(format) || !format->vtable->supports_bitmap_fonts)
        format = msCreateDefaultOutputFormat( NULL, "GD/PC256", "gif" );

    if(!format->transparent) {
        if(map && MS_VALID_COLOR(map->imagecolor)) {
            imagecolorptr = &map->imagecolor;
        } else {
            MS_INIT_COLOR(imagecolor,255,255,255,255);
            imagecolorptr = &imagecolor;
        }
    }

    img = msImageCreate(width,height,format,imagepath,imageurl,MS_DEFAULT_RESOLUTION,MS_DEFAULT_RESOLUTION,imagecolorptr);
    renderer = MS_IMAGE_RENDERER(img);

    for(i=0; i<5; i++) {
        /* use the first font we find */
        if((font = renderer->bitmapFontMetrics[font_index]) != NULL) {
            ls.size = i;
            MS_INIT_COLOR(*ls.color,0,0,0,255);
            MS_INIT_COLOR(*ls.outlinecolor,255,255,255,255);
            break;
        }
    }
    /* if no font found we can't do much. this shouldn't happen */
    if(font) {

        nTextLength = strlen(errormsg);
        nWidthTxt  =  nTextLength * font->charWidth;
        nUsableWidth = width - (nMargin*2);

        /* Check to see if it all fits on one line. If not, split the text on several lines. */
        if(!blank) {
            if (nWidthTxt > nUsableWidth) {
                nMaxCharsPerLine =  nUsableWidth/font->charWidth;
                nLines = (int) ceil ((double)nTextLength / (double)nMaxCharsPerLine);
                if (nLines > 0) {
                    papszLines = (char **)malloc(nLines*sizeof(char *));
                    for (i=0; i<nLines; i++) {
                        papszLines[i] = (char *)malloc((nMaxCharsPerLine+1)*sizeof(char));
                        papszLines[i][0] = '\0';
                    }
                }
                for (i=0; i<nLines; i++) {
                    nStart = i*nMaxCharsPerLine;
                    nEnd = nStart + nMaxCharsPerLine;
                    if (nStart < nTextLength) {
                        if (nEnd > nTextLength)
                            nEnd = nTextLength;
                        nLength = nEnd-nStart;

                        strncpy(papszLines[i], errormsg+nStart, nLength);
                        papszLines[i][nLength] = '\0';
                    }
                }
            } else {
                nLines = 1;
                papszLines = (char **)malloc(nLines*sizeof(char *));
                papszLines[0] = msStrdup(errormsg);
            }
            for (i=0; i<nLines; i++) {
                nYPos = (font->charHeight) * ((i*2) +1);
                nXPos = font->charWidth;;
                renderer->renderBitmapGlyphs(img, nXPos, nYPos, &ls, papszLines[i]);
            }
            if (papszLines) {
                for (i=0; i<nLines; i++) {
                    free(papszLines[i]);
                }
                free(papszLines);
            }
        }
    }

    /* actually write the image */
    if(!filename) {
        msIO_setHeader("Content-type","%s", MS_IMAGE_MIME_TYPE(format));
        msIO_sendHeaders();
    }
    msSaveImage(NULL,img,filename);
    msFreeImage(img);

    if (format->refcount == 0)
        msFreeOutputFormat(format);
    msFree(errormsg);
}
Exemple #8
0
outputFormatObj *msCreateDefaultOutputFormat( mapObj *map, 
                                              const char *driver,
                                              const char *name )

{
    outputFormatObj *format = NULL;

    if( strcasecmp(driver,"GD/PC256") == 0 )
    {
#ifdef USE_GD_GIF
        return msCreateDefaultOutputFormat( map, "GD/GIF", "gif" );
#elif defined(USE_GD_PNG)
        return msCreateDefaultOutputFormat( map, "GD/PNG", "gdpng" );
#else
        return NULL;
#endif
    }

#ifdef USE_GD_GIF
    if( strcasecmp(driver,"GD/GIF") == 0 )
    {
        if(!name) name="gif";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/gif");
        format->imagemode = MS_IMAGEMODE_PC256;
        format->extension = msStrdup("gif");
        format->renderer = MS_RENDER_WITH_GD;
    }
#endif

#ifdef USE_GD_PNG
    if( strcasecmp(driver,"GD/PNG") == 0 )
    {
        if(!name) name="gdpng";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/png");
        format->imagemode = MS_IMAGEMODE_PC256;
        format->extension = msStrdup("png");
        format->renderer = MS_RENDER_WITH_GD;
    }
#endif /* USE_GD_PNG */

    if( strcasecmp(driver,"AGG/PNG") == 0 )
    {
        if(!name) name="png24";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/png");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("png");
        format->renderer = MS_RENDER_WITH_AGG;
    }

    if( strcasecmp(driver,"AGG/PNG8") == 0 )
    {
        if(!name) name="png8";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/png; mode=8bit");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("png");
        format->renderer = MS_RENDER_WITH_AGG;
        msSetOutputFormatOption( format, "QUANTIZE_FORCE", "on");
        msSetOutputFormatOption( format, "QUANTIZE_COLORS", "256");
    }
    
    if( strcasecmp(driver,"AGG/JPEG") == 0 )
    {
        if(!name) name="jpeg";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/jpeg");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("jpg");
        format->renderer = MS_RENDER_WITH_AGG;
    }
    
#if defined(USE_CAIRO)
    if( strcasecmp(driver,"CAIRO/PNG") == 0 )
    {
        if(!name) name="cairopng";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/png; mode=24bit");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("png");
        format->renderer = MS_RENDER_WITH_CAIRO_RASTER;
    }
    if( strcasecmp(driver,"CAIRO/JPEG") == 0 )
    {
        if(!name) name="cairojpeg";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/jpeg");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("jpg");
        format->renderer = MS_RENDER_WITH_CAIRO_RASTER;
    }
    if( strcasecmp(driver,"CAIRO/PDF") == 0 )
    {
        if(!name) name="pdf";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("application/x-pdf");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("pdf");
        format->renderer = MS_RENDER_WITH_CAIRO_PDF;
    }
    if( strcasecmp(driver,"CAIRO/SVG") == 0 )
    {
        if(!name) name="svg";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/svg+xml");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("svg");
        format->renderer = MS_RENDER_WITH_CAIRO_SVG;
    }
#ifdef _WIN32
    if( strcasecmp(driver,"CAIRO/WINGDI") == 0 )
    {
        if(!name) name="cairowinGDI";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("");
        format->renderer = MS_RENDER_WITH_CAIRO_RASTER;
    }
    if( strcasecmp(driver,"CAIRO/WINGDIPRINT") == 0 )
    {
        if(!name) name="cairowinGDIPrint";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("");
        format->imagemode = MS_IMAGEMODE_RGB;
        format->extension = msStrdup("");
        format->renderer = MS_RENDER_WITH_CAIRO_RASTER;
    }
#endif
#endif

#if defined(USE_OGL) 
    if( strcasecmp(driver,"OGL/PNG") == 0 ) 
    { 
        if(!name) name="oglpng24";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("image/png; mode=24bit"); 
        format->imagemode = MS_IMAGEMODE_RGB; 
        format->extension = msStrdup("png"); 
        format->renderer = MS_RENDER_WITH_OGL; 
    } 
#endif 

#if defined(USE_KML) 
    if( strcasecmp(driver,"KML") == 0 ) 
    { 
        if(!name) name="kml";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("application/vnd.google-earth.kml+xml"); 
        format->imagemode = MS_IMAGEMODE_RGB; 
        format->extension = msStrdup("kml"); 
        format->renderer = MS_RENDER_WITH_KML; 
        msSetOutputFormatOption( format, "ATTACHMENT", "mapserver.kml");
    } 
    if( strcasecmp(driver,"KMZ") == 0 ) 
    { 
        if(!name) name="kmz";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = strdup("application/vnd.google-earth.kmz"); 
        format->imagemode = MS_IMAGEMODE_RGB; 
        format->extension = strdup("kmz"); 
        format->renderer = MS_RENDER_WITH_KML; 
        msSetOutputFormatOption( format, "ATTACHMENT", "mapserver.kmz");
    } 
#endif



#ifdef USE_GDAL
    if( strncasecmp(driver,"gdal/",5) == 0 )
    {
        if(!name) name=driver+5;
        format = msAllocOutputFormat( map, name, driver );
        if( msInitDefaultGDALOutputFormat( format ) == MS_FAILURE )
        {
            if( map != NULL )
            {
                map->numoutputformats--;
                map->outputformatlist[map->numoutputformats] = NULL;
            }

            msFreeOutputFormat( format );
            format = NULL;
        }
    }
#endif
#ifdef USE_OGR
    if( strncasecmp(driver,"ogr/",4) == 0 )
    {
        if(!name) name=driver+4;
        format = msAllocOutputFormat( map, name, driver );
        if( msInitDefaultOGROutputFormat( format ) == MS_FAILURE )
        {
            if( map != NULL )
            {
                map->numoutputformats--;
                map->outputformatlist[map->numoutputformats] = NULL;
            }

            msFreeOutputFormat( format );
            format = NULL;
        }
    }
#endif
    if( strcasecmp(driver,"imagemap") == 0 )
    {
        if(!name) name="imagemap";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("text/html; driver=imagemap");
        format->extension = msStrdup("html");
        format->imagemode = MS_IMAGEMODE_NULL;
        format->renderer = MS_RENDER_WITH_IMAGEMAP;
    }

    if( strcasecmp(driver,"template") == 0 ) {
        if(!name) name="template";
        format = msAllocOutputFormat( map, name, driver );
        format->mimetype = msStrdup("text/html");
        format->extension = msStrdup("html");
        format->imagemode = MS_IMAGEMODE_FEATURE;
        format->renderer = MS_RENDER_WITH_TEMPLATE;
    }

    if( format != NULL )
        format->inmapfile = MS_FALSE;
    
    
    return format;
}