From aff395a36dc65743f85c1ed84818f8f2cc0cafcf Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 7 Dec 2012 13:42:37 +0400 Subject: [PATCH] 0023415: OSD_FontMgr can't idenify aspect for fonts with names dependant on system locale. 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 --- src/Font/EXTERNLIB | 1 + src/Font/FILES | 2 + src/Font/Font.cdl | 3 +- src/Font/Font_FontMgr.cdl | 65 +- src/Font/Font_FontMgr.cxx | 895 ++++++++++-------- src/Font/Font_NListOfSystemFont.hxx | 8 +- .../Font_NameOfFont.hxx} | 34 +- src/Font/Font_SystemFont.cdl | 20 +- src/Font/Font_SystemFont.cxx | 76 +- src/Graphic3d/FILES | 1 - src/Graphic3d/Graphic3d_AspectText3d.cdl | 4 +- src/Graphic3d/Graphic3d_AspectText3d.cxx | 8 +- src/MeshVS/MeshVS_TextPrsBuilder.cxx | 2 +- src/MeshVS/MeshVS_Tool.cxx | 6 +- src/OSD/EXTERNLIB | 1 - src/OpenGl/OpenGl_Display.hxx | 2 +- src/OpenGl/OpenGl_Display_1.cxx | 96 +- src/OpenGl/OpenGl_FontMgr.cxx | 356 ++----- src/OpenGl/OpenGl_FontMgr.hxx | 31 +- src/Prs3d/Prs3d_TextAspect.cxx | 4 +- src/QABugs/QABugs_17.cxx | 8 +- src/QABugs/QABugs_MyText.cxx | 2 +- src/TKService/EXTERNLIB | 1 + src/TKernel/EXTERNLIB | 2 - src/V3d/V3d_ColorScale.cxx | 4 +- src/V3d/V3d_LayerMgr.cxx | 4 +- src/ViewerTest/ViewerTest_ObjectCommands.cxx | 3 +- tests/bugs/end | 4 + tests/bugs/modalg/bug322 | 6 +- 29 files changed, 809 insertions(+), 840 deletions(-) create mode 100644 src/Font/EXTERNLIB rename src/{Graphic3d/Graphic3d_NameOfFont.hxx => Font/Font_NameOfFont.hxx} (51%) mode change 100755 => 100644 diff --git a/src/Font/EXTERNLIB b/src/Font/EXTERNLIB new file mode 100644 index 0000000000..026ed1b574 --- /dev/null +++ b/src/Font/EXTERNLIB @@ -0,0 +1 @@ +CSF_FREETYPE diff --git a/src/Font/FILES b/src/Font/FILES index 5c9f2acb58..89437064bc 100644 --- a/src/Font/FILES +++ b/src/Font/FILES @@ -1 +1,3 @@ +EXTERNLIB Font_NListOfSystemFont.hxx +Font_NameOfFont.hxx diff --git a/src/Font/Font.cdl b/src/Font/Font.cdl index 71f2826ea5..a96a7a6f9d 100644 --- a/src/Font/Font.cdl +++ b/src/Font/Font.cdl @@ -21,7 +21,8 @@ package Font uses Standard , Quantity , TCollection, - OSD + OSD, + TColStd is enumeration FontAspect is FA_Undefined, FA_Regular, FA_Bold, FA_Italic, FA_BoldItalic; diff --git a/src/Font/Font_FontMgr.cdl b/src/Font/Font_FontMgr.cdl index 160385f2cf..616f095a16 100644 --- a/src/Font/Font_FontMgr.cdl +++ b/src/Font/Font_FontMgr.cdl @@ -18,27 +18,78 @@ -- 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 ---- Private methods + 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 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; diff --git a/src/Font/Font_FontMgr.cxx b/src/Font/Font_FontMgr.cxx index 5c5af20270..c459336293 100644 --- a/src/Font/Font_FontMgr.cxx +++ b/src/Font/Font_FontMgr.cxx @@ -18,417 +18,564 @@ // and conditions governing the rights and limitations under the License. #include -#ifdef WNT -# include -# include -#else //WNT -# include -# include -#endif //WNT #include #include -#include +#include #include +#include +#include +#include FT_FREETYPE_H -#ifndef WNT -#include +struct Font_FontMgr_FontAliasMapNode +{ + const char * EnumName; + const char * FontName; + Font_FontAspect FontAspect; +}; -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -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() ) - { - TCollection_AsciiString PathName( dir ); - - Standard_Integer rem = PathName.Length(); - - if ( PathName.SearchFromEnd("/") == rem ) - PathName.Remove( rem, 1 ); - - Standard_Boolean need_to_append = Standard_True; - - StringList::Iterator it( dirs ); - for( ; it.More(); it.Next() ) - { - if ( PathName.IsEqual(it.Value().ToCString()) ) { - need_to_append = Standard_False; - break; - } - } - 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 ) - { - osd_dir.Next(); - continue; - } - - 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 //WNT - - -Handle(Font_FontMgr) Font_FontMgr::GetInstance() { - - static Handle(Font_FontMgr) _mgr; - if ( _mgr.IsNull() ) - _mgr = new Font_FontMgr(); - - return _mgr; - -} - -Font_FontMgr::Font_FontMgr() { - - InitFontDataBase(); - -} - -void Font_FontMgr::InitFontDataBase() { - - MyListOfFonts.Clear(); +static const Font_FontMgr_FontAliasMapNode Font_FontMgr_MapOfFontsAliases[] = +{ #ifdef WNT - //detect font directory - OSD_Environment env("windir"); - TCollection_AsciiString windir_str = env.Value(); - if ( windir_str.IsEmpty() ) + { "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 + #include + + #ifdef _MSC_VER + #pragma comment (lib, "freetype.lib") + #endif + + namespace { - 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 ) + // list of supported extensions + static Standard_CString Font_FontMgr_Extensions[] = + { + "ttf", + "otf", + "ttc", + NULL + }; + + }; + +#else + + #include + #include + #include + #include + #include + + 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& theDirsMap) + { + TCollection_AsciiString aDirName; + thePath.SystemName (aDirName); + if (!theDirsMap.Add (aDirName)) + { + return; + } + + for (OSD_DirectoryIterator aDirIterator (thePath, "*"); aDirIterator.More(); aDirIterator.Next()) + { + 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); + } + } + } + + }; + +#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; + } + + 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); + + return aResult; +} + +// ======================================================================= +// function : GetInstance +// purpose : +// ======================================================================= +Handle(Font_FontMgr) Font_FontMgr::GetInstance() +{ + static Handle(Font_FontMgr) _mgr; + if (_mgr.IsNull()) + { + _mgr = new Font_FontMgr(); + } + + return _mgr; +} + +// ======================================================================= +// function : Font_FontMgr +// purpose : +// ======================================================================= +Font_FontMgr::Font_FontMgr() +{ + InitFontDataBase(); +} + +// ======================================================================= +// function : InitFontDataBase +// purpose : +// ======================================================================= +void Font_FontMgr::InitFontDataBase() +{ + myListOfFonts.Clear(); + FT_Library aFtLibrary = NULL; + +#if (defined(_WIN32) || defined(__WIN32__)) + + // font directory is placed in "C:\Windows\Fonts\" + UINT aStrLength = GetSystemWindowsDirectoryA (NULL, 0); + if (aStrLength == 0) { 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) - { - // let the X server find the available connection - disp = XOpenDisplay(":0.0"); - if (!disp) - { - cout << "Display is NULL!" << endl; - return ; - } } - Standard_Integer npaths = 0; + char* aWinDir = new char[aStrLength]; + GetSystemWindowsDirectoryA (aWinDir, aStrLength); + Handle(TCollection_HAsciiString) aFontsDir = new TCollection_HAsciiString (aWinDir); + aFontsDir->AssignCat ("\\Fonts\\"); + delete[] aWinDir; - 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 ); - } - else - { - 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 ); - } - } - XFreeFontPath(fontpath); - - - OSD_OpenMode aMode = OSD_ReadOnly; - OSD_Protection aProtect( OSD_R, OSD_R, OSD_R, OSD_R ); - - for( Standard_Integer j = 0 ; j < font_service_conf_size; j++ ) + // read fonts list from registry + HKEY aFontsKey; + if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts", + 0, KEY_READ, &aFontsKey) != ERROR_SUCCESS) { - TCollection_AsciiString fileOfFontServiceName( font_service_conf[j] ); - OSD_File aFile( fileOfFontServiceName ); + return; + } - if( aFile.Exists() ) - aFile.Open( aMode, aProtect ); - - if( aFile.IsOpen() )//font service + NCollection_Map 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); + 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 + + Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (aNameBuff); + Handle(TCollection_HAsciiString) aFontPath = new TCollection_HAsciiString (aPathBuff); + if (aFontPath->Search ("\\") == -1) { - 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 + aFontPath->Insert (1, aFontsDir); // make absolute path + } - 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() ) + // check file extension is in list of supported + const Standard_Integer anExtensionPosition = aFontPath->SearchFromEnd (".") + 1; + if (anExtensionPosition > 0 && anExtensionPosition < aFontPath->Length()) + { + Handle(TCollection_HAsciiString) aFontExtension = aFontPath->SubString (anExtensionPosition, aFontPath->Length()); + aFontExtension->LowerCase(); + if (aSupportedExtensions.Contains (aFontExtension->String())) { - 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 ) + Handle(Font_SystemFont) aNewFont = checkFont (aFtLibrary, aFontPath->ToCString()); + if (!aNewFont.IsNull()) { -#ifdef TRACE - cout << " Font config find!!" << endl; -#endif - read_dirs = Standard_True; + myListOfFonts.Append (aNewFont); } - - 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 ) - { - if( ( end - begin ) > 0 ) - endStr.AssignCat( aStr.SubString ( begin, end ) );//cutting necessary literals for string - dirs.Append( TCollection_HAsciiString ( endStr ) ); - endStr.Clear(); - } - 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(); - } - } - } - 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 ); + // close registry key + RegCloseKey (aFontsKey); - 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 +#else - OSD_File readFile( fileFontsDir ); - readFile.Open( aModeRead, aProtectRead ); + NCollection_Map aMapOfFontsDirs; + const OSD_Protection aProtectRead (OSD_R, OSD_R, OSD_R, OSD_R); - Standard_Integer aNbyteRead, aNByte = 256; - if( readFile.IsOpen ( ) ) - { - TCollection_AsciiString aLine( aNByte ); - Standard_Integer countOfString = 0 ; - while( ! readFile.IsAtEnd() )//return true if EOF - { - 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++; - } - readFile.Close(); - } - fileFontsDir.Clear(); + // read fonts directories from font service config file (obsolete) + for (Standard_Integer anIter = 0; myFontServiceConf[anIter] != NULL; ++anIter) + { + const TCollection_AsciiString aFileOfFontsPath (myFontServiceConf[anIter]); + OSD_File aFile (aFileOfFontsPath); + if (!aFile.Exists()) + { + continue; } + + 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 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) + { + aStr = aStr.Split (aPathLocation - 1); + TCollection_AsciiString aFontPath; + Standard_Integer aPathNumber = 1; + do + { + // Getting directory paths, which can be splitted by "," or ":" + aFontPath = aStr.Token (":,", aPathNumber); + aFontPath.RightAdjust(); + if (!aFontPath.IsEmpty()) + { + OSD_Path aPath(aFontPath); + addDirsRecursively (aPath, aMapOfFontsDirs); + } + aPathNumber++; + } + while (!aFontPath.IsEmpty()); + } + } + aFile.Close(); + } + + // 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 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::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; + } + + Standard_Integer anExtensionPosition = aLine.Search (".") + 1; + if (anExtensionPosition == 0) + { + continue; // can't find extension position in the font description + } + + Standard_Integer anEndOfFileName = aLine.Location (" ", anExtensionPosition, aLine.Length()) - 1; + if (anEndOfFileName < 0 || anEndOfFileName < anExtensionPosition) + { + continue; // font description have empty extension + } + + TCollection_AsciiString aFontExtension = aLine.SubString (anExtensionPosition, anEndOfFileName); + aFontExtension.LowerCase(); + if (aSupportedExtensions.Contains (aFontExtension) && (aLine.Search (anEncoding) > 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. + 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()) + { + aFontPath->AssignCat ("/"); + } + 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); } -Font_NListOfSystemFont Font_FontMgr::GetAvalableFonts() const +// ======================================================================= +// function : GetAvailableFonts +// purpose : +// ======================================================================= +const Font_NListOfSystemFont& Font_FontMgr::GetAvailableFonts() const { - return MyListOfFonts; + 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()); + } +} +Handle(Font_SystemFont) Font_FontMgr::GetFont (const Handle(TCollection_HAsciiString)& theFontName, + const Font_FontAspect theFontAspect, + const Standard_Integer theFontSize) const +{ + 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. +} diff --git a/src/Font/Font_NListOfSystemFont.hxx b/src/Font/Font_NListOfSystemFont.hxx index 3fa542231f..64dd7c34b7 100644 --- a/src/Font/Font_NListOfSystemFont.hxx +++ b/src/Font/Font_NListOfSystemFont.hxx @@ -23,4 +23,10 @@ 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 diff --git a/src/Graphic3d/Graphic3d_NameOfFont.hxx b/src/Font/Font_NameOfFont.hxx old mode 100755 new mode 100644 similarity index 51% rename from src/Graphic3d/Graphic3d_NameOfFont.hxx rename to src/Font/Font_NameOfFont.hxx index e01ed7254d..8d998f6a31 --- a/src/Graphic3d/Graphic3d_NameOfFont.hxx +++ b/src/Font/Font_NameOfFont.hxx @@ -19,20 +19,20 @@ -#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" +#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" diff --git a/src/Font/Font_SystemFont.cdl b/src/Font/Font_SystemFont.cdl index 6fe62dbef5..492031d5fc 100644 --- a/src/Font/Font_SystemFont.cdl +++ b/src/Font/Font_SystemFont.cdl @@ -28,16 +28,17 @@ is ---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 as name --- .... 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; @@ -58,7 +59,12 @@ is --- 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; diff --git a/src/Font/Font_SystemFont.cxx b/src/Font/Font_SystemFont.cxx index 8285e81e83..bc3804b775 100644 --- a/src/Font/Font_SystemFont.cxx +++ b/src/Font/Font_SystemFont.cxx @@ -45,48 +45,46 @@ MyVerification(Standard_True) } -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" ) ) - 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" ) ) ) + // Detect font aspect + if (aXLFD.Token ("-", 3).IsEqual ("bold") && + (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_BoldItalic; + } + else if (aXLFD.Token ("-", 3).IsEqual ("bold")) + { + MyFontAspect = Font_FA_Bold; + } + else if (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o")) + { + MyFontAspect = Font_FA_Italic; } } } @@ -120,3 +118,23 @@ Font_FontAspect Font_SystemFont::FontAspect() const{ 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; +} diff --git a/src/Graphic3d/FILES b/src/Graphic3d/FILES index e095fa23d5..6379a7e60e 100755 --- a/src/Graphic3d/FILES +++ b/src/Graphic3d/FILES @@ -51,6 +51,5 @@ Graphic3d_CTransPersStruct.cxx Graphic3d_NListOfHAsciiString.hxx Graphic3d_AspectText3d.cxx Graphic3d_WNTGraphicDevice.cxx -Graphic3d_NameOfFont.hxx Graphic3d_PtrFrameBuffer.hxx Graphic3d_BufferType.hxx diff --git a/src/Graphic3d/Graphic3d_AspectText3d.cdl b/src/Graphic3d/Graphic3d_AspectText3d.cdl index cce89813e9..e20cb2d886 100755 --- a/src/Graphic3d/Graphic3d_AspectText3d.cdl +++ b/src/Graphic3d/Graphic3d_AspectText3d.cdl @@ -72,7 +72,7 @@ is ---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; @@ -104,7 +104,7 @@ is ---Purpose: Modifies the font of . ---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") diff --git a/src/Graphic3d/Graphic3d_AspectText3d.cxx b/src/Graphic3d/Graphic3d_AspectText3d.cxx index e7b19cfc6c..687da55f1b 100755 --- a/src/Graphic3d/Graphic3d_AspectText3d.cxx +++ b/src/Graphic3d/Graphic3d_AspectText3d.cxx @@ -44,7 +44,7 @@ #include #include -#include +#include //-Aliases @@ -80,7 +80,7 @@ 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; @@ -98,7 +98,7 @@ MyFont(AFont), MyColor (AColor), MyFactor (AFactor), MySpace (ASpace), MyStyle ( 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 @@ -127,7 +127,7 @@ void Graphic3d_AspectText3d::SetFont (const Standard_CString AFont) { TCollection_AsciiString aTemp(""); if( !strlen(AFont)) - aTemp.AssignCat(Graphic3d_NOF_ASCII_MONO); + aTemp.AssignCat(Font_NOF_ASCII_MONO); else aTemp.AssignCat(AFont); MyFont = aTemp; diff --git a/src/MeshVS/MeshVS_TextPrsBuilder.cxx b/src/MeshVS/MeshVS_TextPrsBuilder.cxx index d614ab4849..24c0475fd9 100755 --- a/src/MeshVS/MeshVS_TextPrsBuilder.cxx +++ b/src/MeshVS/MeshVS_TextPrsBuilder.cxx @@ -40,7 +40,7 @@ #include #include -#include +#include //================================================================ // Function : Constructor MeshVS_TextPrsBuilder diff --git a/src/MeshVS/MeshVS_Tool.cxx b/src/MeshVS/MeshVS_Tool.cxx index 3b4b569e0e..09ec5792c1 100755 --- a/src/MeshVS/MeshVS_Tool.cxx +++ b/src/MeshVS/MeshVS_Tool.cxx @@ -22,7 +22,7 @@ #include #include -#include +#include //================================================================ // Function : CreateAspectFillArea3d @@ -196,10 +196,10 @@ Handle( Graphic3d_AspectText3d ) MeshVS_Tool::CreateAspectText3d 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; diff --git a/src/OSD/EXTERNLIB b/src/OSD/EXTERNLIB index f897e2d1fa..e69de29bb2 100755 --- a/src/OSD/EXTERNLIB +++ b/src/OSD/EXTERNLIB @@ -1 +0,0 @@ -CSF_MotifLibs diff --git a/src/OpenGl/OpenGl_Display.hxx b/src/OpenGl/OpenGl_Display.hxx index 01daf2b7fd..95b8a9abf5 100644 --- a/src/OpenGl/OpenGl_Display.hxx +++ b/src/OpenGl/OpenGl_Display.hxx @@ -115,7 +115,7 @@ class OpenGl_Display : public MMgt_TShared // 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); diff --git a/src/OpenGl/OpenGl_Display_1.cxx b/src/OpenGl/OpenGl_Display_1.cxx index 482c780ccf..43680f1acc 100644 --- a/src/OpenGl/OpenGl_Display_1.cxx +++ b/src/OpenGl/OpenGl_Display_1.cxx @@ -41,48 +41,6 @@ * 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)) - /*-----------------------------------------------------------------------------*/ /* @@ -154,51 +112,25 @@ void OpenGl_Display::getGL2PSFontName (const char *src_font, char *ps_font) /*-----------------------------------------------------------------------------*/ -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; + if (theBestSize != -1) + myFontSize = theBestSize; - OpenGl_FontMgr* mgr = OpenGl_FontMgr::instance(); + OpenGl_FontMgr* anOpenGlFontMgr = OpenGl_FontMgr::instance(); - Handle(TCollection_HAsciiString) family_name = new TCollection_HAsciiString(AFontName); - myFont = mgr->request_font( family_name, AFontAspect, myFontSize ); + Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (theFontName); + myFont = anOpenGlFontMgr->request_font (aFontName, theFontAspect, 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 ); - } - - // 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 ); - } - - // 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 ); - } - - if ( myFont != -1 ) - mgr->setCurrentScale( AXScale, AYScale ); + if (myFont != -1) + anOpenGlFontMgr->setCurrentScale (theXScale, theYScale); return myFont; } diff --git a/src/OpenGl/OpenGl_FontMgr.cxx b/src/OpenGl/OpenGl_FontMgr.cxx index c4413219d9..b461a42c5d 100755 --- a/src/OpenGl/OpenGl_FontMgr.cxx +++ b/src/OpenGl/OpenGl_FontMgr.cxx @@ -19,12 +19,10 @@ #include #include - -#include +#include #ifdef _MSC_VER #pragma comment( lib, "ftgl.lib" ) -#pragma comment( lib, "freetype.lib" ) #endif #undef TRACE @@ -62,9 +60,9 @@ IsEqual( const Handle(TCollection_HAsciiString)& h1, } OpenGl_FontMgr::OpenGl_FontMgr() -: _CurrentFontId(-1), -_XCurrentScale(1.f), -_YCurrentScale(1.f) +: myCurrentFontId(-1), +myXCurrentScale(1.f), +myYCurrentScale(1.f) { } @@ -74,282 +72,92 @@ OpenGl_FontMgr* OpenGl_FontMgr::instance() 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 + // 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(); + } - GLCONTEXT ctx = GET_GL_CONTEXT(); + GLCONTEXT aContext = 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 - - //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; - } - -#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 + // Requested font is already generated, returning it cache ID. + myCurrentFontId = anIDListIterator.Value(); + return myCurrentFontId; } -#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; - } - - 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 ); - - //put font to cache - OGLFont_Cache cache; - cache.Font = font; - cache.FontHeight = aFontHeight; - cache.GlContext = ctx; - - _CurrentFontId =_FontCache.Size() + 1; - _FontCache.Bind( _CurrentFontId, cache ); - DBit.Value()->GeneratedFonts.Append(_CurrentFontId); - -#ifdef TRACE - cout << "TKOpenGl::Loaded New FTGL font:\n" - << " font name: " << fontName->ToCString() << "\n" - << " font aspect: "; - - 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: "<FontPath()->ToCString()); + if ( !aFTGLFont || aFTGLFont->Error() != FT_Err_Ok) + { + return -1; // Error during creation FTGL font object! + } + + if ( !aFTGLFont->FaceSize (aFontHeight) || aFTGLFont->Error() != FT_Err_Ok ) + { + return -1; // Error during setup FTGL font height! + } + + aFTGLFont->UseDisplayList (false); + + // Adding font to cache. + OGLFont_Cache aCache; + aCache.Font = aFTGLFont; + aCache.FontHeight = aFontHeight; + aCache.GlContext = aContext; + + myCurrentFontId = myGeneratedFontCache.Size() + 1; + myGeneratedFontCache.Bind ( myCurrentFontId, aCache); + + if (myGeneratedFontDB.IsBound (aRequestedFont)) + { + myGeneratedFontDB.ChangeFind (aRequestedFont).Append (myCurrentFontId); + } + 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, @@ -360,11 +168,11 @@ 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); @@ -386,7 +194,7 @@ void OpenGl_FontMgr::render_text( const Standard_Integer id, const wchar_t* text 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); @@ -405,20 +213,20 @@ void OpenGl_FontMgr::render_text( const Standard_Integer id, const wchar_t* text 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 ); @@ -428,8 +236,8 @@ Standard_ShortReal OpenGl_FontMgr::computeWidth( const Standard_Integer id, cons void OpenGl_FontMgr::setCurrentScale (const Standard_ShortReal xScale, const Standard_ShortReal yScale) { - _XCurrentScale = xScale; - _YCurrentScale = yScale; + myXCurrentScale = xScale; + myYCurrentScale = yScale; } #include diff --git a/src/OpenGl/OpenGl_FontMgr.hxx b/src/OpenGl/OpenGl_FontMgr.hxx index 153a4254a2..de20a172e2 100755 --- a/src/OpenGl/OpenGl_FontMgr.hxx +++ b/src/OpenGl/OpenGl_FontMgr.hxx @@ -43,9 +43,9 @@ class OpenGl_FontMgr 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, @@ -62,8 +62,6 @@ class OpenGl_FontMgr //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); @@ -77,29 +75,24 @@ private: typedef NCollection_List IDList; - struct OGLFont_SysInfo { - Handle(Font_SystemFont) SysFont; - IDList GeneratedFonts; - }; - struct OGLFont_Cache { FTFont* Font; Standard_Integer FontHeight; GLCONTEXT GlContext; }; - typedef NCollection_List FontDataBase; - typedef FontDataBase::Iterator FontDBIt; - typedef NCollection_DataMap FontCache; - typedef FontCache::Iterator FCacheIt; + typedef NCollection_DataMap FontDataBase; + typedef FontDataBase::Iterator FontDBIterator; + typedef NCollection_DataMap 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 diff --git a/src/Prs3d/Prs3d_TextAspect.cxx b/src/Prs3d/Prs3d_TextAspect.cxx index 0fffcb814b..eef1775781 100755 --- a/src/Prs3d/Prs3d_TextAspect.cxx +++ b/src/Prs3d/Prs3d_TextAspect.cxx @@ -25,7 +25,7 @@ #include #include -#include +#include Prs3d_TextAspect::Prs3d_TextAspect () : myAngle(0.), @@ -36,7 +36,7 @@ Prs3d_TextAspect::Prs3d_TextAspect () myTextAspect = new Graphic3d_AspectText3d ( Quantity_Color(Quantity_NOC_YELLOW), - Graphic3d_NOF_ASCII_TRIPLEX, + Font_NOF_ASCII_TRIPLEX, 1., 0.); } diff --git a/src/QABugs/QABugs_17.cxx b/src/QABugs/QABugs_17.cxx index 13f7e4a290..6d7a4faf5a 100644 --- a/src/QABugs/QABugs_17.cxx +++ b/src/QABugs/QABugs_17.cxx @@ -108,7 +108,7 @@ Standard_EXPORT Viewer2dTest_DoubleMapOfInteractiveAndName& GetMapOfAIS2D(); #include #include -#include +#include static Standard_Integer BUC60842 (Draw_Interpretor& di, Standard_Integer /*argc*/,const char ** /*argv*/) { @@ -462,13 +462,13 @@ static Standard_Integer BUC60821(Draw_Interpretor& di, Standard_Integer argc,con 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; diff --git a/src/QABugs/QABugs_MyText.cxx b/src/QABugs/QABugs_MyText.cxx index b69452a505..3e15574dc6 100644 --- a/src/QABugs/QABugs_MyText.cxx +++ b/src/QABugs/QABugs_MyText.cxx @@ -28,7 +28,7 @@ #include #include #include -#include +#include /************************************************************************* * diff --git a/src/TKService/EXTERNLIB b/src/TKService/EXTERNLIB index af7a3b1bc0..f363a3d056 100755 --- a/src/TKService/EXTERNLIB +++ b/src/TKService/EXTERNLIB @@ -4,3 +4,4 @@ CSF_XwLibs CSF_dpsLibs CSF_XmuLibs CSF_FreeImagePlus +CSF_FREETYPE diff --git a/src/TKernel/EXTERNLIB b/src/TKernel/EXTERNLIB index e3c988e8d4..cff6c773ea 100755 --- a/src/TKernel/EXTERNLIB +++ b/src/TKernel/EXTERNLIB @@ -7,5 +7,3 @@ CSF_user32 CSF_kernel32 STLPortLib CSF_TBB -CSF_MotifLibs - diff --git a/src/V3d/V3d_ColorScale.cxx b/src/V3d/V3d_ColorScale.cxx index e8336a6d47..6227e31b46 100755 --- a/src/V3d/V3d_ColorScale.cxx +++ b/src/V3d/V3d_ColorScale.cxx @@ -36,7 +36,7 @@ #include #include -#include +#include V3d_ColorScale::V3d_ColorScale( const Handle(V3d_LayerMgr)& aMgr ) : Aspect_ColorScale(), @@ -99,7 +99,7 @@ void V3d_ColorScale::PaintText( const TCollection_ExtendedString& aText, 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; diff --git a/src/V3d/V3d_LayerMgr.cxx b/src/V3d/V3d_LayerMgr.cxx index 3b21255b44..2bb72eaf2a 100755 --- a/src/V3d/V3d_LayerMgr.cxx +++ b/src/V3d/V3d_LayerMgr.cxx @@ -23,7 +23,7 @@ #include #include #include -#include +#include V3d_LayerMgr::V3d_LayerMgr( const Handle(V3d_View)& AView ) @@ -98,7 +98,7 @@ Standard_Boolean V3d_LayerMgr::Begin() 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; diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 289c8ed825..28b72e7c7e 100755 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -2255,7 +2255,6 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha //=============================================================================================== #include #include -#include #include #include #include @@ -2264,6 +2263,8 @@ static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const cha #include #include +#include + #include #include diff --git a/tests/bugs/end b/tests/bugs/end index 38b1e60106..f9b9af6c2d 100755 --- a/tests/bugs/end +++ b/tests/bugs/end @@ -20,6 +20,10 @@ if { [info exist only_screen] } { vdump $imagedir/${test_image}.png } +if { [info exist only_screen2d] } { + v2ddump $imagedir/${test_image}.png +} + # to end a test script puts "TEST COMPLETED" diff --git a/tests/bugs/modalg/bug322 b/tests/bugs/modalg/bug322 index d131ca80de..acc4752cfe 100755 --- a/tests/bugs/modalg/bug322 +++ b/tests/bugs/modalg/bug322 @@ -1,9 +1,10 @@ -pload QAcommands puts "================" puts "OCC322" puts "================" puts "" +pload QAcommands + restore [locate_data_file OCC322.brep] a puts [checkshape a] @@ -21,10 +22,11 @@ set x1 204 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 +