[mapserver-commits] r10400 - sandbox/mapserver6

svn at osgeo.org svn at osgeo.org
Tue Jul 27 12:33:52 EDT 2010


Author: tbonfort
Date: 2010-07-27 16:33:51 +0000 (Tue, 27 Jul 2010)
New Revision: 10400

Modified:
   sandbox/mapserver6/mapagg.cpp
   sandbox/mapserver6/mapcairo.c
   sandbox/mapserver6/mapdraw.c
   sandbox/mapserver6/mapdummyrenderer.c
   sandbox/mapserver6/mapgd.c
   sandbox/mapserver6/mapkml.cpp
   sandbox/mapserver6/mapkmlrenderer.cpp
   sandbox/mapserver6/mapkmlrenderer.h
   sandbox/mapserver6/maprendering.c
   sandbox/mapserver6/mapserver.h
Log:
update kml output driver


Modified: sandbox/mapserver6/mapagg.cpp
===================================================================
--- sandbox/mapserver6/mapagg.cpp	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapagg.cpp	2010-07-27 16:33:51 UTC (rev 10400)
@@ -126,9 +126,7 @@
    bool use_alpha;
 };
 
-inline AGG2Renderer *agg2GetRenderer(imageObj *image) {
-   return (AGG2Renderer*) image->img.plugin;
-}
+#define AGG_RENDERER(image) ((AGG2Renderer*) (image)->img.plugin)
 
 template<class VertexSource>
 static void applyCJC(VertexSource &stroke, int caps, int joins) {
@@ -160,7 +158,7 @@
 
 int agg2RenderLine(imageObj *img, shapeObj *p, strokeStyleObj *style) {
 
-   AGG2Renderer *r = agg2GetRenderer(img);
+   AGG2Renderer *r = AGG_RENDERER(img);
    line_adaptor lines = line_adaptor(p);
    r->m_rasterizer_aa.reset();
    r->m_rasterizer_aa.filling_rule(mapserver::fill_non_zero);
@@ -196,7 +194,7 @@
 }
 
 int agg2RenderPolygon(imageObj *img, shapeObj *p, colorObj * color) {
-   AGG2Renderer *r = agg2GetRenderer(img);
+   AGG2Renderer *r = AGG_RENDERER(img);
    polygon_adaptor polygons(p);
    r->m_rasterizer_aa.reset();
    r->m_rasterizer_aa.filling_rule(mapserver::fill_even_odd);
@@ -207,10 +205,10 @@
 }
 
 int agg2RenderPolygonTiled(imageObj *img, shapeObj *p, imageObj * tile) {
-    assert(img->renderer == tile->renderer);
+    assert(img->format->renderer == tile->format->renderer);
     
-    AGG2Renderer *r = agg2GetRenderer(img);
-    AGG2Renderer *tileRenderer = agg2GetRenderer(tile);
+    AGG2Renderer *r = AGG_RENDERER(img);
+    AGG2Renderer *tileRenderer = AGG_RENDERER(tile);
     polygon_adaptor polygons(p);
     typedef mapserver::wrap_mode_repeat wrap_type;
     typedef mapserver::image_accessor_wrap<pixel_format,wrap_type,wrap_type> img_source_type;
@@ -226,7 +224,7 @@
 }
 
 int agg2RenderGlyphs(imageObj *img, double x, double y, labelStyleObj *style, char *text) {
-   AGG2Renderer *r = agg2GetRenderer(img);
+   AGG2Renderer *r = AGG_RENDERER(img);
    aggRendererCache *cache = (aggRendererCache*)MS_RENDERER_CACHE(MS_IMAGE_RENDERER(img));
    if (!cache->m_feng.load_font(style->font, 0, mapserver::glyph_ren_outline)) {
       msSetError(MS_TTFERR, "AGG error loading font (%s)", "agg2RenderGlyphs()", style->font);
@@ -305,7 +303,7 @@
 		msSetError(MS_RENDERERERR,"invalid bitmap font size", "agg2RenderBitmapGlyphs()");
 		return MS_FAILURE;
 	}
-	AGG2Renderer *r = agg2GetRenderer(img);
+	AGG2Renderer *r = AGG_RENDERER(img);
 	glyph_gen glyph(0);
 	mapserver::renderer_raster_htext_solid<renderer_base, glyph_gen> rt(r->m_renderer_base, glyph);
 	glyph.font(rasterfonts[size]);
@@ -376,7 +374,7 @@
 
 int agg2RenderVectorSymbol(imageObj *img, double x, double y,
         symbolObj *symbol, symbolStyleObj * style) {
-    AGG2Renderer *r = agg2GetRenderer(img);
+    AGG2Renderer *r = AGG_RENDERER(img);
     double ox = symbol->sizex * 0.5;
     double oy = symbol->sizey * 0.5;
 
@@ -407,7 +405,7 @@
 }
 
 int agg2RenderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj * style) {
-	AGG2Renderer *r = agg2GetRenderer(img);
+	AGG2Renderer *r = AGG_RENDERER(img);
 	pixel_format pf;
    rendering_buffer b;
 	rasterBufferObj *pixmap = symbol->pixmap_buffer;
@@ -484,7 +482,7 @@
 
 int agg2RenderEllipseSymbol(imageObj *image, double x, double y,
         symbolObj *symbol, symbolStyleObj * style) {
-	AGG2Renderer *r = agg2GetRenderer(image);
+	AGG2Renderer *r = AGG_RENDERER(image);
 	mapserver::path_storage path;
 	mapserver::ellipse ellipse(x,y,symbol->sizex*style->scale/2,symbol->sizey*style->scale/2);
 	path.concat_path(ellipse);
@@ -518,7 +516,7 @@
 
 int agg2RenderTruetypeSymbol(imageObj *img, double x, double y,
         symbolObj *symbol, symbolStyleObj * style) {
-   AGG2Renderer *r = agg2GetRenderer(img);
+   AGG2Renderer *r = AGG_RENDERER(img);
    aggRendererCache *cache = (aggRendererCache*)MS_RENDERER_CACHE(MS_IMAGE_RENDERER(img));
    if (!cache->m_feng.load_font(symbol->full_font_path, 0, mapserver::glyph_ren_outline)) {
       msSetError(MS_TTFERR, "AGG error loading font (%s)", "agg2RenderTruetypeSymbol()", symbol->full_font_path);
@@ -600,7 +598,7 @@
 
 
 int aggGetRasterBufferHandle(imageObj *img, rasterBufferObj * rb) {
-   AGG2Renderer *r = agg2GetRenderer(img);
+   AGG2Renderer *r = AGG_RENDERER(img);
    rb->type =MS_BUFFER_BYTE_RGBA;
    rb->data.rgba.pixels = r->buffer;
    rb->data.rgba.row_step = r->m_rendering_buffer.stride();
@@ -618,7 +616,7 @@
 }
 
 int aggGetRasterBufferCopy(imageObj *img, rasterBufferObj *rb) {
-   AGG2Renderer *r = agg2GetRenderer(img);
+   AGG2Renderer *r = AGG_RENDERER(img);
    aggInitializeRasterBuffer(rb, img->width, img->height, MS_IMAGEMODE_RGBA);
    int nBytes = r->m_rendering_buffer.stride()*r->m_rendering_buffer.height();
    memcpy(rb->data.rgba.pixels,r->buffer, nBytes);
@@ -631,7 +629,7 @@
 	assert(overlay->type == MS_BUFFER_BYTE_RGBA);
 	rendering_buffer b(overlay->data.rgba.pixels, overlay->width, overlay->height, overlay->data.rgba.row_step);
 	pixel_format pf(b);
-	AGG2Renderer *r = agg2GetRenderer(dest);
+	AGG2Renderer *r = AGG_RENDERER(dest);
 	r->m_renderer_base.blend_from(pf,0, 0, 0,unsigned(opacity * 255));
 	return MS_FAILURE;
 }
@@ -747,7 +745,7 @@
 
 int agg2FreeImage(imageObj * image) {
 
-   AGG2Renderer *r = agg2GetRenderer(image);
+   AGG2Renderer *r = AGG_RENDERER(image);
    free(r->buffer);
    delete r;
    image->img.plugin = NULL;
@@ -785,7 +783,8 @@
 int msPopulateRendererVTableAGG(rendererVTableObj * renderer) {
    renderer->supports_transparent_layers = 0;
    renderer->supports_pixel_buffer = 1;
-   renderer->supports_imagecache = 0;
+   renderer->use_imagecache = 0;
+   renderer->supports_clipping = 0;
    
    agg2InitCache(&(MS_RENDERER_CACHE(renderer)));
    renderer->cleanup = agg2Cleanup;

Modified: sandbox/mapserver6/mapcairo.c
===================================================================
--- sandbox/mapserver6/mapcairo.c	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapcairo.c	2010-07-27 16:33:51 UTC (rev 10400)
@@ -803,7 +803,7 @@
 
 inline int populateRendererVTableCairoVector( rendererVTableObj *renderer ) {
 #ifdef USE_CAIRO
-    renderer->supports_imagecache=0;
+    renderer->use_imagecache=0;
     renderer->supports_pixel_buffer=0;
     renderer->supports_transparent_layers = 1;
     initializeCache(&MS_RENDERER_CACHE(renderer));

Modified: sandbox/mapserver6/mapdraw.c
===================================================================
--- sandbox/mapserver6/mapdraw.c	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapdraw.c	2010-07-27 16:33:51 UTC (rev 10400)
@@ -1236,12 +1236,7 @@
     {
         if( MS_RENDERER_PLUGIN(image->format) )
         {
-#ifdef USE_KML
-            if (MS_RENDERER_KML(image->format))
-              return  msDrawRasterLayerKml(map, layer, image);
-            else
-#endif
-              return msDrawRasterLayerPlugin(map, layer, image);
+           return msDrawRasterLayerPlugin(map, layer, image);
         }
         else if( MS_RENDERER_RAWDATA(image->format) )
             return msDrawRasterLayerLow(map, layer, image, NULL);
@@ -2214,7 +2209,7 @@
 #endif
 
   /* initialize a few things for handling a background */
-  if(MS_VALID_COLOR(label->backgroundcolor)) {
+  if(MS_VALID_COLOR(label->backgroundcolor) && image->format->renderer != MS_RENDER_WITH_KML) {
     billboard.numlines = 1;
     billboard.line = &billboard_line;
     billboard.line->numpoints = 5;
@@ -2237,7 +2232,7 @@
   if(label->position != MS_XY) {
     pointObj p;
 
-    if(MS_VALID_COLOR(label->backgroundcolor)) {
+    if(MS_VALID_COLOR(label->backgroundcolor) && image->format->renderer != MS_RENDER_WITH_KML) {
       p = get_metrics_line(&labelPnt, label->position, r, label_offset_x, label_offset_y, label->angle, 1, billboard.line);
 
       /* draw the background and background shadow (if necessary) */
@@ -2260,7 +2255,7 @@
     labelPnt.x += label_offset_x;
     labelPnt.y += label_offset_y;
 
-    if(MS_VALID_COLOR(label->backgroundcolor)) {
+    if(MS_VALID_COLOR(label->backgroundcolor) && image->format->renderer != MS_RENDER_WITH_KML) {
       get_metrics_line(&labelPnt, label->position, r, label_offset_x, label_offset_y, label->angle, 1, billboard.line);
 
       /* draw the background and background shadow (if necessary) */

Modified: sandbox/mapserver6/mapdummyrenderer.c
===================================================================
--- sandbox/mapserver6/mapdummyrenderer.c	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapdummyrenderer.c	2010-07-27 16:33:51 UTC (rev 10400)
@@ -226,7 +226,7 @@
 
 int msInitializeDummyRenderer(rendererVTableObj *renderer) {
 	
-	renderer->supports_imagecache = 0;
+	renderer->use_imagecache = 0;
 	renderer->supports_pixel_buffer = 0;
 	renderer->supports_transparent_layers = 0;
 	renderer->supports_clipping = 0;

Modified: sandbox/mapserver6/mapgd.c
===================================================================
--- sandbox/mapserver6/mapgd.c	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapgd.c	2010-07-27 16:33:51 UTC (rev 10400)
@@ -903,7 +903,7 @@
 
 int msPopulateRendererVTableGD( rendererVTableObj *renderer ) {
   int i;
-   renderer->supports_imagecache=0;
+  renderer->use_imagecache=0;
   renderer->supports_pixel_buffer=1;
   renderer->supports_transparent_layers = 0;
   renderer->supports_bitmap_fonts = 1;

Modified: sandbox/mapserver6/mapkml.cpp
===================================================================
--- sandbox/mapserver6/mapkml.cpp	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapkml.cpp	2010-07-27 16:33:51 UTC (rev 10400)
@@ -48,7 +48,7 @@
 	image = (imageObj*)malloc(sizeof(imageObj));
 	memset(image, 0, sizeof(imageObj));
 
-	KmlRenderer *ren = new KmlRenderer(width, height, bg);
+	KmlRenderer *ren = new KmlRenderer(width, height, format, bg);
 	image->img.plugin = (void *) ren;
 
 	return image;
@@ -134,17 +134,22 @@
    return MS_FAILURE; //not supported for kml
 }
 
-int msMergeRasterBufferKml(imageObj *dest, rasterBufferObj *overlay, double opacity, 
-                           int srcX, int srcY, int dstX, int dstY, int width, int height)
-{
-   return MS_SUCCESS;
-}
 
 int msGetTruetypeTextBBoxKml(rendererVTableObj *r,char *font, double size, char *string,
 		rectObj *rect, double **advances)
 {
-	KmlRenderer* renderer = getKmlRenderer(img);
-	return renderer->getTruetypeTextBBox(img, font, size, string, rect, advances);
+   rect->minx=0.0;
+   rect->maxx=0.0;
+   rect->miny=0.0;
+   rect->maxy=0.0;
+   if (advances) {
+         int numglyphs = msGetNumGlyphs(string);
+         *advances = (double*) malloc(numglyphs * sizeof (double));
+         for(int i=0;i<numglyphs;i++) {
+            (*advances)[i] = size;
+         }
+   }
+   return MS_SUCCESS;
 }
 
 int msStartNewLayerKml(imageObj *img, mapObj *map, layerObj *layer)
@@ -164,7 +169,7 @@
    return MS_SUCCESS;
 }
 
-void msFreeImageKml(imageObj *image)
+int msFreeImageKml(imageObj *image)
 {
 	KmlRenderer* renderer = getKmlRenderer(image);
 	if (renderer)
@@ -172,34 +177,33 @@
 		delete renderer;
 	}
 	image->img.plugin=NULL;
+	return MS_SUCCESS;
 }
 
-void msFreeTileKml(imageObj *tile)
+int msFreeSymbolKml(symbolObj *symbol)
 {
+   return MS_SUCCESS;
 }
 
-void msFreeSymbolKml(symbolObj *symbol)
+int msStartShapeKml(imageObj *img, shapeObj *shape)
 {
-}
-
-void msStartShapeKml(imageObj *img, shapeObj *shape)
-{
 	KmlRenderer* renderer = getKmlRenderer(img);
 	renderer->startShape(img, shape);
+	return MS_SUCCESS;
 }
 
-void msEndShapeKml(imageObj *img, shapeObj *shape)
+int msEndShapeKml(imageObj *img, shapeObj *shape)
 {
     KmlRenderer* renderer = getKmlRenderer(img);
     renderer->endShape(img, shape);
+    return MS_SUCCESS;
 }
 
-int  msDrawRasterLayerKml(mapObj *map, layerObj *layer, imageObj *img)
-{
-    KmlRenderer* renderer = getKmlRenderer(img);
-    return renderer->renderRasterLayer(img);
-    
+int msMergeRasterBufferKml(imageObj *dest, rasterBufferObj *overlay, double opacity, int srcX, int srcY, int dstX, int dstY, int width, int height) {
+   KmlRenderer* renderer = getKmlRenderer(dest);
+   return renderer->mergeRasterBuffer(dest,overlay);
 }
+
 #ifdef __cplusplus
 }
 #endif
@@ -207,13 +211,18 @@
 
 #endif /*USE_KML*/
 
+int aggInitializeRasterBuffer(rasterBufferObj *rb, int width, int height, int mode);
+
 int msPopulateRendererVTableKML( rendererVTableObj *renderer )
 {
 #ifdef USE_KML
 
    renderer->supports_transparent_layers = 1;
    renderer->supports_pixel_buffer = 0;
-   renderer->supports_imagecache = 0;
+   renderer->supports_bitmap_fonts = 0;
+   renderer->supports_clipping = 0;
+   renderer->use_imagecache = 0;
+   
 
    renderer->startLayer = msStartNewLayerKml;
    renderer->endLayer = msCloseNewLayerKml;
@@ -228,17 +237,14 @@
    renderer->renderPixmapSymbol = &msRenderPixmapSymbolKml;
    renderer->renderTruetypeSymbol = &msRenderTruetypeSymbolKml;
    renderer->mergeRasterBuffer = &msMergeRasterBufferKml;
+   renderer->initializeRasterBuffer = aggInitializeRasterBuffer;
    renderer->getTruetypeTextBBox = &msGetTruetypeTextBBoxKml;
-   renderer->createPixmapSymbolTile = &msCreatePixmapSymbolTileKml;
-   renderer->createVectorSymbolTile = &msCreateVectorSymbolTileKml;
-   renderer->createEllipseSymbolTile = &msCreateEllipseSymbolTileKml;
-   renderer->createTruetypeSymbolTile = &msCreateTruetypeSymbolTileKml;
    renderer->renderTile = &msRenderTileKml;
    renderer->renderPolygonTiled = &msRenderPolygonTiledKml;
    renderer->renderLineTiled = &msRenderLineTiledKml;
-   renderer->freeTile = &msFreeTileKml;
    renderer->freeSymbol = &msFreeSymbolKml;
    renderer->freeImage=&msFreeImageKml;
+   renderer->mergeRasterBuffer = msMergeRasterBufferKml;
 
    renderer->startShape=&msStartShapeKml;
    renderer->endShape=&msEndShapeKml;

Modified: sandbox/mapserver6/mapkmlrenderer.cpp
===================================================================
--- sandbox/mapserver6/mapkmlrenderer.cpp	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapkmlrenderer.cpp	2010-07-27 16:33:51 UTC (rev 10400)
@@ -35,10 +35,9 @@
 #include "mapio.h"
 
 
-KmlRenderer::KmlRenderer(int width, int height, colorObj* color/*=NULL*/) 
+KmlRenderer::KmlRenderer(int width, int height, outputFormatObj *format, colorObj* color/*=NULL*/) 
 	:	XmlDoc(NULL), LayerNode(NULL), GroundOverlayNode(NULL), Width(width), Height(height),
-		FirstLayer(MS_TRUE), RasterizerOutputFormat(NULL), ImgLayer(NULL),
-		VectorMode(MS_TRUE), RasterMode(MS_FALSE), MapCellsize(1.0),
+		FirstLayer(MS_TRUE), MapCellsize(1.0),
 		PlacemarkNode(NULL), GeomNode(NULL),
 		Items(NULL), NumItems(0), map(NULL), currentLayer(NULL)
 
@@ -87,6 +86,7 @@
 
 
 	StyleHashTable = msCreateHashTable();
+	
 }
 
 KmlRenderer::~KmlRenderer()
@@ -100,28 +100,6 @@
 	xmlCleanupParser();
 }
 
-imageObj* KmlRenderer::createInternalImage()
-{
-    rendererVTableObj *r = RasterizerOutputFormat->vtable;
-    assert(r);
-    imageObj *image =NULL;
-    mapObj *map = currentLayer->map;
-    
-    image = r->createImage(Width, Height, RasterizerOutputFormat, &BgColor);
-    image->format = RasterizerOutputFormat;
-    image->format->refcount++;
-    image->width = currentLayer->map->width;
-    image->height = currentLayer->map->height;
-   
-    image->resolution = currentLayer->map->resolution;
-    image->resolutionfactor = currentLayer->map->resolution/currentLayer->map->defresolution;
-    if (currentLayer->map->web.imagepath)
-       image->imagepath = strdup(currentLayer->map->web.imagepath);
-    if (map->web.imageurl)
-       image->imageurl = strdup(currentLayer->map->web.imageurl);
-    return image;
-}
-
 imageObj* KmlRenderer::createImage(int, int, outputFormatObj*, colorObj*)
 {
 	return NULL;
@@ -221,24 +199,6 @@
     char *layerName=NULL;
     const char *value=NULL;
 
-    VectorMode = MS_FALSE;
-    RasterMode = MS_FALSE;
-
-    if (layer->type ==  MS_LAYER_RASTER)
-      RasterMode = MS_TRUE;
-    else
-      VectorMode = MS_TRUE;
-
-
-    /*check if a vector layer will be dumped as a raster*/
-    const char *outputAsRaster=msLookupHashTable(&(layer->metadata),"KML_OUTPUTASRASTER");
-    if (outputAsRaster && strlen(outputAsRaster) > 0 && 
-        (strcasecmp(outputAsRaster, "true") == 0 || strcasecmp(outputAsRaster, "yes") == 0))
-    {
-         RasterMode = MS_TRUE;
-         VectorMode = MS_FALSE;
-    }
-
     LayerNode = xmlNewNode(NULL, BAD_CAST "Folder");
 	
     layerName = getLayerName(layer);
@@ -253,10 +213,7 @@
       layerDsiplayFolder = msLookupHashTable(&(layer->map->web.metadata), "kml_folder_display");
     if (!layerDsiplayFolder || strlen(layerDsiplayFolder)<=0)
     {
-        if (RasterMode)
-          xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_checkHideChildren");
-        else
-          xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_check"); 
+        xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_check"); 
     }
 
     else
@@ -298,112 +255,74 @@
         BgColor = layer->map->imagecolor;
 
          xmlNewChild(DocNode, NULL, BAD_CAST "name", BAD_CAST layer->map->name);
+         
+         for (int i=0; i<map->numoutputformats; i++)
+         {
+             outputFormatObj *iFormat = layer->map->outputformatlist[i];
+             if(!strcasecmp(iFormat->name,"png24"))
+             {
+                 aggFormat = iFormat;
+                 break;
+             }
+         } 
 
         
     }
 
     currentLayer = layer;
 
-    if (VectorMode)
-    {
+   
 
-        if (!msLayerIsOpen(layer))
-        {
-            if (msLayerOpen(layer) != MS_SUCCESS)
-            {
-                msSetError(MS_MISCERR, "msLayerOpen failed", "KmlRenderer::startNewLayer" );
-            }
-        }
+     if (!msLayerIsOpen(layer))
+     {
+         if (msLayerOpen(layer) != MS_SUCCESS)
+         {
+             msSetError(MS_MISCERR, "msLayerOpen failed", "KmlRenderer::startNewLayer" );
+         }
+     }
 
-        /*pre process the layer to set things that make sense for kml output*/
-        processLayer(layer);
+     /*pre process the layer to set things that make sense for kml output*/
+     processLayer(layer);
 
-        if (msLookupHashTable(&layer->metadata, "kml_description"))
-          pszLayerDescMetadata = msLookupHashTable(&layer->metadata, "kml_description");
-        
-        value=msLookupHashTable(&layer->metadata, "kml_include_items");
-        if (value)
-          papszLayerIncludeItems = msStringSplit(value, ',', &nIncludeItems);
+     if (msLookupHashTable(&layer->metadata, "kml_description"))
+       pszLayerDescMetadata = msLookupHashTable(&layer->metadata, "kml_description");
+     
+     value=msLookupHashTable(&layer->metadata, "kml_include_items");
+     if (value)
+       papszLayerIncludeItems = msStringSplit(value, ',', &nIncludeItems);
 
-        
-        DumpAttributes = MS_FALSE;
-        char *attribVal = msLookupHashTable(&layer->metadata, "kml_dumpattributes");
-        if (attribVal && strlen(attribVal) > 0)
-        {
+     
+     DumpAttributes = MS_FALSE;
+     char *attribVal = msLookupHashTable(&layer->metadata, "kml_dumpattributes");
+     if (attribVal && strlen(attribVal) > 0)
+     {
 
-            DumpAttributes = MS_TRUE;
-            msLayerWhichItems(layer, MS_FALSE, attribVal);
+         DumpAttributes = MS_TRUE;
+         msLayerWhichItems(layer, MS_FALSE, attribVal);
 
-        }
-        else
-        {
-            msLayerWhichItems(layer, MS_TRUE, NULL);
-        }
+     }
+     else
+     {
+         msLayerWhichItems(layer, MS_TRUE, NULL);
+     }
 
-        NumItems = layer->numitems;
-        if (NumItems)
-        {
-            Items = (char **)calloc(NumItems, sizeof(char *));
-            for (int i=0; i<NumItems; i++)
-              Items[i] = strdup(layer->items[i]);
-        }
+     NumItems = layer->numitems;
+     if (NumItems)
+     {
+         Items = (char **)calloc(NumItems, sizeof(char *));
+         for (int i=0; i<NumItems; i++)
+           Items[i] = strdup(layer->items[i]);
+     }
 
-    }    
-
-    ImgLayer= NULL;
     
-    
-    /*check if kml_folder_display is set*/
-    /* setup internal rasterizer format */
-    char rasterizerFomatName[128];
 
-    for (int i=0; i<layer->map->numoutputformats; i++)
-    {
-        outputFormatObj *iFormat = layer->map->outputformatlist[i];
-        if(!strcasecmp(iFormat->name,"png24"))
-        {
-            RasterizerOutputFormat = iFormat;
-            /*always set RGBA*/
-            RasterizerOutputFormat->imagemode = MS_IMAGEMODE_RGBA;
-            RasterizerOutputFormat->transparent = MS_TRUE;
-            break;
-        }
-    } 
-    
-    ImgLayer = RasterMode ? createInternalImage() : NULL;
-
     setupRenderingParams(&layer->metadata);
     return MS_SUCCESS;
 }
 
 int KmlRenderer::closeNewLayer(imageObj *img, layerObj *layer)
 {
-    if (VectorMode)
-      flushPlacemark();
-
-    /*if we rendering through a raster buffer, save the layer into a file and create
-      a GroundOverlay node*/
-    if (RasterMode && ImgLayer)
-    {       
-        char *tmpFileName = NULL;
-        char *tmpUrl = NULL;
-            
-        tmpFileName = msTmpFile(MapPath, img->imagepath, MS_IMAGE_EXTENSION(RasterizerOutputFormat));
-        if (tmpFileName)
-        {
-            msSaveImage(layer->map, ImgLayer, tmpFileName);
-            tmpUrl = strdup( img->imageurl);
-            tmpUrl = msStringConcatenate(tmpUrl, (char *)(msGetBasename(tmpFileName)));
-            tmpUrl = msStringConcatenate(tmpUrl, ".");
-            tmpUrl = msStringConcatenate(tmpUrl, (char *)MS_IMAGE_EXTENSION(RasterizerOutputFormat));
-                
-            createGroundOverlayNode(LayerNode, tmpUrl, layer);
-            msFree(tmpFileName);
-            msFree(tmpUrl);
-            msFreeImage(ImgLayer);
-                
-        }        
-    }
+    flushPlacemark();
         
     xmlAddChild(DocNode, LayerNode);
 
@@ -424,6 +343,32 @@
     return MS_SUCCESS;
 }
 
+int KmlRenderer::mergeRasterBuffer(imageObj *image, rasterBufferObj *rb) {
+   assert(rb && rb->type == MS_BUFFER_BYTE_RGBA);
+   char *tmpFileName = NULL;
+   char *tmpUrl = NULL;
+   FILE *tmpFile = NULL;
+    
+   tmpFileName = msTmpFile(MapPath, image->imagepath, "png");
+   tmpFile = fopen(tmpFileName,"w");
+   if (tmpFile)
+   {
+     
+     msSaveRasterBuffer(rb,tmpFile,aggFormat);
+     tmpUrl = strdup( image->imageurl);
+     tmpUrl = msStringConcatenate(tmpUrl, (char *)(msGetBasename(tmpFileName)));
+     tmpUrl = msStringConcatenate(tmpUrl, ".png");
+        
+     createGroundOverlayNode(LayerNode, tmpUrl, currentLayer);
+     msFree(tmpFileName);
+     msFree(tmpUrl);
+     fclose(tmpFile);
+     return MS_SUCCESS;
+   } else {
+      msSetError(MS_IOERR,"Failed to create file for kml overlay","KmlRenderer::mergeRasterBuffer()");
+      return MS_FAILURE;
+   }
+}
 
 void KmlRenderer::setupRenderingParams(hashTableObj *layerMetadata)
 {
@@ -503,7 +448,7 @@
     /*always add a name. It will be replaced by a text value if available*/
     char tmpid[100];
     char *stmp=NULL, *layerName=NULL;
-    sprintf(tmpid, ".%d", CurrentShapeIndex);
+    sprintf(tmpid, ".%d_%d", CurrentShapeIndex);
     layerName = getLayerName(currentLayer);
     stmp = msStringConcatenate(stmp, layerName);
     stmp = msStringConcatenate(stmp, tmpid);
@@ -516,7 +461,7 @@
     return placemarkNode;
 }
 
-void KmlRenderer::renderLineVector(imageObj*, shapeObj *p, strokeStyleObj *style)
+void KmlRenderer::renderLine(imageObj*, shapeObj *p, strokeStyleObj *style)
 {
     if (p->numlines == 0)
       return;
@@ -556,30 +501,8 @@
       
 }
 
-void KmlRenderer::renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style)
+void KmlRenderer::renderPolygon(imageObj*, shapeObj *p, colorObj *color)
 {
-    if (VectorMode)
-      renderLineVector(img, p, style);
-
-    if (RasterMode)
-    {
-      shapeObj rasShape;
-
-          /* internal renderer used for rasterizing*/
-      rendererVTableObj *r = RasterizerOutputFormat->vtable;
-
-      msInitShape(&rasShape);
-      msCopyShape(p,&rasShape);
-
-      r->transformShape(&rasShape, MapExtent, MapCellsize, MS_SIMPLIFY_DEFAULT);
-
-      r->renderLine(ImgLayer, &rasShape, style);
-      msFreeShape(&rasShape);
-    }
-}
-
-void KmlRenderer::renderPolygonVector(imageObj*, shapeObj *p, colorObj *color)
-{
     if (PlacemarkNode == NULL)
       PlacemarkNode = createPlacemarkNode(LayerNode, NULL);
 
@@ -615,28 +538,6 @@
       
 }
 
-void KmlRenderer::renderPolygon(imageObj *img, shapeObj *p, colorObj *color)
-{
-    if (VectorMode)
-      renderPolygonVector(img, p, color);
-
-    if (RasterMode)
-    {
-      shapeObj rasShape;
-
-          /* internal renderer used for rasterizing*/           
-      rendererVTableObj *r = RasterizerOutputFormat->vtable;
-
-      msInitShape(&rasShape);
-      msCopyShape(p,&rasShape);
-
-      r->transformShape(&rasShape, MapExtent, MapCellsize, MS_SIMPLIFY_DEFAULT);
-
-      r->renderPolygon(ImgLayer, &rasShape, color);
-      msFreeShape(&rasShape);
-    }
-}
-
 void KmlRenderer::addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts)
 {
     char lineBuf[128];
@@ -662,7 +563,7 @@
     xmlNodeAddContent(coordsNode, BAD_CAST "\t");
 }
 
-void KmlRenderer::renderGlyphsVector(imageObj*, double x, double y, labelStyleObj *style, char *text)
+void KmlRenderer::renderGlyphs(imageObj*, double x, double y, labelStyleObj *style, char *text)
 {
     xmlNodePtr node; 
 
@@ -698,40 +599,6 @@
     addCoordsNode(geomNode, &pt, 1);
 }
 
-void KmlRenderer::renderGlyphs(imageObj *img, double x, double y, labelStyleObj *style, char *text)
-{
-	if (VectorMode)
-		renderGlyphsVector(img, x, y, style, text);
-
-	if (RasterMode)
-	{
-              /* internal renderer used for rasterizing*/
-		rendererVTableObj *r = RasterizerOutputFormat->vtable;
-		r->renderGlyphs(ImgLayer, x, y, style, text);
-	}
-}
-
-int KmlRenderer::getTruetypeTextBBox(imageObj*,char *font, double size, char *string,
-		rectObj *rect, double **advances)
-{
-    if (VectorMode)
-    {
-          /* TODO*/     
-      rect->minx=0.0;
-      rect->maxx=0.0;
-      rect->miny=0.0;
-      rect->maxy=0.0;
-    }
-
-    if (RasterMode)
-    {
-      rendererVTableObj *r = RasterizerOutputFormat->vtable;
-      r->getTruetypeTextBBox(ImgLayer, font, size, string, rect, advances);
-    }
-
-    return true;
-}
-
 void KmlRenderer::addAddRenderingSpecifications(xmlNodePtr node)
 {
 	/*
@@ -755,19 +622,18 @@
 }
 
 
+imageObj *agg2CreateImage(int width, int height, outputFormatObj *format, colorObj * bg);
+
 int KmlRenderer::createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *symstyle)
 {
     pointObj p;
+    
     imageObj *tmpImg = NULL;
-
-        /* internal renderer used for rasterizing*/
-    rendererVTableObj *r = RasterizerOutputFormat->vtable;
-
-        /*RasterizerOutputFormat->imagemode = MS_IMAGEMODE_RGBA;*/
-    tmpImg = r->createImage((int)(symbol->sizex*symstyle->scale), 
+    
+    agg2CreateImage((int)(symbol->sizex*symstyle->scale), 
                             (int)(symbol->sizey*symstyle->scale), 
-                            RasterizerOutputFormat, NULL);
-    tmpImg->format = RasterizerOutputFormat;
+                            aggFormat, NULL);
+    tmpImg->format = aggFormat;
 
     p.x = symbol->sizex * symstyle->scale / 2;
     p.y = symbol->sizey *symstyle->scale / 2;
@@ -802,53 +668,25 @@
 void KmlRenderer::renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, 
                                      symbolStyleObj *style)
 {
-    if (VectorMode)
-      renderSymbol(img, x, y, symbol, style);
-
-    if (RasterMode)
-    {
-      rendererVTableObj *r = RasterizerOutputFormat->vtable;
-      r->renderPixmapSymbol(ImgLayer, x, y, symbol, style);
-    }
+    renderSymbol(img, x, y, symbol, style);
 }
 
 void KmlRenderer::renderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, 
                                      symbolStyleObj *style)
 {
-    if (VectorMode)
-      renderSymbol(img, x, y, symbol, style);
-
-    if (RasterMode)
-    {
-      rendererVTableObj *r = RasterizerOutputFormat->vtable;
-      r->renderVectorSymbol(ImgLayer, x, y, symbol, style);
-    }
+    renderSymbol(img, x, y, symbol, style);
 }
 
 void KmlRenderer::renderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, 
                                       symbolStyleObj *style)
 {
-    if (VectorMode)
-      renderSymbol(img, x, y, symbol, style);
-
-    if (RasterMode)
-    {
-      rendererVTableObj *r = RasterizerOutputFormat->vtable;
-      r->renderEllipseSymbol(ImgLayer, x, y, symbol, style);
-    }
+    renderSymbol(img, x, y, symbol, style);
 }
 
 void KmlRenderer::renderTruetypeSymbol(imageObj *img, double x, double y, symbolObj *symbol, 
                                        symbolStyleObj *style)
 {
-    if (VectorMode)
-      renderSymbol(img, x, y, symbol, style);
-
-    if (RasterMode)
-    {
-      rendererVTableObj *r = RasterizerOutputFormat->vtable;
-      r->renderTruetypeSymbol(ImgLayer, x, y, symbol, style);
-    }
+    renderSymbol(img, x, y, symbol, style);
 }
 
 xmlNodePtr KmlRenderer::createGroundOverlayNode(xmlNodePtr parentNode, char *imageHref, layerObj *layer)
@@ -934,10 +772,7 @@
     PlacemarkNode = NULL;
     GeomNode = NULL;
 
-    if (VectorMode)/* && DumpAttributes && NumItems)*/
-      DescriptionNode = createDescriptionNode(shape);
-    else
-      DescriptionNode = NULL;
+    DescriptionNode = createDescriptionNode(shape);
 
     memset(SymbologyFlag, 0, NumSymbologyFlag);
 }
@@ -984,8 +819,8 @@
                 </Style>
 	*/
 
-    sprintf(symbolHexColor,"%02x%02x%02x%02x", style->color.alpha, style->color.blue,
-            style->color.green, style->color.red);
+    sprintf(symbolHexColor,"%02x%02x%02x%02x", style->color->alpha, style->color->blue,
+            style->color->green, style->color->red);
     sprintf(SymbolName, "symbol_%s_%.1f_%s", symbol->name, style->scale, symbolHexColor);
 
     char *symbolUrl = msLookupHashTable(StyleHashTable, SymbolName);
@@ -996,13 +831,13 @@
 
       if (img->imagepath)
       {
-        char *tmpFileName = msTmpFile(MapPath, img->imagepath, MS_IMAGE_EXTENSION(RasterizerOutputFormat));
+        char *tmpFileName = msTmpFile(MapPath, img->imagepath, "png");
         sprintf(iconFileName, "%s", tmpFileName);
         msFree(tmpFileName);
       }
       else
       {
-        sprintf(iconFileName, "symbol_%s_%.1f.%s", symbol->name, style->scale, MS_IMAGE_EXTENSION(RasterizerOutputFormat));
+        sprintf(iconFileName, "symbol_%s_%.1f.%s", symbol->name, style->scale, "png");
       }
 
       if (createIconImage(iconFileName, symbol, style) != MS_SUCCESS)
@@ -1014,7 +849,7 @@
       }
 
       if (img->imageurl)
-        sprintf(iconUrl, "%s%s.%s", img->imageurl, msGetBasename(iconFileName), MS_IMAGE_EXTENSION(RasterizerOutputFormat));
+        sprintf(iconUrl, "%s%s.%s", img->imageurl, msGetBasename(iconFileName), "png");
       else
         sprintf(iconUrl, "%s", iconFileName);
 
@@ -1050,11 +885,11 @@
         for (int i=0; i<numLineStyle; i++)
         {
             if (currentLayer && currentLayer->opacity > 0 && currentLayer->opacity < 100 &&
-                LineStyle[i].color.alpha == 255)
-              LineStyle[i].color.alpha = MS_NINT(currentLayer->opacity*2.55);
+                LineStyle[i].color->alpha == 255)
+              LineStyle[i].color->alpha = MS_NINT(currentLayer->opacity*2.55);
               
-            sprintf(lineHexColor,"%02x%02x%02x%02x", LineStyle[i].color.alpha, LineStyle[0].color.blue,
-                    LineStyle[i].color.green, LineStyle[i].color.red);
+            sprintf(lineHexColor,"%02x%02x%02x%02x", LineStyle[i].color->alpha, LineStyle[0].color->blue,
+                    LineStyle[i].color->green, LineStyle[i].color->red);
 
             char lineStyleName[32];
             sprintf(lineStyleName, "_line_%s_w%.1f", lineHexColor, LineStyle[i].width);
@@ -1100,9 +935,9 @@
           */
 
       if (currentLayer && currentLayer->opacity > 0 && currentLayer->opacity < 100 &&
-          LabelStyle.color.alpha == 255)
-        LabelStyle.color.alpha = MS_NINT(currentLayer->opacity*2.55);
-      sprintf(labelHexColor,"%02x%02x%02x%02x", LabelStyle.color.alpha, LabelStyle.color.blue, LabelStyle.color.green, LabelStyle.color.red);
+          LabelStyle.color->alpha == 255)
+        LabelStyle.color->alpha = MS_NINT(currentLayer->opacity*2.55);
+      sprintf(labelHexColor,"%02x%02x%02x%02x", LabelStyle.color->alpha, LabelStyle.color->blue, LabelStyle.color->green, LabelStyle.color->red);
 
           // __TODO__ add label scale
 
@@ -1157,8 +992,8 @@
             for (int i=0; i<numLineStyle; i++)
             {
                 xmlNodePtr lineStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LineStyle", NULL);
-                sprintf(lineHexColor,"%02x%02x%02x%02x", LineStyle[i].color.alpha, LineStyle[i].color.blue,
-                    LineStyle[i].color.green, LineStyle[i].color.red);
+                sprintf(lineHexColor,"%02x%02x%02x%02x", LineStyle[i].color->alpha, LineStyle[i].color->blue,
+                    LineStyle[i].color->green, LineStyle[i].color->red);
                 xmlNewChild(lineStyleNode, NULL, BAD_CAST "color", BAD_CAST lineHexColor);
 
                 char width[16];
@@ -1294,11 +1129,6 @@
     return NULL;
 }
 
-int KmlRenderer::renderRasterLayer(imageObj*)
-{
-    return msDrawRasterLayer(currentLayer->map, currentLayer, ImgLayer);
-}
-
 void KmlRenderer::addLineStyleToList(strokeStyleObj *style)
 {
     /*actually this is not necessary. kml only uses the last LineStyle
@@ -1307,10 +1137,10 @@
     for (i=0; i<numLineStyle; i++)
     {
         if (style->width == LineStyle[i].width &&
-            LineStyle[i].color.alpha == style->color.alpha &&
-            LineStyle[i].color.red == style->color.red &&
-            LineStyle[i].color.green == style->color.green &&
-            LineStyle[i].color.blue == style->color.blue)
+            LineStyle[i].color->alpha == style->color->alpha &&
+            LineStyle[i].color->red == style->color->red &&
+            LineStyle[i].color->green == style->color->green &&
+            LineStyle[i].color->blue == style->color->blue)
           break;
     }
     if (i == numLineStyle)

Modified: sandbox/mapserver6/mapkmlrenderer.h
===================================================================
--- sandbox/mapserver6/mapkmlrenderer.h	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapkmlrenderer.h	2010-07-27 16:33:51 UTC (rev 10400)
@@ -85,28 +85,18 @@
 
 	enum			symbFlagsEnum { Label, Line, Polygon, Symbol };
 
-	// internal output format containing cairo renderer used for rasterizing and rendering symbols
-	outputFormatObj	*RasterizerOutputFormat;
-
-	imageObj		*ImgLayer;
-
 	int				FirstLayer;
         
         mapObj                  *map;
         layerObj                *currentLayer;
-	
 
-	// if true - features are rasterized
-	int				VectorMode;
-
-	// if true - features are written directly in kml
-	int				RasterMode;
-
 	int				AltitudeMode;
 	int				Tessellate;
 	int				Extrude;
 
 	enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute };
+	
+	outputFormatObj *aggFormat;
 
 protected:
 
@@ -143,7 +133,7 @@
 
 public:
 
-	KmlRenderer(int width, int height, colorObj* color = NULL);
+	KmlRenderer(int width, int height, outputFormatObj *format, colorObj* color = NULL);
 	virtual ~KmlRenderer();
 
     imageObj* createImage(int width, int height, outputFormatObj *format, colorObj* bg);
@@ -167,8 +157,7 @@
 	void renderTruetypeSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
 
 	int getTruetypeTextBBox(imageObj *img,char *font, double size, char *string, rectObj *rect, double **advances);
-
-        int renderRasterLayer(imageObj *img);
+	int mergeRasterBuffer(imageObj *image, rasterBufferObj *rb);
 };
 
 #endif /* USE_KML */

Modified: sandbox/mapserver6/maprendering.c
===================================================================
--- sandbox/mapserver6/maprendering.c	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/maprendering.c	2010-07-27 16:33:51 UTC (rev 10400)
@@ -621,7 +621,7 @@
          p_x = p->x + style->offsetx * scalefactor;
          p_y = p->y + style->offsety * scalefactor;
 
-         if(renderer->supports_imagecache) {
+         if(renderer->use_imagecache) {
             imageObj *tile = getTile(image, symbol, &s, -1, -1);
             if(tile!=NULL)
                return renderer->renderTile(image, tile, p_x, p_y);

Modified: sandbox/mapserver6/mapserver.h
===================================================================
--- sandbox/mapserver6/mapserver.h	2010-07-27 14:29:22 UTC (rev 10399)
+++ sandbox/mapserver6/mapserver.h	2010-07-27 16:33:51 UTC (rev 10400)
@@ -1486,7 +1486,6 @@
 #ifdef SWIG
 %mutable;
 #endif
-  int renderer;
 #ifndef SWIG
   int size;
 #endif
@@ -2501,9 +2500,9 @@
 struct rendererVTableObj {
 	int supports_transparent_layers;
 	int supports_pixel_buffer;
-	int supports_imagecache;
 	int supports_clipping;
 	int supports_bitmap_fonts;
+	int use_imagecache;
 	
 	void *renderer_data;
 



More information about the mapserver-commits mailing list