[mapserver-commits] r8909 - sandbox/graphics

svn at osgeo.org svn at osgeo.org
Tue Apr 14 13:32:37 EDT 2009


Author: assefa
Date: 2009-04-14 13:32:36 -0400 (Tue, 14 Apr 2009)
New Revision: 8909

Modified:
   sandbox/graphics/mapcairo.c
   sandbox/graphics/mapimageio.c
   sandbox/graphics/mapoutput.c
   sandbox/graphics/maprendering.c
   sandbox/graphics/mapserver.h
   sandbox/graphics/maputil.c
Log:
Build on windows

Modified: sandbox/graphics/mapcairo.c
===================================================================
--- sandbox/graphics/mapcairo.c	2009-04-14 13:39:42 UTC (rev 8908)
+++ sandbox/graphics/mapcairo.c	2009-04-14 17:32:36 UTC (rev 8909)
@@ -31,8 +31,14 @@
 
 #include "mapserver.h"
 #include <cairo.h>
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <cairo-pdf.h>
+#include <cairo-svg.h>
+#else
 #include <cairo/cairo-pdf.h>
 #include <cairo/cairo-svg.h>
+#endif
+
 # include <cairo-ft.h>
 /*
 #include <pango/pangocairo.h>
@@ -90,16 +96,18 @@
 }
 
 cairo_font_face_t *getFontFace(cairo_renderer *r, char *font) {
+    faceCacheObj *newface = NULL;
+    FT_Face	face;// = malloc(sizeof(FT_Face));
     faceCacheObj *cur=r->facecache;
     static const cairo_user_data_key_t key;
     while(cur) {
         if(cur->path == font) return cur->face;
         cur = cur->next;
     }
-    faceCacheObj *newface = malloc(sizeof(faceCacheObj));
+    newface = malloc(sizeof(faceCacheObj));
     newface->next = r->facecache;
     r->facecache = newface;
-    FT_Face	face;// = malloc(sizeof(FT_Face));
+    
     FT_New_Face(r->library, font, 0, &face);
     newface->face = cairo_ft_font_face_create_for_ft_face(face, 0);
 
@@ -168,20 +176,21 @@
 }
 
 void msDrawPolygonTiledCairo(imageObj *img, shapeObj *p,colorObj *oc, double outlineWidth, void *tile) {
-	cairo_renderer *r = getCairoRenderer(img);
-	cairo_pattern_t *pattern = cairo_pattern_create_for_surface(tile);
-	cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
-	int i,j;
-	cairo_set_source(r->cr, pattern);
-	for (i = 0; i < p->numlines; i++) {
-		lineObj *l = &(p->line[i]);
-		cairo_move_to(r->cr, l->point[0].x, l->point[0].y);
-		for (j = 1; j < l->numpoints; j++) {
-			cairo_line_to(r->cr, l->point[j].x, l->point[j].y);
-		}
-		//cairo_close_path(r->cr);
-	}
-	cairo_fill(r->cr);
+    int i,j;
+    cairo_renderer *r = getCairoRenderer(img);
+    cairo_pattern_t *pattern = cairo_pattern_create_for_surface(tile);
+    cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
+	
+    cairo_set_source(r->cr, pattern);
+    for (i = 0; i < p->numlines; i++) {
+      lineObj *l = &(p->line[i]);
+      cairo_move_to(r->cr, l->point[0].x, l->point[0].y);
+      for (j = 1; j < l->numpoints; j++) {
+        cairo_line_to(r->cr, l->point[j].x, l->point[j].y);
+      }
+      //cairo_close_path(r->cr);
+    }
+    cairo_fill(r->cr);
 }
 
 cairo_surface_t *createSurfaceFromBuffer(rasterBufferObj *b) {
@@ -299,17 +308,18 @@
 void renderTruetypeSymbolCairo(imageObj *img, double x, double y, symbolObj *symbol,
         symbolStyleObj *s) {
 	cairo_renderer *r = getCairoRenderer(img);
+        cairo_font_face_t *ff = getFontFace(r,symbol->full_font_path);
+	cairo_text_extents_t extents;
+        cairo_matrix_t trans;
+        double ox,oy;
 	cairo_save(r->cr);
-    cairo_font_face_t *ff = getFontFace(r,symbol->full_font_path);
-	cairo_text_extents_t extents;
 
 	cairo_set_font_face(r->cr, ff);
 	cairo_set_font_size(r->cr, s->scale * 96 / 72.0);
 	cairo_text_extents(r->cr, symbol->character, &extents);
 
-	cairo_matrix_t trans;
 	cairo_matrix_init_rotate(&trans,-s->rotation);
-	double ox,oy;
+
 	ox=extents.x_bearing+extents.width/2.;
 	oy=extents.y_bearing+extents.height/2.;
 	cairo_matrix_transform_point(&trans,&ox,&oy);
@@ -336,25 +346,31 @@
 		colorObj *bc,
 		colorObj *oc, double ow) {
 	cairo_renderer *r = getCairoRenderer(img);
+        int w,h;
 	//cairo_font_face_t *ff = getFontFace(r,font);
 	cairo_text_extents_t extents;
+        cairo_surface_t *surface;
+        cairo_t *cr;
+        cairo_matrix_t trans;
+        double ox,oy;
 
 	//cairo_set_font_face(r->cr, ff);
 	cairo_set_font_size(r->cr, size * 96 / 72.0);
 	cairo_text_extents(r->cr, text, &extents);
 
-	int w=extents.width*1.5,h=extents.height*1.5;
-	cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+	w=extents.width*1.5;
+        h=extents.height*1.5;
+	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
 					w,h);
-	cairo_t *cr = cairo_create(surface);
+	cr = cairo_create(surface);
 	if (bc && MS_VALID_COLOR(*bc)) {
 			msCairoSetSourceColor(cr, bc);
 			cairo_paint(cr);
 		}
 
-	cairo_matrix_t trans;
+	
 	cairo_matrix_init_rotate(&trans,-angle);
-	double ox,oy;
+
 	ox=extents.x_bearing+extents.width/2.;
 	oy=extents.y_bearing+extents.height/2.;
 	cairo_matrix_transform_point(&trans,&ox,&oy);
@@ -501,13 +517,13 @@
 	cairo_renderer *r = getCairoRenderer(image);
 
 	cairo_font_face_t *ff = getFontFace(r,style->font);
+        const char *string_ptr;
+        char s[11];
+        int i = 0;
 
     cairo_set_font_face(r->cr,ff);
     cairo_set_font_size(r->cr,style->size*96/72.0);
 
-    const char *string_ptr;
-    char s[11];
-    int i = 0;
 
     if (&style->outlinecolor != NULL && MS_VALID_COLOR(style->outlinecolor)) {
         msCairoSetSourceColor(r->cr, &style->outlinecolor);
@@ -565,6 +581,7 @@
 
 imageObj* msImageCreateCairo(int width, int height, outputFormatObj *format,colorObj* bg) {
 	imageObj *image = NULL;
+        cairo_renderer *r=NULL;
 	if (format->imagemode != MS_IMAGEMODE_RGB && format->imagemode!= MS_IMAGEMODE_RGBA) {
 		msSetError(MS_MISCERR,
 		"Cairo driver only supports RGB or RGBA pixel models.","msImageCreateCairo()");
@@ -572,7 +589,7 @@
 	}
 	if (width > 0 && height > 0) {
 		image = (imageObj *) calloc(1, sizeof(imageObj));
-		cairo_renderer *r = (cairo_renderer*)malloc(sizeof(cairo_renderer));
+		r = (cairo_renderer*)malloc(sizeof(cairo_renderer));
 		if(!strcasecmp(format->driver,"cairo/pdf")) {
             r->outputStream = (bufferObj*)malloc(sizeof(bufferObj));
             msBufferInit(r->outputStream);

Modified: sandbox/graphics/mapimageio.c
===================================================================
--- sandbox/graphics/mapimageio.c	2009-04-14 13:39:42 UTC (rev 8908)
+++ sandbox/graphics/mapimageio.c	2009-04-14 17:32:36 UTC (rev 8909)
@@ -88,6 +88,8 @@
   	struct jpeg_compress_struct cinfo;
 	struct jpeg_error_mgr jerr;
     ms_destination_mgr *dest;
+    JSAMPLE *rowdata; 
+    unsigned int row;
     cinfo.err = jpeg_std_error(&jerr);
     jpeg_create_compress(&cinfo);
 
@@ -121,8 +123,7 @@
     jpeg_set_quality(&cinfo, quality, TRUE);
     jpeg_start_compress(&cinfo, TRUE);
 
-    JSAMPLE *rowdata = (JSAMPLE*)malloc(data->width*cinfo.input_components*sizeof(JSAMPLE));
-    unsigned int row;
+    rowdata = (JSAMPLE*)malloc(data->width*cinfo.input_components*sizeof(JSAMPLE));
     for(row=0;row<data->height;row++) {
         JSAMPLE *pixptr = rowdata;
         int col;
@@ -150,13 +151,16 @@
 }
 
 int saveAsPNG(rasterBufferObj *data, streamInfo *info) {
-    
+    png_infop info_ptr; 
+    int color_type;
+    int row;
+    unsigned int *rowdata;
     png_structp png_ptr = png_create_write_struct(
             PNG_LIBPNG_VER_STRING, NULL,NULL,NULL);
     if (!png_ptr)
         return (MS_FAILURE);
 
-    png_infop info_ptr = png_create_info_struct(png_ptr);
+    info_ptr = png_create_info_struct(png_ptr);
     if (!info_ptr)
     {
         png_destroy_write_struct(&png_ptr,
@@ -174,7 +178,6 @@
     else
         png_set_write_fn(png_ptr,info, png_write_data_to_buffer, png_flush_data);
 
-    int color_type;
     if(data->a)
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
     else
@@ -189,8 +192,7 @@
     if(!data->a && data->pixel_step==4)
        png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
 
-    int row;
-    unsigned int *rowdata = (unsigned int*)malloc(data->width*sizeof(unsigned int));
+    rowdata = (unsigned int*)malloc(data->width*sizeof(unsigned int));
     for(row=0;row<data->height;row++) {
         unsigned int *pixptr = rowdata;
         int col;

Modified: sandbox/graphics/mapoutput.c
===================================================================
--- sandbox/graphics/mapoutput.c	2009-04-14 13:39:42 UTC (rev 8908)
+++ sandbox/graphics/mapoutput.c	2009-04-14 17:32:36 UTC (rev 8909)
@@ -393,6 +393,17 @@
     if( msSelectOutputFormat( map, "svg" ) == NULL )
         msCreateDefaultOutputFormat( map, "svg" );
 
+#if defined(USE_CAIRO)
+    if( msSelectOutputFormat( map, "cairopng24" ) == NULL )
+        msCreateDefaultOutputFormat( map, "CAIRO/PNG" );
+    if( msSelectOutputFormat( map, "cairojpeg" ) == NULL )
+        msCreateDefaultOutputFormat( map, "CAIRO/JPEG" );
+    if( msSelectOutputFormat( map, "cairopdf" ) == NULL )
+        msCreateDefaultOutputFormat( map, "CAIRO/PDF" );
+    if( msSelectOutputFormat( map, "cairosvg" ) == NULL )
+        msCreateDefaultOutputFormat( map, "CAIRO/SVG" );
+#endif
+
     if( map->imagetype != NULL )
         free( map->imagetype );
     map->imagetype = saved_imagetype;

Modified: sandbox/graphics/maprendering.c
===================================================================
--- sandbox/graphics/maprendering.c	2009-04-14 13:39:42 UTC (rev 8908)
+++ sandbox/graphics/maprendering.c	2009-04-14 17:32:36 UTC (rev 8909)
@@ -300,6 +300,7 @@
 
 rasterBufferObj *loadGDImg(gdImagePtr img) {
     rasterBufferObj *b = malloc(sizeof(rasterBufferObj));
+    int row,col;
     b->width = img->sx;
 	b->height = img->sy;
     b->pixelbuffer  = (unsigned char*)malloc(b->width*b->height*sizeof(int));
@@ -310,7 +311,6 @@
     b->b = &b->pixelbuffer[2];
     b->a = &b->pixelbuffer[3];
 
-	int row,col;
 	for (row = 0; row < b->height; row++) {
 		unsigned char* rowptr = &(b->pixelbuffer[row*b->row_step]);
 		for (col = 0; col < b->width; col++) {
@@ -717,14 +717,14 @@
 int msDrawText(imageObj *image, pointObj labelPnt, char *string,
 		labelObj *label, fontSetObj *fontset, double scalefactor) {
 	int nReturnVal = -1;
-	if (image) {
+        labelStyleObj s;
+ 	if (image) {
 		if (MS_RENDERER_PLUGIN(image->format)) {
 			renderObj *r = image->format->r;
             double x, y;
 			if (!string || !strlen(string))
 				return (0); // not errors, just don't want to do anything
             
-            labelStyleObj s;
             
             computeLabelStyle(&s,label,fontset,scalefactor);
 			x = labelPnt.x;
@@ -758,14 +758,13 @@
 int msDrawTextLine(imageObj *image, char *string, labelObj *label, labelPathObj *labelpath, fontSetObj *fontset, double scalefactor)
 {
     int nReturnVal = -1;
-
     if(image) {
         if (MS_RENDERER_PLUGIN(image->format)) {
             renderObj *r = image->format->r;
+            labelStyleObj s;
             if (!string || !strlen(string))
                 return (0); // not errors, just don't want to do anything
 
-            labelStyleObj s;
 
             computeLabelStyle(&s,label,fontset,scalefactor);
             if (label->type == MS_TRUETYPE) {

Modified: sandbox/graphics/mapserver.h
===================================================================
--- sandbox/graphics/mapserver.h	2009-04-14 13:39:42 UTC (rev 8908)
+++ sandbox/graphics/mapserver.h	2009-04-14 17:32:36 UTC (rev 8909)
@@ -2579,8 +2579,8 @@
 
 inline void msBufferInit(bufferObj *buffer);
 inline void msBufferResize(bufferObj *buffer, size_t target_size);
-inline void msBufferFree(bufferObj *buffer);
-inline void msBufferAppend(bufferObj *buffer, void *data, size_t length);
+MS_DLL_EXPORT  inline void msBufferFree(bufferObj *buffer);
+MS_DLL_EXPORT  inline void msBufferAppend(bufferObj *buffer, void *data, size_t length);
 
 struct renderer{
 	void *renderer_data;

Modified: sandbox/graphics/maputil.c
===================================================================
--- sandbox/graphics/maputil.c	2009-04-14 13:39:42 UTC (rev 8908)
+++ sandbox/graphics/maputil.c	2009-04-14 17:32:36 UTC (rev 8909)
@@ -773,11 +773,11 @@
 {
     *size_ptr = 0;
     if( MS_RENDERER_PLUGIN(image->format)){
+        rasterBufferObj data;
         renderObj *r = image->format->r;
         if(r->supports_pixel_buffer) {
             bufferObj buffer;
             msBufferInit(&buffer);
-            rasterBufferObj data;
             r->getRasterBuffer(image,&data);
             msSaveRasterBufferToBuffer(&data,&buffer,format);
             return buffer.data;



More information about the mapserver-commits mailing list