Added function DetectFontsAspects to Font_FontMgr class. This function uses workaround from OpenGl_FontMgr with FreeType for detecting font aspect.
Removed font name parsing from Font_FontMgr::InitFontDataBase(). Now the font name and font style we get through the FreeType.
Fixed Unix part of Font_FontMgr::InitFontDataBase() method. Font name and font style now detected through the FreeType.
Remarks fix. Added recursive default font directories scanning .
Fixed adding fonts folders recursively from configuration files.
Moved fonts aliases map from OpenGl_Display_1 to Font_FontMgr.
Moved fonts name definition from Graphic3d_NameOfFont.hxx to Font_NameOfFont.hxx.
Added new methods to Font_FontMgr: GetAvailableFontsNames, GetFont and FindFont.
Modified Font_SystemFont creation from XLFD. Added method IsEqual to Font_SystemFont.
Modified methods OpenGl_Display::FindFont, OpenGl_FontMgr::request_font in accordance to the new functionality of the Font_FontMgr.
OpenGl_FontMgr now stores only generated fonts instead of duplication of available fonts list.
Removed method OpenGl_FontMgr::requestFontList. Its function now performs Font_FontMgr::GetAvailableFontsNames.
Documentation was fixed
Adjusting testing cases for current state of OCCT
--- /dev/null
+CSF_FREETYPE
+EXTERNLIB
Font_NListOfSystemFont.hxx
+Font_NameOfFont.hxx
uses Standard ,
Quantity ,
TCollection,
- OSD
+ OSD,
+ TColStd
is
enumeration FontAspect is FA_Undefined, FA_Regular, FA_Bold, FA_Italic, FA_BoldItalic;
-- and conditions governing the rights and limitations under the License.
class FontMgr from Font inherits TShared from MMgt
----Purpose: Structure for store of Font System Information
+---Purpose: Collects and provides information about available fonts in system.
+---On Windows it gets information about available fonts from registry value
+---"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts". If the description
+---of the font does not contain the full path to it, FontMgr looks for it in the
+---default fonts directory. (WinAPI function GetSystemWindowsDirectory is used
+---to get the path of the shared Windows directory on a multi-user system.)
+---On Linux and Mac OS X platforms for getting the directories with fonts, at first
+---it checks X11 configuration files, which can be located at "/etc/X11/fs/config",
+---"/usr/X11R6/lib/X11/fs/config" or "/usr/X11/lib/X11/fs/config". Then it adds
+---default directories(for Linux: "/usr/share/fonts" and "/usr/local/share/fonts",
+---for Mac OS X: "/System/Library/Fonts" and "/Library/Fonts"). After that FontMgr
+---looks for the "fonts.dir" file in each stored directory. This file contain
+---fonts description in XLFD (X Logical Font Description) format.
+---On all platforms (Windows, Linux, Mac OS X) we use FreeType library for getting
+---font name and aspect.
+---On Linux and Mac OS X in cases when the font description obtained from FreeType
+---does not match the description in XLFD, FontMgr stores such fonts as two different
+---fonts (font management feature on Unix systems).
-uses SystemFont,
+uses FontAspect,
+ SystemFont,
NListOfSystemFont,
Path from OSD,
- AsciiString from TCollection
+ AsciiString from TCollection,
+ HAsciiString from TCollection,
+ SequenceOfHAsciiString from TColStd
is
GetInstance(myclass) returns FontMgr;
---Level: Public
- GetAvalableFonts(me) returns NListOfSystemFont;
+ GetAvailableFonts(me) returns NListOfSystemFont;
+ ---C++: return const &
+
+ GetAvailableFontsNames(me;
+ theFontsNames: out SequenceOfHAsciiString);
+ ---Purpose: Returns sequence of available fonts names
+ ---Level: Public
+
+ GetFont (me;
+ theFontName : HAsciiString;
+ theFontAspect : FontAspect;
+ theFontSize : Integer) returns SystemFont;
+ ---Purpose: Returns font that match given parameters.
+ --- If theFontName is empty string returned font can have any FontName.
+ --- If theFontAspect is Font_FA_Undefined returned font can have any FontAspect.
+ --- If theFontSize is "-1" returned font can have any FontSize.
+ ---Level: Public
+
+ FindFont (me;
+ theFontName : HAsciiString;
+ theFontAspect : FontAspect;
+ theFontSize : Integer) returns SystemFont;
+ ---Purpose: Tries to find font by given parameters.
+ --- If the specified font is not found tries to use font names mapping.
+ --- If the requested family name not found -> search for any font family
+ --- with given aspect and height. If the font is still not found, returns
+ --- any font available in the system. Returns NULL in case when the fonts
+ --- are not found in the system.
+ ---Level: Public
---- Private methods
+ --- Private methods
Create returns FontMgr is private;
---Purpose: Creates empty font object
---Level: Private
- InitFontDataBase(me:mutable) is private;
+ InitFontDataBase(me:mutable) is private;
+ ---Purpose: Collects available fonts paths.
+ ---Level: Private
fields
- MyListOfFonts: NListOfSystemFont;
+
+ myListOfFonts : NListOfSystemFont;
end FontMgr;
// and conditions governing the rights and limitations under the License.
#include <Font_FontMgr.ixx>
-#ifdef WNT
-# include <windows.h>
-# include <stdlib.h>
-#else //WNT
-# include <dirent.h>
-# include <X11/Xlib.h>
-#endif //WNT
#include <OSD_Environment.hxx>
#include <NCollection_List.hxx>
-#include <TCollection_HAsciiString.hxx>
+#include <NCollection_Map.hxx>
#include <Standard_Stream.hxx>
+#include <TCollection_HAsciiString.hxx>
+#include <ft2build.h>
+#include FT_FREETYPE_H
-#ifndef WNT
-#include <TCollection_AsciiString.hxx>
+struct Font_FontMgr_FontAliasMapNode
+{
+ const char * EnumName;
+ const char * FontName;
+ Font_FontAspect FontAspect;
+};
-#include <NCollection_DefineList.hxx>
-#include <NCollection_List.hxx>
+static const Font_FontMgr_FontAliasMapNode Font_FontMgr_MapOfFontsAliases[] =
+{
+
+#ifdef WNT
+
+ { "Courier" , "Courier New" , Font_FA_Regular },
+ { "Times-Roman" , "Times New Roman", Font_FA_Regular },
+ { "Times-Bold" , "Times New Roman", Font_FA_Bold },
+ { "Times-Italic" , "Times New Roman", Font_FA_Italic },
+ { "Times-BoldItalic" , "Times New Roman", Font_FA_BoldItalic },
+ { "ZapfChancery-MediumItalic", "Script" , Font_FA_Regular },
+ { "Symbol" , "Symbol" , Font_FA_Regular },
+ { "ZapfDingbats" , "WingDings" , Font_FA_Regular },
+ { "Rock" , "Arial" , Font_FA_Regular },
+ { "Iris" , "Lucida Console" , Font_FA_Regular }
+
+#else //X11
+
+ { "Courier" , "Courier" , Font_FA_Regular },
+ { "Times-Roman" , "Times" , Font_FA_Regular },
+ { "Times-Bold" , "Times" , Font_FA_Bold },
+ { "Times-Italic" , "Times" , Font_FA_Italic },
+ { "Times-BoldItalic" , "Times" , Font_FA_BoldItalic },
+ { "Arial" , "Helvetica" , Font_FA_Regular },
+ { "ZapfChancery-MediumItalic", "-adobe-itc zapf chancery-medium-i-normal--*-*-*-*-*-*-iso8859-1" , Font_FA_Regular },
+ { "Symbol" , "-adobe-symbol-medium-r-normal--*-*-*-*-*-*-adobe-fontspecific" , Font_FA_Regular },
+ { "ZapfDingbats" , "-adobe-itc zapf dingbats-medium-r-normal--*-*-*-*-*-*-adobe-fontspecific" , Font_FA_Regular },
+ { "Rock" , "-sgi-rock-medium-r-normal--*-*-*-*-p-*-iso8859-1" , Font_FA_Regular },
+ { "Iris" , "--iris-medium-r-normal--*-*-*-*-m-*-iso8859-1" , Font_FA_Regular }
+#endif
+
+};
+
+#define NUM_FONT_ENTRIES (sizeof(Font_FontMgr_MapOfFontsAliases)/sizeof(Font_FontMgr_FontAliasMapNode))
+
+#if (defined(_WIN32) || defined(__WIN32__))
-#include <OSD_Path.hxx>
-#include <OSD_FileIterator.hxx>
-#include <OSD_DirectoryIterator.hxx>
-#include <OSD_File.hxx>
-#include <OSD_FileNode.hxx>
-#include <OSD_OpenMode.hxx>
-#include <OSD_Protection.hxx>
-#include <Font_NListOfSystemFont.hxx>
-
-const Standard_Integer font_service_conf_size = 3;
-static Standard_Character font_service_conf[font_service_conf_size][64] = { {"/etc/X11/fs/config"},
- {"/usr/X11R6/lib/X11/fs/config"},
- {"/usr/X11/lib/X11/fs/config"}
- };
-
-DEFINE_LIST( StringList, NCollection_List, TCollection_HAsciiString );
-
-void find_path_with_font_dir( const TCollection_AsciiString& dir,StringList& dirs )
-{
- if( !dir.IsEmpty() )
+ #include <windows.h>
+ #include <stdlib.h>
+
+ #ifdef _MSC_VER
+ #pragma comment (lib, "freetype.lib")
+ #endif
+
+ namespace
{
- TCollection_AsciiString PathName( dir );
- Standard_Integer rem = PathName.Length();
+ // list of supported extensions
+ static Standard_CString Font_FontMgr_Extensions[] =
+ {
+ "ttf",
+ "otf",
+ "ttc",
+ NULL
+ };
+
+ };
+
+#else
- if ( PathName.SearchFromEnd("/") == rem )
- PathName.Remove( rem, 1 );
+ #include <OSD_DirectoryIterator.hxx>
+ #include <OSD_Path.hxx>
+ #include <OSD_File.hxx>
+ #include <OSD_OpenMode.hxx>
+ #include <OSD_Protection.hxx>
- Standard_Boolean need_to_append = Standard_True;
-
- StringList::Iterator it( dirs );
- for( ; it.More(); it.Next() )
+ namespace
+ {
+
+ // list of supported extensions
+ static Standard_CString Font_FontMgr_Extensions[] =
+ {
+ "ttf",
+ "otf",
+ "ttc",
+ "pfa",
+ "pfb",
+ NULL
+ };
+
+ // X11 configuration file in plain text format (obsolete - doesn't exists in modern distributives)
+ static Standard_CString myFontServiceConf[] = {"/etc/X11/fs/config",
+ "/usr/X11R6/lib/X11/fs/config",
+ "/usr/X11/lib/X11/fs/config",
+ NULL
+ };
+
+ #ifdef __APPLE__
+ // default fonts paths in Mac OS X
+ static Standard_CString myDefaultFontsDirs[] = {"/System/Library/Fonts",
+ "/Library/Fonts",
+ NULL
+ };
+ #else
+ // default fonts paths in most Unix systems (Linux and others)
+ static Standard_CString myDefaultFontsDirs[] = {"/usr/share/fonts",
+ "/usr/local/share/fonts",
+ NULL
+ };
+ #endif
+
+ static void addDirsRecursively (const OSD_Path& thePath,
+ NCollection_Map<TCollection_AsciiString>& theDirsMap)
{
- if ( PathName.IsEqual(it.Value().ToCString()) ) {
- need_to_append = Standard_False;
- break;
+ TCollection_AsciiString aDirName;
+ thePath.SystemName (aDirName);
+ if (!theDirsMap.Add (aDirName))
+ {
+ return;
}
- }
- if ( need_to_append )
- dirs.Append( PathName );
- OSD_DirectoryIterator osd_dir(PathName,"*");
- while(osd_dir.More())
- {
- OSD_Path path_file;
- osd_dir.Values().Path( path_file );
- if( path_file.Name().Length() < 1 )
+ for (OSD_DirectoryIterator aDirIterator (thePath, "*"); aDirIterator.More(); aDirIterator.Next())
{
- osd_dir.Next();
- continue;
+ OSD_Path aChildDirPath;
+ aDirIterator.Values().Path (aChildDirPath);
+
+ TCollection_AsciiString aChildDirName;
+ aChildDirPath.SystemName (aChildDirName);
+ if (!aChildDirName.IsEqual (".") && !aChildDirName.IsEqual (".."))
+ {
+ aChildDirName = aDirName + "/" + aChildDirName;
+ OSD_Path aPath (aChildDirName);
+ addDirsRecursively (aPath, theDirsMap);
+ }
}
-
- TCollection_AsciiString full_path_name = PathName + "/" + path_file.Name();
- rem = full_path_name.Length();
- if ( full_path_name.SearchFromEnd("/") == rem )
- full_path_name.Remove( rem, 1 );
- find_path_with_font_dir( full_path_name, dirs );
- osd_dir.Next();
}
+
+ };
+
+#endif
+
+// =======================================================================
+// function : checkFont
+// purpose :
+// =======================================================================
+static Handle(Font_SystemFont) checkFont (FT_Library theFTLib,
+ const Standard_CString theFontPath)
+{
+ FT_Face aFontFace;
+ FT_Error aFaceError = FT_New_Face (theFTLib, theFontPath, 0, &aFontFace);
+ if (aFaceError != FT_Err_Ok)
+ {
+ return NULL;
}
-}
-#endif //WNT
+ Font_FontAspect anAspect = Font_FA_Regular;
+ if (aFontFace->style_flags == (FT_STYLE_FLAG_ITALIC | FT_STYLE_FLAG_BOLD))
+ {
+ anAspect = Font_FA_BoldItalic;
+ }
+ else if (aFontFace->style_flags == FT_STYLE_FLAG_ITALIC)
+ {
+ anAspect = Font_FA_Italic;
+ }
+ else if (aFontFace->style_flags == FT_STYLE_FLAG_BOLD)
+ {
+ anAspect = Font_FA_Bold;
+ }
+
+ Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (aFontFace->family_name);
+ Handle(TCollection_HAsciiString) aFontPath = new TCollection_HAsciiString (theFontPath);
+ Handle(Font_SystemFont) aResult = new Font_SystemFont (aFontName, anAspect, aFontPath);
+ FT_Done_Face (aFontFace);
-Handle(Font_FontMgr) Font_FontMgr::GetInstance() {
+ return aResult;
+}
+// =======================================================================
+// function : GetInstance
+// purpose :
+// =======================================================================
+Handle(Font_FontMgr) Font_FontMgr::GetInstance()
+{
static Handle(Font_FontMgr) _mgr;
- if ( _mgr.IsNull() )
+ if (_mgr.IsNull())
+ {
_mgr = new Font_FontMgr();
+ }
return _mgr;
-
}
-Font_FontMgr::Font_FontMgr() {
-
+// =======================================================================
+// function : Font_FontMgr
+// purpose :
+// =======================================================================
+Font_FontMgr::Font_FontMgr()
+{
InitFontDataBase();
-
}
-void Font_FontMgr::InitFontDataBase() {
-
- MyListOfFonts.Clear();
+// =======================================================================
+// function : InitFontDataBase
+// purpose :
+// =======================================================================
+void Font_FontMgr::InitFontDataBase()
+{
+ myListOfFonts.Clear();
+ FT_Library aFtLibrary = NULL;
-#ifdef WNT
- //detect font directory
+#if (defined(_WIN32) || defined(__WIN32__))
- OSD_Environment env("windir");
- TCollection_AsciiString windir_str = env.Value();
- if ( windir_str.IsEmpty() )
+ // font directory is placed in "C:\Windows\Fonts\"
+ UINT aStrLength = GetSystemWindowsDirectoryA (NULL, 0);
+ if (aStrLength == 0)
{
- return;
+ return;
}
- Handle(TCollection_HAsciiString) HFontDir = new TCollection_HAsciiString( windir_str );
- HFontDir->AssignCat( "\\Fonts\\" );
- #ifdef TRACE
- cout << "System font directory: " << HFontDir->ToCString() << "\n";
- #endif TRACE
-
- //read registry
- HKEY fonts_hkey;
- if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"),
- 0,
- KEY_READ,
- &fonts_hkey )
- != ERROR_SUCCESS )
+
+ char* aWinDir = new char[aStrLength];
+ GetSystemWindowsDirectoryA (aWinDir, aStrLength);
+ Handle(TCollection_HAsciiString) aFontsDir = new TCollection_HAsciiString (aWinDir);
+ aFontsDir->AssignCat ("\\Fonts\\");
+ delete[] aWinDir;
+
+ // read fonts list from registry
+ HKEY aFontsKey;
+ if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
+ 0, KEY_READ, &aFontsKey) != ERROR_SUCCESS)
{
return;
- }
- Standard_Integer id = 0;
- Standard_Character buf_name[100];
- Standard_Byte buf_data[100];
- DWORD size_name = 100,
- size_data = 100;
-
- while ( true )
- {
- //detect file name
- DWORD type;
- size_name = 100,
- size_data = 100;
- Font_FontAspect aspect;
- if( RegEnumValue( fonts_hkey,
- id,
- buf_name,
- &size_name,
- NULL,
- &type,
- buf_data,
- &size_data) == ERROR_NO_MORE_ITEMS ) {
- break;
- }
- Handle(TCollection_HAsciiString) fname =
- new TCollection_HAsciiString(buf_name);
- fname->RightAdjust();
- fname->LeftAdjust();
- //remove construction like (TrueType....
- Standard_Integer anIndexTT = fname->SearchFromEnd( new TCollection_HAsciiString( " (" ) );
- Standard_Boolean aTruncate = Standard_False;
- if ( anIndexTT > 1 )
- fname->Trunc( anIndexTT );
- Standard_Integer anIndex = 0;
- fname->RightAdjust();
- if ( ( anIndex = fname->SearchFromEnd( new TCollection_HAsciiString("Bold Italic") ) ) > 0 ) {
- aTruncate = ( anIndex > 1 ) && ( fname->Value(anIndex - 1 ) == ' ' );
- aspect = Font_FA_BoldItalic;
- } else if ( ( anIndex = fname->SearchFromEnd( new TCollection_HAsciiString("Bold") ) ) > 0 ) {
- aTruncate = ( anIndex > 1 ) && ( fname->Value(anIndex - 1 ) == ' ' );
- aspect = Font_FA_Bold;
- } else if ( ( anIndex = fname->SearchFromEnd( new TCollection_HAsciiString("Italic") ) ) > 0 ) {
- aTruncate = ( anIndex > 1 ) && ( fname->Value(anIndex - 1 ) == ' ' );
- aspect = Font_FA_Italic;
- } else {
- aspect = Font_FA_Regular;
- }
- if( aTruncate )
- fname->Trunc( anIndex - 1 );
- fname->RightAdjust();
- Handle(TCollection_HAsciiString) file_path =
- new TCollection_HAsciiString( (Standard_Character*)buf_data );
- if ( strchr( (Standard_Character*)buf_data, '\\' ) == NULL ) {
- file_path->Insert( 1, HFontDir );
- }
-
- if( ( ( file_path->Search(".ttf") > 0 ) || ( file_path->Search(".TTF") > 0 ) ||
- ( file_path->Search(".otf") > 0 ) || ( file_path->Search(".OTF") > 0 ) ||
- ( file_path->Search(".ttc") > 0 ) || ( file_path->Search(".TTC") > 0 ) ) ){
- MyListOfFonts.Append( new Font_SystemFont( fname, aspect, file_path ) );
-#ifdef TRACE
- cout << "Adding font...\n"
- << " font name: " << fname->ToCString() << "\n"
- << " font file: " << file_path->ToCString() << "\n"
- << " font aspect: ";
- switch( aspect ) {
- case Font_FA_Bold:
- cout << "Font_FA_Bold\n";
- break;
- case Font_FA_BoldItalic:
- cout << "Font_FA_BoldItalic\n";
- break;
- case Font_FA_Italic:
- cout << "Font_FA_Italic\n";
- break;
- default:
- cout << "Font_FA_Regular\n";
- break;
- }
-#endif
- }
- id++;
}
- //close registry
- RegCloseKey( fonts_hkey );
-#endif //WNT
-#ifndef WNT
- StringList dirs;
- Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString;
- Display * disp = XOpenDisplay("localhost:0.0");
-
- if (!disp)
+ NCollection_Map<TCollection_AsciiString> aSupportedExtensions;
+ for (Standard_Integer anIter = 0; Font_FontMgr_Extensions[anIter] != NULL; ++anIter)
{
- // let the X server find the available connection
- disp = XOpenDisplay(":0.0");
- if (!disp)
- {
- cout << "Display is NULL!" << endl;
- return ;
- }
+ Standard_CString anExt = Font_FontMgr_Extensions[anIter];
+ aSupportedExtensions.Add (TCollection_AsciiString (anExt));
}
- Standard_Integer npaths = 0;
+ FT_Init_FreeType (&aFtLibrary);
+ static const DWORD aBufferSize = 256;
+ char aNameBuff[aBufferSize];
+ char aPathBuff[aBufferSize];
+ DWORD aNameSize = aBufferSize;
+ DWORD aPathSize = aBufferSize;
+ for (DWORD anIter = 0;
+ RegEnumValueA (aFontsKey, anIter,
+ aNameBuff, &aNameSize, NULL, NULL,
+ (LPBYTE )aPathBuff, &aPathSize) != ERROR_NO_MORE_ITEMS;
+ ++anIter, aNameSize = aBufferSize, aPathSize = aBufferSize)
+ {
+ aPathBuff[(aPathSize < aBufferSize) ? aPathSize : (aBufferSize - 1)] = '\0'; // ensure string is NULL-terminated
- Standard_Character** fontpath = XGetFontPath(disp, &npaths);
-#ifdef TRACE
- cout << "NPATHS = " << npaths << endl ;
-#endif
- for (Standard_Integer i = 0; i < npaths; i++ )
- {
-#ifdef TRACE
- cout << "Font Path: " << fontpath[i] << endl;
-#endif
- if ( fontpath[i][0] == '/' ) {
- TCollection_AsciiString aFontPath( fontpath[i] );
- find_path_with_font_dir( aFontPath, dirs );
+ Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (aNameBuff);
+ Handle(TCollection_HAsciiString) aFontPath = new TCollection_HAsciiString (aPathBuff);
+ if (aFontPath->Search ("\\") == -1)
+ {
+ aFontPath->Insert (1, aFontsDir); // make absolute path
}
- else
+
+ // check file extension is in list of supported
+ const Standard_Integer anExtensionPosition = aFontPath->SearchFromEnd (".") + 1;
+ if (anExtensionPosition > 0 && anExtensionPosition < aFontPath->Length())
{
- TCollection_AsciiString aFontPath( fontpath[i] );
- TCollection_AsciiString aCutFontPath;
- Standard_Integer location = -1 ;
- location = aFontPath.Location( "/",1,aFontPath.Length() );
- if( location > 0 )
- aCutFontPath.AssignCat( aFontPath.SubString(location, aFontPath.Length() ) );
- find_path_with_font_dir( aCutFontPath, dirs );
+ Handle(TCollection_HAsciiString) aFontExtension = aFontPath->SubString (anExtensionPosition, aFontPath->Length());
+ aFontExtension->LowerCase();
+ if (aSupportedExtensions.Contains (aFontExtension->String()))
+ {
+ Handle(Font_SystemFont) aNewFont = checkFont (aFtLibrary, aFontPath->ToCString());
+ if (!aNewFont.IsNull())
+ {
+ myListOfFonts.Append (aNewFont);
+ }
+ }
}
}
- XFreeFontPath(fontpath);
+ // close registry key
+ RegCloseKey (aFontsKey);
+
+#else
- OSD_OpenMode aMode = OSD_ReadOnly;
- OSD_Protection aProtect( OSD_R, OSD_R, OSD_R, OSD_R );
+ NCollection_Map<TCollection_AsciiString> aMapOfFontsDirs;
+ const OSD_Protection aProtectRead (OSD_R, OSD_R, OSD_R, OSD_R);
- for( Standard_Integer j = 0 ; j < font_service_conf_size; j++ )
+ // read fonts directories from font service config file (obsolete)
+ for (Standard_Integer anIter = 0; myFontServiceConf[anIter] != NULL; ++anIter)
{
- TCollection_AsciiString fileOfFontServiceName( font_service_conf[j] );
- OSD_File aFile( fileOfFontServiceName );
+ const TCollection_AsciiString aFileOfFontsPath (myFontServiceConf[anIter]);
+ OSD_File aFile (aFileOfFontsPath);
+ if (!aFile.Exists())
+ {
+ continue;
+ }
- if( aFile.Exists() )
- aFile.Open( aMode, aProtect );
-
- if( aFile.IsOpen() )//font service
+ aFile.Open (OSD_ReadOnly, aProtectRead);
+ if (!aFile.IsOpen())
+ {
+ continue;
+ }
+
+ Standard_Integer aNByte = 256;
+ Standard_Integer aNbyteRead;
+ TCollection_AsciiString aStr; // read string with information
+ while (!aFile.IsAtEnd())
{
- Standard_Integer aNByte = 256;
- Standard_Integer aNbyteRead;
- TCollection_AsciiString aStr( aNByte );//read string with information
- TCollection_AsciiString aStrCut( aNByte );//cut of string
- TCollection_AsciiString endStr;//cutting string
-
- Standard_Boolean read_dirs = Standard_False;
- Standard_Integer location =- 1; //disposition of necessary literals
- Standard_Integer begin =- 1; //first left entry in string
- Standard_Integer end =- 1; //first right entry in string
- while( !aFile.IsAtEnd() )
+ Standard_Integer aLocation = -1;
+ Standard_Integer aPathLocation = -1;
+
+ aFile.ReadLine (aStr, aNByte, aNbyteRead); // reading 1 line (256 bytes)
+ aLocation = aStr.Search ("catalogue=");
+ if (aLocation < 0)
+ {
+ aLocation = aStr.Search ("catalogue =");
+ }
+
+ aPathLocation = aStr.Search ("/");
+ if (aLocation > 0 && aPathLocation > 0)
{
- aFile.ReadLine( aStr, aNByte, aNbyteRead );//reading 1 lines(256 bytes)
- location = aStr.Location( "catalogue = ", 1, aStr.Length() );
- if(location == 0)
- location = aStr.Location( "catalogue=", 1, aStr.Length() );
- if(location == 0)
- location = aStr.Location( "catalogue= ", 1, aStr.Length() );
- if(location == 0)
- location = aStr.Location( "catalogue = ", 1, aStr.Length() );
- if( location > 0 )
+ aStr = aStr.Split (aPathLocation - 1);
+ TCollection_AsciiString aFontPath;
+ Standard_Integer aPathNumber = 1;
+ do
{
-#ifdef TRACE
- cout << " Font config find!!" << endl;
-#endif
- read_dirs = Standard_True;
- }
-
- if( read_dirs )
- {
- begin = aStr.Location( "/", 1, aStr.Length() );//begin of path name
- end = aStr.Location( ":", 1, aStr.Length() );//end of path name
- if( end < 1 )
- end = aStr.Location( ",", 1, aStr.Length() );//also end of path name
- end -= 1;
- if( begin > 0 && end > 0 )
+ // Getting directory paths, which can be splitted by "," or ":"
+ aFontPath = aStr.Token (":,", aPathNumber);
+ aFontPath.RightAdjust();
+ if (!aFontPath.IsEmpty())
{
- if( ( end - begin ) > 0 )
- endStr.AssignCat( aStr.SubString ( begin, end ) );//cutting necessary literals for string
- dirs.Append( TCollection_HAsciiString ( endStr ) );
- endStr.Clear();
+ OSD_Path aPath(aFontPath);
+ addDirsRecursively (aPath, aMapOfFontsDirs);
}
- else
- if( begin > 0 && end == -1 )
- {
- //if end of string don't have "," or ":"
- //it is possible last sentence in block of word
- endStr.AssignCat( aStr.SubString( begin, aStr.Length() - 1 ) );
- dirs.Append( TCollection_HAsciiString( endStr ) );
- endStr.Clear();
- }
- }
-
+ aPathNumber++;
+ }
+ while (!aFontPath.IsEmpty());
}
- aFile.Close();
}
+ aFile.Close();
}
- if( dirs.Size() > 0 )
- {
- //if dirs list contains elements
- OSD_OpenMode aModeRead = OSD_ReadOnly;
- OSD_Protection aProtectRead( OSD_R, OSD_R , OSD_R , OSD_R );
+ // append default directories
+ for (Standard_Integer anIter = 0; myDefaultFontsDirs[anIter] != NULL; ++anIter)
+ {
+ Standard_CString anItem = myDefaultFontsDirs[anIter];
+ TCollection_AsciiString aPathStr (anItem);
+ OSD_Path aPath (aPathStr);
+ addDirsRecursively (aPath, aMapOfFontsDirs);
+ }
+
+ NCollection_Map<TCollection_AsciiString> aSupportedExtensions;
+ for (Standard_Integer anIter = 0; Font_FontMgr_Extensions[anIter] != NULL; ++anIter)
+ {
+ Standard_CString anExt = Font_FontMgr_Extensions[anIter];
+ aSupportedExtensions.Add (TCollection_AsciiString (anExt));
+ }
+
+ FT_Init_FreeType (&aFtLibrary);
+ for (NCollection_Map<TCollection_AsciiString>::Iterator anIter (aMapOfFontsDirs);
+ anIter.More(); anIter.Next())
+ {
+ OSD_File aReadFile (anIter.Value() + "/fonts.dir");
+ if (!aReadFile.Exists())
+ {
+ continue; // invalid fonts directory
+ }
+
+ aReadFile.Open (OSD_ReadOnly, aProtectRead);
+ if (!aReadFile.IsOpen())
+ {
+ continue; // invalid fonts directory
+ }
+
+ Standard_Integer aNbyteRead, aNByte = 256;
+ TCollection_AsciiString aLine (aNByte);
+ Standard_Boolean isFirstLine = Standard_True;
+ const TCollection_AsciiString anEncoding ("iso8859-1\n");
+ while (!aReadFile.IsAtEnd())
+ {
+ aReadFile.ReadLine (aLine, aNByte, aNbyteRead);
+ if (isFirstLine)
+ {
+ // first line contains the number of fonts in this file
+ // just ignoring it...
+ isFirstLine = Standard_False;
+ continue;
+ }
- TCollection_AsciiString fileFontsDir;
- StringList::Iterator it( dirs );
- for( ; it.More(); it.Next() )
- {
- fileFontsDir.AssignCat( it.Value().ToCString() );
- fileFontsDir.AssignCat( "/fonts.dir" );//append file name in path way
+ Standard_Integer anExtensionPosition = aLine.Search (".") + 1;
+ if (anExtensionPosition == 0)
+ {
+ continue; // can't find extension position in the font description
+ }
- OSD_File readFile( fileFontsDir );
- readFile.Open( aModeRead, aProtectRead );
+ Standard_Integer anEndOfFileName = aLine.Location (" ", anExtensionPosition, aLine.Length()) - 1;
+ if (anEndOfFileName < 0 || anEndOfFileName < anExtensionPosition)
+ {
+ continue; // font description have empty extension
+ }
- Standard_Integer aNbyteRead, aNByte = 256;
- if( readFile.IsOpen ( ) )
+ TCollection_AsciiString aFontExtension = aLine.SubString (anExtensionPosition, anEndOfFileName);
+ aFontExtension.LowerCase();
+ if (aSupportedExtensions.Contains (aFontExtension) && (aLine.Search (anEncoding) > 0))
{
- TCollection_AsciiString aLine( aNByte );
- Standard_Integer countOfString = 0 ;
- while( ! readFile.IsAtEnd() )//return true if EOF
+ // In current implementation use fonts with ISO-8859-1 coding page.
+ // OCCT not give to manage coding page by means of programm interface.
+ // TODO: make high level interface for choosing necessary coding page.
+ Handle(TCollection_HAsciiString) aXLFD =
+ new TCollection_HAsciiString (aLine.SubString (anEndOfFileName + 2, aLine.Length()));
+ Handle(TCollection_HAsciiString) aFontPath =
+ new TCollection_HAsciiString (anIter.Value().ToCString());
+ if (aFontPath->SearchFromEnd ("/") != aFontPath->Length())
{
- if( countOfString > 1 )
- {
- readFile.ReadLine( aLine , aNByte , aNbyteRead );
- if( ( ( aLine.Search(".pfa") > 0 ) || ( aLine.Search(".PFA") > 0 ) ||
- ( aLine.Search(".pfb") > 0 ) || ( aLine.Search(".PFB") > 0 ) ||
- ( aLine.Search(".ttf") > 0 ) || ( aLine.Search(".TTF") > 0 ) ||
- ( aLine.Search(".otf") > 0 ) || ( aLine.Search(".OTF") > 0 ) ||
- ( aLine.Search(".ttc") > 0 ) || ( aLine.Search(".TTC") > 0 ) )
- && ( aLine.Search( "iso8859-1\n" ) > 0 ) )
- {
-
- // In current implementation use fonts with ISO-8859-1 coding page.
- // OCCT not give to manage coding page by means of programm interface.
- // TODO: make high level interface for
- // choosing necessary coding page.
- TCollection_AsciiString aXLFD;
- Standard_Integer leftXLFD = aLine.SearchFromEnd(" ");
- Standard_Integer rightXLFD = aLine.Length();
- if( leftXLFD && rightXLFD )
- aXLFD.AssignCat(aLine.SubString( leftXLFD + 1, rightXLFD ) );
-
- TCollection_AsciiString aPath;
- TCollection_AsciiString aTemp( it.Value().ToCString() );
- if ( aTemp.SearchFromEnd("/") == aTemp.Length() )
- {
- //this branch intend to SUN
- aPath.AssignCat( aTemp.ToCString() );
- aPath.AssignCat( aLine.Token( " ", 1 ) );
- }
- else {
- //this branch intend to Linux
- aPath.AssignCat( aTemp.ToCString( ) );
- aPath.AssignCat( "/" );
- aPath.AssignCat( aLine.Token( " ", 1 ) );
- }
- MyListOfFonts.Append( new Font_SystemFont( new TCollection_HAsciiString( aXLFD ),
- new TCollection_HAsciiString( aPath ) ) );
- }
-
- }
- else
- readFile.ReadLine( aLine, aNByte, aNbyteRead );
- countOfString++;
+ aFontPath->AssignCat ("/");
}
- readFile.Close();
- }
- fileFontsDir.Clear();
+ Handle(TCollection_HAsciiString) aFontFileName =
+ new TCollection_HAsciiString (aLine.SubString (1, anEndOfFileName));
+ aFontPath->AssignCat (aFontFileName);
+
+ Handle(Font_SystemFont) aNewFontFromXLFD = new Font_SystemFont (aXLFD, aFontPath);
+ Handle(Font_SystemFont) aNewFont = checkFont (aFtLibrary, aFontPath->ToCString());
+
+ if (aNewFontFromXLFD->IsValid() && !aNewFont.IsNull() &&
+ !aNewFont->IsEqual (aNewFontFromXLFD))
+ {
+ myListOfFonts.Append (aNewFont);
+ myListOfFonts.Append (aNewFontFromXLFD);
+ }
+ else if (!aNewFont.IsNull())
+ {
+ myListOfFonts.Append (aNewFont);
+ }
+ else if (aNewFontFromXLFD->IsValid())
+ {
+ myListOfFonts.Append (aNewFontFromXLFD);
+ }
+
+ }
}
+ aReadFile.Close();
}
#endif
+ FT_Done_FreeType (aFtLibrary);
+}
+
+// =======================================================================
+// function : GetAvailableFonts
+// purpose :
+// =======================================================================
+const Font_NListOfSystemFont& Font_FontMgr::GetAvailableFonts() const
+{
+ return myListOfFonts;
+}
+
+void Font_FontMgr::GetAvailableFontsNames (TColStd_SequenceOfHAsciiString& theFontsNames) const
+{
+ theFontsNames.Clear();
+ for (Font_NListOfSystemFont::Iterator anIter(myListOfFonts); anIter.More(); anIter.Next())
+ {
+ theFontsNames.Append (anIter.Value()->FontName());
+ }
}
-Font_NListOfSystemFont Font_FontMgr::GetAvalableFonts() const
+Handle(Font_SystemFont) Font_FontMgr::GetFont (const Handle(TCollection_HAsciiString)& theFontName,
+ const Font_FontAspect theFontAspect,
+ const Standard_Integer theFontSize) const
{
- return MyListOfFonts;
+ if ( (theFontSize < 2 && theFontSize != -1) || theFontName.IsNull())
+ {
+ return NULL;
+ }
+
+ Font_NListOfSystemFont::Iterator aFontsIterator (myListOfFonts);
+
+ for (; aFontsIterator.More(); aFontsIterator.Next())
+ {
+ if (!theFontName->IsEmpty() && !aFontsIterator.Value()->FontName()->IsSameString (theFontName, Standard_False))
+ {
+ continue;
+ }
+
+ if (theFontAspect != Font_FA_Undefined && aFontsIterator.Value()->FontAspect() != theFontAspect)
+ {
+ continue;
+ }
+
+ if (theFontSize == -1 || aFontsIterator.Value()->FontHeight() == -1 ||
+ theFontSize == aFontsIterator.Value()->FontHeight())
+ {
+ return aFontsIterator.Value();
+ }
+ }
+
+ return NULL;
}
+Handle(Font_SystemFont) Font_FontMgr::FindFont (const Handle(TCollection_HAsciiString)& theFontName,
+ const Font_FontAspect theFontAspect,
+ const Standard_Integer theFontSize) const
+{
+ Handle(TCollection_HAsciiString) aFontName = theFontName;
+ Font_FontAspect aFontAspect = theFontAspect;
+ Standard_Integer aFontSize = theFontSize;
+
+ Handle(Font_SystemFont) aFont = GetFont (aFontName, aFontAspect, aFontSize);
+
+ if (!aFont.IsNull())
+ {
+ return aFont;
+ }
+
+ // Trying to use font names mapping
+ for (Standard_Integer anIter = 0; anIter < NUM_FONT_ENTRIES; ++anIter)
+ {
+ Handle(TCollection_HAsciiString) aFontAlias =
+ new TCollection_HAsciiString (Font_FontMgr_MapOfFontsAliases[anIter].EnumName);
+ if (aFontAlias->IsSameString (aFontName, Standard_False))
+ {
+ aFontName = new TCollection_HAsciiString (Font_FontMgr_MapOfFontsAliases[anIter].FontName);
+ aFontAspect = Font_FontMgr_MapOfFontsAliases[anIter].FontAspect;
+ break;
+ }
+ }
+
+ aFont = GetFont (aFontName, aFontAspect, aFontSize);
+
+ if (!aFont.IsNull())
+ {
+ return aFont;
+ }
+
+ // Requested family name not found -> search for any font family with given aspect and height
+ aFontName = new TCollection_HAsciiString ("");
+ aFont = GetFont (aFontName, aFontAspect, aFontSize);
+
+ if (!aFont.IsNull())
+ {
+ return aFont;
+ }
+
+ // The last resort: trying to use ANY font available in the system
+ aFontAspect = Font_FA_Undefined;
+ aFontSize = -1;
+ aFont = GetFont (aFontName, aFontAspect, aFontSize);
+
+ if (!aFont.IsNull())
+ {
+ return aFont;
+ }
+
+ return NULL; // Fonts are not found in the system.
+}
DEFINE_LIST (Font_NListOfSystemFont,
NCollection_List,
Handle(Font_SystemFont))
-#endif
+
+inline Standard_Boolean IsEqual (const Handle(Font_SystemFont)& theFirstFont,
+ const Handle(Font_SystemFont)& theSecondFont)
+{
+ return theFirstFont->IsEqual (theSecondFont);
+}
+#endif
\ No newline at end of file
--- /dev/null
+// Created on: 2009-05-10
+// Created by: Paul V. SUPRYATKIN
+// Copyright (c) 2009-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+
+
+#define Font_NOF_ASCII_MONO "Courier"
+#define Font_NOF_ASCII_SIMPLEX "Times-Roman"
+#define Font_NOF_ASCII_COMPLEX "Times-Roman"
+#define Font_NOF_ASCII_DUPLEX "Times-Bold"
+#define Font_NOF_ASCII_TRIPLEX "Times-Bold"
+#define Font_NOF_ASCII_ITALIC_COMPLEX "Times-Italic"
+#define Font_NOF_ASCII_ITALIC_TRIPLEX "Times-BoldItalic"
+#define Font_NOF_ASCII_SCRIPT_SIMPLEX "ZapfChancery-MediumItalic"
+#define Font_NOF_ASCII_SCRIPT_COMPLEX "ZapfChancery-MediumItalic"
+#define Font_NOF_GREEK_MONO "Symbol"
+#define Font_NOF_GREEK_SIMPLEX "Symbol"
+#define Font_NOF_GREEK_COMPLEX "Symbol"
+#define Font_NOF_SYMBOL_MONO "ZapfDingbats"
+#define Font_NOF_SYMBOL_SIMPLEX "ZapfDingbats"
+#define Font_NOF_CARTOGRAPHIC_SIMPLEX "Rock"
+#define Font_NOF_KANJI_MONO "Iris"
+#define Font_NOF_KATAKANA_MONO "Iris"
---Purpose: Creates empty font object
---Level: Public
- Create (FontName : HAsciiString;
- Aspect : FontAspect;
- FilePath : HAsciiString ) returns SystemFont;
+ Create (theFontName : HAsciiString;
+ theFontAspect : FontAspect;
+ theFilePath : HAsciiString ) returns SystemFont;
---Purpose: Creates Font object initialized with <FontName> as name
--- <FontAspect>.... TODO
---Level: Public
- Create (XLFD : HAsciiString;
- FilePath : HAsciiString ) returns SystemFont;
- ---Purpose: TODO
+ Create (theXLFD : HAsciiString;
+ theFilePath : HAsciiString ) returns SystemFont;
+ ---Purpose: Creates Font object and initialize class fields with
+ --- values taken from XLFD (X Logical Font Description)
---Level: Public
FontName (me) returns HAsciiString;
--- Level: Public
IsValid (me) returns Boolean;
-
+
+ IsEqual (me;
+ theOtherFont: SystemFont) returns Boolean;
+ --- Purpose: Return true if the FontName, FontAspect and FontSize are the same.
+ --- Level: Public
+
fields
MyFontName: HAsciiString; --Font family name
MyFontAspect: FontAspect;
}
-Font_SystemFont::Font_SystemFont( const Handle(TCollection_HAsciiString)& XLFD,
- const Handle(TCollection_HAsciiString)& FilePath) :
-MyFilePath(FilePath),
-MyFontAspect(Font_FA_Undefined)
+Font_SystemFont::Font_SystemFont (const Handle(TCollection_HAsciiString)& theXLFD,
+ const Handle(TCollection_HAsciiString)& theFilePath) :
+MyFilePath(theFilePath),
+MyFontAspect(Font_FA_Regular)
{
MyVerification = Standard_True;
- if ( XLFD.IsNull() )
+ if (theXLFD.IsNull())
{
- MyVerification=Standard_False;
- printf("NULL XLFD handler \n");
+ MyVerification = Standard_False; // empty font description handler
}
- if ( XLFD->IsEmpty() )
+ if (theXLFD->IsEmpty())
{
- MyVerification=Standard_False;
- printf("EMPTY XLFD handler \n");
+ MyVerification = Standard_False; // empty font description
}
- if(MyVerification)
+ if (MyVerification)
{
- MyFontName = XLFD->Token( "-", 2 );
- TCollection_AsciiString str( XLFD->ToCString() );
+ MyFontName = theXLFD->Token ("-", 2);
+ TCollection_AsciiString aXLFD (theXLFD->ToCString());
- if ( str.Search( "-0-0-0-0-" ) >=0 )
- MyFaceSize = -1;
+ // Getting font size for fixed size fonts
+ if (aXLFD.Search ("-0-0-0-0-") >= 0)
+ MyFaceSize = -1; // Scalable font
else
//TODO catch exeption
- MyFaceSize = str.Token( "-", 7 ).IntegerValue();
+ MyFaceSize = aXLFD.Token ("-", 7).IntegerValue();
- //detect aspect
- if ( str.Token("-", 3).IsEqual( "bold" ) )
+ // Detect font aspect
+ if (aXLFD.Token ("-", 3).IsEqual ("bold") &&
+ (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o")))
+ {
+ MyFontAspect = Font_FA_BoldItalic;
+ }
+ else if (aXLFD.Token ("-", 3).IsEqual ("bold"))
+ {
MyFontAspect = Font_FA_Bold;
- else if ( str.Token("-", 3).IsEqual( "medium" ) ||
- str.Token("-", 3).IsEqual( "normal" ) )
- MyFontAspect = Font_FA_Regular;
-
- if ( MyFontAspect != Font_FA_Undefined &&
- ( str.Token("-",4 ).IsEqual( "i" ) || str.Token("-",4 ).IsEqual( "o" ) ) )
+ }
+ else if (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o"))
{
- if ( MyFontAspect == Font_FA_Bold )
- MyFontAspect = Font_FA_BoldItalic;
- else
- MyFontAspect = Font_FA_Italic;
+ MyFontAspect = Font_FA_Italic;
}
}
}
Standard_Integer Font_SystemFont::FontHeight() const {
return MyFaceSize;
}
+
+Standard_Boolean Font_SystemFont::IsEqual(const Handle(Font_SystemFont)& theOtherFont) const
+{
+ if (!MyFontName->IsSameString (theOtherFont->FontName(), Standard_False))
+ {
+ return Standard_False;
+ }
+
+ if (MyFontAspect != theOtherFont->FontAspect())
+ {
+ return Standard_False;
+ }
+
+ if (MyFaceSize != theOtherFont->FontHeight())
+ {
+ return Standard_False;
+ }
+
+ return Standard_True;
+}
Graphic3d_NListOfHAsciiString.hxx
Graphic3d_AspectText3d.cxx
Graphic3d_WNTGraphicDevice.cxx
-Graphic3d_NameOfFont.hxx
Graphic3d_PtrFrameBuffer.hxx
Graphic3d_BufferType.hxx
---Purpose: Creates a context table for text primitives
-- defined with the specified values.
-- AFont may be to take means from User(example "Courier New")
- -- or Font described in OpenGl_FontName(example Graphic3d_NOF_ASCII_MONO)
+ -- or Font name defined in Font_NameOfFont(example Font_NOF_ASCII_MONO)
-- or use default font("Courier")
--
raises AspectTextDefinitionError from Graphic3d;
---Purpose: Modifies the font of <me>.
---Category: Methods to modify the class definition
---AFont may be to take means from User(example "Courier New")
- ---or Font described in OpenGl_FontName(example Graphic3d_NOF_ASCII_MONO)
+ ---or Font name defined in Font_NameOfFont(example Font_NOF_ASCII_MONO)
---or use default font("Courier")
#include <TCollection_AsciiString.hxx>
#include <OSD_Environment.hxx>
-#include <Graphic3d_NameOfFont.hxx>
+#include <Font_NameOfFont.hxx>
//-Aliases
Graphic3d_AspectText3d::Graphic3d_AspectText3d ():
-MyFont (Graphic3d_NOF_ASCII_MONO), MyColor (Quantity_NOC_YELLOW), MyFactor (1.0), MySpace (0.0), MyStyle (Aspect_TOST_NORMAL), MyDisplayType (Aspect_TODT_NORMAL), MyColorSubTitle (Quantity_NOC_WHITE) {
+MyFont (Font_NOF_ASCII_MONO), MyColor (Quantity_NOC_YELLOW), MyFactor (1.0), MySpace (0.0), MyStyle (Aspect_TOST_NORMAL), MyDisplayType (Aspect_TODT_NORMAL), MyColorSubTitle (Quantity_NOC_WHITE) {
MyTextZoomable = Standard_False;
MyTextAngle = 0.0;
MyTextFontAspect = Font_FA_Regular;
MyTextAngle = 0.0;
MyTextFontAspect = Font_FA_Regular;
if(MyFont.Length() == 0)
- MyFont.AssignCat(Graphic3d_NOF_ASCII_MONO);
+ MyFont.AssignCat(Font_NOF_ASCII_MONO);
if (AFactor <= 0.0)
Graphic3d_AspectTextDefinitionError::Raise
TCollection_AsciiString aTemp("");
if( !strlen(AFont))
- aTemp.AssignCat(Graphic3d_NOF_ASCII_MONO);
+ aTemp.AssignCat(Font_NOF_ASCII_MONO);
else
aTemp.AssignCat(AFont);
MyFont = aTemp;
+++ /dev/null
-// Created on: 2009-05-10
-// Created by: Paul V. SUPRYATKIN
-// Copyright (c) 2009-2012 OPEN CASCADE SAS
-//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
-//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
-//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-
-
-#define Graphic3d_NOF_ASCII_MONO "Courier"
-#define Graphic3d_NOF_ASCII_SIMPLEX "Times-Roman"
-#define Graphic3d_NOF_ASCII_COMPLEX "Times-Roman"
-#define Graphic3d_NOF_ASCII_DUPLEX "Times-Bold"
-#define Graphic3d_NOF_ASCII_TRIPLEX "Times-Bold"
-#define Graphic3d_NOF_ASCII_ITALIC_COMPLEX "Times-Italic"
-#define Graphic3d_NOF_ASCII_ITALIC_TRIPLEX "Times-BoldItalic"
-#define Graphic3d_NOF_ASCII_SCRIPT_SIMPLEX "ZapfChancery-MediumItalic"
-#define Graphic3d_NOF_ASCII_SCRIPT_COMPLEX "ZapfChancery-MediumItalic"
-#define Graphic3d_NOF_GREEK_MONO "Symbol"
-#define Graphic3d_NOF_GREEK_SIMPLEX "Symbol"
-#define Graphic3d_NOF_GREEK_COMPLEX "Symbol"
-#define Graphic3d_NOF_SYMBOL_MONO "ZapfDingbats"
-#define Graphic3d_NOF_SYMBOL_SIMPLEX "ZapfDingbats"
-#define Graphic3d_NOF_CARTOGRAPHIC_SIMPLEX "Rock"
-#define Graphic3d_NOF_KANJI_MONO "Iris"
-#define Graphic3d_NOF_KATAKANA_MONO "Iris"
#include <MeshVS_DrawerAttribute.hxx>
#include <MeshVS_Buffer.hxx>
-#include <Graphic3d_NameOfFont.hxx>
+#include <Font_NameOfFont.hxx>
//================================================================
// Function : Constructor MeshVS_TextPrsBuilder
#include <MeshVS_DrawerAttribute.hxx>
#include <Precision.hxx>
-#include <Graphic3d_NameOfFont.hxx>
+#include <Font_NameOfFont.hxx>
//================================================================
// Function : CreateAspectFillArea3d
Quantity_Color aTColor = Quantity_NOC_YELLOW;
Standard_Real anExpFactor = 1.0,
aSpace = 0.0;
- Standard_CString aFont = Graphic3d_NOF_ASCII_MONO;
+ Standard_CString aFont = Font_NOF_ASCII_MONO;
Aspect_TypeOfStyleText aStyle = Aspect_TOST_NORMAL;
Aspect_TypeOfDisplayText aDispText = Aspect_TODT_NORMAL;
- TCollection_AsciiString aFontString = Graphic3d_NOF_ASCII_MONO;
+ TCollection_AsciiString aFontString = Font_NOF_ASCII_MONO;
Font_FontAspect aFontAspect = Font_FA_Regular;
Standard_Integer aStyleI = (Standard_Integer)Aspect_TOST_NORMAL;
Standard_Integer aDispTextI = (Standard_Integer)Aspect_TODT_NORMAL;
// Fonts
- int FindFont (const char* AFontName, const Font_FontAspect AFontAspect, const int ABestSize = -1, const float AXScale = 1.F, const float AYScale = 1.F);
+ Standard_Integer FindFont (Standard_CString theFontName, const Font_FontAspect theFontAspect, const Standard_Integer theBestSize = -1, const Standard_ShortReal theXScale = 1.F, const Standard_ShortReal theYScale = 1.F);
void StringSize (const wchar_t *text, int &width, int &ascent, int &descent);
* Prototypes variables statiques
*/
-struct FontMapNode
-{
- const char * EnumName;
- const char * FontName;
- Font_FontAspect FontAspect;
-};
-
-static const FontMapNode myFontMap[] =
-{
-
-#ifdef WNT
-
- { "Courier" , "Courier New" , Font_FA_Regular },
- { "Times-Roman" , "Times New Roman", Font_FA_Regular },
- { "Times-Bold" , "Times New Roman", Font_FA_Bold },
- { "Times-Italic" , "Times New Roman", Font_FA_Italic },
- { "Times-BoldItalic" , "Times New Roman", Font_FA_BoldItalic },
- { "ZapfChancery-MediumItalic", "Script" , Font_FA_Regular },
- { "Symbol" , "Symbol" , Font_FA_Regular },
- { "ZapfDingbats" , "WingDings" , Font_FA_Regular },
- { "Rock" , "Arial" , Font_FA_Regular },
- { "Iris" , "Lucida Console" , Font_FA_Regular }
-
-#else //X11
-
- { "Courier" , "Courier" , Font_FA_Regular },
- { "Times-Roman" , "Times" , Font_FA_Regular },
- { "Times-Bold" , "Times" , Font_FA_Bold },
- { "Times-Italic" , "Times" , Font_FA_Italic },
- { "Times-BoldItalic" , "Times" , Font_FA_BoldItalic },
- { "Arial" , "Helvetica" , Font_FA_Regular },
- { "ZapfChancery-MediumItalic", "-adobe-itc zapf chancery-medium-i-normal--*-*-*-*-*-*-iso8859-1" , Font_FA_Regular },
- { "Symbol" , "-adobe-symbol-medium-r-normal--*-*-*-*-*-*-adobe-fontspecific" , Font_FA_Regular },
- { "ZapfDingbats" , "-adobe-itc zapf dingbats-medium-r-normal--*-*-*-*-*-*-adobe-fontspecific" , Font_FA_Regular },
- { "Rock" , "-sgi-rock-medium-r-normal--*-*-*-*-p-*-iso8859-1" , Font_FA_Regular },
- { "Iris" , "--iris-medium-r-normal--*-*-*-*-m-*-iso8859-1" , Font_FA_Regular }
-#endif
-
-};
-
-#define NUM_FONT_ENTRIES (sizeof(myFontMap)/sizeof(FontMapNode))
-
/*-----------------------------------------------------------------------------*/
/*
/*-----------------------------------------------------------------------------*/
-int OpenGl_Display::FindFont (const char* AFontName, const Font_FontAspect AFontAspect,
- const int ABestSize, const float AXScale, const float AYScale)
-{
- if (!AFontName)
+Standard_Integer OpenGl_Display::FindFont (Standard_CString theFontName,
+ const Font_FontAspect theFontAspect,
+ const Standard_Integer theBestSize,
+ const Standard_ShortReal theXScale,
+ const Standard_ShortReal theYScale)
+{
+ if (!theFontName)
return -1;
- if (ABestSize != -1)
- myFontSize = ABestSize;
-
- OpenGl_FontMgr* mgr = OpenGl_FontMgr::instance();
-
- Handle(TCollection_HAsciiString) family_name = new TCollection_HAsciiString(AFontName);
- myFont = mgr->request_font( family_name, AFontAspect, myFontSize );
-
- if( myFont == -1 )
- {
- //try to use font names mapping
- FontMapNode newTempFont = myFontMap[0];
- for ( int i = 0; i < NUM_FONT_ENTRIES; ++i )
- {
- if ( TCollection_AsciiString(myFontMap[i].EnumName).IsEqual( family_name->ToCString() ) )
- {
- newTempFont = myFontMap[i];
- break;
- }
- }
- family_name = new TCollection_HAsciiString(newTempFont.FontName);
- myFont = mgr->request_font( family_name, newTempFont.FontAspect, myFontSize );
- }
+ if (theBestSize != -1)
+ myFontSize = theBestSize;
- // Requested family name not found -> serach for any font family with given aspect and height
- if ( myFont == -1 )
- {
- family_name = new TCollection_HAsciiString( "" );
- myFont = mgr->request_font( family_name, AFontAspect, myFontSize );
- }
+ OpenGl_FontMgr* anOpenGlFontMgr = OpenGl_FontMgr::instance();
- // The last resort: trying to use ANY font available in the system
- if ( myFont == -1 )
- {
- myFont = mgr->request_font( family_name, Font_FA_Undefined, -1 );
- }
+ Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (theFontName);
+ myFont = anOpenGlFontMgr->request_font (aFontName, theFontAspect, myFontSize);
- if ( myFont != -1 )
- mgr->setCurrentScale( AXScale, AYScale );
+ if (myFont != -1)
+ anOpenGlFontMgr->setCurrentScale (theXScale, theYScale);
return myFont;
}
#include <OpenGl_GlCore11.hxx>
#include <Standard_Stream.hxx>
-
-#include <ft2build.h>
+#include <TColStd_SequenceOfHAsciiString.hxx>
#ifdef _MSC_VER
#pragma comment( lib, "ftgl.lib" )
-#pragma comment( lib, "freetype.lib" )
#endif
#undef TRACE
}
OpenGl_FontMgr::OpenGl_FontMgr()
-: _CurrentFontId(-1),
-_XCurrentScale(1.f),
-_YCurrentScale(1.f)
+: myCurrentFontId(-1),
+myXCurrentScale(1.f),
+myYCurrentScale(1.f)
{
}
if ( _mgr == NULL )
{
_mgr = new OpenGl_FontMgr();
- _mgr->_initializeFontDB();
}
return _mgr;
}
-void OpenGl_FontMgr::_initializeFontDB()
-{
- Handle(Font_FontMgr) fntMgr = Font_FontMgr::GetInstance();
- if ( !fntMgr.IsNull() ) {
-
- Font_NListOfSystemFont fontList = fntMgr->GetAvalableFonts();
- if ( fontList.Size() != 0 ) {
-
- // The library used as a tool for checking font aspect since Font_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);
-
- Font_NListOfSystemFont::Iterator it(fontList);
- for ( ; it.More(); it.Next() ) {
- OGLFont_SysInfo* info = new OGLFont_SysInfo();
- if ( it.Value()->FontAspect() == Font_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"
- FT_Face aFontFace;
- FT_Error aFaceError = FT_New_Face(aFtLibrary,
- aFontPath->ToCString(), 0,
- &aFontFace);
-
- if ( aFaceError == FT_Err_Ok ) {
- if ( aFontFace->style_flags == 0 ) {
- info->SysFont = it.Value();
- }
- else {
- //new aspect detected for current font item
-#ifdef TRACE
- cout << "TKOpenGl::initializeFontDB() detected new font!\n"
- << "\tFont Previous Name: " << it.Value()->FontName()->ToCString() << endl
- << "\tFont New Name: " << aFontFace->family_name << endl
- << "\tFont Aspect: " << aFontFace->style_flags << endl;
-#endif
- Font_FontAspect aspect = Font_FA_Regular;
- if ( aFontFace->style_flags == (FT_STYLE_FLAG_ITALIC | FT_STYLE_FLAG_BOLD) )
- aspect = Font_FA_BoldItalic;
- else if ( aFontFace->style_flags == FT_STYLE_FLAG_ITALIC )
- aspect = Font_FA_Italic;
- else if ( aFontFace->style_flags == FT_STYLE_FLAG_BOLD )
- aspect = Font_FA_Bold;
-
-#ifdef TRACE
- cout << "\tFont_FontAspect: " << aspect << endl;
-#endif
- Handle(TCollection_HAsciiString) aFontName =
- new TCollection_HAsciiString( aFontFace->family_name );
- info->SysFont = new Font_SystemFont( aFontName, aspect, aFontPath );
- }
-
- FT_Done_Face(aFontFace);
- }
- else
- continue;
- } else {
- info->SysFont = it.Value();
- }
- _FontDB.Append(info);
-
- }
-
- // finalize library instance
- if ( aLibError == FT_Err_Ok )
- {
- FT_Done_FreeType(aFtLibrary);
- }
- }
- }
-
-#ifdef TRACE
- if ( !_FontDB.Size() ) {
- cout << "\nTKOpenGl::initializeFontDB() FAILED!!!\n"
- << "No fonts detected in the system!\n"
- << "Text rendering in 3D viewer will not be available." << endl;
- }
-#endif
-}
-
-bool OpenGl_FontMgr::requestFontList( Graphic3d_NListOfHAsciiString& lst)
-{
- FontDBIt DBit(_FontDB);
- lst.Clear();
- for ( ; DBit.More(); DBit.Next() ) {
- lst.Append( DBit.Value()->SysFont->FontName() );
- }
- return true;
-}
-
// Empty fontName means that ANY family name can be used.
// fontAspect == Font_FA_Undefined means ANY font aspect is acceptable.
// fontheight == -1 means ANY font height is acceptable.
-int OpenGl_FontMgr::request_font( const Handle(TCollection_HAsciiString)& fontName,
- const Font_FontAspect fontAspect,
- const Standard_Integer fontHeight )
+int OpenGl_FontMgr::request_font (const Handle(TCollection_HAsciiString)& theFontName,
+ const Font_FontAspect theFontAspect,
+ const Standard_Integer& theFontHeight)
{
- Standard_Integer aFontHeight = fontHeight;
- if ( aFontHeight < 2 && aFontHeight != -1 )
+ Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
+ Handle(Font_SystemFont) aRequestedFont = aFontMgr->FindFont (theFontName, theFontAspect, theFontHeight);
+
+ if (aRequestedFont.IsNull())
{
-#ifdef TRACE
- cout << "TKOpenGl::request_font\n"
- << " Error: font height is invalid!!!\n"
- << " font height:" << aFontHeight << "\n";
-#endif //TRACE
return -1;
- }
-
-#ifdef TRACE
- cout << "TKOpenGl::request_font\n"
- << " font name: " << fontName->ToCString() << endl
- << " font aspect: " << fontAspect << endl
- << " font height: " << aFontHeight << endl;
-#endif
-
- GLCONTEXT ctx = GET_GL_CONTEXT();
-
- //check for font
- FontDBIt DBit(_FontDB);
-
-#ifdef TRACE
- cout << "Searching font in font database...\n";
-#endif
+ }
- for ( ; DBit.More(); DBit.Next() ) {
- // san (23.07.2010): comparing font names in case-insensitive mode,
- // as on SUN and SGI system font names are in lower-case
- if ( fontName->IsEmpty() || DBit.Value()->SysFont->FontName()->IsSameString(fontName, Standard_False) ) {
-#ifdef TRACE
- cout << "\tName is found...\n\tCheking aspect...\n";
-#endif
+ // Setting font height
+ Standard_Integer aFontHeight = theFontHeight;
+ if (theFontHeight < 2 && aRequestedFont->FontHeight() == -1)
+ {
+ // Font height is not specified -> use DEFAULT_FONT_HEIGHT for variable-height fonts
+ aFontHeight = DEFAULT_FONT_HEIGHT;
+ }
+ else if (theFontHeight < 2)
+ {
+ // Font height is not specified -> use font height for fixed size fonts
+ aFontHeight = aRequestedFont->FontHeight();
+ }
- //check for font aspect
- if (fontAspect != Font_FA_Undefined && DBit.Value()->SysFont->FontAspect() != fontAspect) {
-#ifdef TRACE
- cout << "\tAspect of candidate font: " << DBit.Value()->SysFont->FontAspect() << endl;
- cout << "\tAspects are not equal! Continue seaching...\n";
-#endif
- continue;
- }
+ GLCONTEXT aContext = GET_GL_CONTEXT();
-#ifdef TRACE
- cout << "\tAspect is found...\n\tCheking height...\n";
-#endif
- //check for fixed height
- if (DBit.Value()->SysFont->FontHeight() != -1) {
-#ifdef TRACE
- cout << "\tChecking fixed height: " << DBit.Value()->SysFont->FontHeight() << endl;
-#endif
- //fixed height font
- if ( aFontHeight != -1 && DBit.Value()->SysFont->FontHeight() != aFontHeight ){
-#ifdef TRACE
- cout << "\tHeights are not equal! Continue seaching...\n";
-#endif
- continue;
- }
- else
- {
- // We need to remember the font height to be used
- if ( aFontHeight == -1 )
- aFontHeight = DBit.Value()->SysFont->FontHeight();
-#ifdef TRACE
- cout << "\tHeight is found\n";
-#endif
- }
- }
- else
+ // Check in already generated fonts.
+ if (myGeneratedFontDB.IsBound (aRequestedFont))
+ {
+ const IDList& anIDList = myGeneratedFontDB.Find (aRequestedFont);
+ for (IDList::Iterator anIDListIterator (anIDList); anIDListIterator.More();
+ anIDListIterator.Next())
+ {
+ OGLFont_Cache aFontCache = myGeneratedFontCache (anIDListIterator.Value());
+ if (aFontCache.FontHeight == aFontHeight && aFontCache.GlContext == aContext)
{
- // If font height is not specified -> use DEFAULT_FONT_HEIGHT for variable-height fonts
- if ( aFontHeight == -1 )
- aFontHeight = DEFAULT_FONT_HEIGHT;
-#ifdef TRACE
- cout << "\tFont has variable height == -1. height is found\n";
-#endif
- }
-#ifdef TRACE
- cout << "\tChecking font manager cache...\n";
-#endif
- //check in loaded fonts
- IDList::Iterator fIt(DBit.Value()->GeneratedFonts);
- for ( ; fIt.More(); fIt.Next() ) {
- OGLFont_Cache cache = _FontCache.Find( fIt.Value() );
- if ( cache.FontHeight == aFontHeight && cache.GlContext == ctx ) {
- //requested font is generated already
-
-#ifdef TRACE
- cout << "\tRequested font is generated already\n\tId = " ;
- cout << fIt.Value() << endl;
-#endif
- _CurrentFontId = fIt.Value();
- return _CurrentFontId;
- } else {
-#ifdef TRACE
- cout << "\t\tHeights or contexts are not equal:\n"
- << "\t\t\tfont height: " << aFontHeight << "\tchache height: " << cache.FontHeight << endl
- << "\t\t\tfont context: " << ctx << "\tchache context: " << cache.GlContext << endl;
- cout << "\t\tContinue searching in cache...\n";
-#endif
- }
- }
-#ifdef TRACE
- cout << "\tRequested font is not found among genarated fonts.\n\tCreating new...\n";
-#endif
- //if not found in generated fonts
- //create new
- FTGLTextureFont* font = new FTGLTextureFont(DBit.Value()->SysFont->FontPath()->ToCString());
- //by default creates regular font
- if ( ! font || font->Error() != FT_Err_Ok) {
-#ifdef TRACE
- cout << "\t\tError during creation FTGL font object!\n";
-#endif
- return -1;
+ // Requested font is already generated, returning it cache ID.
+ myCurrentFontId = anIDListIterator.Value();
+ return myCurrentFontId;
}
+ }
+ }
- if ( ! font->FaceSize( aFontHeight) || font->Error() != FT_Err_Ok ){
-#ifdef TRACE
- cout << "\t\tError during setup FTGL font height!\n";
-#endif
- return -1;
- }
- font->UseDisplayList( false );
+ // Cache for requested font is not found. Generating new FTGL font.
+ FTGLTextureFont* aFTGLFont = new FTGLTextureFont(aRequestedFont->FontPath()->ToCString());
+ if ( !aFTGLFont || aFTGLFont->Error() != FT_Err_Ok)
+ {
+ return -1; // Error during creation FTGL font object!
+ }
- //put font to cache
- OGLFont_Cache cache;
- cache.Font = font;
- cache.FontHeight = aFontHeight;
- cache.GlContext = ctx;
+ if ( !aFTGLFont->FaceSize (aFontHeight) || aFTGLFont->Error() != FT_Err_Ok )
+ {
+ return -1; // Error during setup FTGL font height!
+ }
- _CurrentFontId =_FontCache.Size() + 1;
- _FontCache.Bind( _CurrentFontId, cache );
- DBit.Value()->GeneratedFonts.Append(_CurrentFontId);
+ aFTGLFont->UseDisplayList (false);
-#ifdef TRACE
- cout << "TKOpenGl::Loaded New FTGL font:\n"
- << " font name: " << fontName->ToCString() << "\n"
- << " font aspect: ";
+ // Adding font to cache.
+ OGLFont_Cache aCache;
+ aCache.Font = aFTGLFont;
+ aCache.FontHeight = aFontHeight;
+ aCache.GlContext = aContext;
- switch( fontAspect )
- {
- case Font_FA_Bold:
- cout << "Font_FA_Bold\n";
- break;
- case Font_FA_BoldItalic:
- cout << "Font_FA_BoldItalic\n";
- break;
- case Font_FA_Italic:
- cout << "Font_FA_Italic\n";
- break;
- case Font_FA_Regular:
- cout << "Font_FA_Regular\n";
- break;
- default:
- cout << "Font_FA_Undefined\n";
- break;
- }
- cout << " font height: "<<aFontHeight<<"\n";
- cout << " font id: " << _CurrentFontId << "\n";
-#endif
+ myCurrentFontId = myGeneratedFontCache.Size() + 1;
+ myGeneratedFontCache.Bind ( myCurrentFontId, aCache);
- return _CurrentFontId;
- }
+ if (myGeneratedFontDB.IsBound (aRequestedFont))
+ {
+ myGeneratedFontDB.ChangeFind (aRequestedFont).Append (myCurrentFontId);
}
- //invalid family name
-#ifdef TRACE
- cout << "\n---Invalid Family Name!!!---\n";
-#endif
- return -1;
+ else
+ {
+ IDList anIDList;
+ anIDList.Append (myCurrentFontId);
+ myGeneratedFontDB.Bind (aRequestedFont, anIDList);
+ }
+
+ return myCurrentFontId;
}
void OpenGl_FontMgr::render_text( const Standard_Integer id, const wchar_t* text,
<< "\tfont id = " << id << endl
<< "\ttext = " << text << endl;
#endif
- if ( text && _FontCache.IsBound( id ) ) {
+ if ( text && myGeneratedFontCache.IsBound( id ) ) {
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
- glScalef( _XCurrentScale, _YCurrentScale, 1 );
+ glScalef( myXCurrentScale, myYCurrentScale, 1 );
glPushAttrib( GL_ENABLE_BIT );
GLboolean enableTexture = glIsEnabled(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glAlphaFunc(GL_GEQUAL, 0.285f);
glEnable(GL_ALPHA_TEST);
- OGLFont_Cache cache = _FontCache.Find( id );
+ OGLFont_Cache cache = myGeneratedFontCache.Find( id );
cache.Font->Render( text );
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
void OpenGl_FontMgr::render_text ( const wchar_t* text, const Standard_Boolean is2d )
{
- render_text( _CurrentFontId, text, is2d );
+ render_text( myCurrentFontId, text, is2d );
}
const FTFont* OpenGl_FontMgr::fontById (const Standard_Integer id)
{
- return _FontCache.IsBound( id ) ? _FontCache.Find( id ).Font: NULL;
+ return myGeneratedFontCache.IsBound( id ) ? myGeneratedFontCache.Find( id ).Font: NULL;
}
Standard_ShortReal OpenGl_FontMgr::computeWidth( const Standard_Integer id, const wchar_t* text )
{
- if( !_FontCache.IsBound( id ) )
+ if( !myGeneratedFontCache.IsBound( id ) )
return 0.f;
- OGLFont_Cache cache = _FontCache.Find( id );
+ OGLFont_Cache cache = myGeneratedFontCache.Find( id );
Standard_ShortReal w = cache.Font->Advance( text );
void OpenGl_FontMgr::setCurrentScale (const Standard_ShortReal xScale,
const Standard_ShortReal yScale)
{
- _XCurrentScale = xScale;
- _YCurrentScale = yScale;
+ myXCurrentScale = xScale;
+ myYCurrentScale = yScale;
}
#include <AlienImage_BMPAlienData.hxx>
public:
static OpenGl_FontMgr* instance();
- int request_font( const Handle(TCollection_HAsciiString)& fontName,
- const Font_FontAspect fontAspect,
- const Standard_Integer fontHeight );
+ int request_font (const Handle(TCollection_HAsciiString)& theFontName,
+ const Font_FontAspect theFontAspect,
+ const Standard_Integer& theFontHeight);
void render_text( const Standard_Integer id,
const wchar_t* text,
//returns width of string
Standard_ShortReal computeWidth( const Standard_Integer id, const wchar_t *str );
- bool requestFontList( Graphic3d_NListOfHAsciiString& );
-
void setCurrentScale( const Standard_ShortReal xScale = 1.f,
const Standard_ShortReal yScale = 1.f);
typedef NCollection_List<Standard_Integer> IDList;
- struct OGLFont_SysInfo {
- Handle(Font_SystemFont) SysFont;
- IDList GeneratedFonts;
- };
-
struct OGLFont_Cache {
FTFont* Font;
Standard_Integer FontHeight;
GLCONTEXT GlContext;
};
- typedef NCollection_List<OGLFont_SysInfo*> FontDataBase;
- typedef FontDataBase::Iterator FontDBIt;
- typedef NCollection_DataMap<Standard_Integer,OGLFont_Cache> FontCache;
- typedef FontCache::Iterator FCacheIt;
+ typedef NCollection_DataMap<Handle(Font_SystemFont), IDList> FontDataBase;
+ typedef FontDataBase::Iterator FontDBIterator;
+ typedef NCollection_DataMap<Standard_Integer, OGLFont_Cache> FontCache;
+ typedef FontCache::Iterator FontCacheIterator;
- FontDataBase _FontDB;
- FontCache _FontCache;
+ FontDataBase myGeneratedFontDB;
+ FontCache myGeneratedFontCache;
- Standard_Integer _CurrentFontId;
+ Standard_Integer myCurrentFontId;
- Standard_ShortReal _XCurrentScale,
- _YCurrentScale;
+ Standard_ShortReal myXCurrentScale,
+ myYCurrentScale;
};
#endif //OPENGL_FONT_MGR_H
#include <Prs3d_TextAspect.ixx>
#include <Quantity_Color.hxx>
-#include <Graphic3d_NameOfFont.hxx>
+#include <Font_NameOfFont.hxx>
Prs3d_TextAspect::Prs3d_TextAspect ()
: myAngle(0.),
myTextAspect = new Graphic3d_AspectText3d (
Quantity_Color(Quantity_NOC_YELLOW),
- Graphic3d_NOF_ASCII_TRIPLEX,
+ Font_NOF_ASCII_TRIPLEX,
1.,
0.);
}
#include <GGraphic2d_SetOfCurves.hxx>
#include <Graphic2d_SetOfSegments.hxx>
-#include <Graphic3d_NameOfFont.hxx>
+#include <Font_NameOfFont.hxx>
static Standard_Integer BUC60842 (Draw_Interpretor& di, Standard_Integer /*argc*/,const char ** /*argv*/)
{
return -1;
}
- Handle(QABugs_MyText) txt1 = new QABugs_MyText("Gosha1",gp_Pnt(0,0,0),Graphic3d_NOF_ASCII_SIMPLEX,Quantity_NOC_RED,atoi(argv[1]));
+ Handle(QABugs_MyText) txt1 = new QABugs_MyText("Gosha1",gp_Pnt(0,0,0),Font_NOF_ASCII_SIMPLEX,Quantity_NOC_RED,atoi(argv[1]));
aContext->Display(txt1);
- Handle(QABugs_MyText) txt2 = new QABugs_MyText("Gosha2",gp_Pnt(0,0,100),Graphic3d_NOF_ASCII_SIMPLEX,Quantity_NOC_YELLOW,atoi(argv[2]));
+ Handle(QABugs_MyText) txt2 = new QABugs_MyText("Gosha2",gp_Pnt(0,0,100),Font_NOF_ASCII_SIMPLEX,Quantity_NOC_YELLOW,atoi(argv[2]));
aContext->Display(txt2);
- Handle(QABugs_MyText) txt3 = new QABugs_MyText("Gosha3",gp_Pnt(0,100,100),Graphic3d_NOF_ASCII_SIMPLEX,Quantity_NOC_SKYBLUE,atoi(argv[3]));
+ Handle(QABugs_MyText) txt3 = new QABugs_MyText("Gosha3",gp_Pnt(0,100,100),Font_NOF_ASCII_SIMPLEX,Quantity_NOC_SKYBLUE,atoi(argv[3]));
aContext->Display(txt3);
return 0;
#include <Prs3d_Text.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <SelectMgr_Selection.hxx>
-#include <Graphic3d_NameOfFont.hxx>
+#include <Font_NameOfFont.hxx>
/*************************************************************************
*
CSF_dpsLibs
CSF_XmuLibs
CSF_FreeImagePlus
+CSF_FREETYPE
CSF_kernel32
STLPortLib
CSF_TBB
-CSF_MotifLibs
-
#include <TCollection_AsciiString.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
-#include <Graphic3d_NameOfFont.hxx>
+#include <Font_NameOfFont.hxx>
V3d_ColorScale::V3d_ColorScale( const Handle(V3d_LayerMgr)& aMgr )
: Aspect_ColorScale(),
return;
theLayer->SetColor( aColor );
- theLayer->SetTextAttributes( Graphic3d_NOF_ASCII_MONO, Aspect_TODT_NORMAL, aColor );
+ theLayer->SetTextAttributes( Font_NOF_ASCII_MONO, Aspect_TODT_NORMAL, aColor );
TCollection_AsciiString theText( aText.ToExtString(), '?' );
Standard_Integer aTextH = GetTextHeight();
Standard_Integer aWidth, anAscent, aDescent;
#include <Aspect_Window.hxx>
#include <Visual3d_View.hxx>
#include <V3d_ColorScale.hxx>
-#include <Graphic3d_NameOfFont.hxx>
+#include <Font_NameOfFont.hxx>
V3d_LayerMgr::V3d_LayerMgr( const Handle(V3d_View)& AView )
myOverlay->Clear();
myOverlay->SetViewport( aW, aH ); //szv:!!!
myOverlay->Begin();
- myOverlay->SetTextAttributes( Graphic3d_NOF_ASCII_MONO, Aspect_TODT_NORMAL, Quantity_Color() );
+ myOverlay->SetTextAttributes( Font_NOF_ASCII_MONO, Aspect_TODT_NORMAL, Quantity_Color() );
myOverlay->SetOrtho( 0, Max( aW, aH ), Max( aW, aH ), 0, Aspect_TOC_TOP_LEFT );
return Standard_True;
//===============================================================================================
#include <Graphic3d_Group.hxx>
#include <Graphic3d_Structure.hxx>
-#include <Graphic3d_NameOfFont.hxx>
#include <Graphic3d_AspectText3d.hxx>
#include <Graphic2d_GraphicObject.hxx>
#include <Graphic3d_Array1OfVertex.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
+#include <Font_NameOfFont.hxx>
+
#include <Visual3d_ViewManager.hxx>
#include <ViewerTest_Tool.ixx>
vdump $imagedir/${test_image}.png
}
+if { [info exist only_screen2d] } {
+ v2ddump $imagedir/${test_image}.png
+}
+
# to end a test script
puts "TEST COMPLETED"
-pload QAcommands
puts "================"
puts "OCC322"
puts "================"
puts ""
+pload QAcommands
+
restore [locate_data_file OCC322.brep] a
puts [checkshape a]
set y1 297
set x2 251
-set y2 230
+set y2 232
QAGetPixelColor $x1 $y1 $Yellow_R $Yellow_G $Yellow_B
QAGetPixelColor $x2 $y2 $Yellow_R $Yellow_G $Yellow_B
set square 20000
set only_screen 1
+