[mapserver-commits] r8429 - sandbox/graphics

svn at osgeo.org svn at osgeo.org
Tue Jan 13 07:46:15 EST 2009


Author: toby
Date: 2009-01-13 07:46:15 -0500 (Tue, 13 Jan 2009)
New Revision: 8429

Modified:
   sandbox/graphics/Makefile.in
   sandbox/graphics/configure
   sandbox/graphics/configure.in
   sandbox/graphics/mapogl.cpp
   sandbox/graphics/mapoglrenderer.cpp
   sandbox/graphics/mapoglrenderer.h
Log:
Added OpenGL label rendering with FTGL


Modified: sandbox/graphics/Makefile.in
===================================================================
--- sandbox/graphics/Makefile.in	2009-01-13 06:20:12 UTC (rev 8428)
+++ sandbox/graphics/Makefile.in	2009-01-13 12:46:15 UTC (rev 8429)
@@ -73,7 +73,14 @@
 AGG_LIB=  @AGG_LIB@
 AGG_INC=  @AGG_INC@
 
+#
+# Optional Opengl Support.
+#
+FTGL=     @FTGL_ENABLED@
+FTGL_LIB=  @FTGL_LIB@
+FTGL_INC=  @FTGL_INC@
 
+
 #
 # Optional Opengl Support.
 #
@@ -244,7 +251,7 @@
 
 DEFINES = -DUSE_CAIRO $(IGNORE_MISSING_DATA) $(USE_POINT_Z_M) $(STRINGS) @ALL_ENABLED@ $(FRIBIDI)
 
-INCLUDES = $(REGEX_INC) $(PNG_INC) $(GD_INC) $(AGG_INC) $(OGL_INC) $(PDF_INC) $(PROJ_INC) $(TIFF_INC) $(JPEG_INC) $(EGIS_INC) \
+INCLUDES = $(REGEX_INC) $(PNG_INC) $(GD_INC) $(AGG_INC) $(OGL_INC) $(FTGL_INC) $(PDF_INC) $(PROJ_INC) $(TIFF_INC) $(JPEG_INC) $(EGIS_INC) \
         $(SDE_INC) $(GDAL_INC) $(POSTGIS_INC) $(MYGIS_INC) \
         $(CURL_INC) $(MING_INC) $(ORACLESPATIAL_INC) $(GEOS_INC) $(ICONV_INC) \
         $(FASTCGI_INC) $(ZLIB_INC) $(XML2_INC) $(FRIBIDI_INC) $(CAIRO_INC)
@@ -255,7 +262,7 @@
 CXXFLAGS = @CXXFLAGS@ $(FLAGS)
 
 # Link flags and shared libs only
-SUP_LIBS =  $(GD_LIB) $(AGG_LIB) $(OGL_LIB) $(PDF_LIB) $(TIFF_LIB) $(PROJ_LIBS) \
+SUP_LIBS =  $(GD_LIB) $(AGG_LIB) $(OGL_LIB) $(FTGL_LIB) $(PDF_LIB) $(TIFF_LIB) $(PROJ_LIBS) \
           $(JPEG_LIB) $(PNG_LIB) $(SDE_LIB) $(GDAL_LIB) $(MING_LIB) $(POSTGIS_LIB) \
 	  $(MYGIS_LIB) $(CURL_LIB) $(ORACLESPATIAL_LIB) $(GEOS_LIB) \
 	  $(THREAD_LIB) $(ICONV_LIB) $(FASTCGI_LIB) \

Modified: sandbox/graphics/configure
===================================================================
--- sandbox/graphics/configure	2009-01-13 06:20:12 UTC (rev 8428)
+++ sandbox/graphics/configure	2009-01-13 12:46:15 UTC (rev 8429)
@@ -693,6 +693,9 @@
 PDF_ENABLED
 PDF_INC
 PDF_LIB
