0024428: Implementation of LGPL license
[occt.git] / src / Font / Font_SystemFont.cxx
1 // Created on: 2008-01-20
2 // Created by: Alexander A. BORODIN
3 // Copyright (c) 2008-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public 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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 // Updated:
17
18 #include <Font_SystemFont.ixx>
19 #include <OSD_Path.hxx>
20 #include <TCollection_HAsciiString.hxx>
21
22
23 Font_SystemFont::Font_SystemFont():
24 MyFontName(),
25 MyFontAspect(Font_FA_Undefined),
26 MyFaceSize(-1),
27 MyVerification(Standard_False)
28 {
29 }
30
31 Font_SystemFont::Font_SystemFont( const Handle(TCollection_HAsciiString)& FontName,
32                                 const Font_FontAspect FontAspect,
33                                 const Handle(TCollection_HAsciiString)& FilePath ):
34 MyFontName(FontName),
35 MyFontAspect(FontAspect),
36 MyFaceSize(-1),
37 MyFilePath(FilePath),
38 MyVerification(Standard_True)
39 {
40
41 }
42
43 Font_SystemFont::Font_SystemFont (const Handle(TCollection_HAsciiString)& theXLFD,
44                                   const Handle(TCollection_HAsciiString)& theFilePath) :
45 MyFontAspect(Font_FA_Regular),
46 MyFaceSize(-1),
47 MyFilePath(theFilePath)
48 {
49   MyVerification = Standard_True;
50   if (theXLFD.IsNull())
51   {
52     MyVerification = Standard_False; // empty font description handler
53   }
54   if (theXLFD->IsEmpty())
55   {
56     MyVerification = Standard_False; // empty font description
57   }
58
59   if (MyVerification)
60   {
61     MyFontName = theXLFD->Token ("-", 2);
62     TCollection_AsciiString aXLFD (theXLFD->ToCString());
63
64     // Getting font size for fixed size fonts
65     if (aXLFD.Search ("-0-0-0-0-") >= 0)
66       MyFaceSize = -1; // Scalable font
67     else
68       //TODO catch exeption
69       MyFaceSize = aXLFD.Token ("-", 7).IntegerValue();
70
71     // Detect font aspect
72     if (aXLFD.Token ("-", 3).IsEqual ("bold") &&
73        (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o")))
74     {
75       MyFontAspect = Font_FA_BoldItalic;
76     }
77     else if (aXLFD.Token ("-", 3).IsEqual ("bold"))
78     {
79       MyFontAspect = Font_FA_Bold;
80     }
81     else if (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o"))
82     {
83       MyFontAspect = Font_FA_Italic;
84     }
85   }
86 }
87
88 Standard_Boolean Font_SystemFont::IsValid() const{
89   if ( !MyVerification)
90     return Standard_False;
91
92   if ( MyFontAspect == Font_FA_Undefined )
93     return Standard_False;
94
95   if ( MyFontName->IsEmpty() || !MyFontName->IsAscii() )
96     return Standard_False;
97
98   OSD_Path path;
99   return path.IsValid( MyFilePath->String() );
100 }
101
102 Handle(TCollection_HAsciiString) Font_SystemFont::FontPath() const{
103   return MyFilePath;
104 }
105
106 Handle(TCollection_HAsciiString) Font_SystemFont::FontName() const{
107   return MyFontName;
108 }
109
110 Font_FontAspect Font_SystemFont::FontAspect() const{
111   return MyFontAspect;
112 }
113
114 Standard_Integer Font_SystemFont::FontHeight() const {
115   return MyFaceSize;
116 }
117
118 Standard_Boolean Font_SystemFont::IsEqual(const Handle(Font_SystemFont)& theOtherFont) const
119 {
120   if (!MyFontName->IsSameString (theOtherFont->FontName(), Standard_False))
121   {
122     return Standard_False;
123   }
124
125   if (MyFontAspect != theOtherFont->FontAspect())
126   {
127     return Standard_False;
128   }
129
130   if (MyFaceSize != theOtherFont->FontHeight())
131   {
132     return Standard_False;
133   }
134
135   return Standard_True;
136 }