From 22b3e42f503d0900f333c7813c1ced0c1b8a6ef1 Mon Sep 17 00:00:00 2001
From: scuri 
Date: Fri, 25 Jun 2010 19:34:31 +0000
Subject: *** empty log message ***
---
 html/en/drv/gl.html         |   7 +-
 html/en/drv/irgb.html       |   2 +-
 include/cd_private.h        |   2 +
 mak.vc9/cd.sln              |   3 +
 mak.vc9/cd_freetype.vcproj  | 900 ++++++++++++++++++++++++++++++++++++++++++++
 src/cd.def                  |  13 +-
 src/cd_util.c               |  95 +++++
 src/cdgdk.def               |  45 ++-
 src/cdgl.mak                |  14 +-
 src/drv/cdgl.c              | 192 ++++++----
 src/ftgl/FTContour.cpp      |   3 +
 src/sim/cd_truetype.c       |  77 +---
 test/simple/gdiplustest.cpp | 116 ------
 test/simple/simple.c        |  41 +-
 test/simple/simple.led      |   2 +-
 test/simple/simple_led.c    |  43 +--
 16 files changed, 1228 insertions(+), 327 deletions(-)
 delete mode 100644 test/simple/gdiplustest.cpp
diff --git a/html/en/drv/gl.html b/html/en/drv/gl.html
index e7c07d5..a7e9883 100644
--- a/html/en/drv/gl.html
+++ b/html/en/drv/gl.html
@@ -48,7 +48,7 @@ must be set with the new size or cdCanvasGetSize will return an incorrect value.
   To use this driver, the application must be linked with the "cdgl", 
 	the ftgl library 
 	and the OpenGL library. The FTGL library is dependent also on the GLU 
-	library.
+	library. In UNIX cdgl is also dependent on iconv.
   In Lua, it is necessary to call function  cdluagl_open()  after a call 
   to function cdlua_open(), apart from linkediting with the "cdluagl" 
   library. This is not necessary if you do require"cdluagl". 
@@ -111,7 +111,10 @@ must be set with the new size or cdCanvasGetSize will return an incorrect value.
 	"Courier New", "Helvetica" is mapped to "Arial", and "Times" is mapped to 
 	"Times New Roman". In UNIX, "Courier" is mapped to 
 	"freemono", "Helvetica" is mapped to "freesans", and "Times" is mapped to 
-	"freeserif". Underline and Strikeout are NOT supported.
+	"freeserif". Underline and Strikeout are NOT supported. If not 
+	found then the font file is searched used the same logic of the Simulation 
+	driver, but ADDFONTMAP is not supported. If still is not 
+	found then the typeface is used as file name for the font. 
 
 Colors 
 
diff --git a/html/en/drv/irgb.html b/html/en/drv/irgb.html
index 5f6718e..f44a9d4 100644
--- a/html/en/drv/irgb.html
+++ b/html/en/drv/irgb.html
@@ -62,7 +62,7 @@ cd.ImageRGBBitmap(canvas: cdCanvas) -> (bitmap: cdBitmap) [in Lua]Behavior of Functions
 
-  All primitives are from the Simulation driver, see the Simulation driver's documentation for 
+  
All primitives are from the Simulation driver, see the Simulation driver documentation for 
   further information.
 
 Control
diff --git a/include/cd_private.h b/include/cd_private.h
index e6adef5..05395b2 100644
--- a/include/cd_private.h
+++ b/include/cd_private.h
@@ -273,10 +273,12 @@ int cdfCheckBoxSize(double *xmin, double *xmax, double *ymin, double *ymax);
 void cdNormalizeLimits(int w, int h, int *xmin, int *xmax, int *ymin, int *ymax);
 int cdGetFileName(const char* strdata, char* filename);
 int cdStrEqualNoCase(const char* str1, const char* str2);
+int cdStrEqualNoCasePartial(const char* str1, const char* str2);
 int cdStrLineCount(const char* str);
 char* cdStrDup(const char* str);
 char* cdStrDupN(const char* str, int len);
 void cdSetPaperSize(int size, double *w_pt, double *h_pt);
+int cdGetFontFileName(const char* font, char* filename);
 
 void cdCanvasPoly(cdCanvas* canvas, int mode, cdPoint* points, int n);
 void cdCanvasGetArcBox(int xc, int yc, int w, int h, double a1, double a2, int *xmin, int *xmax, int *ymin, int *ymax);
diff --git a/mak.vc9/cd.sln b/mak.vc9/cd.sln
index 7959a46..54e2f2b 100644
--- a/mak.vc9/cd.sln
+++ b/mak.vc9/cd.sln
@@ -137,6 +137,9 @@ EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cdluapdf52", "cdluapdf52.vcproj", "{B4823266-DF8C-ABC1-DF8C-12688C234EAC}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cdgl", "cdgl.vcproj", "{8441F69D-7135-AB59-1F94-4522123C8467}"
+	ProjectSection(ProjectDependencies) = postProject
+		{1D758EEA-59C3-46E4-BEF5-16DCCA8C0B21} = {1D758EEA-59C3-46E4-BEF5-16DCCA8C0B21}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ftgl", "cd_ftgl.vcproj", "{1D758EEA-59C3-46E4-BEF5-16DCCA8C0B21}"
 EndProject
diff --git a/mak.vc9/cd_freetype.vcproj b/mak.vc9/cd_freetype.vcproj
index 333d103..810fb75 100644
--- a/mak.vc9/cd_freetype.vcproj
+++ b/mak.vc9/cd_freetype.vcproj
@@ -276,6 +276,906 @@
 					>
 				
 			
