"/usr/X11/lib/X11/fs/config",
NULL
};
+
+ // Although fontconfig library can be built for various platforms,
+ // practically it is useful only on desktop Linux distributions, where it is always packaged.
+ #include <fontconfig/fontconfig.h>
#endif
#ifdef __APPLE__
void Font_FontMgr::InitFontDataBase()
{
myFontMap.Clear();
- Handle(Font_FTLibrary) aFtLibrary;
+ Handle(Font_FTLibrary) aFtLibrary = new Font_FTLibrary();
#if defined(OCCT_UWP)
// system font files are not accessible
aSupportedExtensions.Add (TCollection_AsciiString (anExt));
}
- aFtLibrary = new Font_FTLibrary();
static const DWORD aBufferSize = 256;
char aNameBuff[aBufferSize];
char aPathBuff[aBufferSize];
NCollection_Map<TCollection_AsciiString> aMapOfFontsDirs;
#if !defined(__ANDROID__) && !defined(__APPLE__)
- const OSD_Protection aProtectRead (OSD_R, OSD_R, OSD_R, OSD_R);
-
- // read fonts directories from font service config file (obsolete)
- for (Standard_Integer anIter = 0; myFontServiceConf[anIter] != NULL; ++anIter)
+ if (FcConfig* aFcCfg = FcInitLoadConfig())
{
- const TCollection_AsciiString aFileOfFontsPath (myFontServiceConf[anIter]);
- OSD_File aFile (aFileOfFontsPath);
- if (!aFile.Exists())
+ if (FcStrList* aFcFontDir = FcConfigGetFontDirs (aFcCfg))
{
- continue;
- }
+ for (;;)
+ {
+ FcChar8* aFcFolder = FcStrListNext (aFcFontDir);
+ if (aFcFolder == NULL)
+ {
+ break;
+ }
- aFile.Open (OSD_ReadOnly, aProtectRead);
- if (!aFile.IsOpen())
- {
- continue;
+ TCollection_AsciiString aPathStr ((const char* )aFcFolder);
+ OSD_Path aPath (aPathStr);
+ addDirsRecursively (aPath, aMapOfFontsDirs);
+ }
+ FcStrListDone (aFcFontDir);
}
+ FcConfigDestroy (aFcCfg);
+ }
- Standard_Integer aNByte = 256;
- Standard_Integer aNbyteRead;
- TCollection_AsciiString aStr; // read string with information
- while (!aFile.IsAtEnd())
+ const OSD_Protection aProtectRead (OSD_R, OSD_R, OSD_R, OSD_R);
+ if (aMapOfFontsDirs.IsEmpty())
+ {
+ Message::DefaultMessenger()->Send ("Font_FontMgr, fontconfig library returns an empty folder list", Message_Alarm);
+
+ // read fonts directories from font service config file (obsolete)
+ for (Standard_Integer anIter = 0; myFontServiceConf[anIter] != NULL; ++anIter)
{
- Standard_Integer aLocation = -1;
- Standard_Integer aPathLocation = -1;
+ const TCollection_AsciiString aFileOfFontsPath (myFontServiceConf[anIter]);
+ OSD_File aFile (aFileOfFontsPath);
+ if (!aFile.Exists())
+ {
+ continue;
+ }
- aFile.ReadLine (aStr, aNByte, aNbyteRead); // reading 1 line (256 bytes)
- aLocation = aStr.Search ("catalogue=");
- if (aLocation < 0)
+ aFile.Open (OSD_ReadOnly, aProtectRead);
+ if (!aFile.IsOpen())
{
- aLocation = aStr.Search ("catalogue =");
+ continue;
}
- aPathLocation = aStr.Search ("/");
- if (aLocation > 0 && aPathLocation > 0)
+ Standard_Integer aNByte = 256;
+ Standard_Integer aNbyteRead;
+ TCollection_AsciiString aStr; // read string with information
+ while (!aFile.IsAtEnd())
{
- aStr = aStr.Split (aPathLocation - 1);
- TCollection_AsciiString aFontPath;
- Standard_Integer aPathNumber = 1;
- do
+ 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)
{
- // Getting directory paths, which can be splitted by "," or ":"
- aFontPath = aStr.Token (":,", aPathNumber);
- aFontPath.RightAdjust();
- if (!aFontPath.IsEmpty())
+ aStr = aStr.Split (aPathLocation - 1);
+ TCollection_AsciiString aFontPath;
+ Standard_Integer aPathNumber = 1;
+ do
{
- OSD_Path aPath(aFontPath);
- addDirsRecursively (aPath, aMapOfFontsDirs);
+ // 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++;
}
- aPathNumber++;
+ while (!aFontPath.IsEmpty());
}
- while (!aFontPath.IsEmpty());
}
+ aFile.Close();
}
- aFile.Close();
}
#endif
aSupportedExtensions.Add (TCollection_AsciiString (anExt));
}
- aFtLibrary = new Font_FTLibrary();
for (NCollection_Map<TCollection_AsciiString>::Iterator anIter (aMapOfFontsDirs);
anIter.More(); anIter.Next())
{
//function : VFont
//purpose : Font management
//=======================================================================
+struct FontComparator
+{
+ bool operator() (const Handle(Font_SystemFont)& theFontA,
+ const Handle(Font_SystemFont)& theFontB)
+ {
+ return theFontA->FontKey().IsLess (theFontB->FontKey());
+ }
+};
static int VFont (Draw_Interpretor& theDI,
Standard_Integer theArgNb,
// just print the list of available fonts
Standard_Boolean isFirst = Standard_True;
const Font_NListOfSystemFont aFonts = aMgr->GetAvailableFonts();
- for (Font_NListOfSystemFont::Iterator anIter (aFonts); anIter.More(); anIter.Next())
+ std::vector<Handle(Font_SystemFont)> aFontsSorted;
+ aFontsSorted.reserve (aFonts.Size());
+ for (Font_NListOfSystemFont::Iterator aFontIter (aFonts); aFontIter.More(); aFontIter.Next())
+ {
+ aFontsSorted.push_back (aFontIter.Value());
+ }
+ std::stable_sort (aFontsSorted.begin(), aFontsSorted.end(), FontComparator());
+ for (std::vector<Handle(Font_SystemFont)>::iterator aFontIter = aFontsSorted.begin(); aFontIter != aFontsSorted.end(); ++aFontIter)
{
- const Handle(Font_SystemFont)& aFont = anIter.Value();
+ const Handle(Font_SystemFont)& aFont = *aFontIter;
if (!isFirst)
{
theDI << "\n";