+FTGL_ENABLED
+FTGL_INC
+FTGL_LIB
 OGL_ENABLED
 OGL_INC
 OGL_LIB
@@ -1407,6 +1410,7 @@
                           install dir).
   --without-pdf           Disable PDF support.
   --with-pdf[=DIR]        Include PDF support (DIR is PDFlib's install dir).
+  --with-ftgl[=DIR]        Include OpenGl support (DIR is OpenGL's install dir).
   --with-opengl[=DIR]        Include OpenGl support (DIR is OpenGL's install dir).
   --with-agg[=DIR]        Include AGG support (DIR is AGG's install dir).
   --with-experimental-png       Include experimental palette support for rgba png.
@@ -9112,7 +9116,99 @@
 LIBS="$ms_saved_LIBS"
 
 
+{ echo "$as_me:$LINENO: checking if FTGL support requested" >&5
+echo $ECHO_N "checking if FTGL support requested... $ECHO_C" >&6; }
 
+# Check whether --with-ftgl was given.
+if test "${with_ftgl+set}" = set; then
+  withval=$with_ftgl;
+fi
+
+
+if test "$with_ftgl" = "yes" ; then
+  with_ftgl="/usr"
+  { echo "$as_me:$LINENO: result: looking for ftgl libs in /usr" >&5
+echo "${ECHO_T}looking for ftgl libs in /usr" >&6; }
+fi
+if test -n "$with_ftgl" -a "$with_ftgl" != "no" ; then
+
+
+  if test -z "$with_ftgl" || echo "$with_ftgl" | grep '^/' >/dev/null ; then
+    FTGL_DIR="$with_ftgl"
+  else
+    FTGL_DIR="`pwd`/$with_ftgl"
+  fi
+
+
+  test -f $FTGL_DIR/include/FTGL/ftgl.h -a -f $FTGL_DIR/include/FTGL/FTGLTextureFont.h && FTGL_INCLUDE="-I$FTGL_DIR/include/FTGL/"
+
+  if test -z "$FTGL_INCLUDE" ; then
+      { { echo "$as_me:$LINENO: error: \"could not find ftgl.h in $FTGL_DIR/include/FTGL.\"" >&5
+echo "$as_me: error: \"could not find ftgl.h in $FTGL_DIR/include/FTGL.\"" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+
+  test -f $FTGL_DIR/lib/libftgl.so && FTGL_LIBDIR="$FTGL_DIR/lib"
+  test -f $FTGL_DIR/lib64/libftgl.so && FTGL_LIBDIR="$FTGL_DIR/lib64"
+
+  if test -z "$FTGL_LIBDIR" ; then
+      { { echo "$as_me:$LINENO: error: \"could not find libftgl in $FTGL_DIR.\"" >&5
+echo "$as_me: error: \"could not find libftgl in $FTGL_DIR.\"" >&2;}
+   { (exit 1); exit 1; }; }
+  fi
+
+
+
+    FTGL_ENABLED="-DUSE_FTGL"
+  FTGL_INC="$FTGL_INCLUDE"
+  FTGL_LIB="-L$FTGL_LIBDIR -lftgl"
+
+  if test ""$FTGL_LIBDIR"" != "/usr/lib"; then
+
+  if test -z ""$FTGL_LIBDIR"" || echo ""$FTGL_LIBDIR"" | grep '^/' >/dev/null ; then
+    ai_p=""$FTGL_LIBDIR""
+  else
+    ai_p="`pwd`/"$FTGL_LIBDIR""
+  fi
+
+
+  unique=`echo $ac_n "$ai_p$ac_c" | tr -c -d a-zA-Z0-9`
+  cmd="echo $ac_n \"\$LIBPATH$unique$ac_c\""
+  if test -n "$unique" && test "`eval $cmd`" = "" ; then
+    eval "LIBPATH$unique=set"
+
+      EXTRA_LIBS="$EXTRA_LIBS -L$ai_p"
+        RPATHS="$RPATHS ${ld_runpath_switch}$ai_p"
+
+  fi
+
+  fi
+
+
+  { echo "$as_me:$LINENO: result: using ftgl from $FTGL_DIR" >&5
+echo "${ECHO_T}using ftgl from $FTGL_DIR" >&6; }
+
+else
+
+  { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+
+fi
+
+FTGL_ENABLED=$FTGL_ENABLED
+
+FTGL_INC=$FTGL_INC
+
+FTGL_LIB=$FTGL_LIB
+
+
+
+ALL_ENABLED="$FTGL_ENABLED $ALL_ENABLED"
+ALL_INC="$FTGL_INC $ALL_INC"
+ALL_LIB="$FTGL_LIB $ALL_LIB"
+
+
+
 { echo "$as_me:$LINENO: checking if OGL support requested" >&5
 echo $ECHO_N "checking if OGL support requested... $ECHO_C" >&6; }
 
@@ -9130,7 +9226,15 @@
 fi
 if test -n "$with_opengl" -a "$with_opengl" != "no" ; then
 
+  if test -n "$FTGL_LIB" ; then
+     FT_INC=`$FTGL_LIB --cflags`
+  else
+     { { echo "$as_me:$LINENO: error: FTGL required for opengl support - please configure --with-ftgl." >&5
+echo "$as_me: error: FTGL required for opengl support - please configure --with-ftgl." >&2;}
+   { (exit 1); exit 1; }; }
+  fi
 
+
   if test -z "$with_opengl" || echo "$with_opengl" | grep '^/' >/dev/null ; then
     OGL_DIR="$with_opengl"
   else
@@ -14037,6 +14141,9 @@
 PDF_ENABLED!$PDF_ENABLED$ac_delim
 PDF_INC!$PDF_INC$ac_delim
 PDF_LIB!$PDF_LIB$ac_delim
+FTGL_ENABLED!$FTGL_ENABLED$ac_delim
+FTGL_INC!$FTGL_INC$ac_delim
+FTGL_LIB!$FTGL_LIB$ac_delim
 OGL_ENABLED!$OGL_ENABLED$ac_delim
 OGL_INC!$OGL_INC$ac_delim
 OGL_LIB!$OGL_LIB$ac_delim
@@ -14051,9 +14158,6 @@
 EPPL_ENABLED!$EPPL_ENABLED$ac_delim
 EPPL_OBJ!$EPPL_OBJ$ac_delim
 PROJ_ENABLED!$PROJ_ENABLED$ac_delim
-PROJ_INC!$PROJ_INC$ac_delim
-PROJ_LIBS!$PROJ_LIBS$ac_delim
-THREAD_FLAG!$THREAD_FLAG$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -14095,6 +14199,9 @@
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+PROJ_INC!$PROJ_INC$ac_delim
+PROJ_LIBS!$PROJ_LIBS$ac_delim
+THREAD_FLAG!$THREAD_FLAG$ac_delim
 THREAD_LIB!$THREAD_LIB$ac_delim
 SDE_ENABLED!$SDE_ENABLED$ac_delim
 SDE_INC!$SDE_INC$ac_delim
@@ -14175,7 +14282,7 @@
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 78; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 81; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5

Modified: sandbox/graphics/configure.in
===================================================================
--- sandbox/graphics/configure.in	2009-01-13 06:20:12 UTC (rev 8428)
+++ sandbox/graphics/configure.in	2009-01-13 12:46:15 UTC (rev 8429)
@@ -803,7 +803,61 @@
 dnl Restore LIBS environment to state at beginning of PDF tests.
 LIBS="$ms_saved_LIBS"
 
+dnl ---------------------------------------------------------------------
+dnl FTGL Support.
+dnl ---------------------------------------------------------------------
 
+AC_MSG_CHECKING(if FTGL support requested)
+AC_ARG_WITH(ftgl,
+[  --with-ftgl[[=DIR]]        Include OpenGl support (DIR is OpenGL's install dir).],,)
+
+if test "$with_ftgl" = "yes" ; then
+  with_ftgl="/usr"
+  AC_MSG_RESULT([looking for ftgl libs in /usr])
+fi
+if test -n "$with_ftgl" -a "$with_ftgl" != "no" ; then
+
+  AC_EXPAND_PATH($with_ftgl, FTGL_DIR)
+
+  test -f $FTGL_DIR/include/FTGL/ftgl.h -a -f $FTGL_DIR/include/FTGL/FTGLTextureFont.h && FTGL_INCLUDE="-I$FTGL_DIR/include/FTGL/"
+
+  if test -z "$FTGL_INCLUDE" ; then
+      AC_MSG_ERROR("could not find ftgl.h in $FTGL_DIR/include/FTGL.")
+  fi
+  
+  test -f $FTGL_DIR/lib/libftgl.so && FTGL_LIBDIR="$FTGL_DIR/lib"
+  test -f $FTGL_DIR/lib64/libftgl.so && FTGL_LIBDIR="$FTGL_DIR/lib64"
+   
+  if test -z "$FTGL_LIBDIR" ; then
+      AC_MSG_ERROR("could not find libftgl in $FTGL_DIR.")
+  fi
+
+  
+
+  dnl If we got this far all is well!
+  FTGL_ENABLED="-DUSE_FTGL"
+  FTGL_INC="$FTGL_INCLUDE"
+  FTGL_LIB="-L$FTGL_LIBDIR -lftgl"
+  AC_ADD_RUNPATH("$FTGL_LIBDIR")
+  
+  AC_MSG_RESULT([using ftgl from $FTGL_DIR])
+  
+else
+
+  AC_MSG_RESULT([no])
+
+fi
+
+AC_SUBST(FTGL_ENABLED,$FTGL_ENABLED)
+AC_SUBST(FTGL_INC,    $FTGL_INC)
+AC_SUBST(FTGL_LIB,    $FTGL_LIB)
+
+
+ALL_ENABLED="$FTGL_ENABLED $ALL_ENABLED"
+ALL_INC="$FTGL_INC $ALL_INC"
+ALL_LIB="$FTGL_LIB $ALL_LIB"
+
+
 dnl ---------------------------------------------------------------------
 dnl Optional OGL Support.
 dnl ---------------------------------------------------------------------
@@ -819,6 +873,12 @@
 fi
 if test -n "$with_opengl" -a "$with_opengl" != "no" ; then
 
+  if test -n "$FTGL_LIB" ; then
+     FT_INC=`$FTGL_LIB --cflags`
+  else
+     AC_MSG_ERROR([FTGL required for opengl support - please configure --with-ftgl.])
+  fi
+  
   AC_EXPAND_PATH($with_opengl, OGL_DIR)
 
   test -f $OGL_DIR/include/GL/gl.h -a -f $OGL_DIR/include/GL/glx.h -a -f $OGL_DIR/include/GL/glu.h && OGL_INCLUDE="-I$OGL_DIR/include"

Modified: sandbox/graphics/mapogl.cpp
===================================================================
--- sandbox/graphics/mapogl.cpp	2009-01-13 06:20:12 UTC (rev 8428)
+++ sandbox/graphics/mapogl.cpp	2009-01-13 12:46:15 UTC (rev 8429)
@@ -223,44 +223,21 @@
 
 #define CAIROLINESPACE 1.33
 
-int msGetTruetypeTextBBoxOgl(imageObj *img, char *font, double size,
-		char *string, rectObj *rect, double **advances)
+int msGetTruetypeTextBBoxOgl(imageObj *img, char *font, double size, char *string, rectObj *rect, double **advances)
 {
-	//	cairo_renderer *r = getCairoRenderer(img);
-	//
-	//	cairo_font_face_t *ff = getFontFace(r,font);
-	//
-	//	int numlines, i;
-	//	char **lines = msStringSplit(string, '\n', &numlines);
-	//	cairo_text_extents_t extents;
-	//
-	//	cairo_set_font_face(r->cr, ff);
-	//	cairo_set_font_size(r->cr, size * 96 / 72.0);
-	//
-	//	for(i=0;i<numlines;i++) {
-	//		cairo_text_extents(r->cr, lines[i], &extents);
-	//		if(i==0) {
-	//			rect->minx = extents.x_bearing;
-	//			rect->miny = extents.y_bearing;
-	//			rect->maxx = extents.x_bearing+extents.width;
-	//			rect->maxy = extents.y_bearing+extents.height;
-	//		} else {
-	//			rect->minx = MS_MIN(rect->minx,extents.x_bearing);
-	//			rect->miny = MS_MIN(rect->miny,extents.y_bearing);
-	//			rect->maxy += CAIROLINESPACE*size;
-	//			rect->maxx = MS_MAX(rect->maxx,extents.x_bearing+extents.width);
-	//		}
-	//	}
-	//
-	//	msFreeCharArray(lines,numlines);
-	//	return MS_SUCCESS;
+	OglRenderer* renderer = getOglRenderer(img);
+	renderer->getStringBBox(font, size, string, rect);
+	return 0;
 }
 
+
 void msRenderGlyphsOgl(imageObj *img, double x, double y, colorObj *c,
 		colorObj *outlinecolor, double size, char *font, char *thechars,
 		double angle, colorObj *shadowcolor, double shdx, double shdy,
 		int outlinewidth)
 {
+	OglRenderer* renderer = getOglRenderer(img);
+	renderer->renderGlyphs(x, y, c, outlinecolor, size, font, thechars, angle, shadowcolor, shdx, shdy);
 	//	cairo_renderer *r = getCairoRenderer(img);
 	//
 	//	cairo_font_face_t *ff = getFontFace(r,font);

Modified: sandbox/graphics/mapoglrenderer.cpp
===================================================================
--- sandbox/graphics/mapoglrenderer.cpp	2009-01-13 06:20:12 UTC (rev 8428)
+++ sandbox/graphics/mapoglrenderer.cpp	2009-01-13 12:46:15 UTC (rev 8429)
@@ -89,6 +89,32 @@
 	return in + 1;
 }
 
+FTFont* OglRenderer::getFTFont(char* font, double size)
+{
+	FTFont** face = &fontCache[font][size];
+	if (*face == NULL)
+	{
+		*face = new FTGLTextureFont( font );
+		(*face)->FaceSize(size*SIZE_RES);
+		(*face)->Render("ABCDEFGHIJKLMNOPQRSTUVWXZYabcdefghijklmnopqrstuvwxyz");
+	}
+	return *face;
+}
+
+void OglRenderer::getStringBBox(char *font, double size, char *string, rectObj *rect)
+{
+	FTFont* face = getFTFont(font, size);
+	float llx =0.0f, lly=0.0f, llz=0.0f, urx=0.0f, ury=0.0f, urz=0.0f;
+	glPushAttrib( GL_ALL_ATTRIB_BITS );
+	face->BBox(string, llx, lly, llz, urx, ury, urz);
+	glPopAttrib();
+
+	rect->minx = llx;
+	rect->maxx = urx;
+	rect->miny = -ury;
+	rect->maxy = -lly;
+}
+
 bool OglRenderer::loadClass(classObj* cl, mapObj *map)
 {
 	for (int i = 0; i < cl->numstyles; i++)
@@ -376,22 +402,6 @@
 
 }
 
-/*
- ** Free gdImagePtr // TODO
- */
-void msFreeImageOGL(imageObj *img)
-{
-	/*delete (OglContext*)img->imageextra;
-	 if( img->img.gd != NULL ) {
-	 if ( img->img.gd->tpixels != NULL ) {
-	 delete[] img->img.gd->tpixels[0];
-	 gdFree( img->img.gd->tpixels );
-	 img->img.gd->tpixels = NULL;
-	 }
-	 msFreeImageGD(img->img.gd);
-	 }*/
-}
-
 void OglRenderer::attach(imageObj* img)
 {
 	int* buffer = new int[4 * img->width * img->height];
@@ -686,7 +696,7 @@
 
 void OglRenderer::setColor(colorObj *color)
 {
-	glColor4d((double) color->red / 255, (double) color->green / 255, (double) color->blue / 255, ((double)(color->alpha / 100)) * transparency);
+	glColor4d((double) color->red / 255, (double) color->green / 255, (double) color->blue / 255, ((double)(color->alpha / 100)));
 }
 
 ///render a shape represented by an agg::path_storage
@@ -815,12 +825,11 @@
 ///     given x,y (false), or if the text should be centered on x,y (true).
 ///     when set to true, will only center the text if this one is a single character
 int OglRenderer::renderGlyphs(double x, double y, colorObj *color,
-		colorObj *outlinecolor, labelObj* label, char *thechars, double angle,
-		colorObj *shadowcolor, double shdx, double shdy, bool isMarker,
-		bool isUTF8Encoded)
+		colorObj *outlinecolor, double size, char* font, char *thechars, double angle,
+		colorObj *shadowcolor, double shdx, double shdy)
 {
 
-	FTFont* face = NULL;//(FTFont*)(label->face);
+	FTFont* face = getFTFont(font, size);
 
 	glPushMatrix();
 	glTranslated(floor(x), floor(y), 0);

Modified: sandbox/graphics/mapoglrenderer.h
===================================================================
--- sandbox/graphics/mapoglrenderer.h	2009-01-13 06:20:12 UTC (rev 8428)
+++ sandbox/graphics/mapoglrenderer.h	2009-01-13 12:46:15 UTC (rev 8429)
@@ -7,6 +7,7 @@
 #include <vector>
 #include <map>
 #include <FTGL/ftgl.h>
+#include <FTGL/FTGLTextureFont.h>
 
 #include "mapoglcontext.h"
 #include "mapserver.h"
@@ -33,10 +34,9 @@
             int lineCap=MS_CJC_ROUND,
             int joinStyle=MS_CJC_ROUND);
 
-	int renderGlyphs(double x, double y, colorObj *color, colorObj *outlinecolor,
-            labelObj* label, char *thechars, double angle=0,
-            colorObj *shadowcolor=NULL, double shdx=1, double shdy=1,
-            bool isMarker=false, bool isUTF8Encoded=false);
+	int renderGlyphs(double x, double y, colorObj *color,
+			colorObj *outlinecolor, double size, char* font, char *thechars, double angle,
+			colorObj *shadowcolor, double shdx, double shdy);
 
 	void renderPolylineVectorSymbol(shapeObj *shape, symbolObj *symbol, styleObj* style,
             int tilewidth, int tileheight,
@@ -49,6 +49,7 @@
     void renderEllipse(double x, double y, double w, double h, colorObj *color, colorObj *outlinecolor, double outlinewidth);
     void renderPathSolidClipped(int *pattern, shapeObj *clipper, colorObj *color);
     void renderPathTiledPixmapBGRA(shapeObj *path, int *tile);
+    void getStringBBox(char *font, double size, char *string, rectObj *rect);
 
     void setTransparency(double transparency);
 
@@ -57,6 +58,7 @@
 	typedef std::map<char*,std::map<double,FTFont*> > fontCache_t;
     typedef std::map<symbolObj*,std::map<double,GLuint> > dashCache_t;
 
+    FTFont* getFTFont(char* font, double size);
     bool loadLabel(labelObj *label, fontSetObj *fontset, classObj *cl);
     bool loadSymbol(symbolObj *symbol);
     bool loadClass(classObj *cl, mapObj *map);



More information about the mapserver-commits mailing list