1 // Created on: 2008-01-20
2 // Created by: Alexander A. BORODIN
3 // Copyright (c) 2008-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Font_SystemFont.hxx>
18 #include <OSD_Path.hxx>
19 #include <Standard_Type.hxx>
20 #include <TCollection_HAsciiString.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(Font_SystemFont, Standard_Transient)
24 // =======================================================================
25 // function : Font_SystemFont
27 // =======================================================================
28 Font_SystemFont::Font_SystemFont()
29 : myFontAspect (Font_FA_Undefined),
31 myIsSingleLine (Standard_False),
32 myIsDefined (Standard_False)
37 // =======================================================================
38 // function : Font_SystemFont
40 // =======================================================================
41 Font_SystemFont::Font_SystemFont (const Handle(TCollection_HAsciiString)& theFontName,
42 const Font_FontAspect theFontAspect,
43 const Handle(TCollection_HAsciiString)& theFilePath)
44 : myFontName (theFontName),
45 myFontAspect (theFontAspect),
47 myFilePath (theFilePath),
48 myIsSingleLine (Standard_False),
49 myIsDefined (Standard_True)
54 // =======================================================================
55 // function : Font_SystemFont
57 // =======================================================================
58 Font_SystemFont::Font_SystemFont (const Handle(TCollection_HAsciiString)& theXLFD,
59 const Handle(TCollection_HAsciiString)& theFilePath)
60 : myFontAspect (Font_FA_Regular),
62 myFilePath (theFilePath),
63 myIsSingleLine (Standard_False),
64 myIsDefined (Standard_True)
67 || theXLFD->IsEmpty())
69 myIsDefined = Standard_False;
73 myFontName = theXLFD->Token ("-", 2);
74 const TCollection_AsciiString& aXLFD = theXLFD->String();
76 // Getting font size for fixed size fonts
77 if (aXLFD.Search ("-0-0-0-0-") >= 0)
79 myFaceSize = -1; // Scalable font
83 myFaceSize = aXLFD.Token ("-", 7).IntegerValue();
87 if (aXLFD.Token ("-", 3).IsEqual ("bold")
88 && (aXLFD.Token ("-", 4).IsEqual ("i")
89 || aXLFD.Token ("-", 4).IsEqual ("o")))
91 myFontAspect = Font_FA_BoldItalic;
93 else if (aXLFD.Token ("-", 3).IsEqual ("bold"))
95 myFontAspect = Font_FA_Bold;
97 else if (aXLFD.Token ("-", 4).IsEqual ("i")
98 || aXLFD.Token ("-", 4).IsEqual ("o"))
100 myFontAspect = Font_FA_Italic;
104 // =======================================================================
105 // function : IsValid
107 // =======================================================================
108 Standard_Boolean Font_SystemFont::IsValid() const
111 && myFontAspect != Font_FA_Undefined
112 && !myFontName->IsEmpty()
113 && OSD_Path::IsValid (myFilePath->String());
116 // =======================================================================
117 // function : IsEqual
119 // =======================================================================
120 Standard_Boolean Font_SystemFont::IsEqual (const Handle(Font_SystemFont)& theOtherFont) const
122 return myFontName->IsSameString (myFontName, Standard_False)
123 && myFontAspect == theOtherFont->myFontAspect
124 && myFaceSize == theOtherFont->myFaceSize;