0023196: Porting to the latest version of ftgl library
authorapl <apl@opencascade.com>
Fri, 7 Sep 2012 12:50:42 +0000 (16:50 +0400)
committerapl <apl@opencascade.com>
Fri, 7 Sep 2012 12:50:42 +0000 (16:50 +0400)
Use FreeType entities instead of private helper classes from FTGL.
OpenGl package: link freetype.lib and ftgl.lib on Windows with #pragma comment.

src/OpenGl/OpenGl_FontMgr.cxx
src/OpenGl/OpenGl_FontMgr.hxx

index 4602c06..7665039 100755 (executable)
 // and conditions governing the rights and limitations under the License.
 
 #include <OpenGl_FontMgr.hxx>
+#include <OpenGl_GlCore11.hxx>
 
-#include <FTGLTextureFont.h>        
-#include <FTLibrary.h>
-#include <FTFace.h>
 #include <Standard_Stream.hxx>
 
+#include <ft2build.h>
+
+#ifdef _MSC_VER
+#pragma comment( lib, "ftgl.lib" )
+#pragma comment( lib, "freetype.lib" )
+#endif
+
 #undef TRACE
 
 #define DEFAULT_FONT_HEIGHT 16
@@ -82,16 +87,28 @@ void OpenGl_FontMgr::_initializeFontDB()
     OSD_NListOfSystemFont fontList = fntMgr->GetAvalableFonts();
     if ( fontList.Size() != 0 ) {
 
+      // The library used as a tool for checking font aspect since OSD_FontMgr
+      // fails to get aspect for the fonts that have name dependant
+      // on system locale.
+      FT_Library aFtLibrary;
+      FT_Error aLibError = FT_Init_FreeType(&aFtLibrary);
+      
       OSD_NListOfSystemFont::Iterator it(fontList);
       for ( ; it.More(); it.Next() ) {
         OGLFont_SysInfo* info = new OGLFont_SysInfo();
         if ( it.Value()->FontAspect() == OSD_FA_Regular ) {
+          
+          Handle(TCollection_HAsciiString) aFontPath = it.Value()->FontPath();
+            
           //this workaround for fonts with names dependent on system locale.
           //for example: "Times New Roman Fett Kursive" or "Times New Roman Gras Italiqui"
-          FTFace face(it.Value()->FontPath()->ToCString());
+          FT_Face aFontFace;
+          FT_Error aFaceError = FT_New_Face(aFtLibrary,
+                                            aFontPath->ToCString(), 0,
+                                            &aFontFace);
               
-          if ( face.Error() == FT_Err_Ok ) {
-            if ( (*face.Face())->style_flags == 0 ) {
+          if ( aFaceError == FT_Err_Ok ) {
+            if ( aFontFace->style_flags == 0 ) {
               info->SysFont = it.Value();
             }
             else {
@@ -99,24 +116,26 @@ void OpenGl_FontMgr::_initializeFontDB()
 #ifdef TRACE
               cout << "TKOpenGl::initializeFontDB() detected new font!\n"
                 << "\tFont Previous Name: " << it.Value()->FontName()->ToCString() << endl
-                << "\tFont New Name: " << (*face.Face())->family_name << endl
-                << "\tFont Aspect: " << (*face.Face())->style_flags << endl;
+                << "\tFont New Name: " << aFontFace->family_name << endl
+                << "\tFont Aspect: " << aFontFace->style_flags << endl;
 #endif
               OSD_FontAspect aspect = OSD_FA_Regular;
-              if ( (*face.Face())->style_flags == (FT_STYLE_FLAG_ITALIC | FT_STYLE_FLAG_BOLD) )
+              if ( aFontFace->style_flags == (FT_STYLE_FLAG_ITALIC | FT_STYLE_FLAG_BOLD) )
                 aspect = OSD_FA_BoldItalic;
-              else if ( (*face.Face())->style_flags == FT_STYLE_FLAG_ITALIC )
+              else if ( aFontFace->style_flags == FT_STYLE_FLAG_ITALIC )
                 aspect = OSD_FA_Italic;
-              else if ( (*face.Face())->style_flags == FT_STYLE_FLAG_BOLD )
+              else if ( aFontFace->style_flags == FT_STYLE_FLAG_BOLD )
                 aspect = OSD_FA_Bold;
 
 #ifdef TRACE
               cout << "\tOSD_FontAspect: " << aspect << endl;
 #endif
               Handle(TCollection_HAsciiString) aFontName =
-                new TCollection_HAsciiString( (*face.Face())->family_name );
-              info->SysFont = new OSD_SystemFont( aFontName, aspect, it.Value()->FontPath() );
+                new TCollection_HAsciiString( aFontFace->family_name );
+              info->SysFont = new OSD_SystemFont( aFontName, aspect, aFontPath );
             }
+            
+            FT_Done_Face(aFontFace);
           }
           else
             continue;
@@ -126,6 +145,12 @@ void OpenGl_FontMgr::_initializeFontDB()
         _FontDB.Append(info);
 
       }
+      
+      // finalize library instance
+      if ( aLibError == FT_Err_Ok )
+      {
+        FT_Done_FreeType(aFtLibrary);
+      }
     }
   }
 
index 3675e9d..ebe95f2 100755 (executable)
@@ -23,7 +23,7 @@
 # include <stdlib.h>
 #endif
 
-#include <FTFont.h>
+#include <FTGL/ftgl.h>
 
 #include <InterfaceGraphic.hxx>
 #include <TCollection_HAsciiString.hxx>