[mapserver-commits] r10237 - sandbox/mapserver6

svn at osgeo.org svn at osgeo.org
Fri Jun 18 07:51:16 EDT 2010


Author: tbonfort
Date: 2010-06-18 11:51:15 +0000 (Fri, 18 Jun 2010)
New Revision: 10237

Modified:
   sandbox/mapserver6/mapagg2.cpp
   sandbox/mapserver6/mapdraw.c
   sandbox/mapserver6/mapgd2.c
Log:
gd bitmap fonts
agg bitmap font baseline


Modified: sandbox/mapserver6/mapagg2.cpp
===================================================================
--- sandbox/mapserver6/mapagg2.cpp	2010-06-18 09:27:36 UTC (rev 10236)
+++ sandbox/mapserver6/mapagg2.cpp	2010-06-18 11:51:15 UTC (rev 10237)
@@ -82,19 +82,19 @@
 static color_type AGG_NO_COLOR = color_type(0, 0, 0, 0);
 
 const mapserver::int8u* rasterfonts[]= { 
-        mapserver::verdana12, /*gd tiny. gse5x7 is a bit less high than gd tiny*/
-        mapserver::verdana13, /*gd small*/
-        mapserver::verdana13_bold, /*gd medium*/
-        mapserver::verdana16, /*gd large*/
-        mapserver::verdana16_bold /*gd huge*/
+        mapserver::mcs5x10_mono, /*gd tiny. gse5x7 is a bit less high than gd tiny*/
+        mapserver::mcs5x11_mono, /*gd small*/
+        mapserver::mcs6x11_mono, /*gd medium*/
+        mapserver::mcs7x12_mono_low, /*gd large*/
+        mapserver::mcs7x12_mono_high /*gd huge*/
 };
 
