0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / Font / Font_FontMgr.cxx
CommitLineData
b311480e 1// Created on: 2008-01-20
2// Created by: Alexander A. BORODIN
3// Copyright (c) 2008-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
eeaaaefb 20#include <Font_FontMgr.ixx>
7fd59977 21
725ef85e 22#include <Font_FTLibrary.hxx>
a6535b1d 23#include <OSD_Environment.hxx>
7fd59977 24#include <NCollection_List.hxx>
aff395a3 25#include <NCollection_Map.hxx>
7fd59977 26#include <Standard_Stream.hxx>
aff395a3 27#include <TCollection_HAsciiString.hxx>
7fd59977 28
aff395a3 29#include <ft2build.h>
30#include FT_FREETYPE_H
7fd59977 31
aff395a3 32struct Font_FontMgr_FontAliasMapNode
33{
34 const char * EnumName;
35 const char * FontName;
36 Font_FontAspect FontAspect;
37};
7fd59977 38
aff395a3 39static const Font_FontMgr_FontAliasMapNode Font_FontMgr_MapOfFontsAliases[] =
40{
41
42#ifdef WNT
43
44 { "Courier" , "Courier New" , Font_FA_Regular },
45 { "Times-Roman" , "Times New Roman", Font_FA_Regular },
46 { "Times-Bold" , "Times New Roman", Font_FA_Bold },
47 { "Times-Italic" , "Times New Roman", Font_FA_Italic },
48 { "Times-BoldItalic" , "Times New Roman", Font_FA_BoldItalic },
49 { "ZapfChancery-MediumItalic", "Script" , Font_FA_Regular },
50 { "Symbol" , "Symbol" , Font_FA_Regular },
51 { "ZapfDingbats" , "WingDings" , Font_FA_Regular },
52 { "Rock" , "Arial" , Font_FA_Regular },
53 { "Iris" , "Lucida Console" , Font_FA_Regular }
54
55#else //X11
56
57 { "Courier" , "Courier" , Font_FA_Regular },
58 { "Times-Roman" , "Times" , Font_FA_Regular },
59 { "Times-Bold" , "Times" , Font_FA_Bold },
60 { "Times-Italic" , "Times" , Font_FA_Italic },
61 { "Times-BoldItalic" , "Times" , Font_FA_BoldItalic },
62 { "Arial" , "Helvetica" , Font_FA_Regular },
63 { "ZapfChancery-MediumItalic", "-adobe-itc zapf chancery-medium-i-normal--*-*-*-*-*-*-iso8859-1" , Font_FA_Regular },
64 { "Symbol" , "-adobe-symbol-medium-r-normal--*-*-*-*-*-*-adobe-fontspecific" , Font_FA_Regular },
65 { "ZapfDingbats" , "-adobe-itc zapf dingbats-medium-r-normal--*-*-*-*-*-*-adobe-fontspecific" , Font_FA_Regular },
66 { "Rock" , "-sgi-rock-medium-r-normal--*-*-*-*-p-*-iso8859-1" , Font_FA_Regular },
67 { "Iris" , "--iris-medium-r-normal--*-*-*-*-m-*-iso8859-1" , Font_FA_Regular }
68#endif
69
70};
71
566f8441 72#define NUM_FONT_ENTRIES (int)(sizeof(Font_FontMgr_MapOfFontsAliases)/sizeof(Font_FontMgr_FontAliasMapNode))
aff395a3 73
74#if (defined(_WIN32) || defined(__WIN32__))
7fd59977 75
aff395a3 76 #include <windows.h>
77 #include <stdlib.h>
78
79 #ifdef _MSC_VER
80 #pragma comment (lib, "freetype.lib")
81 #endif
82
83 namespace
7fd59977 84 {
7fd59977 85
aff395a3 86 // list of supported extensions
87 static Standard_CString Font_FontMgr_Extensions[] =
88 {
89 "ttf",
90 "otf",
91 "ttc",
92 NULL
93 };
94
95 };
96
97#else
7fd59977 98
aff395a3 99 #include <OSD_DirectoryIterator.hxx>
100 #include <OSD_Path.hxx>
101 #include <OSD_File.hxx>
102 #include <OSD_OpenMode.hxx>
103 #include <OSD_Protection.hxx>
7fd59977 104
aff395a3 105 namespace
106 {
107
108 // list of supported extensions
109 static Standard_CString Font_FontMgr_Extensions[] =
110 {
111 "ttf",
112 "otf",
113 "ttc",
114 "pfa",
115 "pfb",
116 NULL
117 };
118
119 // X11 configuration file in plain text format (obsolete - doesn't exists in modern distributives)
120 static Standard_CString myFontServiceConf[] = {"/etc/X11/fs/config",
121 "/usr/X11R6/lib/X11/fs/config",
122 "/usr/X11/lib/X11/fs/config",
123 NULL
124 };
125
126 #ifdef __APPLE__
127 // default fonts paths in Mac OS X
128 static Standard_CString myDefaultFontsDirs[] = {"/System/Library/Fonts",
129 "/Library/Fonts",
130 NULL
131 };
132 #else
133 // default fonts paths in most Unix systems (Linux and others)
134 static Standard_CString myDefaultFontsDirs[] = {"/usr/share/fonts",
135 "/usr/local/share/fonts",
136 NULL
137 };
138 #endif
139
140 static void addDirsRecursively (const OSD_Path& thePath,
141 NCollection_Map<TCollection_AsciiString>& theDirsMap)
7fd59977 142 {
aff395a3 143 TCollection_AsciiString aDirName;
144 thePath.SystemName (aDirName);
145 if (!theDirsMap.Add (aDirName))
146 {
147 return;
7fd59977 148 }
7fd59977 149
aff395a3 150 for (OSD_DirectoryIterator aDirIterator (thePath, "*"); aDirIterator.More(); aDirIterator.Next())
7fd59977 151 {
aff395a3 152 OSD_Path aChildDirPath;
153 aDirIterator.Values().Path (aChildDirPath);
154
155 TCollection_AsciiString aChildDirName;
156 aChildDirPath.SystemName (aChildDirName);
157 if (!aChildDirName.IsEqual (".") && !aChildDirName.IsEqual (".."))
158 {
159 aChildDirName = aDirName + "/" + aChildDirName;
160 OSD_Path aPath (aChildDirName);
161 addDirsRecursively (aPath, theDirsMap);
162 }
7fd59977 163 }
7fd59977 164 }
aff395a3 165
166 };
167
168#endif
169
170// =======================================================================
171// function : checkFont
172// purpose :
173// =======================================================================
725ef85e 174static Handle(Font_SystemFont) checkFont (const Handle(Font_FTLibrary)& theFTLib,
175 const Standard_CString theFontPath)
aff395a3 176{
177 FT_Face aFontFace;
725ef85e 178 FT_Error aFaceError = FT_New_Face (theFTLib->Instance(), theFontPath, 0, &aFontFace);
aff395a3 179 if (aFaceError != FT_Err_Ok)
180 {
181 return NULL;
7fd59977 182 }
7fd59977 183
aff395a3 184 Font_FontAspect anAspect = Font_FA_Regular;
185 if (aFontFace->style_flags == (FT_STYLE_FLAG_ITALIC | FT_STYLE_FLAG_BOLD))
186 {
187 anAspect = Font_FA_BoldItalic;
188 }
189 else if (aFontFace->style_flags == FT_STYLE_FLAG_ITALIC)
190 {
191 anAspect = Font_FA_Italic;
192 }
193 else if (aFontFace->style_flags == FT_STYLE_FLAG_BOLD)
194 {
195 anAspect = Font_FA_Bold;
196 }
197
198 Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (aFontFace->family_name);
199 Handle(TCollection_HAsciiString) aFontPath = new TCollection_HAsciiString (theFontPath);
200 Handle(Font_SystemFont) aResult = new Font_SystemFont (aFontName, anAspect, aFontPath);
7fd59977 201
aff395a3 202 FT_Done_Face (aFontFace);
7fd59977 203
aff395a3 204 return aResult;
205}
7fd59977 206
aff395a3 207// =======================================================================
208// function : GetInstance
209// purpose :
210// =======================================================================
211Handle(Font_FontMgr) Font_FontMgr::GetInstance()
212{
eeaaaefb 213 static Handle(Font_FontMgr) _mgr;
aff395a3 214 if (_mgr.IsNull())
215 {
eeaaaefb 216 _mgr = new Font_FontMgr();
aff395a3 217 }
7fd59977 218
219 return _mgr;
7fd59977 220}
221
aff395a3 222// =======================================================================
223// function : Font_FontMgr
224// purpose :
225// =======================================================================
226Font_FontMgr::Font_FontMgr()
227{
7fd59977 228 InitFontDataBase();
7fd59977 229}
230
aff395a3 231// =======================================================================
725ef85e 232// function : CheckFont
233// purpose :
234// =======================================================================
235Handle(Font_SystemFont) Font_FontMgr::CheckFont (Standard_CString theFontPath) const
236{
237 Handle(Font_FTLibrary) aFtLibrary = new Font_FTLibrary();
238 return checkFont (aFtLibrary, theFontPath);
239}
240
241// =======================================================================
242// function : RegisterFont
243// purpose :
244// =======================================================================
245Standard_Boolean Font_FontMgr::RegisterFont (const Handle(Font_SystemFont)& theFont,
246 const Standard_Boolean theToOverride)
247{
248 if (theFont.IsNull())
249 {
250 return Standard_False;
251 }
252
253 for (Font_NListOfSystemFont::Iterator aFontIter (myListOfFonts);
254 aFontIter.More(); aFontIter.Next())
255 {
256 if (!aFontIter.Value()->FontName()->IsSameString (theFont->FontName(), Standard_False))
257 {
258 continue;
259 }
260
261 if (theFont->FontAspect() != Font_FA_Undefined
262 && aFontIter.Value()->FontAspect() != theFont->FontAspect())
263 {
264 continue;
265 }
266
267 if (theFont->FontHeight() == -1 || aFontIter.Value()->FontHeight() == -1
268 || theFont->FontHeight() == aFontIter.Value()->FontHeight())
269 {
270 if (theFont->FontPath()->String() == aFontIter.Value()->FontPath()->String())
271 {
272 return Standard_True;
273 }
274 else if (theToOverride)
275 {
276 myListOfFonts.Remove (aFontIter);
277 }
278 else
279 {
280 return Standard_False;
281 }
282 }
283 }
284
285 myListOfFonts.Append (theFont);
286 return Standard_True;
287}
288
289// =======================================================================
aff395a3 290// function : InitFontDataBase
291// purpose :
292// =======================================================================
293void Font_FontMgr::InitFontDataBase()
294{
295 myListOfFonts.Clear();
725ef85e 296 Handle(Font_FTLibrary) aFtLibrary;
7fd59977 297
725ef85e 298#if defined(_WIN32)
7fd59977 299
aff395a3 300 // font directory is placed in "C:\Windows\Fonts\"
301 UINT aStrLength = GetSystemWindowsDirectoryA (NULL, 0);
302 if (aStrLength == 0)
a6535b1d 303 {
aff395a3 304 return;
a6535b1d 305 }
aff395a3 306
307 char* aWinDir = new char[aStrLength];
308 GetSystemWindowsDirectoryA (aWinDir, aStrLength);
309 Handle(TCollection_HAsciiString) aFontsDir = new TCollection_HAsciiString (aWinDir);
310 aFontsDir->AssignCat ("\\Fonts\\");
311 delete[] aWinDir;
312
313 // read fonts list from registry
314 HKEY aFontsKey;
315 if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
316 0, KEY_READ, &aFontsKey) != ERROR_SUCCESS)
7fd59977 317 {
318 return;
7fd59977 319 }
7fd59977 320
aff395a3 321 NCollection_Map<TCollection_AsciiString> aSupportedExtensions;
322 for (Standard_Integer anIter = 0; Font_FontMgr_Extensions[anIter] != NULL; ++anIter)
7fd59977 323 {
aff395a3 324 Standard_CString anExt = Font_FontMgr_Extensions[anIter];
325 aSupportedExtensions.Add (TCollection_AsciiString (anExt));
7fd59977 326 }
327
725ef85e 328 aFtLibrary = new Font_FTLibrary();
aff395a3 329 static const DWORD aBufferSize = 256;
330 char aNameBuff[aBufferSize];
331 char aPathBuff[aBufferSize];
332 DWORD aNameSize = aBufferSize;
333 DWORD aPathSize = aBufferSize;
334 for (DWORD anIter = 0;
335 RegEnumValueA (aFontsKey, anIter,
336 aNameBuff, &aNameSize, NULL, NULL,
337 (LPBYTE )aPathBuff, &aPathSize) != ERROR_NO_MORE_ITEMS;
338 ++anIter, aNameSize = aBufferSize, aPathSize = aBufferSize)
339 {
340 aPathBuff[(aPathSize < aBufferSize) ? aPathSize : (aBufferSize - 1)] = '\0'; // ensure string is NULL-terminated
7fd59977 341
aff395a3 342 Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (aNameBuff);
343 Handle(TCollection_HAsciiString) aFontPath = new TCollection_HAsciiString (aPathBuff);
344 if (aFontPath->Search ("\\") == -1)
345 {
346 aFontPath->Insert (1, aFontsDir); // make absolute path
7fd59977 347 }
aff395a3 348
349 // check file extension is in list of supported
350 const Standard_Integer anExtensionPosition = aFontPath->SearchFromEnd (".") + 1;
351 if (anExtensionPosition > 0 && anExtensionPosition < aFontPath->Length())
7fd59977 352 {
aff395a3 353 Handle(TCollection_HAsciiString) aFontExtension = aFontPath->SubString (anExtensionPosition, aFontPath->Length());
354 aFontExtension->LowerCase();
355 if (aSupportedExtensions.Contains (aFontExtension->String()))
356 {
357 Handle(Font_SystemFont) aNewFont = checkFont (aFtLibrary, aFontPath->ToCString());
358 if (!aNewFont.IsNull())
359 {
360 myListOfFonts.Append (aNewFont);
361 }
362 }
7fd59977 363 }
364 }
7fd59977 365
aff395a3 366 // close registry key
367 RegCloseKey (aFontsKey);
368
369#else
7fd59977 370
aff395a3 371 NCollection_Map<TCollection_AsciiString> aMapOfFontsDirs;
372 const OSD_Protection aProtectRead (OSD_R, OSD_R, OSD_R, OSD_R);
7fd59977 373
aff395a3 374 // read fonts directories from font service config file (obsolete)
375 for (Standard_Integer anIter = 0; myFontServiceConf[anIter] != NULL; ++anIter)
7fd59977 376 {
aff395a3 377 const TCollection_AsciiString aFileOfFontsPath (myFontServiceConf[anIter]);
378 OSD_File aFile (aFileOfFontsPath);
379 if (!aFile.Exists())
380 {
381 continue;
382 }
7fd59977 383
aff395a3 384 aFile.Open (OSD_ReadOnly, aProtectRead);
385 if (!aFile.IsOpen())
386 {
387 continue;
388 }
389
390 Standard_Integer aNByte = 256;
391 Standard_Integer aNbyteRead;
392 TCollection_AsciiString aStr; // read string with information
393 while (!aFile.IsAtEnd())
7fd59977 394 {
aff395a3 395 Standard_Integer aLocation = -1;
396 Standard_Integer aPathLocation = -1;
397
398 aFile.ReadLine (aStr, aNByte, aNbyteRead); // reading 1 line (256 bytes)
399 aLocation = aStr.Search ("catalogue=");
400 if (aLocation < 0)
401 {
402 aLocation = aStr.Search ("catalogue =");
403 }
404
405 aPathLocation = aStr.Search ("/");
406 if (aLocation > 0 && aPathLocation > 0)
7fd59977 407 {
aff395a3 408 aStr = aStr.Split (aPathLocation - 1);
409 TCollection_AsciiString aFontPath;
410 Standard_Integer aPathNumber = 1;
411 do
7fd59977 412 {
aff395a3 413 // Getting directory paths, which can be splitted by "," or ":"
414 aFontPath = aStr.Token (":,", aPathNumber);
415 aFontPath.RightAdjust();
416 if (!aFontPath.IsEmpty())
7fd59977 417 {
aff395a3 418 OSD_Path aPath(aFontPath);
419 addDirsRecursively (aPath, aMapOfFontsDirs);
7fd59977 420 }
aff395a3 421 aPathNumber++;
422 }
423 while (!aFontPath.IsEmpty());
7fd59977 424 }
7fd59977 425 }
aff395a3 426 aFile.Close();
7fd59977 427 }
428
aff395a3 429 // append default directories
430 for (Standard_Integer anIter = 0; myDefaultFontsDirs[anIter] != NULL; ++anIter)
431 {
432 Standard_CString anItem = myDefaultFontsDirs[anIter];
433 TCollection_AsciiString aPathStr (anItem);
434 OSD_Path aPath (aPathStr);
435 addDirsRecursively (aPath, aMapOfFontsDirs);
436 }
437
438 NCollection_Map<TCollection_AsciiString> aSupportedExtensions;
439 for (Standard_Integer anIter = 0; Font_FontMgr_Extensions[anIter] != NULL; ++anIter)
440 {
441 Standard_CString anExt = Font_FontMgr_Extensions[anIter];
442 aSupportedExtensions.Add (TCollection_AsciiString (anExt));
443 }
444
725ef85e 445 aFtLibrary = new Font_FTLibrary();
aff395a3 446 for (NCollection_Map<TCollection_AsciiString>::Iterator anIter (aMapOfFontsDirs);
447 anIter.More(); anIter.Next())
448 {
449 OSD_File aReadFile (anIter.Value() + "/fonts.dir");
450 if (!aReadFile.Exists())
451 {
452 continue; // invalid fonts directory
453 }
454
455 aReadFile.Open (OSD_ReadOnly, aProtectRead);
456 if (!aReadFile.IsOpen())
457 {
458 continue; // invalid fonts directory
459 }
460
461 Standard_Integer aNbyteRead, aNByte = 256;
462 TCollection_AsciiString aLine (aNByte);
463 Standard_Boolean isFirstLine = Standard_True;
464 const TCollection_AsciiString anEncoding ("iso8859-1\n");
465 while (!aReadFile.IsAtEnd())
466 {
467 aReadFile.ReadLine (aLine, aNByte, aNbyteRead);
468 if (isFirstLine)
469 {
470 // first line contains the number of fonts in this file
471 // just ignoring it...
472 isFirstLine = Standard_False;
473 continue;
474 }
7fd59977 475
aff395a3 476 Standard_Integer anExtensionPosition = aLine.Search (".") + 1;
477 if (anExtensionPosition == 0)
478 {
479 continue; // can't find extension position in the font description
480 }
7fd59977 481
aff395a3 482 Standard_Integer anEndOfFileName = aLine.Location (" ", anExtensionPosition, aLine.Length()) - 1;
483 if (anEndOfFileName < 0 || anEndOfFileName < anExtensionPosition)
484 {
485 continue; // font description have empty extension
486 }
7fd59977 487
aff395a3 488 TCollection_AsciiString aFontExtension = aLine.SubString (anExtensionPosition, anEndOfFileName);
489 aFontExtension.LowerCase();
490 if (aSupportedExtensions.Contains (aFontExtension) && (aLine.Search (anEncoding) > 0))
7fd59977 491 {
aff395a3 492 // In current implementation use fonts with ISO-8859-1 coding page.
493 // OCCT not give to manage coding page by means of programm interface.
494 // TODO: make high level interface for choosing necessary coding page.
495 Handle(TCollection_HAsciiString) aXLFD =
496 new TCollection_HAsciiString (aLine.SubString (anEndOfFileName + 2, aLine.Length()));
497 Handle(TCollection_HAsciiString) aFontPath =
498 new TCollection_HAsciiString (anIter.Value().ToCString());
499 if (aFontPath->SearchFromEnd ("/") != aFontPath->Length())
7fd59977 500 {
aff395a3 501 aFontPath->AssignCat ("/");
7fd59977 502 }
aff395a3 503 Handle(TCollection_HAsciiString) aFontFileName =
504 new TCollection_HAsciiString (aLine.SubString (1, anEndOfFileName));
505 aFontPath->AssignCat (aFontFileName);
506
507 Handle(Font_SystemFont) aNewFontFromXLFD = new Font_SystemFont (aXLFD, aFontPath);
508 Handle(Font_SystemFont) aNewFont = checkFont (aFtLibrary, aFontPath->ToCString());
509
510 if (aNewFontFromXLFD->IsValid() && !aNewFont.IsNull() &&
511 !aNewFont->IsEqual (aNewFontFromXLFD))
512 {
513 myListOfFonts.Append (aNewFont);
514 myListOfFonts.Append (aNewFontFromXLFD);
515 }
516 else if (!aNewFont.IsNull())
517 {
518 myListOfFonts.Append (aNewFont);
519 }
520 else if (aNewFontFromXLFD->IsValid())
521 {
522 myListOfFonts.Append (aNewFontFromXLFD);
523 }
524
525 }
7fd59977 526 }
aff395a3 527 aReadFile.Close();
7fd59977 528 }
529#endif
aff395a3 530}
531
532// =======================================================================
533// function : GetAvailableFonts
534// purpose :
535// =======================================================================
536const Font_NListOfSystemFont& Font_FontMgr::GetAvailableFonts() const
537{
538 return myListOfFonts;
539}
540
b514beda 541// =======================================================================
542// function : GetAvailableFontsNames
543// purpose :
544// =======================================================================
aff395a3 545void Font_FontMgr::GetAvailableFontsNames (TColStd_SequenceOfHAsciiString& theFontsNames) const
546{
547 theFontsNames.Clear();
548 for (Font_NListOfSystemFont::Iterator anIter(myListOfFonts); anIter.More(); anIter.Next())
549 {
550 theFontsNames.Append (anIter.Value()->FontName());
551 }
7fd59977 552}
553
b514beda 554// =======================================================================
555// function : GetFont
556// purpose :
557// =======================================================================
aff395a3 558Handle(Font_SystemFont) Font_FontMgr::GetFont (const Handle(TCollection_HAsciiString)& theFontName,
b514beda 559 const Font_FontAspect theFontAspect,
aff395a3 560 const Standard_Integer theFontSize) const
7fd59977 561{
aff395a3 562 if ( (theFontSize < 2 && theFontSize != -1) || theFontName.IsNull())
563 {
564 return NULL;
565 }
566
725ef85e 567 for (Font_NListOfSystemFont::Iterator aFontsIterator (myListOfFonts);
568 aFontsIterator.More(); aFontsIterator.Next())
aff395a3 569 {
570 if (!theFontName->IsEmpty() && !aFontsIterator.Value()->FontName()->IsSameString (theFontName, Standard_False))
571 {
572 continue;
573 }
574
575 if (theFontAspect != Font_FA_Undefined && aFontsIterator.Value()->FontAspect() != theFontAspect)
576 {
577 continue;
578 }
579
580 if (theFontSize == -1 || aFontsIterator.Value()->FontHeight() == -1 ||
581 theFontSize == aFontsIterator.Value()->FontHeight())
582 {
583 return aFontsIterator.Value();
584 }
585 }
586
587 return NULL;
7fd59977 588}
589
b514beda 590// =======================================================================
591// function : FindFont
592// purpose :
593// =======================================================================
aff395a3 594Handle(Font_SystemFont) Font_FontMgr::FindFont (const Handle(TCollection_HAsciiString)& theFontName,
b514beda 595 const Font_FontAspect theFontAspect,
aff395a3 596 const Standard_Integer theFontSize) const
597{
598 Handle(TCollection_HAsciiString) aFontName = theFontName;
599 Font_FontAspect aFontAspect = theFontAspect;
b514beda 600 Standard_Integer aFontSize = theFontSize;
aff395a3 601
602 Handle(Font_SystemFont) aFont = GetFont (aFontName, aFontAspect, aFontSize);
aff395a3 603 if (!aFont.IsNull())
604 {
605 return aFont;
606 }
607
608 // Trying to use font names mapping
609 for (Standard_Integer anIter = 0; anIter < NUM_FONT_ENTRIES; ++anIter)
610 {
611 Handle(TCollection_HAsciiString) aFontAlias =
612 new TCollection_HAsciiString (Font_FontMgr_MapOfFontsAliases[anIter].EnumName);
7fd59977 613
aff395a3 614 if (aFontAlias->IsSameString (aFontName, Standard_False))
615 {
616 aFontName = new TCollection_HAsciiString (Font_FontMgr_MapOfFontsAliases[anIter].FontName);
617 aFontAspect = Font_FontMgr_MapOfFontsAliases[anIter].FontAspect;
618 break;
619 }
620 }
621
b514beda 622 // check font family alias with specified font aspect
623 if (theFontAspect != Font_FA_Undefined
624 && theFontAspect != Font_FA_Regular
625 && theFontAspect != aFontAspect)
626 {
627 aFont = GetFont (aFontName, theFontAspect, aFontSize);
628 if (!aFont.IsNull())
629 {
630 return aFont;
631 }
632 }
aff395a3 633
b514beda 634 // check font alias with aspect in the name
635 aFont = GetFont (aFontName, aFontAspect, aFontSize);
aff395a3 636 if (!aFont.IsNull())
637 {
638 return aFont;
639 }
640
641 // Requested family name not found -> search for any font family with given aspect and height
642 aFontName = new TCollection_HAsciiString ("");
643 aFont = GetFont (aFontName, aFontAspect, aFontSize);
aff395a3 644 if (!aFont.IsNull())
645 {
646 return aFont;
647 }
648
649 // The last resort: trying to use ANY font available in the system
650 aFontAspect = Font_FA_Undefined;
651 aFontSize = -1;
652 aFont = GetFont (aFontName, aFontAspect, aFontSize);
aff395a3 653 if (!aFont.IsNull())
654 {
655 return aFont;
656 }
657
658 return NULL; // Fonts are not found in the system.
659}