+			
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+				
+			
 		
 		
+static int sReadStringKey(HKEY base_key, char* key_name, char* value_name, char* value)
+{
+	HKEY key;
+	DWORD max_size = 512;
+
+	if (RegOpenKeyEx(base_key, key_name, 0, KEY_READ, &key) != ERROR_SUCCESS)
+		return 0;
+
+  if (RegQueryValueEx(key, value_name, NULL, NULL, (LPBYTE)value, &max_size) != ERROR_SUCCESS)
+  {
+    RegCloseKey(key);
+		return 0;
+  }
+
+	RegCloseKey(key);
+	return 1;
+}
+
+static char* sGetFontDir(void)
+{
+  static char font_dir[512];
+  if (!sReadStringKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Fonts", font_dir))
+    return "";
+  else
+  {
+    int i, size = (int)strlen(font_dir);
+    for(i = 0; i < size; i++)
+    {
+      if (font_dir[i] == '\\')
+        font_dir[i] = '/';
+    }
+    return font_dir;
+  }
+}
+#endif
+
+int cdGetFontFileName(const char* font, char* filename)
+{
+  FILE *file;
+
+  /* current directory */
+  sprintf(filename, "%s.ttf", font);
+  file = fopen(filename, "r");
+
+  if (file)
+    fclose(file);
+  else
+  {
+    /* CD environment */
+    char* env = getenv("CDDIR");
+    if (env)
+    {
+      sprintf(filename, "%s/%s.ttf", env, font);
+      file = fopen(filename, "r");
+    }
+
+    if (file)
+      fclose(file);
+    else
+    {
+#ifdef WIN32
+      /* Windows Font folder */
+      sprintf(filename, "%s/%s.ttf", sGetFontDir(), font);
+      file = fopen(filename, "r");
+
+      if (file)
+        fclose(file);
+      else
+        return 0;
+#else
+      return 0;
+#endif
+    }
+  }
+
+  return 1;
+}
diff --git a/src/cdgdk.def b/src/cdgdk.def
index c240a3d..dba219a 100644
--- a/src/cdgdk.def
+++ b/src/cdgdk.def
@@ -17,15 +17,6 @@ EXPORTS
   cdContextDebug
   cdContextSVG
 
-  cdContextCairoImage
-  cdContextCairoImageRGB
-  cdContextCairoPS
-  cdContextCairoNativeWindow
-  cdContextCairoDBuffer
-  cdContextCairoSVG
-  cdContextCairoPDF
-  cdInitContextPlus
-  
   cdRedImage
   cdGreenImage
   cdBlueImage
@@ -201,7 +192,7 @@ EXPORTS
   wdVectorText
   wdMultiLineVectorText
   wdGetVectorTextBounds
-
+  
   cdLineStyleDashes
   cdRegionBox
   wdRegionBox
@@ -223,6 +214,15 @@ EXPORTS
   cdGetFontSizePixels
   cdGetFontSizePoints
   cdStrEqualNoCase
+  cdSetPaperSize
+  cdCanvasGetArcPath
+  cdfCanvasGetArcPath
+  cdCanvasGetArcPathF
+  cdCanvasGetArcBox
+  cdCanvasGetArcStartEnd
+  cdfCanvasGetArcStartEnd
+  cdStrEqualNoCasePartial
+  cdGetFontFileName
   
   wdCanvasLineWidth
   wdCanvasMarkSize
@@ -364,6 +364,7 @@ EXPORTS
   cdCanvasVectorTextDirection
   cdCanvasVectorTextSize
   cdCanvasVertex
+  cdCanvasPathSet
   
   cdfCanvasGetClipArea
   cdfCanvasArc
@@ -390,6 +391,28 @@ EXPORTS
   cdCanvasSetBackground
   cdCanvasTransformPoint
   cdfCanvasTransformPoint
-
+  cdRound
+  cdStrDup
+  
   cdInitContextPlusList
   cdGetContextPlus
+  
+  cdfSimPolyPath
+  cdSimArc
+  cdSimPolyPath
+  cdfRotatePoint
+  cdSimSector
+  cdfSimArc
+  cdfSimSector
+  cdfSimChord
+  cdSimChord
+
+  cdContextCairoImage
+  cdContextCairoImageRGB
+  cdContextCairoPS
+  cdContextCairoNativeWindow
+  cdContextCairoDBuffer
+  cdContextCairoSVG
+  cdContextCairoPDF
+  cdInitContextPlus
+  
diff --git a/src/cdgl.mak b/src/cdgl.mak
index 21a9b88..7b5f8e6 100644
--- a/src/cdgl.mak
+++ b/src/cdgl.mak
@@ -8,13 +8,25 @@ SRC = drv/cdgl.c
 INCLUDES = . sim ftgl freetype2
 LIBS = ftgl
 ifeq ($(findstring Win, $(TEC_SYSNAME)), )
-  LIBS += iconv
+#  LIBS += iconv
 endif
 
 USE_OPENGL = YES
 USE_CD = YES
 CD = ..
 
+ifneq ($(findstring AIX, $(TEC_UNAME)), )
+  NO_FONTCONFIG = Yes
+endif
+
+ifneq ($(findstring IRIX, $(TEC_UNAME)), )
+  NO_FONTCONFIG = Yes
+endif
+
+ifneq ($(findstring SunOS, $(TEC_UNAME)), )
+  NO_FONTCONFIG = Yes
+endif
+
 ifneq ($(findstring MacOS, $(TEC_UNAME)), )
   ifeq ($(TEC_SYSMINOR), 5)
     #Darwin9 Only - OpenGL bug fix for Fink, when the message bellow appears
diff --git a/src/drv/cdgl.c b/src/drv/cdgl.c
index 94b1367..4357e5a 100644
--- a/src/drv/cdgl.c
+++ b/src/drv/cdgl.c
@@ -57,7 +57,6 @@ struct _cdCtxCanvas
   cdCanvas* canvas;
 
   FTGLfont *font;
-  char fontfilename[10240];
 
   char* glLastConvertUTF8;
 
@@ -71,7 +70,7 @@ struct _cdCtxCanvas
 
 /******************************************************/
 
-static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, unsigned int len)
+static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, int len)
 {
   if (ctxcanvas->glLastConvertUTF8)
     free(ctxcanvas->glLastConvertUTF8);
@@ -102,7 +101,8 @@ static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, unsig
 	  /* Based on http://www.lemoda.net/c/iconv-example/iconv-example.html
 		   Last access: June 15th, 2010. */
     iconv_t cd;
-    unsigned int utf8len = len*2;
+    size_t ulen = (size_t)len;
+    size_t utf8len = ulen*2;
     char* utf8 = calloc(utf8len, 1);
 
     cd = iconv_open("UTF-8", "ISO-8859-1");
@@ -110,7 +110,7 @@ static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, unsig
       return (char*)str;
 
     ctxcanvas->glLastConvertUTF8 = utf8;
-		iconv(cd, (char**)&str, &len, &utf8, &utf8len);
+		iconv(cd, (char**)&str, &ulen, &utf8, &utf8len);
 
 		iconv_close(cd);
   }