-fontMetrics rasterfont_sizes[] = { //the width here are an approximation. (not fixed width fonts)
-        {6,10},
-        {7,11},
-        {8,11},
-        {8,13}, 
-        {9,13}
+fontMetrics rasterfont_sizes[] = {
+        {5,mapserver::mcs5x10_mono[0]},
+        {5,mapserver::mcs5x11_mono[0]},
+        {6,mapserver::mcs6x11_mono[0]},
+        {7,mapserver::mcs7x12_mono_low[0]}, 
+        {7,mapserver::mcs7x12_mono_high[0]}
 };
 
 inline static color_type aggColor(colorObj *c) {
@@ -342,7 +342,7 @@
 	}
 	color_type color = aggColor(&(style->color));
 	color_type ocolor = aggColor(&(style->outlinecolor));
-		
+	y -= glyph.base_line();
 	for(int n=0;n<numlines;n++) {
 		len = strlen(lines[n]);
 		for (int i = 0; i < len; i++)

Modified: sandbox/mapserver6/mapdraw.c
===================================================================
--- sandbox/mapserver6/mapdraw.c	2010-06-18 09:27:36 UTC (rev 10236)
+++ sandbox/mapserver6/mapdraw.c	2010-06-18 11:51:15 UTC (rev 10237)
@@ -2210,9 +2210,13 @@
     billboard.line->point = billboard_points;
     initStyle(&style);
   }
-  size = label->size * scalefactor;
-  size = MS_MAX(size, label->minsize*image->resolutionfactor);
-  size = MS_MIN(size, label->maxsize*image->resolutionfactor);
+  if(label->type == MS_TRUETYPE){
+     size = label->size * scalefactor;
+     size = MS_MAX(size, label->minsize*image->resolutionfactor);
+     size = MS_MIN(size, label->maxsize*image->resolutionfactor);
+  } else {
+     size = label->size;
+  }
   if(msGetLabelSize(map, label, string, size, &r, NULL)!= MS_SUCCESS)
 	  return MS_FAILURE;
 
@@ -2326,10 +2330,14 @@
 
           if(!cachePtr->text || strlen(cachePtr->text) == 0)
             continue; /* not an error, just don't want to do anything */
-          size = labelPtr->size * layerPtr->scalefactor;
-          size = MS_MAX(size, labelPtr->minsize*image->resolutionfactor);
-          size = MS_MIN(size, labelPtr->maxsize*image->resolutionfactor);
-          scalefactor = size / labelPtr->size;
+          if(labelPtr->type == MS_TRUETYPE) {
+             size = labelPtr->size * layerPtr->scalefactor;
+             size = MS_MAX(size, labelPtr->minsize*image->resolutionfactor);
+             size = MS_MIN(size, labelPtr->maxsize*image->resolutionfactor);
+             scalefactor = size / labelPtr->size;
+          } else {
+             size = labelPtr->size;
+          }
           if(msGetLabelSize(map,labelPtr,cachePtr->text,size,&r,NULL) != MS_SUCCESS)
             return(-1);
 

Modified: sandbox/mapserver6/mapgd2.c
===================================================================
--- sandbox/mapserver6/mapgd2.c	2010-06-18 09:27:36 UTC (rev 10236)
+++ sandbox/mapserver6/mapgd2.c	2010-06-18 11:51:15 UTC (rev 10237)
@@ -29,6 +29,11 @@
 #include "mapserver.h"
 #include "mapthread.h"
 #include <time.h>
+#include <gdfonts.h>
+#include <gdfontl.h>
+#include <gdfontt.h>
+#include <gdfontmb.h>
+#include <gdfontg.h>
 
 #ifdef _WIN32
 #include <fcntl.h>
@@ -37,6 +42,8 @@
 
 #define MS_IMAGE_GET_GDIMAGEPTR(image) ((gdImagePtr) image->img.plugin)
 
+fontMetrics bitmapFontMetricsGD[5];
+
 int msImageSetPenGD(gdImagePtr img, colorObj *color) 
 {
   if(MS_VALID_COLOR(*color))
@@ -843,6 +850,57 @@
 #endif
 }
 
+int renderBitmapGlyphsGD(imageObj *img, double x, double y, labelStyleObj *style, char *text) {
+   int size = MS_NINT(style->size);
+   gdFontPtr fontPtr;
+   gdImagePtr ip;
+   int numlines=0,t;
+   char **lines;
+   if(!(ip = MS_IMAGE_GET_GDIMAGEPTR(img))) return MS_FAILURE;
+   if(size<0 || size>4 || (fontPtr = msGetBitmapFont(size))==NULL) {
+      msSetError(MS_RENDERERERR,"invalid bitmap font size", "renderBitmapGlyphsGD()");
+      return MS_FAILURE;
+   }
+   
+   if(style->color.pen == MS_PEN_UNSET) setPen(ip, &(style->color));
+   if(style->outlinecolor.pen == MS_PEN_UNSET) setPen(ip, &(style->outlinecolor));
+   if(style->shadowcolor.pen == MS_PEN_UNSET) setPen(ip, &(style->shadowcolor));
+   
+   if(msCountChars(text,'\n')) {
+      if((lines = msStringSplit((const char*)text, '\n', &(numlines))) == NULL)
+         return(-1);
+   } else {
+      lines = &text;
+      numlines = 1;
+   }
+
+   y -= fontPtr->h;
+   for(t=0; t<numlines; t++) {
+      if(style->outlinecolor.pen >= 0) {    
+         gdImageString(ip, fontPtr, x, y-1, (unsigned char *) lines[t], style->outlinecolor.pen);
+         gdImageString(ip, fontPtr, x, y+1, (unsigned char *) lines[t], style->outlinecolor.pen);
+         gdImageString(ip, fontPtr, x+1, y, (unsigned char *) lines[t], style->outlinecolor.pen);
+         gdImageString(ip, fontPtr, x-1, y, (unsigned char *) lines[t], style->outlinecolor.pen);
+         gdImageString(ip, fontPtr, x+1, y-1, (unsigned char *) lines[t], style->outlinecolor.pen);
+         gdImageString(ip, fontPtr, x+1, y+1, (unsigned char *) lines[t], style->outlinecolor.pen);
+         gdImageString(ip, fontPtr, x-1, y-1, (unsigned char *) lines[t], style->outlinecolor.pen);
+         gdImageString(ip, fontPtr, x-1, y+1, (unsigned char *) lines[t], style->outlinecolor.pen);
+      }
+
+      if(style->shadowcolor.pen >= 0)
+         gdImageString(ip, fontPtr, x+style->shadowsizex, y+style->shadowsizey, (unsigned char *) lines[t], style->shadowcolor.pen);
+
+      gdImageString(ip, fontPtr, x, y, (unsigned char *) lines[t], style->color.pen);
+
+      y += fontPtr->h; /* shift down */
+   }
+
+
+   if(*lines != text)
+      msFreeCharArray(lines, numlines);
+   return MS_SUCCESS;
+}
+
 /*
 ** Misc. cleanup functions for GD driver.
 */
@@ -856,9 +914,20 @@
 }
 
 int msPopulateRendererVTableGD( rendererVTableObj *renderer ) {
-  renderer->supports_imagecache=0;
+  int i;
+   renderer->supports_imagecache=0;
   renderer->supports_pixel_buffer=1;
   renderer->supports_transparent_layers = 0;
+  renderer->supports_bitmap_fonts = 1;
+  
+  for(i=0;i<5;i++) {
+     gdFontPtr f = msGetBitmapFont(i);
+     bitmapFontMetricsGD[i].charWidth = f->w;
+     bitmapFontMetricsGD[i].charHeight = f->h;
+     renderer->bitmapFontMetrics[i] = &bitmapFontMetricsGD[i];
+  }
+    
+  
   renderer->startLayer = startNewLayerGD;
   renderer->endLayer = closeNewLayerGD;
   renderer->renderLine = &renderLineGD;
@@ -873,6 +942,7 @@
   renderer->renderPolygon = &renderPolygonGD;
   renderer->renderGlyphsLine = &renderGlyphsLineGD;
   renderer->renderGlyphs = &renderGlyphsGD;
+  renderer->renderBitmapGlyphs = &renderBitmapGlyphsGD;
   renderer->freeImage = &freeImageGD;
   renderer->renderEllipseSymbol = &renderEllipseSymbolGD;
   renderer->renderVectorSymbol = &renderVectorSymbolGD;



More information about the mapserver-commits mailing list