0023415: OSD_FontMgr can't idenify aspect for fonts with names dependant on system...
[occt.git] / src / Font / Font_SystemFont.cxx
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
20
21 // Updated:
22
23 #include <Font_SystemFont.ixx>
24 #include <OSD_Path.hxx>
25 #include <TCollection_HAsciiString.hxx>
26
27
28 Font_SystemFont::Font_SystemFont():
29 MyFontName(),
30 MyFontAspect(Font_FA_Undefined),
31 MyFaceSize(-1),
32 MyVerification(Standard_False)
33 {
34 }
35
36 Font_SystemFont::Font_SystemFont( const Handle(TCollection_HAsciiString)& FontName,
37                                 const Font_FontAspect FontAspect,
38                                 const Handle(TCollection_HAsciiString)& FilePath ):
39 MyFontName(FontName),
40 MyFontAspect(FontAspect),
41 MyFilePath(FilePath),
42 MyFaceSize(-1),
43 MyVerification(Standard_True)
44 {
45
46 }
47
48 Font_SystemFont::Font_SystemFont (const Handle(TCollection_HAsciiString)& theXLFD,
49                                   const Handle(TCollection_HAsciiString)& theFilePath) :
50 MyFilePath(theFilePath),
51 MyFontAspect(Font_FA_Regular)
52 {
53   MyVerification = Standard_True;
54   if (theXLFD.IsNull())
55   {
56     MyVerification = Standard_False; // empty font description handler
57   }
58   if (theXLFD->IsEmpty())
59   {
60     MyVerification = Standard_False; // empty font description
61   }
62
63   if (MyVerification)
64   {
65     MyFontName = theXLFD->Token ("-", 2);
66     TCollection_AsciiString aXLFD (theXLFD->ToCString());
67
68     // Getting font size for fixed size fonts
69     if (aXLFD.Search ("-0-0-0-0-") >= 0)
70       MyFaceSize = -1; // Scalable font
71     else
72       //TODO catch exeption
73       MyFaceSize = aXLFD.Token ("-", 7).IntegerValue();
74
75     // Detect font aspect
76     if (aXLFD.Token ("-", 3).IsEqual ("bold") && 
77        (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o")))
78     {
79       MyFontAspect = Font_FA_BoldItalic;
80     }
81     else if (aXLFD.Token ("-", 3).IsEqual ("bold"))
82     {
83       MyFontAspect = Font_FA_Bold;
84     }
85     else if (aXLFD.Token ("-", 4).IsEqual ("i") || aXLFD.Token ("-", 4).IsEqual ("o"))
86     {
87       MyFontAspect = Font_FA_Italic;
88     }
89   }
90 }
91
92 Standard_Boolean Font_SystemFont::IsValid() const{
93   if ( !MyVerification)
94     return Standard_False;
95
96   if ( MyFontAspect == Font_FA_Undefined )
97     return Standard_False;
98
99   if ( MyFontName->IsEmpty() || !MyFontName->IsAscii() )
100     return Standard_False;
101
102   OSD_Path path;  
103   return path.IsValid( MyFilePath->String() );
104 }
105
106 Handle(TCollection_HAsciiString) Font_SystemFont::FontPath() const{
107   return MyFilePath;
108 }
109
110 Handle(TCollection_HAsciiString) Font_SystemFont::FontName() const{
111   return MyFontName;
112 }
113
114 Font_FontAspect Font_SystemFont::FontAspect() const{
115   return MyFontAspect;
116 }
117
118 Standard_Integer Font_SystemFont::FontHeight() const {
119   return MyFaceSize;
120 }
121
122 Standard_Boolean Font_SystemFont::IsEqual(const Handle(Font_SystemFont)& theOtherFont) const
123 {
124   if (!MyFontName->IsSameString (theOtherFont->FontName(), Standard_False))
125   {
126     return Standard_False;
127   }
128
129   if (MyFontAspect != theOtherFont->FontAspect())
130   {
131     return Standard_False;
132   }
133
134   if (MyFaceSize != theOtherFont->FontHeight())
135   {
136     return Standard_False;
137   }
138
139   return Standard_True;
140 }