@@ -347,6 +347,7 @@ static LONG cdglWGetNextNameValue(HKEY key, LPCTSTR subkey, LPTSTR szName, LPTST
       RegCloseKey(hkey);
   
     hkey = NULL;
+    dwIndex = 0;
     return ERROR_SUCCESS;
   }
 
@@ -382,43 +383,78 @@ static LONG cdglWGetNextNameValue(HKEY key, LPCTSTR subkey, LPTSTR szName, LPTST
   return retval;
 }
 
-static int cdglWGetFontFileName(LPCTSTR lpszFontName, int bold, int italic, char* fileName)
+static int sReadStringKey(HKEY base_key, char* key_name, char* value_name, char* value)
+{
+	HKEY key;
+	DWORD max_size = 512;
+
+	if (RegOpenKeyEx(base_key, key_name, 0, KEY_READ, &key) != ERROR_SUCCESS)
+		return 0;
+
+  if (RegQueryValueEx(key, value_name, NULL, NULL, (LPBYTE)value, &max_size) != ERROR_SUCCESS)
+  {
+    RegCloseKey(key);
+		return 0;
+  }
+
+	RegCloseKey(key);
+	return 1;
+}
+
+static char* sGetFontDir(void)
+{
+  static char font_dir[1024];
+  if (!sReadStringKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Fonts", font_dir))
+    return "";
+  else
+    return font_dir;
+}
+
+static int sGetFontFileName(const char *font_name, int bold, int italic, char* fileName)
 {
   TCHAR szName[2 * MAX_PATH];
   TCHAR szData[2 * MAX_PATH];
-  TCHAR displayName[2 * MAX_PATH];
   LPCTSTR strFont = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
   char localFontName[256];
   int bResult = 0;
 
-  sprintf(localFontName, "%s", lpszFontName);
+  if (cdStrEqualNoCase(font_name, "Courier") || cdStrEqualNoCase(font_name, "Monospace"))
+    font_name = "Courier New";
+  else if (cdStrEqualNoCase(font_name, "Times") || cdStrEqualNoCase(font_name, "Serif"))
+    font_name = "Times New Roman";
+  else if (cdStrEqualNoCase(font_name, "Helvetica") || cdStrEqualNoCase(font_name, "Sans"))
+    font_name = "Arial";
+
+  strcpy(localFontName, font_name);
 
-  if( bold )
+  if (bold)
     strcat(localFontName, " Bold");
 
-  if( italic )
+  if (italic)
     strcat(localFontName, " Italic");
 
   while (cdglWGetNextNameValue(HKEY_LOCAL_MACHINE, strFont, szName, szData) == ERROR_SUCCESS)
   {
-    if (_strnicmp(localFontName, szName, strlen(localFontName)) == 0)
+    if (cdStrEqualNoCasePartial(szName, localFontName))
     {
-      sprintf(displayName, "%s", szName);
-      sprintf(fileName, "%s", szData);
+      //"%s/%s.ttf"
+      sprintf(fileName, "%s\\%s", sGetFontDir(), szData);
       bResult = 1;
       break;
     }
-    strFont = "";
+    strFont = NULL;
   }
+
   /* close the registry key */
   cdglWGetNextNameValue(HKEY_LOCAL_MACHINE, NULL, NULL, NULL);
 
   return bResult;
 }
 #else
+#ifndef NO_FONTCONFIG
 #include 
 
-static int cdglXGetFontFileName(const char *font_name, int bold, int italic, char* fileName)
+static int sGetFontFileName(const char *font_name, int bold, int italic, char* fileName)
 {
   char styles[4][20];
   int style_size;
@@ -427,30 +463,37 @@ static int cdglXGetFontFileName(const char *font_name, int bold, int italic, cha
   FcPattern *pat;
   int bResult = 0;
 
+  if (cdStrEqualNoCase(font_name, "Courier") || cdStrEqualNoCase(font_name, "Courier New") || cdStrEqualNoCase(font_name, "Monospace"))
+    font_name = "freemono";
+  else if (cdStrEqualNoCase(font_name, "Times") || cdStrEqualNoCase(font_name, "Times New Roman")|| cdStrEqualNoCase(font_name, "Serif"))
+    font_name = "freeserif";
+  else if (cdStrEqualNoCase(font_name, "Helvetica") || cdStrEqualNoCase(font_name, "Arial") || cdStrEqualNoCase(font_name, "Sans"))
+    font_name = "freesans";
+
   if( bold && italic )
   {
-    sprintf(styles[0], "%s", "BoldItalic");
-    sprintf(styles[1], "%s", "Bold Italic");
-    sprintf(styles[2], "%s", "Bold Oblique");
-    sprintf(styles[3], "%s", "BoldOblique");
+    strcpy(styles[0], "BoldItalic");
+    strcpy(styles[1], "Bold Italic");
+    strcpy(styles[2], "Bold Oblique");
+    strcpy(styles[3], "BoldOblique");
     style_size = 4;
   }
   else if( bold )
   {
-    sprintf(styles[0], "%s", "Bold");
+    strcpy(styles[0], "Bold");
     style_size = 1;
   }
   else if( italic )
   {
-    sprintf(styles[0], "%s", "Italic");
-    sprintf(styles[1], "%s", "Oblique");
+    strcpy(styles[0], "Italic");
+    strcpy(styles[1], "Oblique");
     style_size = 2;
   }
   else
   {
-    sprintf(styles[0], "%s", "Regular");
-    sprintf(styles[1], "%s", "Normal");
-    sprintf(styles[2], "%s", "Medium");
+    strcpy(styles[0], "Regular");
+    strcpy(styles[1], "Normal");
+    strcpy(styles[2], "Medium");
     style_size = 3;
   }
 
@@ -474,22 +517,21 @@ static int cdglXGetFontFileName(const char *font_name, int bold, int italic, cha
       FcPatternGetString(fs->fonts[j], FC_STYLE, 0, &style );
       FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family );
 
-      if (strncasecmp(font_name, (char*)family, strlen(font_name)) == 0)
+      if (cdStrEqualNoCasePartial((char*)family, font_name))
       {
         /* check if the font is of the correct type. */
         for(s = 0; s < style_size; s++ )
         {
-          if (strcasecmp(styles[s], (char*)style ) == 0)
+          if (cdStrEqualNoCase(styles[s], (char*)style))
           {
-            sprintf(fileName, "%s", (char*)file);
+            strcpy(fileName, (char*)file);
             bResult = 1;
             FcFontSetDestroy (fs);
-
             return bResult;
           }
 
           /* set value to use if no more correct font of same family is found. */
-          sprintf(fileName, "%s", (char*)file);
+          strcpy(fileName, (char*)file);
           bResult = 1;
         }
       }
@@ -499,12 +541,22 @@ static int cdglXGetFontFileName(const char *font_name, int bold, int italic, cha
 
   return bResult;
 }
+#else
+static int sGetFontFileName(const char *font_name, int bold, int italic, char* fileName)
+{
+  (void)font_name;
+  (void)bold;
+  (void)italic;
+  (void)fileName;
+  return 0;
+}
+#endif
 #endif
 
 static int cdfont(cdCtxCanvas *ctxcanvas, const char *typeface, int style, int size)
 {
   int is_italic = 0, is_bold = 0;   /* default is CD_PLAIN */
-  char strFontFileName[256];
+  char strFontFileName[10240];
 
   if (style & CD_BOLD)
     is_bold = 1;
@@ -512,34 +564,44 @@ static int cdfont(cdCtxCanvas *ctxcanvas, const char *typeface, int style, int s
   if (style & CD_ITALIC)
     is_italic = 1;
 
-#ifdef WIN32
-  if (cdStrEqualNoCase(typeface, "Courier") || cdStrEqualNoCase(typeface, "Monospace"))
-    typeface = "Courier New";
-  else if (cdStrEqualNoCase(typeface, "Times") || cdStrEqualNoCase(typeface, "Serif"))
-    typeface = "Times New Roman";
-  else if (cdStrEqualNoCase(typeface, "Helvetica") || cdStrEqualNoCase(typeface, "Sans"))
-    typeface = "Arial";
-
-  if(!cdglWGetFontFileName(typeface, is_bold, is_italic, strFontFileName))
-    return 0;
-
-  sprintf(ctxcanvas->fontfilename, "%s\\fonts\\%s", getenv("windir"), strFontFileName);
-#else
-  if (cdStrEqualNoCase(typeface, "Courier") || cdStrEqualNoCase(typeface, "Courier New") || cdStrEqualNoCase(typeface, "Monospace"))
-    typeface = "freemono";
-  else if (cdStrEqualNoCase(typeface, "Times") || cdStrEqualNoCase(typeface, "Times New Roman")|| cdStrEqualNoCase(typeface, "Serif"))
-    typeface = "freeserif";
-  else if (cdStrEqualNoCase(typeface, "Helvetica") || cdStrEqualNoCase(typeface, "Arial") || cdStrEqualNoCase(typeface, "Sans"))
-    typeface = "freesans";
-
-  if(!cdglXGetFontFileName(typeface, is_bold, is_italic, strFontFileName))
-    return 0;
-
-  sprintf(ctxcanvas->fontfilename, "%s", strFontFileName);
-#endif
+  /* search for the font in the system */
+  if (!sGetFontFileName(typeface, is_bold, is_italic, strFontFileName))
+  {
+    /* try typeface as a file title, compose to get a filename */
+    if (!cdGetFontFileName(typeface, strFontFileName))
+    {
+      /* try the same configuration of the simulation driver */
+      static char * cd_ttf_font_style[4] = {
+        "",
+        "bd",
+        "i",
+        "bi"};
+      char* face = NULL;
+
+      /* check for the pre-defined names */
+      if (cdStrEqualNoCase(typeface, "System"))
+        face = "cour";
+      else if (cdStrEqualNoCase(typeface, "Courier"))
+        face = "cour";
+      else if (cdStrEqualNoCase(typeface, "Times"))
+        face = "times";
+      else if (cdStrEqualNoCase(typeface, "Helvetica"))
+        face = "arial";
+
+      if (face)
+      {
+        /* create a shortname for the file title */
+        char shorname[100];
+        sprintf(shorname, "%s%s", face, cd_ttf_font_style[style&3]);
+        if (!cdGetFontFileName(shorname, strFontFileName))
+          strcpy(strFontFileName, typeface);  /* try the typeface as file name */
+      }
+      else
+        strcpy(strFontFileName, typeface);  /* try the typeface as file name */
+    }
+  }
 
-  ctxcanvas->font = ftglCreateBufferFont(ctxcanvas->fontfilename);
-  
+  ctxcanvas->font = ftglCreateBufferFont(strFontFileName);
   if (!ctxcanvas->font)
     return 0;
 
@@ -650,9 +712,9 @@ static void cdbox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax
 
 static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, int len)
 {
-  int dir = -1, stipple = 0;
+  int stipple = 0;
   float bounds[6];
-  int w, h, desc;
+  int w, h, descent, baseline;
   double x_origin = x;
   double y_origin = y;
 
@@ -662,9 +724,10 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, i
   s = cdglStrConvertToUTF8(ctxcanvas, s, len);
   ftglGetFontBBox(ctxcanvas->font, s, len, bounds);
 
-  desc = (int)ftglGetFontDescender(ctxcanvas->font);
+  descent = (int)ftglGetFontDescender(ctxcanvas->font);
   w = (int)ceil(bounds[3] - bounds[0]);
   h = (int)ceil(bounds[4] - bounds[1]);
+  baseline = (int)ftglGetFontLineHeight(ctxcanvas->font) - (int)ftglGetFontAscender(ctxcanvas->font);
 
   switch (ctxcanvas->canvas->text_alignment)
   {
@@ -688,9 +751,6 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, i
       break;
   }
 
-  if (ctxcanvas->canvas->invert_yaxis)
-    dir = 1;
-
   switch (ctxcanvas->canvas->text_alignment)
   {
     case CD_BASE_LEFT:
@@ -701,17 +761,17 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, i
     case CD_SOUTH_EAST:
     case CD_SOUTH_WEST:
     case CD_SOUTH:
-      y = y + dir * desc;
+      y = y - descent;
       break;
     case CD_NORTH_EAST:
     case CD_NORTH:
     case CD_NORTH_WEST:
-      y = y + dir * (h + desc);
+      y = y - h/2 - baseline;
       break;
     case CD_CENTER:
     case CD_EAST:
     case CD_WEST:
-      y = y + dir * (h / 2);
+      y = y - baseline;
       break;
   }
 
diff --git a/src/ftgl/FTContour.cpp b/src/ftgl/FTContour.cpp
index cef1f3b..6b92812 100644
--- a/src/ftgl/FTContour.cpp
+++ b/src/ftgl/FTContour.cpp
@@ -33,6 +33,9 @@
 
 static const unsigned int BEZIER_STEPS = 5;
 
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
 
 void FTContour::AddPoint(FTPoint point)
 {
diff --git a/src/sim/cd_truetype.c b/src/sim/cd_truetype.c
index e7dad41..9fda0e3 100644
--- a/src/sim/cd_truetype.c
+++ b/src/sim/cd_truetype.c
@@ -9,91 +9,22 @@
 #include 
 #include 
 
+#include "cd.h"
+#include "cd_private.h"
 #include "cd_truetype.h"
 
 /*******************************************
         Inicializa o Rasterizador
 ********************************************/
 
-#ifdef WIN32
-#include 
-static int ReadStringKey(HKEY base_key, char* key_name, char* value_name, char* value)
-{
-	HKEY key;
-	DWORD max_size = 512;
-
-	if (RegOpenKeyEx(base_key, key_name, 0, KEY_READ, &key) != ERROR_SUCCESS)
-		return 0;
-
-  if (RegQueryValueEx(key, value_name, NULL, NULL, (LPBYTE)value, &max_size) != ERROR_SUCCESS)
-  {
-    RegCloseKey(key);
-		return 0;
-  }
-
-	RegCloseKey(key);
-	return 1;
-}
-
-char* GetFontDir(void)
-{
-  static char font_dir[512];
-  if (!ReadStringKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Fonts", font_dir))
-    return "";
-  else
-  {
-    int i, size = (int)strlen(font_dir);
-    for(i = 0; i < size; i++)
-    {
-      if (font_dir[i] == '\\')
-        font_dir[i] = '/';
-    }
-    return font_dir;
-  }
-}
-#endif
-
 int cdTT_load(cdTT_Text * tt_text, const char *font, int size, double xres, double yres)
 {
   char filename[10240];
-  FILE *file;  /* usado apenas para procurar pelo arquivo */
   FT_Error error;
   FT_Face face;          
 
-  /* abre arq. no dir. corrente */
-  sprintf(filename, "%s.ttf", font);
-  file = fopen(filename, "r");
-
-  if (file)
-    fclose(file);
-  else
-  {
-    /* se nao conseguiu, abre arq. no dir. do cd, */
-    char* env = getenv("CDDIR");
-    if (env)
-    {
-      sprintf(filename, "%s/%s.ttf", env, font);
-      file = fopen(filename, "r");
-    }
-
-    if (file)
-      fclose(file);
-    else
-    {
-#ifdef WIN32
-      /* no caso do Windows procura no seu diretorio de fontes. */
-      sprintf(filename, "%s/%s.ttf", GetFontDir(), font);
-      file = fopen(filename, "r");
-
-      if (file)
-        fclose(file);
-      else
-        return 0;
-#else
-      return 0;
-#endif
-    }
-  }
+  if (!cdGetFontFileName(font, filename))
+    return 0;
 
   error = FT_New_Face(tt_text->library, filename, 0, &face );
   if (error) 
diff --git a/test/simple/gdiplustest.cpp b/test/simple/gdiplustest.cpp
deleted file mode 100644
index af7b643..0000000
--- a/test/simple/gdiplustest.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-#include 
-#include 
-using namespace Gdiplus;
-
-/* Visual C++ 7.1 + SP1
-   GDI+ 1.0 File Version 5.1.3102.2180
-*/
-
-void DrawLineMarks(Graphics* graphics, Pen* greenPen, int x, int y, int w, int h)
-{
-  graphics->DrawLine(greenPen, x+w-1, y-5, x+w-1, y+5); // end markers
-  graphics->DrawLine(greenPen, x-5, y+h-1, x+5, y+h-1);
-}
-
-void SimpleImageTest(HWND hWnd)
-{
-  int x, y;
-  Graphics* graphics = new Graphics(hWnd);
-  graphics->Clear(Color(255, 255, 255)); // white background
-
-  Bitmap image(16, 16, PixelFormat24bppRGB);
-  image.SetResolution(graphics->GetDpiX(), graphics->GetDpiX());
-
-  /* black pixel border */
-  for (y = 0; y < 16; y++)
-    image.SetPixel(0, y, Color(0, 0, 0));
-  for (y = 0; y < 16; y++)
-    image.SetPixel(15, y, Color(0, 0, 0));
-  for (x = 1; x < 15; x++)
-    image.SetPixel(x, 0, Color(0, 0, 0));
-  for (x = 1; x < 15; x++)
-    image.SetPixel(x, 15, Color(0, 0, 0));
-
-  /* light yellow contents */
-  for (y = 1; y < 15; y++)
-    for (x = 1; x < 15; x++)
-      image.SetPixel(x, y, Color(192, 192, 0));
-
-  Pen redPen(Color(255, 0, 0), 1);
-  redPen.SetDashStyle(DashStyleDash);
-  Pen greenPen(Color(0, 255, 0), 1);
-  greenPen.SetDashStyle(DashStyleDash);
-
-  // I add {} to avoid reusing some Rect in the next test
-
-  graphics->SetPixelOffsetMode(PixelOffsetModeHalf); // pixel center is (.5,.5) instead of (0, 0)
-
-  // NO zoom
-  {
-  RectF actualRect(10, 10, 16, 16);
-  graphics->DrawImage(&image, 10, 10);  
-  graphics->DrawRectangle(&redPen, actualRect);
-  DrawLineMarks(graphics, &greenPen, 10, 10, 16, 16);
-  }
-
-  // zoom using Bilinear Interpolation
-  {
-  RectF zoomRect(50, 10, 160, 160);
-  graphics->SetInterpolationMode(InterpolationModeBilinear);
-  graphics->DrawImage(&image, zoomRect);
-  graphics->DrawRectangle(&redPen, zoomRect);
-  DrawLineMarks(graphics, &greenPen, 50, 10, 160, 160);
-  }
-
-  // zoom using Nearest Neighborhood
-  {
-  RectF zoomRect2(250, 10, 160, 160);
-  graphics->SetInterpolationMode(InterpolationModeNearestNeighbor);
-  graphics->DrawImage(&image, zoomRect2);
-  graphics->DrawRectangle(&redPen, zoomRect2);
-  DrawLineMarks(graphics, &greenPen, 250, 10, 160, 160);
-  }
-
-
-  // Using a source image size, smaller than actual
-
-
-  // NO zoom
-  {
-  RectF actualRect3(10, 200, 16, 16);
-  graphics->DrawImage(&image, actualRect3, 0, 0, 16-1, 16-1, UnitPixel, NULL, NULL);
-  graphics->DrawRectangle(&redPen, actualRect3);
-  DrawLineMarks(graphics, &greenPen, 10, 400, 16, 16);
-  }
-
-  // zoom using Bilinear Interpolation
-  {
-  RectF zoomRect6(50, 200, 160, 160);
-  graphics->SetInterpolationMode(InterpolationModeBilinear);
-  graphics->DrawImage(&image, zoomRect6, 0, 0, 16-1, 16-1, UnitPixel, NULL, NULL);
-  graphics->DrawRectangle(&redPen, zoomRect6);
-  DrawLineMarks(graphics, &greenPen, 50, 400, 160, 160);
-  }
-
-  // zoom using Nearest Neighborhood
-  {
-  RectF zoomRect7(250, 200, 160, 160);
-  graphics->SetInterpolationMode(InterpolationModeNearestNeighbor);
-  graphics->DrawImage(&image, zoomRect7, 0, 0, 16-1, 16-1, UnitPixel, NULL, NULL);
-  graphics->DrawRectangle(&redPen, zoomRect7);
-  DrawLineMarks(graphics, &greenPen, 250, 400, 160, 160);
-  }
-
-  delete graphics;
-}
-
-#include 
-
-extern "C" char* winData;
-extern "C" void SimpleDrawTest(void);
-
-void SimpleDrawTest(void)
-{
-  HWND hWnd = (HWND)IupGetAttribute((Ihandle*)winData, "HWND");
-  SimpleImageTest(hWnd);
-}
diff --git a/test/simple/simple.c b/test/simple/simple.c
index e9e3429..c47812e 100644
--- a/test/simple/simple.c
+++ b/test/simple/simple.c
@@ -559,6 +559,9 @@ void SimpleDraw(cdCanvas* canvas)
     SimpleUpdateSize(canvas);
 #endif
 
+  /* refresh CD canvas size, when window size has changed */
+  cdCanvasActivate(canvas);
+
   if (simple_draw == DRAW_TEXTFONTS)
     SimpleDrawTextFonts(canvas);
   else if (simple_draw == DRAW_TEXTALIGN)
@@ -568,6 +571,10 @@ void SimpleDraw(cdCanvas* canvas)
   else
     SimpleDrawAll(canvas);
 
+  /* Adds a new page, or 
+     flushes the file, or
+     flushes the screen, or
+     swap the double buffer. */
   cdCanvasFlush(canvas);
 
 #ifdef USE_OPENGL
@@ -712,7 +719,7 @@ void SimpleDrawAll(cdCanvas* canvas)
      Notice that in some drivers the bounding box is not precise. */
   {
     int rect[8];
-    cdCanvasGetTextBounds(canvas, w/2, h/2, "cdMin Draw (çãí)", rect);
+    cdCanvasGetTextBounds(canvas, w/2, h/2, "Simple Draw (pçãí)", rect);
     cdCanvasForeground(canvas, CD_RED);
     cdCanvasBegin(canvas, CD_CLOSED_LINES);
     cdCanvasVertex(canvas, rect[0], rect[1]);
@@ -722,7 +729,7 @@ void SimpleDrawAll(cdCanvas* canvas)
     cdCanvasEnd(canvas);
   }
   cdCanvasForeground(canvas, CD_BLUE);
-  cdCanvasText(canvas, w/2, h/2, "cdMin Draw (çãí)");
+  cdCanvasText(canvas, w/2, h/2, "Simple Draw (pçãí)");
   cdCanvasTextOrientation(canvas, 0);
 
   /* Prepare World Coordinates */
@@ -965,12 +972,6 @@ void SimpleDrawAll(cdCanvas* canvas)
   if (use_transform)
     cdCanvasTransform(canvas, NULL);
   cdCanvasClip(canvas, CD_CLIPOFF);
-
-  /* Adds a new page, or 
-     flushes the file, or
-     flushes the screen, or
-     swap the double buffer. */
-  cdCanvasFlush(canvas);
 }
 
 void DrawVectorTextBox(cdCanvas* canvas, int x, int y, char* text)
@@ -1081,18 +1082,18 @@ void SimpleDrawTextAlign(cdCanvas* canvas)
 
 #if 1
   char* text_aligment_str[] = {
-  "North (Ãyj)\nSecond Line (Ãyj)",
-  "South (Ãyj)\nSecond Line (Ãyj)",
-  "East (Ãyj)\nSecond Line (Ãyj)",
-  "West (Ãyj)\nSecond Line (Ãyj)",
-  "North East (Ãyj)\nSecond Line (Ãyj)",
-  "North West (Ãyj)\nSecond Line (Ãyj)",
-  "South East (Ãyj)\nSecond Line (Ãyj)",
-  "South West (Ãyj)\nSecond Line (Ãyj)",
-  "Center (Ãyj)\nSecond Line (Ãyj)",
-  "Base Center (Ãyj)\nSecond Line (Ãyj)",
-  "Base Right (Ãyj)\nSecond Line (Ãyj)",
-  "Base Left (Ãyj)\nSecond Line (Ãyj)"
+  "North (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "South (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "East (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "West (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "North East (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "North West (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "South East (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "South West (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "Center (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "Base Center (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "Base Right (Ãyj)\nSecond Line (Ãyj)\nThird Line",
+  "Base Left (Ãyj)\nSecond Line (Ãyj)\nThird Line"
   };
 #else
   char* text_aligment_str[] = {
diff --git a/test/simple/simple.led b/test/simple/simple.led
index a431079..d7ec30d 100644
--- a/test/simple/simple.led
+++ b/test/simple/simple.led
@@ -70,7 +70,7 @@ mnSurface = MENU
 (
  ITEM("Window", SimpleDrawWindow),
  ITEM("Server Image", SimpleDrawImage),
- ITEM("Image RGB", SimpleDrawImageRGB)
+ ITEM("Image RGB", SimpleDrawImageRGB),
  ITEM("OpenGL", SimpleDrawGL)
 )    
 
diff --git a/test/simple/simple_led.c b/test/simple/simple_led.c
index dbfb37b..db06a72 100644
--- a/test/simple/simple_led.c
+++ b/test/simple/simple_led.c
@@ -1,4 +1,4 @@
-/* Automatically generated by Iup ledc 2.6         */
+/*   Automatically generated by Iup 3.0 LED Compiler to C.   */
 
 #include 
 #include 
@@ -6,34 +6,17 @@
 
 static Ihandle* named[     13 ];
 
-static Ihandle* decl( char* name, Ihandle* elem, char* first, ...)
-{
-  char *attr, *val;
-  va_list arg;
-  va_start (arg, first);
-  attr = first;
-  while (attr)
-  {
-    val = va_arg(arg,char*);
-    IupSetAttribute( elem, attr, val );
-    attr = va_arg(arg,char*);
-  }
-  va_end (arg);
-  if(name) IupSetHandle( name, elem );
-  return elem;
-}
-
 
 void simple_loadled (void)
 {
-  named[0] = decl( "mnOpen", IupMenu(
+  named[0] = IupSetAtt( "mnOpen", IupMenu(
     IupItem( "CGM - Binary", "SimplePlayCGMBin" ),
     IupItem( "CGM - Text", "SimplePlayCGMText" ),
     IupItem( "METAFILE", "SimplePlayMetafile" ),
     IupItem( "WMF", "SimplePlayWMF" ),
     IupItem( "EMF", "SimplePlayEMF" ),
   NULL), NULL );
-  named[1] = decl( "mnSaveAs", IupMenu(
+  named[1] = IupSetAtt( "mnSaveAs", IupMenu(
     IupItem( "DEBUG", "SimpleDrawDebug" ),
     IupItem( "CGM - Binary", "SimpleDrawCGMBin" ),
     IupItem( "CGM - Text", "SimpleDrawCGMText" ),
@@ -47,7 +30,7 @@ void simple_loadled (void)
     IupItem( "SVG", "SimpleDrawSVG" ),
     IupItem( "WMF", "SimpleDrawWMF" ),
   NULL), NULL );
-  named[2] = decl( "mnFile", IupMenu(
+  named[2] = IupSetAtt( "mnFile", IupMenu(
     IupSubmenu( "Open",
       named[0] /* mnOpen */
     ),
@@ -60,24 +43,24 @@ void simple_loadled (void)
     IupSeparator(),
     IupItem( "Exit", "cmdExit" ),
   NULL), NULL );
-  named[3] = decl( "mnEdit", IupMenu(
+  named[3] = IupSetAtt( "mnEdit", IupMenu(
     IupItem( "Copy as Metafile", "SimpleDrawClipboardMetafile" ),
     IupItem( "Copy as EMF", "SimpleDrawClipboardEMF" ),
     IupItem( "Copy as Bitmap", "SimpleDrawClipboardBitmap" ),
     IupItem( "Paste", "SimplePlayClipboard" ),
   NULL), NULL );
-  named[4] = decl( "mnClipping", IupMenu(
+  named[4] = IupSetAtt( "mnClipping", IupMenu(
     IupItem( "Off", "SimpleClippingOff" ),
     IupItem( "Area", "SimpleClippingArea" ),
     IupItem( "Polygon", "SimpleClippingPolygon" ),
     IupItem( "Region", "SimpleClippingRegion" ),
   NULL), NULL );
-  named[5] = decl( "mnWriteMode", IupMenu(
+  named[5] = IupSetAtt( "mnWriteMode", IupMenu(
     IupItem( "Replace", "SimpleReplace" ),
     IupItem( "Xor", "SimpleXor" ),
     IupItem( "Not Xor", "SimpleNotXor" ),
   NULL), NULL );
-  named[6] = decl( "mnOptions", IupMenu(
+  named[6] = IupSetAtt( "mnOptions", IupMenu(
     IupSubmenu( "Clipping",
       named[4] /* mnClipping */
     ),
@@ -88,19 +71,19 @@ void simple_loadled (void)
     IupItem( "Transform", "SimpleTransform" ),
     IupItem( "Context Plus", "SimpleContextPlus" ),
   NULL), NULL );
-  named[7] = decl( "mnSurface", IupMenu(
+  named[7] = IupSetAtt( "mnSurface", IupMenu(
     IupItem( "Window", "SimpleDrawWindow" ),
     IupItem( "Server Image", "SimpleDrawImage" ),
     IupItem( "Image RGB", "SimpleDrawImageRGB" ),
     IupItem( "OpenGL", "SimpleDrawGL" ),
   NULL), NULL );
-  named[8] = decl( "mnPrimitives", IupMenu(
+  named[8] = IupSetAtt( "mnPrimitives", IupMenu(
     IupItem( "All", "SimpleAll" ),
     IupItem( "Text Align", "SimpleTextAlign" ),
     IupItem( "Text Fonts", "SimpleTextFonts" ),
     IupItem( "Test", "SimpleTest" ),
   NULL), NULL );
-  named[9] = decl( "mnSimpleMenu", IupMenu(
+  named[9] = IupSetAtt( "mnSimpleMenu", IupMenu(
     IupSubmenu( "File",
       named[2] /* mnFile */
     ),
@@ -117,9 +100,9 @@ void simple_loadled (void)
       named[8] /* mnPrimitives */
     ),
   NULL), NULL );
-  named[10] = decl( "SimpleCanvas", IupCanvas( "SimpleRepaint" ), 
+  named[10] = IupSetAtt( "SimpleCanvas", IupCanvas( "SimpleRepaint" ), 
     "BORDER", "0", NULL );
-  named[11] = decl( "SimpleDialog", IupDialog(
+  named[11] = IupSetAtt( "SimpleDialog", IupDialog(
     named[10] /* SimpleCanvas */
   ), 
     "TITLE", "Simple Draw", 
-- 
cgit v1.2.3